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>
24 #include <isl_space_private.h>
27 #include <isl_constraint_private.h>
28 #include <isl/polynomial.h>
29 #include <isl/union_set.h>
30 #include <isl/union_map.h>
31 #include <isl_factorization.h>
32 #include <isl/schedule.h>
33 #include <isl/schedule_node.h>
34 #include <isl_options_private.h>
35 #include <isl_vertices_private.h>
36 #include <isl/ast_build.h>
39 #include <isl_ast_build_expr.h>
40 #include <isl/options.h>
42 #include "isl_srcdir.c"
44 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
46 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
49 char *pattern
= "%s/test_inputs/%s.%s";
51 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
53 filename
= isl_alloc_array(ctx
, char, length
);
58 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
63 void test_parse_map(isl_ctx
*ctx
, const char *str
)
67 map
= isl_map_read_from_str(ctx
, str
);
72 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
77 map
= isl_map_read_from_str(ctx
, str
);
78 map2
= isl_map_read_from_str(ctx
, str2
);
79 equal
= isl_map_is_equal(map
, map2
);
86 isl_die(ctx
, isl_error_unknown
, "maps not equal",
92 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
94 isl_pw_qpolynomial
*pwqp
;
96 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
98 isl_pw_qpolynomial_free(pwqp
);
101 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
105 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
107 isl_pw_aff_free(pwaff
);
110 /* Check that we can read an isl_multi_val from "str" without errors.
112 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
116 mv
= isl_multi_val_read_from_str(ctx
, str
);
117 isl_multi_val_free(mv
);
122 /* Check that printing "mpa" and parsing the output results
123 * in the same expression.
125 static isl_stat
check_reparse_mpa(isl_ctx
*ctx
,
126 __isl_take isl_multi_pw_aff
*mpa
)
130 isl_multi_pw_aff
*mpa2
;
132 str
= isl_multi_pw_aff_to_str(mpa
);
133 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
135 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
136 isl_multi_pw_aff_free(mpa
);
137 isl_multi_pw_aff_free(mpa2
);
139 return isl_stat_error
;
141 isl_die(ctx
, isl_error_unknown
,
142 "parsed function not equal to original",
143 return isl_stat_error
);
148 /* String descriptions of multi piecewise affine expressions
149 * that are used for testing printing and parsing.
151 const char *parse_multi_mpa_tests
[] = {
152 "{ A[x, y] -> [] : x + y >= 0 }",
153 "{ A[x, y] -> B[] : x + y >= 0 }",
154 "{ A[x, y] -> [x] : x + y >= 0 }",
155 "[N] -> { A[x, y] -> [x] : x + y <= N }",
156 "{ A[x, y] -> [x, y] : x + y >= 0 }",
157 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
158 "[N] -> { [] : N >= 0 }",
159 "[N] -> { [] : N >= 0 }",
160 "[N] -> { [N] : N >= 0 }",
161 "[N] -> { [N, N + 1] : N >= 0 }",
162 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
165 /* Test parsing of multi piecewise affine expressions by printing
166 * the expressions and checking that parsing the output results
167 * in the same expression.
168 * Do this for a couple of manually constructed expressions and
169 * a set of expressions parsed from strings.
171 static int test_parse_mpa(isl_ctx
*ctx
)
176 isl_multi_pw_aff
*mpa
;
179 space
= isl_space_set_alloc(ctx
, 0, 0);
180 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
181 mpa
= isl_multi_pw_aff_zero(space
);
182 r
= check_reparse_mpa(ctx
, mpa
);
186 space
= isl_space_set_alloc(ctx
, 1, 0);
187 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
188 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
189 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
190 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
191 mpa
= isl_multi_pw_aff_zero(space
);
192 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
193 r
= check_reparse_mpa(ctx
, mpa
);
197 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mpa_tests
); ++i
) {
200 str
= parse_multi_mpa_tests
[i
];
201 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
202 r
= check_reparse_mpa(ctx
, mpa
);
210 /* Check that printing "mupa" and parsing the output results
211 * in the same expression.
213 static isl_stat
check_reparse_mupa(isl_ctx
*ctx
,
214 __isl_take isl_multi_union_pw_aff
*mupa
)
218 isl_multi_union_pw_aff
*mupa2
;
220 str
= isl_multi_union_pw_aff_to_str(mupa
);
221 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
223 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
224 isl_multi_union_pw_aff_free(mupa
);
225 isl_multi_union_pw_aff_free(mupa2
);
227 return isl_stat_error
;
229 isl_die(ctx
, isl_error_unknown
,
230 "parsed function not equal to original",
231 return isl_stat_error
);
236 /* String descriptions of multi union piecewise affine expressions
237 * that are used for testing printing and parsing.
239 const char *parse_multi_mupa_tests
[] = {
243 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
245 "[N] -> (A[] : { })",
246 "[N] -> (A[] : { : N >= 0 })",
247 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
248 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
249 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
250 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
251 "{ S[x] : x > 0; T[y] : y >= 0 })",
254 /* Test parsing of multi union piecewise affine expressions by printing
255 * the expressions and checking that parsing the output results
256 * in the same expression.
257 * Do this for a couple of manually constructed expressions and
258 * a set of expressions parsed from strings.
260 static int test_parse_mupa(isl_ctx
*ctx
)
264 isl_multi_union_pw_aff
*mupa
;
269 space
= isl_space_set_alloc(ctx
, 0, 0);
270 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
271 mupa
= isl_multi_union_pw_aff_zero(space
);
272 r
= check_reparse_mupa(ctx
, mupa
);
276 space
= isl_space_set_alloc(ctx
, 1, 0);
277 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
278 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
279 dom
= isl_set_universe(space
);
280 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
281 uset
= isl_union_set_from_set(dom
);
282 space
= isl_space_set_alloc(ctx
, 1, 0);
283 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
284 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
285 mupa
= isl_multi_union_pw_aff_zero(space
);
286 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
287 r
= check_reparse_mupa(ctx
, mupa
);
291 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mupa_tests
); ++i
) {
294 str
= parse_multi_mupa_tests
[i
];
295 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
296 r
= check_reparse_mupa(ctx
, mupa
);
304 /* Test parsing of multi expressions.
306 static int test_parse_multi(isl_ctx
*ctx
)
308 if (test_parse_mpa(ctx
) < 0)
310 if (test_parse_mupa(ctx
) < 0)
316 /* Pairs of binary relation representations that should represent
317 * the same binary relations.
322 } parse_map_equal_tests
[] = {
323 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
324 "{ [x, y] : 2y >= 6 - x }" },
325 { "{ [x,y] : x <= min(y, 2*y+3) }",
326 "{ [x,y] : x <= y, 2*y + 3 }" },
327 { "{ [x,y] : x >= min(y, 2*y+3) }",
328 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
329 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
330 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
331 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
332 "{ [i,j] -> [min(i,j)] }" },
333 { "{ [i,j] : i != j }",
334 "{ [i,j] : i < j or i > j }" },
335 { "{ [i,j] : (i+1)*2 >= j }",
336 "{ [i, j] : j <= 2 + 2i }" },
337 { "{ [i] -> [i > 0 ? 4 : 5] }",
338 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
339 { "[N=2,M] -> { [i=[(M+N)/4]] }",
340 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
341 { "{ [x] : x >= 0 }",
342 "{ [x] : x-0 >= 0 }" },
343 { "{ [i] : ((i > 10)) }",
344 "{ [i] : i >= 11 }" },
346 "{ [i] -> [0 * i] }" },
347 { "{ [a] -> [b] : (not false) }",
348 "{ [a] -> [b] : true }" },
349 { "{ [i] : i/2 <= 5 }",
350 "{ [i] : i <= 10 }" },
351 { "{Sym=[n] [i] : i <= n }",
352 "[n] -> { [i] : i <= n }" },
355 { "{ [i] : 2*floor(i/2) = i }",
356 "{ [i] : exists a : i = 2 a }" },
357 { "{ [a] -> [b] : a = 5 implies b = 5 }",
358 "{ [a] -> [b] : a != 5 or b = 5 }" },
359 { "{ [a] -> [a - 1 : a > 0] }",
360 "{ [a] -> [a - 1] : a > 0 }" },
361 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
362 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
363 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
364 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
365 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
366 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
367 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
368 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
369 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
370 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
371 { "{ [a,b] -> [i,j] : a,b << i,j }",
372 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
373 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
374 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
375 { "{ [a,b] -> [i,j] : a,b >> i,j }",
376 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
377 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
378 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
379 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
380 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
381 "8c < n - 32a and i < n and c >= 0 and "
382 "c <= 3 and c >= -4a) }",
383 "{ [n] -> [i] : 0 <= i < n }" },
384 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
385 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
386 "{ [x] -> [] : 0 <= x <= 15 }" },
387 { "{ [x] -> [x] : }",
391 int test_parse(struct isl_ctx
*ctx
)
395 const char *str
, *str2
;
397 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
399 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
401 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
403 if (test_parse_multi(ctx
) < 0)
406 str
= "{ [i] -> [-i] }";
407 map
= isl_map_read_from_str(ctx
, str
);
411 str
= "{ A[i] -> L[([i/3])] }";
412 map
= isl_map_read_from_str(ctx
, str
);
416 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
417 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
418 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
420 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
421 str
= parse_map_equal_tests
[i
].map1
;
422 str2
= parse_map_equal_tests
[i
].map2
;
423 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
427 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
428 map
= isl_map_read_from_str(ctx
, str
);
429 str
= "{ [new, old] -> [o0, o1] : "
430 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
431 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
432 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
433 map2
= isl_map_read_from_str(ctx
, str
);
434 assert(isl_map_is_equal(map
, map2
));
438 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
439 map
= isl_map_read_from_str(ctx
, str
);
440 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
441 map2
= isl_map_read_from_str(ctx
, str
);
442 assert(isl_map_is_equal(map
, map2
));
446 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
447 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
448 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
449 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
450 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
455 static int test_read(isl_ctx
*ctx
)
459 isl_basic_set
*bset1
, *bset2
;
460 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
463 filename
= get_filename(ctx
, "set", "omega");
465 input
= fopen(filename
, "r");
468 bset1
= isl_basic_set_read_from_file(ctx
, input
);
469 bset2
= isl_basic_set_read_from_str(ctx
, str
);
471 equal
= isl_basic_set_is_equal(bset1
, bset2
);
473 isl_basic_set_free(bset1
);
474 isl_basic_set_free(bset2
);
482 isl_die(ctx
, isl_error_unknown
,
483 "read sets not equal", return -1);
488 static int test_bounded(isl_ctx
*ctx
)
493 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
494 bounded
= isl_set_is_bounded(set
);
500 isl_die(ctx
, isl_error_unknown
,
501 "set not considered bounded", return -1);
503 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
504 bounded
= isl_set_is_bounded(set
);
511 isl_die(ctx
, isl_error_unknown
,
512 "set considered bounded", return -1);
514 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
515 bounded
= isl_set_is_bounded(set
);
521 isl_die(ctx
, isl_error_unknown
,
522 "set considered bounded", return -1);
527 /* Construct the basic set { [i] : 5 <= i <= N } */
528 static int test_construction_1(isl_ctx
*ctx
)
535 dim
= isl_space_set_alloc(ctx
, 1, 1);
536 bset
= isl_basic_set_universe(isl_space_copy(dim
));
537 ls
= isl_local_space_from_space(dim
);
539 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
540 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
541 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
542 bset
= isl_basic_set_add_constraint(bset
, c
);
544 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
545 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
546 c
= isl_constraint_set_constant_si(c
, -5);
547 bset
= isl_basic_set_add_constraint(bset
, c
);
549 isl_local_space_free(ls
);
550 isl_basic_set_free(bset
);
555 /* Construct the basic set { [x] : -100 <= x <= 100 }
556 * using isl_basic_set_{lower,upper}_bound_val and
557 * check that it is equal the same basic set parsed from a string.
559 static int test_construction_2(isl_ctx
*ctx
)
564 isl_basic_set
*bset1
, *bset2
;
566 v
= isl_val_int_from_si(ctx
, 100);
567 space
= isl_space_set_alloc(ctx
, 0, 1);
568 bset1
= isl_basic_set_universe(space
);
569 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
571 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
573 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
574 equal
= isl_basic_set_is_equal(bset1
, bset2
);
575 isl_basic_set_free(bset1
);
576 isl_basic_set_free(bset2
);
581 isl_die(ctx
, isl_error_unknown
,
582 "failed construction", return -1);
587 /* Basic tests for constructing basic sets.
589 static int test_construction(isl_ctx
*ctx
)
591 if (test_construction_1(ctx
) < 0)
593 if (test_construction_2(ctx
) < 0)
598 static int test_dim(isl_ctx
*ctx
)
601 isl_map
*map1
, *map2
;
604 map1
= isl_map_read_from_str(ctx
,
605 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
606 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
607 map2
= isl_map_read_from_str(ctx
,
608 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
609 equal
= isl_map_is_equal(map1
, map2
);
612 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
613 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
614 if (equal
>= 0 && equal
)
615 equal
= isl_map_is_equal(map1
, map2
);
623 isl_die(ctx
, isl_error_unknown
,
624 "unexpected result", return -1);
626 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
627 map1
= isl_map_read_from_str(ctx
, str
);
628 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
629 map2
= isl_map_read_from_str(ctx
, str
);
630 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
631 equal
= isl_map_is_equal(map1
, map2
);
638 isl_die(ctx
, isl_error_unknown
,
639 "unexpected result", return -1);
645 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
649 { &isl_val_neg
, "0", "0" },
650 { &isl_val_abs
, "0", "0" },
651 { &isl_val_2exp
, "0", "1" },
652 { &isl_val_floor
, "0", "0" },
653 { &isl_val_ceil
, "0", "0" },
654 { &isl_val_neg
, "1", "-1" },
655 { &isl_val_neg
, "-1", "1" },
656 { &isl_val_neg
, "1/2", "-1/2" },
657 { &isl_val_neg
, "-1/2", "1/2" },
658 { &isl_val_neg
, "infty", "-infty" },
659 { &isl_val_neg
, "-infty", "infty" },
660 { &isl_val_neg
, "NaN", "NaN" },
661 { &isl_val_abs
, "1", "1" },
662 { &isl_val_abs
, "-1", "1" },
663 { &isl_val_abs
, "1/2", "1/2" },
664 { &isl_val_abs
, "-1/2", "1/2" },
665 { &isl_val_abs
, "infty", "infty" },
666 { &isl_val_abs
, "-infty", "infty" },
667 { &isl_val_abs
, "NaN", "NaN" },
668 { &isl_val_floor
, "1", "1" },
669 { &isl_val_floor
, "-1", "-1" },
670 { &isl_val_floor
, "1/2", "0" },
671 { &isl_val_floor
, "-1/2", "-1" },
672 { &isl_val_floor
, "infty", "infty" },
673 { &isl_val_floor
, "-infty", "-infty" },
674 { &isl_val_floor
, "NaN", "NaN" },
675 { &isl_val_ceil
, "1", "1" },
676 { &isl_val_ceil
, "-1", "-1" },
677 { &isl_val_ceil
, "1/2", "1" },
678 { &isl_val_ceil
, "-1/2", "0" },
679 { &isl_val_ceil
, "infty", "infty" },
680 { &isl_val_ceil
, "-infty", "-infty" },
681 { &isl_val_ceil
, "NaN", "NaN" },
682 { &isl_val_2exp
, "-3", "1/8" },
683 { &isl_val_2exp
, "-1", "1/2" },
684 { &isl_val_2exp
, "1", "2" },
685 { &isl_val_2exp
, "2", "4" },
686 { &isl_val_2exp
, "3", "8" },
687 { &isl_val_inv
, "1", "1" },
688 { &isl_val_inv
, "2", "1/2" },
689 { &isl_val_inv
, "1/2", "2" },
690 { &isl_val_inv
, "-2", "-1/2" },
691 { &isl_val_inv
, "-1/2", "-2" },
692 { &isl_val_inv
, "0", "NaN" },
693 { &isl_val_inv
, "NaN", "NaN" },
694 { &isl_val_inv
, "infty", "0" },
695 { &isl_val_inv
, "-infty", "0" },
698 /* Perform some basic tests of unary operations on isl_val objects.
700 static int test_un_val(isl_ctx
*ctx
)
704 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
707 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
708 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
709 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
710 fn
= val_un_tests
[i
].op
;
712 is_nan
= isl_val_is_nan(res
);
716 ok
= isl_val_is_nan(v
);
718 ok
= isl_val_eq(v
, res
);
724 isl_die(ctx
, isl_error_unknown
,
725 "unexpected result", return -1);
732 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
733 __isl_take isl_val
*v2
);
735 ['+'] = { &isl_val_add
},
736 ['-'] = { &isl_val_sub
},
737 ['*'] = { &isl_val_mul
},
738 ['/'] = { &isl_val_div
},
739 ['g'] = { &isl_val_gcd
},
740 ['m'] = { &isl_val_min
},
741 ['M'] = { &isl_val_max
},
749 } val_bin_tests
[] = {
750 { "0", '+', "0", "0" },
751 { "1", '+', "0", "1" },
752 { "1", '+', "1", "2" },
753 { "1", '-', "1", "0" },
754 { "1", '*', "1", "1" },
755 { "1", '/', "1", "1" },
756 { "2", '*', "3", "6" },
757 { "2", '*', "1/2", "1" },
758 { "2", '*', "1/3", "2/3" },
759 { "2/3", '*', "3/5", "2/5" },
760 { "2/3", '*', "7/5", "14/15" },
761 { "2", '/', "1/2", "4" },
762 { "-2", '/', "-1/2", "4" },
763 { "-2", '/', "1/2", "-4" },
764 { "2", '/', "-1/2", "-4" },
765 { "2", '/', "2", "1" },
766 { "2", '/', "3", "2/3" },
767 { "2/3", '/', "5/3", "2/5" },
768 { "2/3", '/', "5/7", "14/15" },
769 { "0", '/', "0", "NaN" },
770 { "42", '/', "0", "NaN" },
771 { "-42", '/', "0", "NaN" },
772 { "infty", '/', "0", "NaN" },
773 { "-infty", '/', "0", "NaN" },
774 { "NaN", '/', "0", "NaN" },
775 { "0", '/', "NaN", "NaN" },
776 { "42", '/', "NaN", "NaN" },
777 { "-42", '/', "NaN", "NaN" },
778 { "infty", '/', "NaN", "NaN" },
779 { "-infty", '/', "NaN", "NaN" },
780 { "NaN", '/', "NaN", "NaN" },
781 { "0", '/', "infty", "0" },
782 { "42", '/', "infty", "0" },
783 { "-42", '/', "infty", "0" },
784 { "infty", '/', "infty", "NaN" },
785 { "-infty", '/', "infty", "NaN" },
786 { "NaN", '/', "infty", "NaN" },
787 { "0", '/', "-infty", "0" },
788 { "42", '/', "-infty", "0" },
789 { "-42", '/', "-infty", "0" },
790 { "infty", '/', "-infty", "NaN" },
791 { "-infty", '/', "-infty", "NaN" },
792 { "NaN", '/', "-infty", "NaN" },
793 { "1", '-', "1/3", "2/3" },
794 { "1/3", '+', "1/2", "5/6" },
795 { "1/2", '+', "1/2", "1" },
796 { "3/4", '-', "1/4", "1/2" },
797 { "1/2", '-', "1/3", "1/6" },
798 { "infty", '+', "42", "infty" },
799 { "infty", '+', "infty", "infty" },
800 { "42", '+', "infty", "infty" },
801 { "infty", '-', "infty", "NaN" },
802 { "infty", '*', "infty", "infty" },
803 { "infty", '*', "-infty", "-infty" },
804 { "-infty", '*', "infty", "-infty" },
805 { "-infty", '*', "-infty", "infty" },
806 { "0", '*', "infty", "NaN" },
807 { "1", '*', "infty", "infty" },
808 { "infty", '*', "0", "NaN" },
809 { "infty", '*', "42", "infty" },
810 { "42", '-', "infty", "-infty" },
811 { "infty", '+', "-infty", "NaN" },
812 { "4", 'g', "6", "2" },
813 { "5", 'g', "6", "1" },
814 { "42", 'm', "3", "3" },
815 { "42", 'M', "3", "42" },
816 { "3", 'm', "42", "3" },
817 { "3", 'M', "42", "42" },
818 { "42", 'm', "infty", "42" },
819 { "42", 'M', "infty", "infty" },
820 { "42", 'm', "-infty", "-infty" },
821 { "42", 'M', "-infty", "42" },
822 { "42", 'm', "NaN", "NaN" },
823 { "42", 'M', "NaN", "NaN" },
824 { "infty", 'm', "-infty", "-infty" },
825 { "infty", 'M', "-infty", "infty" },
828 /* Perform some basic tests of binary operations on isl_val objects.
830 static int test_bin_val(isl_ctx
*ctx
)
833 isl_val
*v1
, *v2
, *res
;
834 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
835 __isl_take isl_val
*v2
);
838 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
839 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
840 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
841 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
842 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
844 if (isl_val_is_nan(res
))
845 ok
= isl_val_is_nan(v1
);
847 ok
= isl_val_eq(v1
, res
);
853 isl_die(ctx
, isl_error_unknown
,
854 "unexpected result", return -1);
860 /* Perform some basic tests on isl_val objects.
862 static int test_val(isl_ctx
*ctx
)
864 if (test_un_val(ctx
) < 0)
866 if (test_bin_val(ctx
) < 0)
871 /* Sets described using existentially quantified variables that
872 * can also be described without.
874 static const char *elimination_tests
[] = {
875 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
876 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
877 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
880 /* Check that redundant existentially quantified variables are
883 static int test_elimination(isl_ctx
*ctx
)
889 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
890 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
891 n
= isl_basic_set_dim(bset
, isl_dim_div
);
892 isl_basic_set_free(bset
);
896 isl_die(ctx
, isl_error_unknown
,
897 "expecting no existentials", return -1);
903 static int test_div(isl_ctx
*ctx
)
910 struct isl_basic_set
*bset
;
911 struct isl_constraint
*c
;
914 dim
= isl_space_set_alloc(ctx
, 0, 3);
915 bset
= isl_basic_set_universe(isl_space_copy(dim
));
916 ls
= isl_local_space_from_space(dim
);
918 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
919 c
= isl_constraint_set_constant_si(c
, -1);
920 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
921 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
922 bset
= isl_basic_set_add_constraint(bset
, c
);
924 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
925 c
= isl_constraint_set_constant_si(c
, 1);
926 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
927 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
928 bset
= isl_basic_set_add_constraint(bset
, c
);
930 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
932 assert(bset
&& bset
->n_div
== 1);
933 isl_local_space_free(ls
);
934 isl_basic_set_free(bset
);
937 dim
= isl_space_set_alloc(ctx
, 0, 3);
938 bset
= isl_basic_set_universe(isl_space_copy(dim
));
939 ls
= isl_local_space_from_space(dim
);
941 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
942 c
= isl_constraint_set_constant_si(c
, 1);
943 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
944 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
945 bset
= isl_basic_set_add_constraint(bset
, c
);
947 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
948 c
= isl_constraint_set_constant_si(c
, -1);
949 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
950 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
951 bset
= isl_basic_set_add_constraint(bset
, c
);
953 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
955 assert(bset
&& bset
->n_div
== 1);
956 isl_local_space_free(ls
);
957 isl_basic_set_free(bset
);
960 dim
= isl_space_set_alloc(ctx
, 0, 3);
961 bset
= isl_basic_set_universe(isl_space_copy(dim
));
962 ls
= isl_local_space_from_space(dim
);
964 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
965 c
= isl_constraint_set_constant_si(c
, 1);
966 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
967 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
968 bset
= isl_basic_set_add_constraint(bset
, c
);
970 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
971 c
= isl_constraint_set_constant_si(c
, -3);
972 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
973 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
974 bset
= isl_basic_set_add_constraint(bset
, c
);
976 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
978 assert(bset
&& bset
->n_div
== 1);
979 isl_local_space_free(ls
);
980 isl_basic_set_free(bset
);
983 dim
= isl_space_set_alloc(ctx
, 0, 3);
984 bset
= isl_basic_set_universe(isl_space_copy(dim
));
985 ls
= isl_local_space_from_space(dim
);
987 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
988 c
= isl_constraint_set_constant_si(c
, 2);
989 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
990 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
991 bset
= isl_basic_set_add_constraint(bset
, c
);
993 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
994 c
= isl_constraint_set_constant_si(c
, -1);
995 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
996 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
997 bset
= isl_basic_set_add_constraint(bset
, c
);
999 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1001 assert(isl_basic_set_is_empty(bset
));
1002 isl_local_space_free(ls
);
1003 isl_basic_set_free(bset
);
1006 dim
= isl_space_set_alloc(ctx
, 0, 3);
1007 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1008 ls
= isl_local_space_from_space(dim
);
1010 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1011 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1012 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1013 bset
= isl_basic_set_add_constraint(bset
, c
);
1015 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1016 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1017 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1018 bset
= isl_basic_set_add_constraint(bset
, c
);
1020 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1022 assert(bset
&& bset
->n_div
== 0);
1023 isl_basic_set_free(bset
);
1024 isl_local_space_free(ls
);
1027 dim
= isl_space_set_alloc(ctx
, 0, 3);
1028 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1029 ls
= isl_local_space_from_space(dim
);
1031 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1032 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1033 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1034 bset
= isl_basic_set_add_constraint(bset
, c
);
1036 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1037 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1038 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1039 bset
= isl_basic_set_add_constraint(bset
, c
);
1041 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1043 assert(bset
&& bset
->n_div
== 1);
1044 isl_basic_set_free(bset
);
1045 isl_local_space_free(ls
);
1048 /* This test is a bit tricky. We set up an equality
1049 * a + 3b + 3c = 6 e0
1050 * Normalization of divs creates _two_ divs
1053 * Afterwards e0 is removed again because it has coefficient -1
1054 * and we end up with the original equality and div again.
1055 * Perhaps we can avoid the introduction of this temporary div.
1057 dim
= isl_space_set_alloc(ctx
, 0, 4);
1058 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1059 ls
= isl_local_space_from_space(dim
);
1061 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1062 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1063 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1064 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1065 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1066 bset
= isl_basic_set_add_constraint(bset
, c
);
1068 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1070 /* Test disabled for now */
1072 assert(bset && bset->n_div == 1);
1074 isl_local_space_free(ls
);
1075 isl_basic_set_free(bset
);
1078 dim
= isl_space_set_alloc(ctx
, 0, 5);
1079 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1080 ls
= isl_local_space_from_space(dim
);
1082 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1083 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1084 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1085 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1086 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1087 bset
= isl_basic_set_add_constraint(bset
, c
);
1089 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1090 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1091 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1092 c
= isl_constraint_set_constant_si(c
, 1);
1093 bset
= isl_basic_set_add_constraint(bset
, c
);
1095 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1097 /* Test disabled for now */
1099 assert(bset && bset->n_div == 1);
1101 isl_local_space_free(ls
);
1102 isl_basic_set_free(bset
);
1105 dim
= isl_space_set_alloc(ctx
, 0, 4);
1106 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1107 ls
= isl_local_space_from_space(dim
);
1109 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1110 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1111 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1112 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1113 bset
= isl_basic_set_add_constraint(bset
, c
);
1115 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1116 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1117 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1118 c
= isl_constraint_set_constant_si(c
, 2);
1119 bset
= isl_basic_set_add_constraint(bset
, c
);
1121 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1123 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1125 assert(!isl_basic_set_is_empty(bset
));
1127 isl_local_space_free(ls
);
1128 isl_basic_set_free(bset
);
1131 dim
= isl_space_set_alloc(ctx
, 0, 3);
1132 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1133 ls
= isl_local_space_from_space(dim
);
1135 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1136 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1137 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1138 bset
= isl_basic_set_add_constraint(bset
, c
);
1140 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1142 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1144 isl_local_space_free(ls
);
1145 isl_basic_set_free(bset
);
1147 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1148 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1149 set
= isl_set_read_from_str(ctx
, str
);
1150 set
= isl_set_compute_divs(set
);
1155 if (test_elimination(ctx
) < 0)
1158 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1159 set
= isl_set_read_from_str(ctx
, str
);
1160 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1161 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1162 empty
= isl_set_is_empty(set
);
1167 isl_die(ctx
, isl_error_unknown
,
1168 "result not as accurate as expected", return -1);
1173 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1177 struct isl_basic_set
*bset1
, *bset2
;
1178 struct isl_basic_map
*bmap
;
1180 filename
= get_filename(ctx
, name
, "omega");
1182 input
= fopen(filename
, "r");
1185 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1186 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1188 bset1
= isl_basic_set_apply(bset1
, bmap
);
1190 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1192 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1194 isl_basic_set_free(bset1
);
1195 isl_basic_set_free(bset2
);
1201 static int test_application(isl_ctx
*ctx
)
1203 test_application_case(ctx
, "application");
1204 test_application_case(ctx
, "application2");
1209 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1213 struct isl_basic_set
*bset1
, *bset2
;
1215 filename
= get_filename(ctx
, name
, "polylib");
1217 input
= fopen(filename
, "r");
1220 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1221 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1223 bset1
= isl_basic_set_affine_hull(bset1
);
1225 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1227 isl_basic_set_free(bset1
);
1228 isl_basic_set_free(bset2
);
1234 int test_affine_hull(struct isl_ctx
*ctx
)
1238 isl_basic_set
*bset
, *bset2
;
1242 test_affine_hull_case(ctx
, "affine2");
1243 test_affine_hull_case(ctx
, "affine");
1244 test_affine_hull_case(ctx
, "affine3");
1246 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1247 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1248 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1249 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1250 set
= isl_set_read_from_str(ctx
, str
);
1251 bset
= isl_set_affine_hull(set
);
1252 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1253 isl_basic_set_free(bset
);
1255 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1258 /* Check that isl_map_affine_hull is not confused by
1259 * the reordering of divs in isl_map_align_divs.
1261 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1262 "32e0 = b and 32e1 = c); "
1263 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1264 set
= isl_set_read_from_str(ctx
, str
);
1265 bset
= isl_set_affine_hull(set
);
1266 isl_basic_set_free(bset
);
1270 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1271 "32e2 = 31 + 31e0 }";
1272 set
= isl_set_read_from_str(ctx
, str
);
1273 bset
= isl_set_affine_hull(set
);
1274 str
= "{ [a] : exists e : a = 32 e }";
1275 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1276 subset
= isl_basic_set_is_subset(bset
, bset2
);
1277 isl_basic_set_free(bset
);
1278 isl_basic_set_free(bset2
);
1282 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1288 /* Pairs of maps and the corresponding expected results of
1289 * isl_map_plain_unshifted_simple_hull.
1294 } plain_unshifted_simple_hull_tests
[] = {
1295 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1296 "{ [i] -> [j] : i >= 1 }" },
1297 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1298 "(j mod 4 = 2 and k mod 6 = n) }",
1299 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1302 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1304 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1308 isl_basic_map
*hull
, *expected
;
1311 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1313 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1314 map
= isl_map_read_from_str(ctx
, str
);
1315 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1316 expected
= isl_basic_map_read_from_str(ctx
, str
);
1317 hull
= isl_map_plain_unshifted_simple_hull(map
);
1318 equal
= isl_basic_map_is_equal(hull
, expected
);
1319 isl_basic_map_free(hull
);
1320 isl_basic_map_free(expected
);
1324 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1331 /* Pairs of sets and the corresponding expected results of
1332 * isl_set_unshifted_simple_hull.
1337 } unshifted_simple_hull_tests
[] = {
1338 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1339 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1342 /* Basic tests for isl_set_unshifted_simple_hull.
1344 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1348 isl_basic_set
*hull
, *expected
;
1351 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1353 str
= unshifted_simple_hull_tests
[i
].set
;
1354 set
= isl_set_read_from_str(ctx
, str
);
1355 str
= unshifted_simple_hull_tests
[i
].hull
;
1356 expected
= isl_basic_set_read_from_str(ctx
, str
);
1357 hull
= isl_set_unshifted_simple_hull(set
);
1358 equal
= isl_basic_set_is_equal(hull
, expected
);
1359 isl_basic_set_free(hull
);
1360 isl_basic_set_free(expected
);
1364 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1371 static int test_simple_hull(struct isl_ctx
*ctx
)
1375 isl_basic_set
*bset
;
1378 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1379 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1380 set
= isl_set_read_from_str(ctx
, str
);
1381 bset
= isl_set_simple_hull(set
);
1382 is_empty
= isl_basic_set_is_empty(bset
);
1383 isl_basic_set_free(bset
);
1385 if (is_empty
== isl_bool_error
)
1388 if (is_empty
== isl_bool_false
)
1389 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1392 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1394 if (test_unshifted_simple_hull(ctx
) < 0)
1400 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1404 struct isl_basic_set
*bset1
, *bset2
;
1405 struct isl_set
*set
;
1407 filename
= get_filename(ctx
, name
, "polylib");
1409 input
= fopen(filename
, "r");
1412 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1413 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1415 set
= isl_basic_set_union(bset1
, bset2
);
1416 bset1
= isl_set_convex_hull(set
);
1418 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1420 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1422 isl_basic_set_free(bset1
);
1423 isl_basic_set_free(bset2
);
1432 } convex_hull_tests
[] = {
1433 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1434 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1435 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1436 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1437 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1438 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1439 "i2 <= 5 and i2 >= 4; "
1440 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1441 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1442 "i2 <= 5 + i0 and i2 >= i0 }" },
1443 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1444 "{ [x, y] : 1 = 0 }" },
1445 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1446 "[x, y, 0] : x >= 0 and y < 0 }",
1447 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1450 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1453 int orig_convex
= ctx
->opt
->convex
;
1454 ctx
->opt
->convex
= convex
;
1456 test_convex_hull_case(ctx
, "convex0");
1457 test_convex_hull_case(ctx
, "convex1");
1458 test_convex_hull_case(ctx
, "convex2");
1459 test_convex_hull_case(ctx
, "convex3");
1460 test_convex_hull_case(ctx
, "convex4");
1461 test_convex_hull_case(ctx
, "convex5");
1462 test_convex_hull_case(ctx
, "convex6");
1463 test_convex_hull_case(ctx
, "convex7");
1464 test_convex_hull_case(ctx
, "convex8");
1465 test_convex_hull_case(ctx
, "convex9");
1466 test_convex_hull_case(ctx
, "convex10");
1467 test_convex_hull_case(ctx
, "convex11");
1468 test_convex_hull_case(ctx
, "convex12");
1469 test_convex_hull_case(ctx
, "convex13");
1470 test_convex_hull_case(ctx
, "convex14");
1471 test_convex_hull_case(ctx
, "convex15");
1473 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1474 isl_set
*set1
, *set2
;
1477 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1478 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1479 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1480 equal
= isl_set_is_equal(set1
, set2
);
1487 isl_die(ctx
, isl_error_unknown
,
1488 "unexpected convex hull", return -1);
1491 ctx
->opt
->convex
= orig_convex
;
1496 static int test_convex_hull(isl_ctx
*ctx
)
1498 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1500 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1505 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1509 struct isl_basic_set
*bset1
, *bset2
;
1511 filename
= get_filename(ctx
, name
, "polylib");
1513 input
= fopen(filename
, "r");
1516 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1517 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1519 bset1
= isl_basic_set_gist(bset1
, bset2
);
1521 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1523 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1525 isl_basic_set_free(bset1
);
1526 isl_basic_set_free(bset2
);
1532 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1536 const char *context
;
1538 } plain_gist_tests
[] = {
1539 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1540 "{ [i] -> [j] : i >= 1 }",
1541 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1542 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1543 "(j mod 4 = 2 and k mod 6 = n) }",
1544 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1545 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1546 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1547 "{ [i] -> [j] : i > j }",
1548 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1551 /* Basic tests for isl_map_plain_gist_basic_map.
1553 static int test_plain_gist(isl_ctx
*ctx
)
1557 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1560 isl_map
*map
, *gist
;
1561 isl_basic_map
*context
;
1563 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1564 str
= plain_gist_tests
[i
].context
;
1565 context
= isl_basic_map_read_from_str(ctx
, str
);
1566 map
= isl_map_plain_gist_basic_map(map
, context
);
1567 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1568 equal
= isl_map_is_equal(map
, gist
);
1574 isl_die(ctx
, isl_error_unknown
,
1575 "incorrect gist result", return -1);
1583 const char *context
;
1586 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1587 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1588 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1589 "{ [a, b, c] : a <= 15 }" },
1590 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1591 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1592 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1593 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1594 { "{ [m, n, a, b] : a <= 2147 + n }",
1595 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1596 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1597 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1599 "{ [m, n, ku, kl] }" },
1600 { "{ [a, a, b] : a >= 10 }",
1601 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1602 "{ [a, a, b] : a >= 10 }" },
1603 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1604 "{ [0, j] : j >= 0 }" },
1605 /* Check that no constraints on i6 are introduced in the gist */
1606 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1607 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1608 "5e0 <= 381 - t1 and i4 <= 1) }",
1609 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1610 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1611 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1612 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1613 "20e0 >= 1511 - 4t1 - 5i4) }" },
1614 /* Check that no constraints on i6 are introduced in the gist */
1615 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1616 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1617 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1618 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1619 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1620 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1621 "20e1 <= 1530 - 4t1 - 5i4 and "
1622 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1623 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1624 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1625 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1626 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1627 "10e0 <= -91 + 5i4 + 4i6 and "
1628 "10e0 >= -105 + 5i4 + 4i6) }",
1629 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1630 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1631 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1632 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1633 "{ [a, b, q, p] : b >= 1 + a }",
1634 "{ [a, b, q, p] : false }" },
1635 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1636 "[n] -> { [x] : x mod 32 = 0 }",
1637 "[n] -> { [x = n] }" },
1638 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1639 "{ [x] : x mod 2 = 0 }" },
1640 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1641 "{ [x] : x mod 128 = 0 }" },
1642 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1643 "{ [x] : x mod 3200 = 0 }" },
1644 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1645 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1646 "{ [a, b, c = a] }" },
1647 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1648 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1649 "{ [a, b, c = a] : a mod 3 = 0 }" },
1650 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1651 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1653 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1654 "{ [x,y] : 1 <= y <= 3 }",
1658 /* Check that isl_set_gist behaves as expected.
1660 * For the test cases in gist_tests, besides checking that the result
1661 * is as expected, also check that applying the gist operation does
1662 * not modify the input set (an earlier version of isl would do that) and
1663 * that the test case is consistent, i.e., that the gist has the same
1664 * intersection with the context as the input set.
1666 static int test_gist(struct isl_ctx
*ctx
)
1670 isl_basic_set
*bset1
, *bset2
;
1671 isl_map
*map1
, *map2
;
1674 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1675 int equal_input
, equal_intersection
;
1676 isl_set
*set1
, *set2
, *copy
, *context
;
1678 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1679 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1680 copy
= isl_set_copy(set1
);
1681 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1682 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1683 equal
= isl_set_is_equal(set1
, set2
);
1685 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1686 equal_input
= isl_set_is_equal(set1
, copy
);
1688 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1689 set2
= isl_set_intersect(set2
, context
);
1690 equal_intersection
= isl_set_is_equal(set1
, set2
);
1693 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1696 isl_die(ctx
, isl_error_unknown
,
1697 "incorrect gist result", return -1);
1699 isl_die(ctx
, isl_error_unknown
,
1700 "gist modified input", return -1);
1702 isl_die(ctx
, isl_error_unknown
,
1703 "inconsistent gist test case", return -1);
1706 test_gist_case(ctx
, "gist1");
1708 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1709 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1710 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1711 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1712 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1713 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1714 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1715 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1716 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1717 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1718 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1719 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1720 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1721 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1722 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1723 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1724 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1725 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1726 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1727 bset1
= isl_basic_set_gist(bset1
, bset2
);
1728 assert(bset1
&& bset1
->n_div
== 0);
1729 isl_basic_set_free(bset1
);
1731 /* Check that the integer divisions of the second disjunct
1732 * do not spread to the first disjunct.
1734 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1735 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1736 "(exists (e0 = [(-1 + t1)/16], "
1737 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1738 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1739 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1740 "o0 <= 4294967295 and t1 <= -1)) }";
1741 map1
= isl_map_read_from_str(ctx
, str
);
1742 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1743 map2
= isl_map_read_from_str(ctx
, str
);
1744 map1
= isl_map_gist(map1
, map2
);
1748 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1749 isl_map_free(map1
); return -1);
1750 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1751 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1752 isl_map_free(map1
); return -1);
1755 if (test_plain_gist(ctx
) < 0)
1761 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1763 isl_set
*set
, *set2
;
1767 set
= isl_set_read_from_str(ctx
, str
);
1768 set
= isl_set_coalesce(set
);
1769 set2
= isl_set_read_from_str(ctx
, str
);
1770 equal
= isl_set_is_equal(set
, set2
);
1771 one
= set
&& set
->n
== 1;
1778 isl_die(ctx
, isl_error_unknown
,
1779 "coalesced set not equal to input", return -1);
1780 if (check_one
&& !one
)
1781 isl_die(ctx
, isl_error_unknown
,
1782 "coalesced set should not be a union", return -1);
1787 /* Inputs for coalescing tests with unbounded wrapping.
1788 * "str" is a string representation of the input set.
1789 * "single_disjunct" is set if we expect the result to consist of
1790 * a single disjunct.
1793 int single_disjunct
;
1795 } coalesce_unbounded_tests
[] = {
1796 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1797 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1798 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1799 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1801 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1802 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1803 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1804 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1807 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1808 * option turned off.
1810 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1816 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1817 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1819 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1820 const char *str
= coalesce_unbounded_tests
[i
].str
;
1821 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1822 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1828 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1833 /* Inputs for coalescing tests.
1834 * "str" is a string representation of the input set.
1835 * "single_disjunct" is set if we expect the result to consist of
1836 * a single disjunct.
1839 int single_disjunct
;
1841 } coalesce_tests
[] = {
1842 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1843 "y >= x & x >= 2 & 5 >= y }" },
1844 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1845 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1846 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1847 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1848 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1849 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1850 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1851 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1852 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1853 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1854 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1855 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1856 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1857 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1858 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1859 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1860 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1861 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1862 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1863 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1864 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1865 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1866 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1867 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1868 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1869 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1870 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1871 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1872 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1873 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1874 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1875 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1876 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1877 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1878 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1879 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1880 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1881 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1882 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1883 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1884 "[o0, o1, o2, o3, o4, o5, o6]] : "
1885 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1886 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1887 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1888 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1889 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1890 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1891 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1892 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1893 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1894 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1895 "o6 >= i3 + i6 - o3 and M >= 0 and "
1896 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1897 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1898 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1899 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1900 "(o0 = 0 and M >= 2 and N >= 3) or "
1901 "(M = 0 and o0 = 0 and N >= 3) }" },
1902 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1903 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1904 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1905 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1906 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1907 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1908 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1909 "(y = 3 and x = 1) }" },
1910 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1911 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1912 "i1 <= M and i3 <= M and i4 <= M) or "
1913 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1914 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1915 "i4 <= -1 + M) }" },
1916 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1917 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1918 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1919 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1920 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1921 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1922 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1923 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1924 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1925 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1926 { 0, "{ [a, b] : exists e : 2e = a and "
1927 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1928 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1929 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1930 "j >= 1 and j' <= i + j - i' and i >= 1; "
1932 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1933 "[i,j] : exists a : j = 3a }" },
1934 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1935 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1937 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1938 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1939 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1940 "c <= 6 + 8a and a >= 3; "
1941 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1942 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1943 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1944 "[x,0] : 3 <= x <= 4 }" },
1945 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1946 "[x,0] : 4 <= x <= 5 }" },
1947 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1948 "[x,0] : 3 <= x <= 5 }" },
1949 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1950 "[x,0] : 3 <= x <= 4 }" },
1951 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1953 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1954 { 1, "{ [0,0]; [1,1] }" },
1955 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1956 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1958 "[k, 0, k] : k <= 6 and k >= 1 }" },
1959 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1960 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1961 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1962 { 1, "[n] -> { [1] : n >= 0;"
1963 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1964 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1965 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1966 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1967 "2e0 <= x and 2e0 <= n);"
1968 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1970 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1971 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1972 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1974 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1975 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1977 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1978 "t1 >= 13 and t1 <= 16);"
1979 "[t1] : t1 <= 15 and t1 >= 12 }" },
1980 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1981 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1982 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1983 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1984 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1985 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1987 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1988 "(exists (e0 : 3e0 = -2 + c0)) }" },
1989 { 0, "[n, b0, t0] -> "
1990 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1991 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1992 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1993 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1994 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
1995 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
1996 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
1997 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
1998 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1999 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2000 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2001 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2002 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2003 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2004 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2005 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2006 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2007 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2008 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2009 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2010 { 0, "{ [i0, i1, i2] : "
2011 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2012 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2013 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2014 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2015 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2016 "32e0 <= 31 + i0)) or "
2018 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2019 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2020 "2*floor((c)/2) = c and 0 <= a <= 192;"
2021 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2023 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2024 "(0 <= a <= b <= n) }" },
2025 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2026 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2027 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2028 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2029 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2030 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2031 "b = 3 and 9e0 <= -19 + 2c)) }" },
2032 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2033 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2034 "(a = 4 and b = 3 and "
2035 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2036 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2037 "(b = -1 + a and 0 < a <= 3 and "
2038 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2039 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2040 "b = 3 and 9e0 <= -19 + 2c)) }" },
2041 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2043 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2045 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2046 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2047 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2048 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2049 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2050 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2051 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2052 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2053 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2054 { 1, "{ [a] : a <= 8 and "
2055 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2056 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2057 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2058 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2059 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2060 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2061 "(a < 0 and 3*floor((a)/3) < a) }" },
2062 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2063 "(a < -1 and 3*floor((a)/3) < a) }" },
2064 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2065 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2066 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2067 "or (2 <= a <= 15 and b < a)) }" },
2068 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2069 "32*floor((a)/32) < a) or a <= 15) }" },
2070 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2071 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2072 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2073 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2074 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2075 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2076 "S_0[n] : n <= m <= 2 + n }" },
2077 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2078 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2080 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2081 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2082 "2e0 < -a + 2b) }" },
2083 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2084 "[i, 0, i] : 0 <= i <= 7 }" },
2085 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2086 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2087 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2088 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2089 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2092 /* A specialized coalescing test case that would result
2093 * in a segmentation fault or a failed assertion in earlier versions of isl.
2095 static int test_coalesce_special(struct isl_ctx
*ctx
)
2098 isl_map
*map1
, *map2
;
2100 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2101 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2102 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2103 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2104 "o1 <= 239 and o1 >= 212)) or "
2105 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2106 "o1 <= 241 and o1 >= 240));"
2107 "[S_L220_OUT[] -> T7[]] -> "
2108 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2109 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2110 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2111 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2112 map1
= isl_map_read_from_str(ctx
, str
);
2113 map1
= isl_map_align_divs_internal(map1
);
2114 map1
= isl_map_coalesce(map1
);
2115 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2116 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2117 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2118 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2119 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2120 map2
= isl_map_read_from_str(ctx
, str
);
2121 map2
= isl_map_union(map2
, map1
);
2122 map2
= isl_map_align_divs_internal(map2
);
2123 map2
= isl_map_coalesce(map2
);
2131 /* A specialized coalescing test case that would result in an assertion
2132 * in an earlier version of isl.
2133 * The explicit call to isl_basic_set_union prevents the implicit
2134 * equality constraints in the first basic map from being detected prior
2135 * to the call to isl_set_coalesce, at least at the point
2136 * where this test case was introduced.
2138 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2141 isl_basic_set
*bset1
, *bset2
;
2144 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2145 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2146 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2147 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2148 set
= isl_basic_set_union(bset1
, bset2
);
2149 set
= isl_set_coalesce(set
);
2157 /* Check that calling isl_set_coalesce does not leave other sets
2158 * that may share some information with the input to isl_set_coalesce
2159 * in an inconsistent state.
2160 * In particular, older versions of isl would modify all copies
2161 * of the basic sets in the isl_set_coalesce input in a way
2162 * that could leave them in an inconsistent state.
2163 * The result of printing any other set containing one of these
2164 * basic sets would then result in an invalid set description.
2166 static int test_coalesce_special3(isl_ctx
*ctx
)
2170 isl_set
*set1
, *set2
;
2173 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2174 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2175 set2
= isl_set_read_from_str(ctx
, str
);
2176 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2177 set1
= isl_set_coalesce(set1
);
2180 p
= isl_printer_to_str(ctx
);
2181 p
= isl_printer_print_set(p
, set2
);
2183 s
= isl_printer_get_str(p
);
2184 isl_printer_free(p
);
2185 set1
= isl_set_read_from_str(ctx
, s
);
2195 /* Test the functionality of isl_set_coalesce.
2196 * That is, check that the output is always equal to the input
2197 * and in some cases that the result consists of a single disjunct.
2199 static int test_coalesce(struct isl_ctx
*ctx
)
2203 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2204 const char *str
= coalesce_tests
[i
].str
;
2205 int check_one
= coalesce_tests
[i
].single_disjunct
;
2206 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2210 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2212 if (test_coalesce_special(ctx
) < 0)
2214 if (test_coalesce_special2(ctx
) < 0)
2216 if (test_coalesce_special3(ctx
) < 0)
2222 /* Construct a representation of the graph on the right of Figure 1
2223 * in "Computing the Transitive Closure of a Union of
2224 * Affine Integer Tuple Relations".
2226 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2229 isl_map
*up
, *right
;
2231 dom
= isl_set_read_from_str(ctx
,
2232 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2233 "2 x - 3 y + 3 >= 0 }");
2234 right
= isl_map_read_from_str(ctx
,
2235 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2236 up
= isl_map_read_from_str(ctx
,
2237 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2238 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2239 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2240 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2241 up
= isl_map_intersect_range(up
, dom
);
2242 return isl_map_union(up
, right
);
2245 /* Construct a representation of the power of the graph
2246 * on the right of Figure 1 in "Computing the Transitive Closure of
2247 * a Union of Affine Integer Tuple Relations".
2249 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2251 return isl_map_read_from_str(ctx
,
2252 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2253 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2254 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2257 /* Construct a representation of the transitive closure of the graph
2258 * on the right of Figure 1 in "Computing the Transitive Closure of
2259 * a Union of Affine Integer Tuple Relations".
2261 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2263 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2266 static int test_closure(isl_ctx
*ctx
)
2269 isl_map
*map
, *map2
;
2272 /* COCOA example 1 */
2273 map
= isl_map_read_from_str(ctx
,
2274 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2275 "1 <= i and i < n and 1 <= j and j < n or "
2276 "i2 = i + 1 and j2 = j - 1 and "
2277 "1 <= i and i < n and 2 <= j and j <= n }");
2278 map
= isl_map_power(map
, &exact
);
2282 /* COCOA example 1 */
2283 map
= isl_map_read_from_str(ctx
,
2284 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2285 "1 <= i and i < n and 1 <= j and j < n or "
2286 "i2 = i + 1 and j2 = j - 1 and "
2287 "1 <= i and i < n and 2 <= j and j <= n }");
2288 map
= isl_map_transitive_closure(map
, &exact
);
2290 map2
= isl_map_read_from_str(ctx
,
2291 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2292 "1 <= i and i < n and 1 <= j and j <= n and "
2293 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2294 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2295 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2296 assert(isl_map_is_equal(map
, map2
));
2300 map
= isl_map_read_from_str(ctx
,
2301 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2302 " 0 <= y and y <= n }");
2303 map
= isl_map_transitive_closure(map
, &exact
);
2304 map2
= isl_map_read_from_str(ctx
,
2305 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2306 " 0 <= y and y <= n }");
2307 assert(isl_map_is_equal(map
, map2
));
2311 /* COCOA example 2 */
2312 map
= isl_map_read_from_str(ctx
,
2313 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2314 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2315 "i2 = i + 2 and j2 = j - 2 and "
2316 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2317 map
= isl_map_transitive_closure(map
, &exact
);
2319 map2
= isl_map_read_from_str(ctx
,
2320 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2321 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2322 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2323 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2324 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2325 assert(isl_map_is_equal(map
, map2
));
2329 /* COCOA Fig.2 left */
2330 map
= isl_map_read_from_str(ctx
,
2331 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2332 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2334 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2335 "j <= 2 i - 3 and j <= n - 2 or "
2336 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2337 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2338 map
= isl_map_transitive_closure(map
, &exact
);
2342 /* COCOA Fig.2 right */
2343 map
= isl_map_read_from_str(ctx
,
2344 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2345 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2347 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2348 "j <= 2 i - 4 and j <= n - 3 or "
2349 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2350 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2351 map
= isl_map_power(map
, &exact
);
2355 /* COCOA Fig.2 right */
2356 map
= isl_map_read_from_str(ctx
,
2357 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2358 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2360 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2361 "j <= 2 i - 4 and j <= n - 3 or "
2362 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2363 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2364 map
= isl_map_transitive_closure(map
, &exact
);
2366 map2
= isl_map_read_from_str(ctx
,
2367 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2368 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2369 "j <= n and 3 + i + 2 j <= 3 n and "
2370 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2371 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2372 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2373 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2374 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2375 assert(isl_map_is_equal(map
, map2
));
2379 map
= cocoa_fig_1_right_graph(ctx
);
2380 map
= isl_map_transitive_closure(map
, &exact
);
2382 map2
= cocoa_fig_1_right_tc(ctx
);
2383 assert(isl_map_is_equal(map
, map2
));
2387 map
= cocoa_fig_1_right_graph(ctx
);
2388 map
= isl_map_power(map
, &exact
);
2389 map2
= cocoa_fig_1_right_power(ctx
);
2390 equal
= isl_map_is_equal(map
, map2
);
2396 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2398 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2400 /* COCOA Theorem 1 counter example */
2401 map
= isl_map_read_from_str(ctx
,
2402 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2403 "i2 = 1 and j2 = j or "
2404 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2405 map
= isl_map_transitive_closure(map
, &exact
);
2409 map
= isl_map_read_from_str(ctx
,
2410 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2411 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2412 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2413 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2414 map
= isl_map_transitive_closure(map
, &exact
);
2418 /* Kelly et al 1996, fig 12 */
2419 map
= isl_map_read_from_str(ctx
,
2420 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2421 "1 <= i,j,j+1 <= n or "
2422 "j = n and j2 = 1 and i2 = i + 1 and "
2423 "1 <= i,i+1 <= n }");
2424 map
= isl_map_transitive_closure(map
, &exact
);
2426 map2
= isl_map_read_from_str(ctx
,
2427 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2428 "1 <= i <= n and i = i2 or "
2429 "1 <= i < i2 <= n and 1 <= j <= n and "
2431 assert(isl_map_is_equal(map
, map2
));
2435 /* Omega's closure4 */
2436 map
= isl_map_read_from_str(ctx
,
2437 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2438 "1 <= x,y <= 10 or "
2439 "x2 = x + 1 and y2 = y and "
2440 "1 <= x <= 20 && 5 <= y <= 15 }");
2441 map
= isl_map_transitive_closure(map
, &exact
);
2445 map
= isl_map_read_from_str(ctx
,
2446 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2447 map
= isl_map_transitive_closure(map
, &exact
);
2449 map2
= isl_map_read_from_str(ctx
,
2450 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2451 assert(isl_map_is_equal(map
, map2
));
2455 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2456 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2457 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2458 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2459 map
= isl_map_read_from_str(ctx
, str
);
2460 map
= isl_map_transitive_closure(map
, &exact
);
2462 map2
= isl_map_read_from_str(ctx
, str
);
2463 assert(isl_map_is_equal(map
, map2
));
2467 str
= "{[0] -> [1]; [2] -> [3]}";
2468 map
= isl_map_read_from_str(ctx
, str
);
2469 map
= isl_map_transitive_closure(map
, &exact
);
2471 map2
= isl_map_read_from_str(ctx
, str
);
2472 assert(isl_map_is_equal(map
, map2
));
2476 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2477 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2478 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2479 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2480 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2481 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2482 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2483 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2484 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2485 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2486 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2487 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2488 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2489 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2490 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2491 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2492 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2493 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2494 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2495 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2496 map
= isl_map_read_from_str(ctx
, str
);
2497 map
= isl_map_transitive_closure(map
, NULL
);
2504 static int test_lex(struct isl_ctx
*ctx
)
2510 dim
= isl_space_set_alloc(ctx
, 0, 0);
2511 map
= isl_map_lex_le(dim
);
2512 empty
= isl_map_is_empty(map
);
2518 isl_die(ctx
, isl_error_unknown
,
2519 "expecting non-empty result", return -1);
2524 /* Inputs for isl_map_lexmin tests.
2525 * "map" is the input and "lexmin" is the expected result.
2530 } lexmin_tests
[] = {
2531 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2532 "{ [x] -> [5] : 6 <= x <= 8; "
2533 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2534 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2535 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2536 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2537 "{ [x] -> [y] : (4y = x and x >= 0) or "
2538 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2539 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2540 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2541 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2542 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2543 /* Check that empty pieces are properly combined. */
2544 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2545 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2546 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2547 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2548 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2550 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2551 "a <= 255 and c <= 255 and d <= 255 - j and "
2552 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2553 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2554 "247d <= 247 + i and 248 - b <= 248d <= c and "
2555 "254d >= i - a + b and 254d >= -a + b and "
2556 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2558 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2559 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2560 "247j >= 62738 - i and 509j <= 129795 + i and "
2561 "742j >= 188724 - i; "
2562 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2563 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2564 "16*floor((8 + b)/16) <= 7 + b; "
2566 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2567 "[a] -> [b = 0] : 0 < a <= 509 }" },
2568 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2569 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2572 static int test_lexmin(struct isl_ctx
*ctx
)
2577 isl_basic_map
*bmap
;
2578 isl_map
*map
, *map2
;
2581 isl_pw_multi_aff
*pma
;
2583 str
= "[p0, p1] -> { [] -> [] : "
2584 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2585 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2586 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2587 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2588 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2589 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2590 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2591 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2592 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2593 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2594 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2595 map
= isl_map_read_from_str(ctx
, str
);
2596 map
= isl_map_lexmin(map
);
2599 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2600 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2601 set
= isl_set_read_from_str(ctx
, str
);
2602 set
= isl_set_lexmax(set
);
2603 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2604 set2
= isl_set_read_from_str(ctx
, str
);
2605 set
= isl_set_intersect(set
, set2
);
2606 assert(!isl_set_is_empty(set
));
2609 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2610 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2611 map
= isl_map_lexmin(map
);
2612 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2613 equal
= isl_map_is_equal(map
, map2
);
2620 isl_die(ctx
, isl_error_unknown
,
2621 "unexpected result", return -1);
2624 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2625 " 8i' <= i and 8i' >= -7 + i }";
2626 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2627 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2628 map2
= isl_map_from_pw_multi_aff(pma
);
2629 map
= isl_map_from_basic_map(bmap
);
2630 assert(isl_map_is_equal(map
, map2
));
2634 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2635 " 8i' <= i and 8i' >= -7 + i }";
2636 set
= isl_set_read_from_str(ctx
, str
);
2637 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2638 set2
= isl_set_from_pw_multi_aff(pma
);
2639 equal
= isl_set_is_equal(set
, set2
);
2645 isl_die(ctx
, isl_error_unknown
,
2646 "unexpected difference between set and "
2647 "piecewise affine expression", return -1);
2652 /* A specialized isl_set_min_val test case that would return the wrong result
2653 * in earlier versions of isl.
2654 * The explicit call to isl_basic_set_union prevents the second basic set
2655 * from being determined to be empty prior to the call to isl_set_min_val,
2656 * at least at the point where this test case was introduced.
2658 static int test_min_special(isl_ctx
*ctx
)
2661 isl_basic_set
*bset1
, *bset2
;
2667 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2668 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2669 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2670 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2671 set
= isl_basic_set_union(bset1
, bset2
);
2672 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2674 res
= isl_set_min_val(set
, obj
);
2675 ok
= isl_val_cmp_si(res
, 5) == 0;
2684 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2690 /* A specialized isl_set_min_val test case that would return an error
2691 * in earlier versions of isl.
2693 static int test_min_special2(isl_ctx
*ctx
)
2696 isl_basic_set
*bset
;
2700 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2701 bset
= isl_basic_set_read_from_str(ctx
, str
);
2703 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2705 res
= isl_basic_set_max_val(bset
, obj
);
2707 isl_basic_set_free(bset
);
2720 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2721 __isl_keep isl_aff
*obj
);
2724 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2725 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2726 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2727 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2728 &isl_set_max_val
, "30" },
2732 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2733 * In particular, check the results on non-convex inputs.
2735 static int test_min(struct isl_ctx
*ctx
)
2743 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2744 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2745 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2746 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2747 val
= opt_tests
[i
].fn(set
, obj
);
2748 ok
= isl_val_eq(res
, val
);
2757 isl_die(ctx
, isl_error_unknown
,
2758 "unexpected optimum", return -1);
2761 if (test_min_special(ctx
) < 0)
2763 if (test_min_special2(ctx
) < 0)
2774 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2775 void *dep_user
, void *user
)
2777 struct must_may
*mm
= (struct must_may
*)user
;
2780 mm
->must
= isl_map_union(mm
->must
, dep
);
2782 mm
->may
= isl_map_union(mm
->may
, dep
);
2787 static int common_space(void *first
, void *second
)
2789 int depth
= *(int *)first
;
2793 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2801 map2
= isl_map_read_from_str(map
->ctx
, str
);
2802 equal
= isl_map_is_equal(map
, map2
);
2808 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2812 equal
= map_is_equal(map
, str
);
2816 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2817 "result not as expected", return -1);
2821 static int test_dep(struct isl_ctx
*ctx
)
2826 isl_access_info
*ai
;
2833 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2834 map
= isl_map_read_from_str(ctx
, str
);
2835 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2837 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2838 map
= isl_map_read_from_str(ctx
, str
);
2839 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2841 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2842 map
= isl_map_read_from_str(ctx
, str
);
2843 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2845 flow
= isl_access_info_compute_flow(ai
);
2846 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2847 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2848 mm
.may
= isl_map_empty(dim
);
2850 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2852 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2853 " [1,10,0] -> [2,5,0] }";
2854 assert(map_is_equal(mm
.must
, str
));
2855 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2856 assert(map_is_equal(mm
.may
, str
));
2858 isl_map_free(mm
.must
);
2859 isl_map_free(mm
.may
);
2860 isl_flow_free(flow
);
2863 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2864 map
= isl_map_read_from_str(ctx
, str
);
2865 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2867 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2868 map
= isl_map_read_from_str(ctx
, str
);
2869 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2871 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2872 map
= isl_map_read_from_str(ctx
, str
);
2873 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2875 flow
= isl_access_info_compute_flow(ai
);
2876 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2877 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2878 mm
.may
= isl_map_empty(dim
);
2880 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2882 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2883 assert(map_is_equal(mm
.must
, str
));
2884 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2885 assert(map_is_equal(mm
.may
, str
));
2887 isl_map_free(mm
.must
);
2888 isl_map_free(mm
.may
);
2889 isl_flow_free(flow
);
2892 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2893 map
= isl_map_read_from_str(ctx
, str
);
2894 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2896 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2897 map
= isl_map_read_from_str(ctx
, str
);
2898 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2900 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2901 map
= isl_map_read_from_str(ctx
, str
);
2902 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2904 flow
= isl_access_info_compute_flow(ai
);
2905 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2906 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2907 mm
.may
= isl_map_empty(dim
);
2909 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2911 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2912 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2913 assert(map_is_equal(mm
.may
, str
));
2914 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2915 assert(map_is_equal(mm
.must
, str
));
2917 isl_map_free(mm
.must
);
2918 isl_map_free(mm
.may
);
2919 isl_flow_free(flow
);
2922 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2923 map
= isl_map_read_from_str(ctx
, str
);
2924 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2926 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2927 map
= isl_map_read_from_str(ctx
, str
);
2928 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2930 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2931 map
= isl_map_read_from_str(ctx
, str
);
2932 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2934 flow
= isl_access_info_compute_flow(ai
);
2935 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2936 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2937 mm
.may
= isl_map_empty(dim
);
2939 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2941 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2942 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2943 assert(map_is_equal(mm
.may
, str
));
2944 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2945 assert(map_is_equal(mm
.must
, str
));
2947 isl_map_free(mm
.must
);
2948 isl_map_free(mm
.may
);
2949 isl_flow_free(flow
);
2952 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2953 map
= isl_map_read_from_str(ctx
, str
);
2954 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2956 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2957 map
= isl_map_read_from_str(ctx
, str
);
2958 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2960 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2961 map
= isl_map_read_from_str(ctx
, str
);
2962 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2964 flow
= isl_access_info_compute_flow(ai
);
2965 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2966 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2967 mm
.may
= isl_map_empty(dim
);
2969 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2971 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2972 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2973 assert(map_is_equal(mm
.may
, str
));
2974 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2975 assert(map_is_equal(mm
.must
, str
));
2977 isl_map_free(mm
.must
);
2978 isl_map_free(mm
.may
);
2979 isl_flow_free(flow
);
2984 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2985 map
= isl_map_read_from_str(ctx
, str
);
2986 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2988 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2989 map
= isl_map_read_from_str(ctx
, str
);
2990 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2992 flow
= isl_access_info_compute_flow(ai
);
2993 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2994 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2995 mm
.may
= isl_map_empty(dim
);
2997 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2999 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3000 assert(map_is_equal(mm
.must
, str
));
3001 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3002 assert(map_is_equal(mm
.may
, str
));
3004 isl_map_free(mm
.must
);
3005 isl_map_free(mm
.may
);
3006 isl_flow_free(flow
);
3011 /* Check that the dependence analysis proceeds without errors.
3012 * Earlier versions of isl would break down during the analysis
3013 * due to the use of the wrong spaces.
3015 static int test_flow(isl_ctx
*ctx
)
3018 isl_union_map
*access
, *schedule
;
3019 isl_union_map
*must_dep
, *may_dep
;
3022 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3023 access
= isl_union_map_read_from_str(ctx
, str
);
3024 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3025 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3026 "S2[] -> [1,0,0,0]; "
3027 "S3[] -> [-1,0,0,0] }";
3028 schedule
= isl_union_map_read_from_str(ctx
, str
);
3029 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3030 isl_union_map_copy(access
), schedule
,
3031 &must_dep
, &may_dep
, NULL
, NULL
);
3032 isl_union_map_free(may_dep
);
3033 isl_union_map_free(must_dep
);
3042 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3043 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3044 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3045 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3046 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3047 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3048 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3049 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3050 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3053 int test_sv(isl_ctx
*ctx
)
3055 isl_union_map
*umap
;
3059 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3060 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3061 sv
= isl_union_map_is_single_valued(umap
);
3062 isl_union_map_free(umap
);
3065 if (sv_tests
[i
].sv
&& !sv
)
3066 isl_die(ctx
, isl_error_internal
,
3067 "map not detected as single valued", return -1);
3068 if (!sv_tests
[i
].sv
&& sv
)
3069 isl_die(ctx
, isl_error_internal
,
3070 "map detected as single valued", return -1);
3079 } bijective_tests
[] = {
3080 { "[N,M]->{[i,j] -> [i]}", 0 },
3081 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3082 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3083 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3084 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3085 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3086 { "[N,M]->{[i,j] -> []}", 0 },
3087 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3088 { "[N,M]->{[i,j] -> [2i]}", 0 },
3089 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3090 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3091 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3092 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3095 static int test_bijective(struct isl_ctx
*ctx
)
3101 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3102 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3103 bijective
= isl_map_is_bijective(map
);
3107 if (bijective_tests
[i
].bijective
&& !bijective
)
3108 isl_die(ctx
, isl_error_internal
,
3109 "map not detected as bijective", return -1);
3110 if (!bijective_tests
[i
].bijective
&& bijective
)
3111 isl_die(ctx
, isl_error_internal
,
3112 "map detected as bijective", return -1);
3118 /* Inputs for isl_pw_qpolynomial_gist tests.
3119 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3125 } pwqp_gist_tests
[] = {
3126 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3127 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3128 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3129 "{ [i] -> -1/2 + 1/2 * i }" },
3130 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3133 static int test_pwqp(struct isl_ctx
*ctx
)
3138 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3141 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3142 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3144 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3147 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3148 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3150 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3152 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3154 isl_pw_qpolynomial_free(pwqp1
);
3156 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3157 str
= pwqp_gist_tests
[i
].pwqp
;
3158 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3159 str
= pwqp_gist_tests
[i
].set
;
3160 set
= isl_set_read_from_str(ctx
, str
);
3161 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3162 str
= pwqp_gist_tests
[i
].gist
;
3163 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3164 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3165 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3166 isl_pw_qpolynomial_free(pwqp1
);
3171 isl_die(ctx
, isl_error_unknown
,
3172 "unexpected result", return -1);
3175 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3176 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3177 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3178 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3180 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3182 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3184 isl_pw_qpolynomial_free(pwqp1
);
3186 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3187 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3188 str
= "{ [x] -> x }";
3189 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3191 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3193 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3195 isl_pw_qpolynomial_free(pwqp1
);
3197 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3198 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3199 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3200 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3201 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3202 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3203 isl_pw_qpolynomial_free(pwqp1
);
3205 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3206 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3207 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3208 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3209 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3210 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3211 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3212 isl_pw_qpolynomial_free(pwqp1
);
3213 isl_pw_qpolynomial_free(pwqp2
);
3217 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3219 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3220 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3221 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3222 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3223 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3225 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3226 isl_pw_qpolynomial_free(pwqp1
);
3227 isl_pw_qpolynomial_free(pwqp2
);
3231 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3236 static int test_split_periods(isl_ctx
*ctx
)
3239 isl_pw_qpolynomial
*pwqp
;
3241 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3242 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3243 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3244 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3246 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3248 isl_pw_qpolynomial_free(pwqp
);
3256 static int test_union(isl_ctx
*ctx
)
3259 isl_union_set
*uset1
, *uset2
;
3260 isl_union_map
*umap1
, *umap2
;
3263 str
= "{ [i] : 0 <= i <= 1 }";
3264 uset1
= isl_union_set_read_from_str(ctx
, str
);
3265 str
= "{ [1] -> [0] }";
3266 umap1
= isl_union_map_read_from_str(ctx
, str
);
3268 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3269 equal
= isl_union_map_is_equal(umap1
, umap2
);
3271 isl_union_map_free(umap1
);
3272 isl_union_map_free(umap2
);
3277 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3280 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3281 umap1
= isl_union_map_read_from_str(ctx
, str
);
3282 str
= "{ A[i]; B[i] }";
3283 uset1
= isl_union_set_read_from_str(ctx
, str
);
3285 uset2
= isl_union_map_domain(umap1
);
3287 equal
= isl_union_set_is_equal(uset1
, uset2
);
3289 isl_union_set_free(uset1
);
3290 isl_union_set_free(uset2
);
3295 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3301 /* Check that computing a bound of a non-zero polynomial over an unbounded
3302 * domain does not produce a rational value.
3303 * In particular, check that the upper bound is infinity.
3305 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3308 isl_pw_qpolynomial
*pwqp
;
3309 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3312 str
= "{ [m,n] -> -m * n }";
3313 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3314 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3316 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3317 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3318 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3319 isl_pw_qpolynomial_fold_free(pwf
);
3320 isl_pw_qpolynomial_fold_free(pwf2
);
3325 isl_die(ctx
, isl_error_unknown
,
3326 "expecting infinite polynomial bound", return -1);
3331 static int test_bound(isl_ctx
*ctx
)
3335 isl_pw_qpolynomial
*pwqp
;
3336 isl_pw_qpolynomial_fold
*pwf
;
3338 if (test_bound_unbounded_domain(ctx
) < 0)
3341 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3342 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3343 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3344 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3345 isl_pw_qpolynomial_fold_free(pwf
);
3347 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3350 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3351 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3352 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3353 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3354 isl_pw_qpolynomial_fold_free(pwf
);
3356 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3362 static int test_lift(isl_ctx
*ctx
)
3365 isl_basic_map
*bmap
;
3366 isl_basic_set
*bset
;
3368 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3369 bset
= isl_basic_set_read_from_str(ctx
, str
);
3370 bset
= isl_basic_set_lift(bset
);
3371 bmap
= isl_basic_map_from_range(bset
);
3372 bset
= isl_basic_map_domain(bmap
);
3373 isl_basic_set_free(bset
);
3382 } subset_tests
[] = {
3384 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3385 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3386 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3388 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3389 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3390 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3391 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3392 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3393 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3394 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3395 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3396 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3397 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3398 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3399 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3400 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3401 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3402 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3403 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3404 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3405 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3406 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3407 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3408 "4e0 <= -57 + i0 + i1)) or "
3409 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3410 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3411 "4e0 >= -61 + i0 + i1)) or "
3412 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3413 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3416 static int test_subset(isl_ctx
*ctx
)
3419 isl_set
*set1
, *set2
;
3422 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3423 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3424 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3425 subset
= isl_set_is_subset(set1
, set2
);
3430 if (subset
!= subset_tests
[i
].subset
)
3431 isl_die(ctx
, isl_error_unknown
,
3432 "incorrect subset result", return -1);
3439 const char *minuend
;
3440 const char *subtrahend
;
3441 const char *difference
;
3442 } subtract_domain_tests
[] = {
3443 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3444 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3445 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3448 static int test_subtract(isl_ctx
*ctx
)
3451 isl_union_map
*umap1
, *umap2
;
3452 isl_union_pw_multi_aff
*upma1
, *upma2
;
3453 isl_union_set
*uset
;
3456 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3457 umap1
= isl_union_map_read_from_str(ctx
,
3458 subtract_domain_tests
[i
].minuend
);
3459 uset
= isl_union_set_read_from_str(ctx
,
3460 subtract_domain_tests
[i
].subtrahend
);
3461 umap2
= isl_union_map_read_from_str(ctx
,
3462 subtract_domain_tests
[i
].difference
);
3463 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3464 equal
= isl_union_map_is_equal(umap1
, umap2
);
3465 isl_union_map_free(umap1
);
3466 isl_union_map_free(umap2
);
3470 isl_die(ctx
, isl_error_unknown
,
3471 "incorrect subtract domain result", return -1);
3474 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3475 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3476 subtract_domain_tests
[i
].minuend
);
3477 uset
= isl_union_set_read_from_str(ctx
,
3478 subtract_domain_tests
[i
].subtrahend
);
3479 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3480 subtract_domain_tests
[i
].difference
);
3481 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3482 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3483 isl_union_pw_multi_aff_free(upma1
);
3484 isl_union_pw_multi_aff_free(upma2
);
3488 isl_die(ctx
, isl_error_unknown
,
3489 "incorrect subtract domain result", return -1);
3495 /* Check that intersecting the empty basic set with another basic set
3496 * does not increase the number of constraints. In particular,
3497 * the empty basic set should maintain its canonical representation.
3499 static int test_intersect(isl_ctx
*ctx
)
3502 isl_basic_set
*bset1
, *bset2
;
3504 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3505 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3506 n1
= isl_basic_set_n_constraint(bset1
);
3507 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3508 n2
= isl_basic_set_n_constraint(bset1
);
3509 isl_basic_set_free(bset1
);
3513 isl_die(ctx
, isl_error_unknown
,
3514 "number of constraints of empty set changed",
3520 int test_factorize(isl_ctx
*ctx
)
3523 isl_basic_set
*bset
;
3526 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3527 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3528 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3529 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3530 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3531 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3532 "3i5 >= -2i0 - i2 + 3i4 }";
3533 bset
= isl_basic_set_read_from_str(ctx
, str
);
3534 f
= isl_basic_set_factorizer(bset
);
3535 isl_basic_set_free(bset
);
3536 isl_factorizer_free(f
);
3538 isl_die(ctx
, isl_error_unknown
,
3539 "failed to construct factorizer", return -1);
3541 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3542 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3543 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3544 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3545 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3546 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3547 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3548 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3549 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3550 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3551 bset
= isl_basic_set_read_from_str(ctx
, str
);
3552 f
= isl_basic_set_factorizer(bset
);
3553 isl_basic_set_free(bset
);
3554 isl_factorizer_free(f
);
3556 isl_die(ctx
, isl_error_unknown
,
3557 "failed to construct factorizer", return -1);
3562 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3564 int *injective
= user
;
3566 *injective
= isl_map_is_injective(map
);
3569 if (*injective
< 0 || !*injective
)
3570 return isl_stat_error
;
3575 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3576 const char *r
, const char *s
, int tilable
, int parallel
)
3580 isl_union_map
*W
, *R
, *S
;
3581 isl_union_map
*empty
;
3582 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3583 isl_union_map
*validity
, *proximity
, *coincidence
;
3584 isl_union_map
*schedule
;
3585 isl_union_map
*test
;
3586 isl_union_set
*delta
;
3587 isl_union_set
*domain
;
3591 isl_schedule_constraints
*sc
;
3592 isl_schedule
*sched
;
3593 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3595 D
= isl_union_set_read_from_str(ctx
, d
);
3596 W
= isl_union_map_read_from_str(ctx
, w
);
3597 R
= isl_union_map_read_from_str(ctx
, r
);
3598 S
= isl_union_map_read_from_str(ctx
, s
);
3600 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3601 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3603 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3604 isl_union_map_compute_flow(isl_union_map_copy(R
),
3605 isl_union_map_copy(W
), empty
,
3606 isl_union_map_copy(S
),
3607 &dep_raw
, NULL
, NULL
, NULL
);
3608 isl_union_map_compute_flow(isl_union_map_copy(W
),
3609 isl_union_map_copy(W
),
3610 isl_union_map_copy(R
),
3611 isl_union_map_copy(S
),
3612 &dep_waw
, &dep_war
, NULL
, NULL
);
3614 dep
= isl_union_map_union(dep_waw
, dep_war
);
3615 dep
= isl_union_map_union(dep
, dep_raw
);
3616 validity
= isl_union_map_copy(dep
);
3617 coincidence
= isl_union_map_copy(dep
);
3618 proximity
= isl_union_map_copy(dep
);
3620 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3621 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3622 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3623 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3624 sched
= isl_schedule_constraints_compute_schedule(sc
);
3625 schedule
= isl_schedule_get_map(sched
);
3626 isl_schedule_free(sched
);
3627 isl_union_map_free(W
);
3628 isl_union_map_free(R
);
3629 isl_union_map_free(S
);
3632 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3634 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3635 is_complete
= isl_union_set_is_subset(D
, domain
);
3636 isl_union_set_free(D
);
3637 isl_union_set_free(domain
);
3639 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3640 test
= isl_union_map_apply_range(test
, dep
);
3641 test
= isl_union_map_apply_range(test
, schedule
);
3643 delta
= isl_union_map_deltas(test
);
3644 if (isl_union_set_n_set(delta
) == 0) {
3648 isl_union_set_free(delta
);
3650 delta_set
= isl_set_from_union_set(delta
);
3652 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3653 for (i
= 0; i
< tilable
; ++i
)
3654 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3655 is_tilable
= isl_set_is_subset(delta_set
, slice
);
3656 isl_set_free(slice
);
3658 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3659 for (i
= 0; i
< parallel
; ++i
)
3660 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
3661 is_parallel
= isl_set_is_subset(delta_set
, slice
);
3662 isl_set_free(slice
);
3664 origin
= isl_set_universe(isl_set_get_space(delta_set
));
3665 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
3666 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
3668 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
3669 delta_set
= isl_set_lexmin(delta_set
);
3671 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
3673 isl_set_free(origin
);
3674 isl_set_free(delta_set
);
3677 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
3678 is_injection
< 0 || is_complete
< 0)
3681 isl_die(ctx
, isl_error_unknown
,
3682 "generated schedule incomplete", return -1);
3684 isl_die(ctx
, isl_error_unknown
,
3685 "generated schedule not injective on each statement",
3688 isl_die(ctx
, isl_error_unknown
,
3689 "negative dependences in generated schedule",
3692 isl_die(ctx
, isl_error_unknown
,
3693 "generated schedule not as tilable as expected",
3696 isl_die(ctx
, isl_error_unknown
,
3697 "generated schedule not as parallel as expected",
3703 /* Compute a schedule for the given instance set, validity constraints,
3704 * proximity constraints and context and return a corresponding union map
3707 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
3708 const char *domain
, const char *validity
, const char *proximity
,
3709 const char *context
)
3714 isl_union_map
*prox
;
3715 isl_schedule_constraints
*sc
;
3716 isl_schedule
*schedule
;
3717 isl_union_map
*sched
;
3719 con
= isl_set_read_from_str(ctx
, context
);
3720 dom
= isl_union_set_read_from_str(ctx
, domain
);
3721 dep
= isl_union_map_read_from_str(ctx
, validity
);
3722 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3723 sc
= isl_schedule_constraints_on_domain(dom
);
3724 sc
= isl_schedule_constraints_set_context(sc
, con
);
3725 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3726 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3727 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3728 sched
= isl_schedule_get_map(schedule
);
3729 isl_schedule_free(schedule
);
3734 /* Compute a schedule for the given instance set, validity constraints and
3735 * proximity constraints and return a corresponding union map representation.
3737 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3738 const char *domain
, const char *validity
, const char *proximity
)
3740 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
3744 /* Check that a schedule can be constructed on the given domain
3745 * with the given validity and proximity constraints.
3747 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3748 const char *validity
, const char *proximity
)
3750 isl_union_map
*sched
;
3752 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3756 isl_union_map_free(sched
);
3760 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3761 const char *validity
, const char *proximity
, const char *expected_sched
)
3763 isl_union_map
*sched1
, *sched2
;
3766 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3767 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3769 equal
= isl_union_map_is_equal(sched1
, sched2
);
3770 isl_union_map_free(sched1
);
3771 isl_union_map_free(sched2
);
3776 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3782 /* Check that the schedule map is properly padded, i.e., that the range
3783 * lives in a single space.
3785 static int test_padded_schedule(isl_ctx
*ctx
)
3789 isl_union_map
*validity
, *proximity
;
3790 isl_schedule_constraints
*sc
;
3791 isl_schedule
*sched
;
3792 isl_union_map
*umap
;
3793 isl_union_set
*range
;
3796 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3797 D
= isl_union_set_read_from_str(ctx
, str
);
3798 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3799 proximity
= isl_union_map_copy(validity
);
3800 sc
= isl_schedule_constraints_on_domain(D
);
3801 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3802 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3803 sched
= isl_schedule_constraints_compute_schedule(sc
);
3804 umap
= isl_schedule_get_map(sched
);
3805 isl_schedule_free(sched
);
3806 range
= isl_union_map_range(umap
);
3807 set
= isl_set_from_union_set(range
);
3816 /* Check that conditional validity constraints are also taken into
3817 * account across bands.
3818 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3819 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3820 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3821 * is enforced by the rest of the schedule.
3823 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3826 isl_union_set
*domain
;
3827 isl_union_map
*validity
, *proximity
, *condition
;
3828 isl_union_map
*sink
, *source
, *dep
;
3829 isl_schedule_constraints
*sc
;
3830 isl_schedule
*schedule
;
3831 isl_union_access_info
*access
;
3832 isl_union_flow
*flow
;
3835 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3836 "A[k] : k >= 1 and k <= -1 + n; "
3837 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3838 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3839 domain
= isl_union_set_read_from_str(ctx
, str
);
3840 sc
= isl_schedule_constraints_on_domain(domain
);
3841 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3842 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3843 "D[k, i] -> C[1 + k, i] : "
3844 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3845 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3846 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3847 validity
= isl_union_map_read_from_str(ctx
, str
);
3848 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3849 str
= "[n] -> { C[k, i] -> D[k, i] : "
3850 "0 <= i <= -1 + k and k <= -1 + n }";
3851 proximity
= isl_union_map_read_from_str(ctx
, str
);
3852 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3853 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3854 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3855 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3856 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3857 condition
= isl_union_map_read_from_str(ctx
, str
);
3858 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3859 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3860 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3861 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3862 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3863 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3864 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3865 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3866 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3867 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3868 validity
= isl_union_map_read_from_str(ctx
, str
);
3869 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3871 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3872 str
= "{ D[2,0] -> [] }";
3873 sink
= isl_union_map_read_from_str(ctx
, str
);
3874 access
= isl_union_access_info_from_sink(sink
);
3875 str
= "{ C[2,1] -> [] }";
3876 source
= isl_union_map_read_from_str(ctx
, str
);
3877 access
= isl_union_access_info_set_must_source(access
, source
);
3878 access
= isl_union_access_info_set_schedule(access
, schedule
);
3879 flow
= isl_union_access_info_compute_flow(access
);
3880 dep
= isl_union_flow_get_must_dependence(flow
);
3881 isl_union_flow_free(flow
);
3882 empty
= isl_union_map_is_empty(dep
);
3883 isl_union_map_free(dep
);
3888 isl_die(ctx
, isl_error_unknown
,
3889 "conditional validity not respected", return -1);
3894 /* Check that the test for violated conditional validity constraints
3895 * is not confused by domain compression.
3896 * In particular, earlier versions of isl would apply
3897 * a schedule on the compressed domains to the original domains,
3898 * resulting in a failure to detect that the default schedule
3899 * violates the conditional validity constraints.
3901 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
3905 isl_union_set
*domain
;
3906 isl_union_map
*validity
, *condition
;
3907 isl_schedule_constraints
*sc
;
3908 isl_schedule
*schedule
;
3909 isl_union_map
*umap
;
3912 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
3913 domain
= isl_union_set_read_from_str(ctx
, str
);
3914 sc
= isl_schedule_constraints_on_domain(domain
);
3915 str
= "{ B[1, i] -> A[0, i + 1] }";
3916 condition
= isl_union_map_read_from_str(ctx
, str
);
3917 str
= "{ A[0, i] -> B[1, i - 1] }";
3918 validity
= isl_union_map_read_from_str(ctx
, str
);
3919 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3920 isl_union_map_copy(validity
));
3921 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3922 umap
= isl_schedule_get_map(schedule
);
3923 isl_schedule_free(schedule
);
3924 validity
= isl_union_map_apply_domain(validity
,
3925 isl_union_map_copy(umap
));
3926 validity
= isl_union_map_apply_range(validity
, umap
);
3927 map
= isl_map_from_union_map(validity
);
3928 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3929 map
= isl_map_intersect(map
, ge
);
3930 empty
= isl_map_is_empty(map
);
3936 isl_die(ctx
, isl_error_unknown
,
3937 "conditional validity constraints not satisfied",
3943 /* Input for testing of schedule construction based on
3944 * conditional constraints.
3946 * domain is the iteration domain
3947 * flow are the flow dependences, which determine the validity and
3948 * proximity constraints
3949 * condition are the conditions on the conditional validity constraints
3950 * conditional_validity are the conditional validity constraints
3951 * outer_band_n is the expected number of members in the outer band
3956 const char *condition
;
3957 const char *conditional_validity
;
3959 } live_range_tests
[] = {
3960 /* Contrived example that illustrates that we need to keep
3961 * track of tagged condition dependences and
3962 * tagged conditional validity dependences
3963 * in isl_sched_edge separately.
3964 * In particular, the conditional validity constraints on A
3965 * cannot be satisfied,
3966 * but they can be ignored because there are no corresponding
3967 * condition constraints. However, we do have an additional
3968 * conditional validity constraint that maps to the same
3969 * dependence relation
3970 * as the condition constraint on B. If we did not make a distinction
3971 * between tagged condition and tagged conditional validity
3972 * dependences, then we
3973 * could end up treating this shared dependence as an condition
3974 * constraint on A, forcing a localization of the conditions,
3975 * which is impossible.
3977 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3978 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3979 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
3980 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3981 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3982 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
3985 /* TACO 2013 Fig. 7 */
3986 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3987 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3988 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3989 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
3990 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
3991 "0 <= i < n and 0 <= j < n - 1 }",
3992 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
3993 "0 <= i < n and 0 <= j < j' < n;"
3994 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
3995 "0 <= i < i' < n and 0 <= j,j' < n;"
3996 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
3997 "0 <= i,j,j' < n and j < j' }",
4000 /* TACO 2013 Fig. 7, without tags */
4001 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4002 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4003 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4004 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4005 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4006 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4007 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4008 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4011 /* TACO 2013 Fig. 12 */
4012 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4013 "S3[i,3] : 0 <= i <= 1 }",
4014 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4015 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4016 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4017 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4018 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4019 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4020 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4021 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4022 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4023 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4024 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4029 /* Test schedule construction based on conditional constraints.
4030 * In particular, check the number of members in the outer band node
4031 * as an indication of whether tiling is possible or not.
4033 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4036 isl_union_set
*domain
;
4037 isl_union_map
*condition
;
4038 isl_union_map
*flow
;
4039 isl_union_map
*validity
;
4040 isl_schedule_constraints
*sc
;
4041 isl_schedule
*schedule
;
4042 isl_schedule_node
*node
;
4045 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4047 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4050 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4051 domain
= isl_union_set_read_from_str(ctx
,
4052 live_range_tests
[i
].domain
);
4053 flow
= isl_union_map_read_from_str(ctx
,
4054 live_range_tests
[i
].flow
);
4055 condition
= isl_union_map_read_from_str(ctx
,
4056 live_range_tests
[i
].condition
);
4057 validity
= isl_union_map_read_from_str(ctx
,
4058 live_range_tests
[i
].conditional_validity
);
4059 sc
= isl_schedule_constraints_on_domain(domain
);
4060 sc
= isl_schedule_constraints_set_validity(sc
,
4061 isl_union_map_copy(flow
));
4062 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4063 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4064 condition
, validity
);
4065 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4066 node
= isl_schedule_get_root(schedule
);
4068 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4069 node
= isl_schedule_node_first_child(node
);
4070 n_member
= isl_schedule_node_band_n_member(node
);
4071 isl_schedule_node_free(node
);
4072 isl_schedule_free(schedule
);
4076 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4077 isl_die(ctx
, isl_error_unknown
,
4078 "unexpected number of members in outer band",
4084 /* Check that the schedule computed for the given instance set and
4085 * dependence relation strongly satisfies the dependences.
4086 * In particular, check that no instance is scheduled before
4087 * or together with an instance on which it depends.
4088 * Earlier versions of isl would produce a schedule that
4089 * only weakly satisfies the dependences.
4091 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4093 const char *domain
, *dep
;
4094 isl_union_map
*D
, *schedule
;
4098 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4099 "A[i0] : 0 <= i0 <= 1 }";
4100 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4101 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4102 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4103 D
= isl_union_map_read_from_str(ctx
, dep
);
4104 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4105 D
= isl_union_map_apply_range(D
, schedule
);
4106 map
= isl_map_from_union_map(D
);
4107 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4108 map
= isl_map_intersect(map
, ge
);
4109 empty
= isl_map_is_empty(map
);
4115 isl_die(ctx
, isl_error_unknown
,
4116 "dependences not strongly satisfied", return -1);
4121 /* Compute a schedule for input where the instance set constraints
4122 * conflict with the context constraints.
4123 * Earlier versions of isl did not properly handle this situation.
4125 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4127 isl_union_map
*schedule
;
4128 const char *domain
, *context
;
4130 domain
= "[n] -> { A[] : n >= 0 }";
4131 context
= "[n] -> { : n < 0 }";
4132 schedule
= compute_schedule_with_context(ctx
,
4133 domain
, "{}", "{}", context
);
4134 isl_union_map_free(schedule
);
4142 /* Check that the dependence carrying step is not confused by
4143 * a bound on the coefficient size.
4144 * In particular, force the scheduler to move to a dependence carrying
4145 * step by demanding outer coincidence and bound the size of
4146 * the coefficients. Earlier versions of isl would take this
4147 * bound into account while carrying dependences, breaking
4148 * fundamental assumptions.
4149 * On the other hand, the dependence carrying step now tries
4150 * to prevent loop coalescing by default, so check that indeed
4151 * no loop coalescing occurs by comparing the computed schedule
4152 * to the expected non-coalescing schedule.
4154 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
4156 const char *domain
, *dep
;
4159 isl_schedule_constraints
*sc
;
4160 isl_schedule
*schedule
;
4161 isl_union_map
*sched1
, *sched2
;
4164 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
4165 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
4167 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
4168 I
= isl_union_set_read_from_str(ctx
, domain
);
4169 D
= isl_union_map_read_from_str(ctx
, dep
);
4170 sc
= isl_schedule_constraints_on_domain(I
);
4171 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
4172 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
4173 isl_options_set_schedule_outer_coincidence(ctx
, 1);
4174 isl_options_set_schedule_max_coefficient(ctx
, 20);
4175 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4176 isl_options_set_schedule_max_coefficient(ctx
, -1);
4177 isl_options_set_schedule_outer_coincidence(ctx
, 0);
4178 sched1
= isl_schedule_get_map(schedule
);
4179 isl_schedule_free(schedule
);
4181 sched2
= isl_union_map_read_from_str(ctx
, "{ C[x,y] -> [x,y] }");
4182 equal
= isl_union_map_is_equal(sched1
, sched2
);
4183 isl_union_map_free(sched1
);
4184 isl_union_map_free(sched2
);
4189 isl_die(ctx
, isl_error_unknown
,
4190 "unexpected schedule", return -1);
4195 /* Check that the bounds on the coefficients are respected.
4196 * This function checks for a particular output schedule,
4197 * but the exact output is not important, only that it does
4198 * not contain any coefficients greater than 4.
4199 * It is, however, easier to check for a particular output.
4200 * This test is only run for the whole component scheduler
4201 * because the incremental scheduler produces a slightly different schedule.
4203 static int test_bounded_coefficients_schedule_whole(isl_ctx
*ctx
)
4205 const char *domain
, *dep
, *str
;
4208 isl_schedule_constraints
*sc
;
4209 isl_schedule
*schedule
;
4210 isl_union_map
*sched1
, *sched2
;
4213 domain
= "{ S_4[i, j, k] : 0 <= i < j <= 10 and 0 <= k <= 100; "
4214 "S_2[i, j] : 0 <= i < j <= 10; S_6[i, j] : 0 <= i < j <= 10 }";
4215 dep
= "{ S_2[0, j] -> S_4[0, j, 0] : 0 < j <= 10; "
4216 "S_4[0, j, 100] -> S_6[0, j] : 0 < j <= 10 }";
4217 I
= isl_union_set_read_from_str(ctx
, domain
);
4218 D
= isl_union_map_read_from_str(ctx
, dep
);
4219 sc
= isl_schedule_constraints_on_domain(I
);
4220 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4221 isl_options_set_schedule_max_constant_term(ctx
, 10);
4222 isl_options_set_schedule_max_coefficient(ctx
, 4);
4223 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4224 isl_options_set_schedule_max_coefficient(ctx
, -1);
4225 isl_options_set_schedule_max_constant_term(ctx
, -1);
4226 sched1
= isl_schedule_get_map(schedule
);
4227 isl_schedule_free(schedule
);
4229 str
= "{ S_4[i, j, k] -> [i, j, 10 - k]; "
4230 "S_2[i, j] -> [0, i, j]; S_6[i, j] -> [0, 10 + i, j] }";
4231 sched2
= isl_union_map_read_from_str(ctx
, str
);
4232 equal
= isl_union_map_is_equal(sched1
, sched2
);
4233 isl_union_map_free(sched1
);
4234 isl_union_map_free(sched2
);
4239 isl_die(ctx
, isl_error_unknown
,
4240 "unexpected schedule", return -1);
4245 /* Check that a set of schedule constraints that only allow for
4246 * a coalescing schedule still produces a schedule even if the user
4247 * request a non-coalescing schedule. Earlier versions of isl
4248 * would not handle this case correctly.
4250 static int test_coalescing_schedule(isl_ctx
*ctx
)
4252 const char *domain
, *dep
;
4255 isl_schedule_constraints
*sc
;
4256 isl_schedule
*schedule
;
4257 int treat_coalescing
;
4259 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4260 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4261 I
= isl_union_set_read_from_str(ctx
, domain
);
4262 D
= isl_union_map_read_from_str(ctx
, dep
);
4263 sc
= isl_schedule_constraints_on_domain(I
);
4264 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4265 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4266 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4267 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4268 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4269 isl_schedule_free(schedule
);
4275 /* Check that the scheduler does not perform any needless
4276 * compound skewing. Earlier versions of isl would compute
4277 * schedules in terms of transformed schedule coefficients and
4278 * would not accurately keep track of the sum of the original
4279 * schedule coefficients. It could then produce the schedule
4280 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4281 * for the input below instead of the schedule below.
4283 static int test_skewing_schedule(isl_ctx
*ctx
)
4285 const char *D
, *V
, *P
, *S
;
4287 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4288 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4289 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4290 "-1 <= a-i + b-j + c-k <= 1 }";
4292 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4294 return test_special_schedule(ctx
, D
, V
, P
, S
);
4297 int test_schedule(isl_ctx
*ctx
)
4299 const char *D
, *W
, *R
, *V
, *P
, *S
;
4300 int max_coincidence
;
4301 int treat_coalescing
;
4303 /* Handle resulting schedule with zero bands. */
4304 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4308 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4309 W
= "{ S1[t,i] -> a[t,i] }";
4310 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4311 "S1[t,i] -> a[t-1,i+1] }";
4312 S
= "{ S1[t,i] -> [t,i] }";
4313 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4316 /* Fig. 5 of CC2008 */
4317 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4319 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4320 "j >= 2 and j <= -1 + N }";
4321 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4322 "j >= 2 and j <= -1 + N; "
4323 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4324 "j >= 2 and j <= -1 + N }";
4325 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4326 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4329 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4330 W
= "{ S1[i] -> a[i] }";
4331 R
= "{ S2[i] -> a[i+1] }";
4332 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4333 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4336 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4337 W
= "{ S1[i] -> a[i] }";
4338 R
= "{ S2[i] -> a[9-i] }";
4339 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4340 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4343 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4344 W
= "{ S1[i] -> a[i] }";
4345 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4346 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4347 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4350 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4351 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4352 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4353 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4354 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4357 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4358 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4359 R
= "{ S2[i,j] -> a[i-1,j] }";
4360 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4361 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4364 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4365 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4366 R
= "{ S2[i,j] -> a[i,j-1] }";
4367 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4368 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4371 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4372 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4373 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4374 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4375 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4376 "S_0[] -> [0, 0, 0] }";
4377 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4379 ctx
->opt
->schedule_parametric
= 0;
4380 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4382 ctx
->opt
->schedule_parametric
= 1;
4384 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4385 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4386 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4387 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4388 "S4[i] -> a[i,N] }";
4389 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4390 "S4[i] -> [4,i,0] }";
4391 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4392 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4393 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4395 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4397 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4398 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4400 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4402 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4404 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4405 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4408 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4409 " S_2[t] : t >= 0 and t <= -1 + N; "
4410 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4412 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4413 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4414 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4415 "i >= 0 and i <= -1 + N }";
4416 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4417 "i >= 0 and i <= -1 + N; "
4418 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4419 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4420 " S_0[t] -> [0, t, 0] }";
4422 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4424 ctx
->opt
->schedule_parametric
= 0;
4425 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4427 ctx
->opt
->schedule_parametric
= 1;
4429 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4430 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4431 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4434 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4435 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4436 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4437 "j >= 0 and j <= -1 + N; "
4438 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4439 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4440 "j >= 0 and j <= -1 + N; "
4441 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4442 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4443 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4446 D
= "{ S_0[i] : i >= 0 }";
4447 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4448 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4449 S
= "{ S_0[i] -> [0, i, 0] }";
4450 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4453 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4454 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4455 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4456 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4457 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4460 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4461 "k <= -1 + n and k >= 0 }";
4462 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4463 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4464 "k <= -1 + n and k >= 0; "
4465 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4466 "k <= -1 + n and k >= 0; "
4467 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4468 "k <= -1 + n and k >= 0 }";
4469 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4470 ctx
->opt
->schedule_outer_coincidence
= 1;
4471 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4473 ctx
->opt
->schedule_outer_coincidence
= 0;
4475 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4476 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4477 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4478 "Stmt_for_body24[i0, i1, 1, 0]:"
4479 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4480 "Stmt_for_body7[i0, i1, i2]:"
4481 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4484 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4485 "Stmt_for_body24[1, i1, i2, i3]:"
4486 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4488 "Stmt_for_body24[0, i1, i2, i3] -> "
4489 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4490 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4492 "Stmt_for_body24[0, i1, i2, i3] ->"
4493 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4494 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4495 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4496 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4497 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4498 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4499 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4500 "i1 <= 6 and i1 >= 0;"
4501 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4502 "Stmt_for_body7[i0, i1, i2] -> "
4503 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4504 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4505 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4506 "Stmt_for_body7[i0, i1, i2] -> "
4507 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4508 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4509 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4512 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4513 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4514 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4516 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4518 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4519 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4520 "j >= 1 and j <= 7;"
4521 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4522 "j >= 1 and j <= 8 }";
4524 S
= "{ S_0[i, j] -> [i + j, i] }";
4525 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4526 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4528 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4530 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4531 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4532 "j >= 0 and j <= -1 + i }";
4533 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4534 "i <= -1 + N and j >= 0;"
4535 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4538 S
= "{ S_0[i, j] -> [i, j] }";
4539 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4540 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4542 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4544 /* Test both algorithms on a case with only proximity dependences. */
4545 D
= "{ S[i,j] : 0 <= i <= 10 }";
4547 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4548 S
= "{ S[i, j] -> [j, i] }";
4549 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4550 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4552 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4553 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4556 D
= "{ A[a]; B[] }";
4558 P
= "{ A[a] -> B[] }";
4559 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4562 if (test_padded_schedule(ctx
) < 0)
4565 /* Check that check for progress is not confused by rational
4568 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4569 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4571 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4572 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4574 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4575 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4577 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4579 /* Check that we allow schedule rows that are only non-trivial
4580 * on some full-dimensional domains.
4582 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4583 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4584 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4586 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4587 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4589 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4591 if (test_conditional_schedule_constraints(ctx
) < 0)
4594 if (test_strongly_satisfying_schedule(ctx
) < 0)
4597 if (test_conflicting_context_schedule(ctx
) < 0)
4600 if (test_bounded_coefficients_schedule(ctx
) < 0)
4602 if (test_coalescing_schedule(ctx
) < 0)
4604 if (test_skewing_schedule(ctx
) < 0)
4610 /* Perform scheduling tests using the whole component scheduler.
4612 static int test_schedule_whole(isl_ctx
*ctx
)
4617 whole
= isl_options_get_schedule_whole_component(ctx
);
4618 isl_options_set_schedule_whole_component(ctx
, 1);
4619 r
= test_schedule(ctx
);
4621 r
= test_bounded_coefficients_schedule_whole(ctx
);
4622 isl_options_set_schedule_whole_component(ctx
, whole
);
4627 /* Perform scheduling tests using the incremental scheduler.
4629 static int test_schedule_incremental(isl_ctx
*ctx
)
4634 whole
= isl_options_get_schedule_whole_component(ctx
);
4635 isl_options_set_schedule_whole_component(ctx
, 0);
4636 r
= test_schedule(ctx
);
4637 isl_options_set_schedule_whole_component(ctx
, whole
);
4642 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4644 isl_union_map
*umap
;
4647 umap
= isl_union_map_read_from_str(ctx
, str
);
4648 test
= isl_union_map_plain_is_injective(umap
);
4649 isl_union_map_free(umap
);
4652 if (test
== injective
)
4655 isl_die(ctx
, isl_error_unknown
,
4656 "map not detected as injective", return -1);
4658 isl_die(ctx
, isl_error_unknown
,
4659 "map detected as injective", return -1);
4662 int test_injective(isl_ctx
*ctx
)
4666 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4668 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4670 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4672 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4674 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4676 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4678 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4680 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4683 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4684 if (test_plain_injective(ctx
, str
, 1))
4686 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4687 if (test_plain_injective(ctx
, str
, 0))
4693 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4701 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4702 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4708 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4712 equal
= aff_plain_is_equal(aff
, str
);
4716 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4717 "result not as expected", return -1);
4721 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4723 static isl_bool
union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff
*upa
,
4727 isl_union_pw_aff
*upa2
;
4731 return isl_bool_error
;
4733 ctx
= isl_union_pw_aff_get_ctx(upa
);
4734 upa2
= isl_union_pw_aff_read_from_str(ctx
, str
);
4735 equal
= isl_union_pw_aff_plain_is_equal(upa
, upa2
);
4736 isl_union_pw_aff_free(upa2
);
4741 /* Check that "upa" is obviously equal to the isl_union_pw_aff
4742 * represented by "str".
4744 static isl_stat
union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff
*upa
,
4749 equal
= union_pw_aff_plain_is_equal(upa
, str
);
4751 return isl_stat_error
;
4753 isl_die(isl_union_pw_aff_get_ctx(upa
), isl_error_unknown
,
4754 "result not as expected", return isl_stat_error
);
4758 /* Basic tests on isl_union_pw_aff.
4760 * In particular, check that isl_union_pw_aff_aff_on_domain
4761 * aligns the parameters of the input objects and
4762 * that isl_union_pw_aff_param_on_domain_id properly
4763 * introduces the parameter.
4765 static int test_upa(isl_ctx
*ctx
)
4770 isl_union_set
*domain
;
4771 isl_union_pw_aff
*upa
;
4774 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
4775 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
4776 domain
= isl_union_set_read_from_str(ctx
, str
);
4777 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
4778 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
4779 ok
= union_pw_aff_check_plain_equal(upa
, str
);
4780 isl_union_pw_aff_free(upa
);
4784 id
= isl_id_alloc(ctx
, "N", NULL
);
4785 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
4786 domain
= isl_union_set_read_from_str(ctx
, str
);
4787 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
4788 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
4789 ok
= union_pw_aff_check_plain_equal(upa
, str
);
4790 isl_union_pw_aff_free(upa
);
4798 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4799 __isl_take isl_aff
*aff2
);
4801 ['+'] = { &isl_aff_add
},
4802 ['-'] = { &isl_aff_sub
},
4803 ['*'] = { &isl_aff_mul
},
4804 ['/'] = { &isl_aff_div
},
4812 } aff_bin_tests
[] = {
4813 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
4814 "{ [i] -> [2i] }" },
4815 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
4817 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
4818 "{ [i] -> [2i] }" },
4819 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
4820 "{ [i] -> [2i] }" },
4821 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
4822 "{ [i] -> [i/2] }" },
4823 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
4825 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
4826 "{ [i] -> [NaN] }" },
4827 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
4828 "{ [i] -> [NaN] }" },
4829 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
4830 "{ [i] -> [NaN] }" },
4831 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
4832 "{ [i] -> [NaN] }" },
4833 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
4834 "{ [i] -> [NaN] }" },
4835 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
4836 "{ [i] -> [NaN] }" },
4837 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
4838 "{ [i] -> [NaN] }" },
4839 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
4840 "{ [i] -> [NaN] }" },
4841 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
4842 "{ [i] -> [NaN] }" },
4843 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
4844 "{ [i] -> [NaN] }" },
4845 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
4846 "{ [i] -> [NaN] }" },
4847 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
4848 "{ [i] -> [NaN] }" },
4851 /* Perform some basic tests of binary operations on isl_aff objects.
4853 static int test_bin_aff(isl_ctx
*ctx
)
4856 isl_aff
*aff1
, *aff2
, *res
;
4857 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4858 __isl_take isl_aff
*aff2
);
4861 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
4862 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
4863 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
4864 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
4865 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
4866 aff1
= fn(aff1
, aff2
);
4867 if (isl_aff_is_nan(res
))
4868 ok
= isl_aff_is_nan(aff1
);
4870 ok
= isl_aff_plain_is_equal(aff1
, res
);
4876 isl_die(ctx
, isl_error_unknown
,
4877 "unexpected result", return -1);
4884 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
4885 __isl_take isl_pw_aff
*pa2
);
4886 } pw_aff_bin_op
[] = {
4887 ['m'] = { &isl_pw_aff_min
},
4888 ['M'] = { &isl_pw_aff_max
},
4891 /* Inputs for binary isl_pw_aff operation tests.
4892 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
4893 * defined by pw_aff_bin_op, and "res" is the expected result.
4900 } pw_aff_bin_tests
[] = {
4901 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
4903 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
4905 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
4906 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
4907 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
4908 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
4909 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
4910 "{ [i] -> [NaN] }" },
4911 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
4912 "{ [i] -> [NaN] }" },
4915 /* Perform some basic tests of binary operations on isl_pw_aff objects.
4917 static int test_bin_pw_aff(isl_ctx
*ctx
)
4921 isl_pw_aff
*pa1
, *pa2
, *res
;
4923 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
4924 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
4925 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
4926 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
4927 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
4928 if (isl_pw_aff_involves_nan(res
))
4929 ok
= isl_pw_aff_involves_nan(pa1
);
4931 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
4932 isl_pw_aff_free(pa1
);
4933 isl_pw_aff_free(res
);
4937 isl_die(ctx
, isl_error_unknown
,
4938 "unexpected result", return -1);
4945 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4946 __isl_take isl_union_pw_multi_aff
*upma1
,
4947 __isl_take isl_union_pw_multi_aff
*upma2
);
4951 } upma_bin_tests
[] = {
4952 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
4953 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
4954 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
4955 "{ B[x] -> [2] : x >= 0 }",
4956 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
4957 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
4958 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
4959 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
4960 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
4961 "D[i] -> B[2] : i >= 5 }" },
4962 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4963 "{ B[x] -> C[2] : x > 0 }",
4964 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
4965 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4966 "{ B[x] -> A[2] : x >= 0 }",
4967 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
4970 /* Perform some basic tests of binary operations on
4971 * isl_union_pw_multi_aff objects.
4973 static int test_bin_upma(isl_ctx
*ctx
)
4976 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
4979 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
4980 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4981 upma_bin_tests
[i
].arg1
);
4982 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4983 upma_bin_tests
[i
].arg2
);
4984 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
4985 upma_bin_tests
[i
].res
);
4986 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
4987 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
4988 isl_union_pw_multi_aff_free(upma1
);
4989 isl_union_pw_multi_aff_free(res
);
4993 isl_die(ctx
, isl_error_unknown
,
4994 "unexpected result", return -1);
5001 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5002 __isl_take isl_union_pw_multi_aff
*upma1
,
5003 __isl_take isl_union_pw_multi_aff
*upma2
);
5006 } upma_bin_fail_tests
[] = {
5007 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5008 "{ B[x] -> C[2] : x >= 0 }" },
5011 /* Perform some basic tests of binary operations on
5012 * isl_union_pw_multi_aff objects that are expected to fail.
5014 static int test_bin_upma_fail(isl_ctx
*ctx
)
5017 isl_union_pw_multi_aff
*upma1
, *upma2
;
5020 on_error
= isl_options_get_on_error(ctx
);
5021 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5022 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5023 for (i
= 0; i
< n
; ++i
) {
5024 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5025 upma_bin_fail_tests
[i
].arg1
);
5026 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5027 upma_bin_fail_tests
[i
].arg2
);
5028 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5029 isl_union_pw_multi_aff_free(upma1
);
5033 isl_options_set_on_error(ctx
, on_error
);
5035 isl_die(ctx
, isl_error_unknown
,
5036 "operation not expected to succeed", return -1);
5041 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5042 * "fn" is the function that is tested.
5043 * "arg" is a string description of the input.
5044 * "res" is a string description of the expected result.
5047 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5050 } mpa_un_tests
[] = {
5051 { &isl_multi_pw_aff_range_factor_domain
,
5052 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5053 "{ A[x] -> B[(1 : x >= 5)] }" },
5054 { &isl_multi_pw_aff_range_factor_range
,
5055 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5056 "{ A[y] -> C[(2 : y <= 10)] }" },
5057 { &isl_multi_pw_aff_range_factor_domain
,
5058 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5059 "{ A[x] -> B[(1 : x >= 5)] }" },
5060 { &isl_multi_pw_aff_range_factor_range
,
5061 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5062 "{ A[y] -> C[] }" },
5063 { &isl_multi_pw_aff_range_factor_domain
,
5064 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5065 "{ A[x] -> B[] }" },
5066 { &isl_multi_pw_aff_range_factor_range
,
5067 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5068 "{ A[y] -> C[(2 : y <= 10)] }" },
5069 { &isl_multi_pw_aff_range_factor_domain
,
5070 "{ A[x] -> [B[] -> C[]] }",
5071 "{ A[x] -> B[] }" },
5072 { &isl_multi_pw_aff_range_factor_range
,
5073 "{ A[x] -> [B[] -> C[]] }",
5074 "{ A[y] -> C[] }" },
5075 { &isl_multi_pw_aff_factor_range
,
5078 { &isl_multi_pw_aff_range_factor_domain
,
5079 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5080 "{ A[x] -> B[] : x >= 0 }" },
5081 { &isl_multi_pw_aff_range_factor_range
,
5082 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5083 "{ A[y] -> C[] : y >= 0 }" },
5084 { &isl_multi_pw_aff_factor_range
,
5085 "[N] -> { [B[] -> C[]] : N >= 0 }",
5086 "[N] -> { C[] : N >= 0 }" },
5089 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5091 static int test_un_mpa(isl_ctx
*ctx
)
5095 isl_multi_pw_aff
*mpa
, *res
;
5097 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5098 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5099 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5100 mpa
= mpa_un_tests
[i
].fn(mpa
);
5101 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5102 isl_multi_pw_aff_free(mpa
);
5103 isl_multi_pw_aff_free(res
);
5107 isl_die(ctx
, isl_error_unknown
,
5108 "unexpected result", return -1);
5114 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5115 * "fn" is the function that is tested.
5116 * "arg1" and "arg2" are string descriptions of the inputs.
5117 * "res" is a string description of the expected result.
5120 __isl_give isl_multi_pw_aff
*(*fn
)(
5121 __isl_take isl_multi_pw_aff
*mpa1
,
5122 __isl_take isl_multi_pw_aff
*mpa2
);
5126 } mpa_bin_tests
[] = {
5127 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5129 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5130 "{ A[x] -> [(x : x <= 10)] }",
5131 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5132 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5133 "{ A[x] -> [] : x <= 10 }",
5134 "{ A[x] -> [] : 5 <= x <= 10 }" },
5135 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5136 "[N] -> { A[x] -> [] : x <= N }",
5137 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5138 { &isl_multi_pw_aff_add
,
5139 "[N] -> { A[x] -> [] : x <= N }",
5140 "{ A[x] -> [] : x >= 5 }",
5141 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5142 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5143 "{ A[y] -> C[(2 : y <= 10)] }",
5144 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5145 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5146 "{ A[y] -> C[2] : y <= 10 }",
5147 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5148 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5149 "[N] -> { A[y] -> C[2] : y <= N }",
5150 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5151 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5152 "{ A[y] -> C[2] : y <= 10 }",
5153 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5154 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5155 "{ A[] -> [B[1] -> C[2]] }" },
5156 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5157 "{ A[] -> [B[] -> C[]] }" },
5158 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5159 "{ A[y] -> C[] : y <= 10 }",
5160 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5161 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5162 "{ A[x] -> B[(1 : x >= 5)] }",
5163 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5164 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5165 "{ A[y] -> C[(2 : y <= 10)] }",
5166 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5167 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5168 "{ A[y] -> C[] : y <= 10 }",
5169 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5170 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5171 "{ A[x] -> B[(1 : x >= 5)] }",
5172 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5173 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5174 "[N] -> { A[y] -> C[] : y <= N }",
5175 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5176 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5177 "{ A[x] -> B[(1 : x >= 5)] }",
5178 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5179 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5180 "{ A[y] -> C[] : y <= 10 }",
5181 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5182 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5183 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5184 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5185 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5186 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5187 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5188 "{ A[a,b] -> C[b + 2a] }" },
5189 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5190 "{ B[i,j] -> C[i + 2j] }",
5191 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5192 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5193 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5194 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5195 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5196 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5197 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5198 "{ B[i,j] -> C[] }",
5199 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5200 "{ A[a,b] -> C[] }" },
5201 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5202 "{ B[i,j] -> C[] : i > j }",
5203 "{ A[a,b] -> B[b,a] }",
5204 "{ A[a,b] -> C[] : b > a }" },
5205 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5206 "{ B[i,j] -> C[] : j > 5 }",
5207 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5208 "{ A[a,b] -> C[] : b > a > 5 }" },
5209 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5210 "[N] -> { B[i,j] -> C[] : j > N }",
5211 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5212 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5213 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5214 "[M,N] -> { B[] -> C[] : N > 5 }",
5215 "[M,N] -> { A[] -> B[] : M > N }",
5216 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5219 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5221 static int test_bin_mpa(isl_ctx
*ctx
)
5225 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5227 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5228 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5229 mpa_bin_tests
[i
].arg1
);
5230 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5231 mpa_bin_tests
[i
].arg2
);
5232 res
= isl_multi_pw_aff_read_from_str(ctx
,
5233 mpa_bin_tests
[i
].res
);
5234 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5235 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5236 isl_multi_pw_aff_free(mpa1
);
5237 isl_multi_pw_aff_free(res
);
5241 isl_die(ctx
, isl_error_unknown
,
5242 "unexpected result", return -1);
5248 /* Inputs for basic tests of unary operations on
5249 * isl_multi_union_pw_aff objects.
5250 * "fn" is the function that is tested.
5251 * "arg" is a string description of the input.
5252 * "res" is a string description of the expected result.
5255 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5256 __isl_take isl_multi_union_pw_aff
*mupa
);
5259 } mupa_un_tests
[] = {
5260 { &isl_multi_union_pw_aff_factor_range
,
5261 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5262 "C[{ A[] -> [2] }]" },
5263 { &isl_multi_union_pw_aff_factor_range
,
5264 "[B[] -> C[{ A[] -> [2] }]]",
5265 "C[{ A[] -> [2] }]" },
5266 { &isl_multi_union_pw_aff_factor_range
,
5267 "[B[{ A[] -> [1] }] -> C[]]",
5269 { &isl_multi_union_pw_aff_factor_range
,
5272 { &isl_multi_union_pw_aff_factor_range
,
5273 "([B[] -> C[]] : { A[x] : x >= 0 })",
5274 "(C[] : { A[x] : x >= 0 })" },
5275 { &isl_multi_union_pw_aff_factor_range
,
5276 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5277 "[N] -> (C[] : { A[x] : x <= N })" },
5278 { &isl_multi_union_pw_aff_factor_range
,
5279 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5280 "[N] -> (C[] : { : N >= 0 })" },
5283 /* Perform some basic tests of unary operations on
5284 * isl_multi_union_pw_aff objects.
5286 static int test_un_mupa(isl_ctx
*ctx
)
5290 isl_multi_union_pw_aff
*mupa
, *res
;
5292 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5293 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5294 mupa_un_tests
[i
].arg
);
5295 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5296 mupa_un_tests
[i
].res
);
5297 mupa
= mupa_un_tests
[i
].fn(mupa
);
5298 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5299 isl_multi_union_pw_aff_free(mupa
);
5300 isl_multi_union_pw_aff_free(res
);
5304 isl_die(ctx
, isl_error_unknown
,
5305 "unexpected result", return -1);
5311 /* Inputs for basic tests of binary operations on
5312 * isl_multi_union_pw_aff objects.
5313 * "fn" is the function that is tested.
5314 * "arg1" and "arg2" are string descriptions of the inputs.
5315 * "res" is a string description of the expected result.
5318 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5319 __isl_take isl_multi_union_pw_aff
*mupa1
,
5320 __isl_take isl_multi_union_pw_aff
*mupa2
);
5324 } mupa_bin_tests
[] = {
5325 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5326 "[{ A[] -> [3] }]" },
5327 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5328 "[{ A[] -> [-1] }]" },
5329 { &isl_multi_union_pw_aff_add
,
5330 "[{ A[] -> [1]; B[] -> [4] }]",
5331 "[{ A[] -> [2]; C[] -> [5] }]",
5332 "[{ A[] -> [3] }]" },
5333 { &isl_multi_union_pw_aff_union_add
,
5334 "[{ A[] -> [1]; B[] -> [4] }]",
5335 "[{ A[] -> [2]; C[] -> [5] }]",
5336 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5337 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5338 "[{ A[x] -> [(x)] : x <= 10 }]",
5339 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5340 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5341 "([] : { A[x] : x <= 10 })",
5342 "([] : { A[x] : 5 <= x <= 10 })" },
5343 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5344 "[N] -> ([] : { A[x] : x <= N })",
5345 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5346 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5347 "([] : { A[x] : x <= 10 })",
5348 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5349 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5350 "[{ A[x] -> [(x)] : x <= 10 }]",
5351 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5352 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5353 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5354 "([] : { A[x] : x <= 10 })",
5355 "([] : { A[x] })" },
5356 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5357 "[N] -> ([] : { A[x] : x >= N })",
5358 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5359 { &isl_multi_union_pw_aff_union_add
,
5360 "[N] -> ([] : { A[] : N >= 0})",
5361 "[N] -> ([] : { A[] : N <= 0})",
5362 "[N] -> ([] : { A[] })" },
5363 { &isl_multi_union_pw_aff_union_add
,
5364 "[N] -> ([] : { A[] })",
5365 "[N] -> ([] : { : })",
5366 "[N] -> ([] : { : })" },
5367 { &isl_multi_union_pw_aff_union_add
,
5368 "[N] -> ([] : { : })",
5369 "[N] -> ([] : { A[] })",
5370 "[N] -> ([] : { : })" },
5371 { &isl_multi_union_pw_aff_union_add
,
5372 "[N] -> ([] : { : N >= 0})",
5373 "[N] -> ([] : { : N <= 0})",
5374 "[N] -> ([] : { : })" },
5375 { &isl_multi_union_pw_aff_range_product
,
5376 "B[{ A[] -> [1] }]",
5377 "C[{ A[] -> [2] }]",
5378 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5379 { &isl_multi_union_pw_aff_range_product
,
5380 "(B[] : { A[x] : x >= 5 })",
5381 "(C[] : { A[x] : x <= 10 })",
5382 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5383 { &isl_multi_union_pw_aff_range_product
,
5384 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5385 "(C[] : { A[x] : x <= 10 })",
5386 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5387 { &isl_multi_union_pw_aff_range_product
,
5388 "(C[] : { A[x] : x <= 10 })",
5389 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5390 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5391 { &isl_multi_union_pw_aff_range_product
,
5392 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5393 "[N] -> (C[] : { A[x] : x <= N })",
5394 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5395 { &isl_multi_union_pw_aff_range_product
,
5396 "[N] -> (C[] : { A[x] : x <= N })",
5397 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5398 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5399 { &isl_multi_union_pw_aff_range_product
,
5400 "B[{ A[] -> [1]; D[] -> [3] }]",
5401 "C[{ A[] -> [2] }]",
5402 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5405 /* Perform some basic tests of binary operations on
5406 * isl_multi_union_pw_aff objects.
5408 static int test_bin_mupa(isl_ctx
*ctx
)
5412 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
5414 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
5415 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
5416 mupa_bin_tests
[i
].arg1
);
5417 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
5418 mupa_bin_tests
[i
].arg2
);
5419 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5420 mupa_bin_tests
[i
].res
);
5421 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
5422 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
5423 isl_multi_union_pw_aff_free(mupa1
);
5424 isl_multi_union_pw_aff_free(res
);
5428 isl_die(ctx
, isl_error_unknown
,
5429 "unexpected result", return -1);
5435 /* Inputs for basic tests of binary operations on
5436 * pairs of isl_multi_union_pw_aff and isl_set objects.
5437 * "fn" is the function that is tested.
5438 * "arg1" and "arg2" are string descriptions of the inputs.
5439 * "res" is a string description of the expected result.
5442 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5443 __isl_take isl_multi_union_pw_aff
*mupa
,
5444 __isl_take isl_set
*set
);
5448 } mupa_set_tests
[] = {
5449 { &isl_multi_union_pw_aff_intersect_range
,
5450 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5451 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5452 { &isl_multi_union_pw_aff_intersect_range
,
5453 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5454 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5455 { &isl_multi_union_pw_aff_intersect_range
,
5456 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5457 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5458 { &isl_multi_union_pw_aff_intersect_range
,
5459 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5460 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5461 { &isl_multi_union_pw_aff_intersect_range
,
5462 "C[]", "{ C[] }", "C[]" },
5463 { &isl_multi_union_pw_aff_intersect_range
,
5464 "[N] -> (C[] : { : N >= 0 })",
5466 "[N] -> (C[] : { : N >= 0 })" },
5467 { &isl_multi_union_pw_aff_intersect_range
,
5468 "(C[] : { A[a,b] })",
5470 "(C[] : { A[a,b] })" },
5471 { &isl_multi_union_pw_aff_intersect_range
,
5472 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5474 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5475 { &isl_multi_union_pw_aff_intersect_range
,
5477 "[N] -> { C[] : N >= 0 }",
5478 "[N] -> (C[] : { : N >= 0 })" },
5479 { &isl_multi_union_pw_aff_intersect_range
,
5480 "(C[] : { A[a,b] })",
5481 "[N] -> { C[] : N >= 0 }",
5482 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5483 { &isl_multi_union_pw_aff_intersect_range
,
5484 "[N] -> (C[] : { : N >= 0 })",
5485 "[N] -> { C[] : N < 1024 }",
5486 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5487 { &isl_multi_union_pw_aff_intersect_params
,
5488 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5489 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5490 { &isl_multi_union_pw_aff_intersect_params
,
5491 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5492 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5493 { &isl_multi_union_pw_aff_intersect_params
,
5494 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5495 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5496 { &isl_multi_union_pw_aff_intersect_params
,
5497 "C[]", "[N] -> { : N >= 0 }",
5498 "[N] -> (C[] : { : N >= 0 })" },
5499 { &isl_multi_union_pw_aff_intersect_params
,
5500 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5501 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5502 { &isl_multi_union_pw_aff_intersect_params
,
5503 "[N] -> (C[] : { A[a,N] })", "{ : }",
5504 "[N] -> (C[] : { A[a,N] })" },
5505 { &isl_multi_union_pw_aff_intersect_params
,
5506 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5507 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5510 /* Perform some basic tests of binary operations on
5511 * pairs of isl_multi_union_pw_aff and isl_set objects.
5513 static int test_mupa_set(isl_ctx
*ctx
)
5517 isl_multi_union_pw_aff
*mupa
, *res
;
5520 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
5521 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5522 mupa_set_tests
[i
].arg1
);
5523 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
5524 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5525 mupa_set_tests
[i
].res
);
5526 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
5527 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5528 isl_multi_union_pw_aff_free(mupa
);
5529 isl_multi_union_pw_aff_free(res
);
5533 isl_die(ctx
, isl_error_unknown
,
5534 "unexpected result", return -1);
5540 /* Inputs for basic tests of binary operations on
5541 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5542 * "fn" is the function that is tested.
5543 * "arg1" and "arg2" are string descriptions of the inputs.
5544 * "res" is a string description of the expected result.
5547 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5548 __isl_take isl_multi_union_pw_aff
*mupa
,
5549 __isl_take isl_union_set
*uset
);
5553 } mupa_uset_tests
[] = {
5554 { &isl_multi_union_pw_aff_intersect_domain
,
5555 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5556 "C[{ B[i,i] -> [3i] }]" },
5557 { &isl_multi_union_pw_aff_intersect_domain
,
5558 "(C[] : { B[i,j] })", "{ B[i,i] }",
5559 "(C[] : { B[i,i] })" },
5560 { &isl_multi_union_pw_aff_intersect_domain
,
5561 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5562 "[N] -> (C[] : { B[N,N] })" },
5563 { &isl_multi_union_pw_aff_intersect_domain
,
5564 "C[]", "{ B[i,i] }",
5565 "(C[] : { B[i,i] })" },
5566 { &isl_multi_union_pw_aff_intersect_domain
,
5567 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5568 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5571 /* Perform some basic tests of binary operations on
5572 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5574 static int test_mupa_uset(isl_ctx
*ctx
)
5578 isl_multi_union_pw_aff
*mupa
, *res
;
5579 isl_union_set
*uset
;
5581 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
5582 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5583 mupa_uset_tests
[i
].arg1
);
5584 uset
= isl_union_set_read_from_str(ctx
,
5585 mupa_uset_tests
[i
].arg2
);
5586 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5587 mupa_uset_tests
[i
].res
);
5588 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
5589 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5590 isl_multi_union_pw_aff_free(mupa
);
5591 isl_multi_union_pw_aff_free(res
);
5595 isl_die(ctx
, isl_error_unknown
,
5596 "unexpected result", return -1);
5602 /* Inputs for basic tests of binary operations on
5603 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5604 * "fn" is the function that is tested.
5605 * "arg1" and "arg2" are string descriptions of the inputs.
5606 * "res" is a string description of the expected result.
5609 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5610 __isl_take isl_multi_union_pw_aff
*mupa
,
5611 __isl_take isl_multi_aff
*ma
);
5615 } mupa_ma_tests
[] = {
5616 { &isl_multi_union_pw_aff_apply_multi_aff
,
5617 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5618 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5619 "{ C[a,b] -> D[b,a] }",
5620 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5621 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5622 { &isl_multi_union_pw_aff_apply_multi_aff
,
5623 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5624 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5625 "{ C[a,b] -> D[b,a] }",
5626 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5627 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5628 { &isl_multi_union_pw_aff_apply_multi_aff
,
5629 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5630 "[N] -> { C[a] -> D[a + N] }",
5631 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5632 { &isl_multi_union_pw_aff_apply_multi_aff
,
5636 { &isl_multi_union_pw_aff_apply_multi_aff
,
5637 "[N] -> (C[] : { : N >= 0 })",
5639 "[N] -> (D[] : { : N >= 0 })" },
5640 { &isl_multi_union_pw_aff_apply_multi_aff
,
5642 "[N] -> { C[] -> D[N] }",
5643 "[N] -> D[{ [N] }]" },
5644 { &isl_multi_union_pw_aff_apply_multi_aff
,
5645 "(C[] : { A[i,j] : i >= j })",
5647 "(D[] : { A[i,j] : i >= j })" },
5648 { &isl_multi_union_pw_aff_apply_multi_aff
,
5649 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5651 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5652 { &isl_multi_union_pw_aff_apply_multi_aff
,
5653 "(C[] : { A[i,j] : i >= j })",
5654 "[N] -> { C[] -> D[N] }",
5655 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5658 /* Perform some basic tests of binary operations on
5659 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5661 static int test_mupa_ma(isl_ctx
*ctx
)
5665 isl_multi_union_pw_aff
*mupa
, *res
;
5668 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
5669 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5670 mupa_ma_tests
[i
].arg1
);
5671 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
5672 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5673 mupa_ma_tests
[i
].res
);
5674 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
5675 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5676 isl_multi_union_pw_aff_free(mupa
);
5677 isl_multi_union_pw_aff_free(res
);
5681 isl_die(ctx
, isl_error_unknown
,
5682 "unexpected result", return -1);
5688 /* Inputs for basic tests of binary operations on
5689 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5690 * "fn" is the function that is tested.
5691 * "arg1" and "arg2" are string descriptions of the inputs.
5692 * "res" is a string description of the expected result.
5695 __isl_give isl_union_pw_aff
*(*fn
)(
5696 __isl_take isl_multi_union_pw_aff
*mupa
,
5697 __isl_take isl_pw_aff
*pa
);
5701 } mupa_pa_tests
[] = {
5702 { &isl_multi_union_pw_aff_apply_pw_aff
,
5703 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5704 "[N] -> { C[a] -> [a + N] }",
5705 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5706 { &isl_multi_union_pw_aff_apply_pw_aff
,
5707 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5708 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5709 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5710 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5711 { &isl_multi_union_pw_aff_apply_pw_aff
,
5713 "[N] -> { C[] -> [N] }",
5715 { &isl_multi_union_pw_aff_apply_pw_aff
,
5717 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5718 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5719 { &isl_multi_union_pw_aff_apply_pw_aff
,
5720 "[N] -> (C[] : { : N >= 0 })",
5721 "[N] -> { C[] -> [N] }",
5722 "[N] -> { [N] : N >= 0 }" },
5723 { &isl_multi_union_pw_aff_apply_pw_aff
,
5724 "[N] -> (C[] : { : N >= 0 })",
5725 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5726 "[N] -> { [N] : N >= 0 }" },
5727 { &isl_multi_union_pw_aff_apply_pw_aff
,
5728 "[N] -> (C[] : { : N >= 0 })",
5730 "[N] -> { [0] : N >= 0 }" },
5731 { &isl_multi_union_pw_aff_apply_pw_aff
,
5732 "(C[] : { A[i,j] : i >= j })",
5733 "[N] -> { C[] -> [N] }",
5734 "[N] -> { A[i,j] -> [N] : i >= j }" },
5735 { &isl_multi_union_pw_aff_apply_pw_aff
,
5736 "(C[] : { A[i,j] : i >= j })",
5737 "[N] -> { C[] -> [N] : N >= 0 }",
5738 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
5741 /* Perform some basic tests of binary operations on
5742 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5744 static int test_mupa_pa(isl_ctx
*ctx
)
5748 isl_multi_union_pw_aff
*mupa
;
5749 isl_union_pw_aff
*upa
, *res
;
5752 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
5753 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5754 mupa_pa_tests
[i
].arg1
);
5755 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
5756 res
= isl_union_pw_aff_read_from_str(ctx
,
5757 mupa_pa_tests
[i
].res
);
5758 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
5759 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
5760 isl_union_pw_aff_free(upa
);
5761 isl_union_pw_aff_free(res
);
5765 isl_die(ctx
, isl_error_unknown
,
5766 "unexpected result", return -1);
5772 /* Inputs for basic tests of binary operations on
5773 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
5774 * "fn" is the function that is tested.
5775 * "arg1" and "arg2" are string descriptions of the inputs.
5776 * "res" is a string description of the expected result.
5779 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5780 __isl_take isl_multi_union_pw_aff
*mupa
,
5781 __isl_take isl_pw_multi_aff
*pma
);
5785 } mupa_pma_tests
[] = {
5786 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5787 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5788 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5789 "{ C[a,b] -> D[b,a] }",
5790 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5791 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5792 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5793 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5794 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5795 "{ C[a,b] -> D[b,a] }",
5796 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5797 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5798 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5799 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5800 "[N] -> { C[a] -> D[a + N] }",
5801 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
5802 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5803 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5804 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
5805 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5806 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
5807 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5808 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5809 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5810 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
5811 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
5812 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
5813 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
5814 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
5815 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5819 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5820 "[N] -> (C[] : { : N >= 0 })",
5822 "[N] -> (D[] : { : N >= 0 })" },
5823 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5825 "[N] -> { C[] -> D[N] }",
5826 "[N] -> D[{ [N] }]" },
5827 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5828 "(C[] : { A[i,j] : i >= j })",
5830 "(D[] : { A[i,j] : i >= j })" },
5831 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5832 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5834 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5835 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5836 "(C[] : { A[i,j] : i >= j })",
5837 "[N] -> { C[] -> D[N] }",
5838 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5839 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5841 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
5842 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
5843 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5844 "[N] -> (C[] : { : N >= 0 })",
5845 "[N] -> { C[] -> D[N] }",
5846 "[N] -> D[{ [N] : N >= 0 }]" },
5847 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5848 "[N] -> (C[] : { : N >= 0 })",
5849 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
5850 "[N] -> D[{ [N] : N >= 0 }]" },
5851 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5852 "[N] -> (C[] : { : N >= 0 })",
5854 "[N] -> D[{ [0] : N >= 0 }]" },
5855 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5856 "(C[] : { A[i,j] : i >= j })",
5857 "[N] -> { C[] -> D[N] : N >= 0 }",
5858 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
5861 /* Perform some basic tests of binary operations on
5862 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
5864 static int test_mupa_pma(isl_ctx
*ctx
)
5868 isl_multi_union_pw_aff
*mupa
, *res
;
5869 isl_pw_multi_aff
*pma
;
5871 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
5872 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5873 mupa_pma_tests
[i
].arg1
);
5874 pma
= isl_pw_multi_aff_read_from_str(ctx
,
5875 mupa_pma_tests
[i
].arg2
);
5876 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5877 mupa_pma_tests
[i
].res
);
5878 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
5879 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5880 isl_multi_union_pw_aff_free(mupa
);
5881 isl_multi_union_pw_aff_free(res
);
5885 isl_die(ctx
, isl_error_unknown
,
5886 "unexpected result", return -1);
5892 /* Inputs for basic tests of binary operations on
5893 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
5894 * "fn" is the function that is tested.
5895 * "arg1" and "arg2" are string descriptions of the inputs.
5896 * "res" is a string description of the expected result.
5899 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5900 __isl_take isl_multi_union_pw_aff
*mupa
,
5901 __isl_take isl_union_pw_multi_aff
*upma
);
5905 } mupa_upma_tests
[] = {
5906 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5907 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
5908 "C[{ A[a,b] -> [b + 2a] }]" },
5909 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5910 "C[{ B[i,j] -> [i + 2j] }]",
5911 "{ A[a,b] -> B[b,a] : b > a }",
5912 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
5913 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5914 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
5915 "{ A[a,b] -> B[b,a] : b > a }",
5916 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
5917 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5918 "C[{ B[i,j] -> [i + 2j] }]",
5919 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
5920 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
5921 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5922 "(C[] : { B[a,b] })",
5923 "{ A[a,b] -> B[b,a] }",
5924 "(C[] : { A[a,b] })" },
5925 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5926 "(C[] : { B[a,b] })",
5927 "{ B[a,b] -> A[b,a] }",
5929 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5930 "(C[] : { B[a,b] })",
5931 "{ A[a,b] -> B[b,a] : a > b }",
5932 "(C[] : { A[a,b] : a > b })" },
5933 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5934 "(C[] : { B[a,b] : a > b })",
5935 "{ A[a,b] -> B[b,a] }",
5936 "(C[] : { A[a,b] : b > a })" },
5937 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5938 "[N] -> (C[] : { B[a,b] : a > N })",
5939 "{ A[a,b] -> B[b,a] : a > b }",
5940 "[N] -> (C[] : { A[a,b] : a > b > N })" },
5941 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5942 "(C[] : { B[a,b] : a > b })",
5943 "[N] -> { A[a,b] -> B[b,a] : a > N }",
5944 "[N] -> (C[] : { A[a,b] : b > a > N })" },
5945 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5947 "{ A[a,b] -> B[b,a] }",
5949 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5950 "[N] -> (C[] : { : N >= 0 })",
5951 "{ A[a,b] -> B[b,a] }",
5952 "[N] -> (C[] : { : N >= 0 })" },
5953 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5955 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
5956 "[N] -> (C[] : { : N >= 0 })" },
5959 /* Perform some basic tests of binary operations on
5960 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
5962 static int test_mupa_upma(isl_ctx
*ctx
)
5966 isl_multi_union_pw_aff
*mupa
, *res
;
5967 isl_union_pw_multi_aff
*upma
;
5969 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
5970 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5971 mupa_upma_tests
[i
].arg1
);
5972 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5973 mupa_upma_tests
[i
].arg2
);
5974 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5975 mupa_upma_tests
[i
].res
);
5976 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
5977 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5978 isl_multi_union_pw_aff_free(mupa
);
5979 isl_multi_union_pw_aff_free(res
);
5983 isl_die(ctx
, isl_error_unknown
,
5984 "unexpected result", return -1);
5990 int test_aff(isl_ctx
*ctx
)
5995 isl_local_space
*ls
;
5999 if (test_upa(ctx
) < 0)
6001 if (test_bin_aff(ctx
) < 0)
6003 if (test_bin_pw_aff(ctx
) < 0)
6005 if (test_bin_upma(ctx
) < 0)
6007 if (test_bin_upma_fail(ctx
) < 0)
6009 if (test_un_mpa(ctx
) < 0)
6011 if (test_bin_mpa(ctx
) < 0)
6013 if (test_un_mupa(ctx
) < 0)
6015 if (test_bin_mupa(ctx
) < 0)
6017 if (test_mupa_set(ctx
) < 0)
6019 if (test_mupa_uset(ctx
) < 0)
6021 if (test_mupa_ma(ctx
) < 0)
6023 if (test_mupa_pa(ctx
) < 0)
6025 if (test_mupa_pma(ctx
) < 0)
6027 if (test_mupa_upma(ctx
) < 0)
6030 space
= isl_space_set_alloc(ctx
, 0, 1);
6031 ls
= isl_local_space_from_space(space
);
6032 aff
= isl_aff_zero_on_domain(ls
);
6034 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6035 aff
= isl_aff_scale_down_ui(aff
, 3);
6036 aff
= isl_aff_floor(aff
);
6037 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6038 aff
= isl_aff_scale_down_ui(aff
, 2);
6039 aff
= isl_aff_floor(aff
);
6040 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6043 set
= isl_set_read_from_str(ctx
, str
);
6044 aff
= isl_aff_gist(aff
, set
);
6046 aff
= isl_aff_add_constant_si(aff
, -16);
6047 zero
= isl_aff_plain_is_zero(aff
);
6053 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6055 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6056 aff
= isl_aff_scale_down_ui(aff
, 64);
6057 aff
= isl_aff_floor(aff
);
6058 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6066 /* Check that "pa" consists of a single expression.
6068 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
6072 n
= isl_pw_aff_n_piece(pa
);
6073 isl_pw_aff_free(pa
);
6078 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
6084 /* Check that the computation below results in a single expression.
6085 * One or two expressions may result depending on which constraint
6086 * ends up being considered as redundant with respect to the other
6087 * constraints after the projection that is performed internally
6088 * by isl_set_dim_min.
6090 static int test_dim_max_1(isl_ctx
*ctx
)
6096 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6097 "-4a <= b <= 3 and b < n - 4a }";
6098 set
= isl_set_read_from_str(ctx
, str
);
6099 pa
= isl_set_dim_min(set
, 0);
6100 return check_single_piece(ctx
, pa
);
6103 /* Check that the computation below results in a single expression.
6104 * The PIP problem corresponding to these constraints has a row
6105 * that causes a split of the solution domain. The solver should
6106 * first pick rows that split off empty parts such that the actual
6107 * solution domain does not get split.
6108 * Note that the description contains some redundant constraints.
6109 * If these constraints get removed first, then the row mentioned
6110 * above does not appear in the PIP problem.
6112 static int test_dim_max_2(isl_ctx
*ctx
)
6118 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6119 "N > 0 and P >= 0 }";
6120 set
= isl_set_read_from_str(ctx
, str
);
6121 pa
= isl_set_dim_max(set
, 0);
6122 return check_single_piece(ctx
, pa
);
6125 int test_dim_max(isl_ctx
*ctx
)
6129 isl_set
*set1
, *set2
;
6134 if (test_dim_max_1(ctx
) < 0)
6136 if (test_dim_max_2(ctx
) < 0)
6139 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
6140 set
= isl_set_read_from_str(ctx
, str
);
6141 pwaff
= isl_set_dim_max(set
, 0);
6142 set1
= isl_set_from_pw_aff(pwaff
);
6143 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6144 set2
= isl_set_read_from_str(ctx
, str
);
6145 equal
= isl_set_is_equal(set1
, set2
);
6151 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6153 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6154 set
= isl_set_read_from_str(ctx
, str
);
6155 pwaff
= isl_set_dim_max(set
, 0);
6156 set1
= isl_set_from_pw_aff(pwaff
);
6157 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6158 set2
= isl_set_read_from_str(ctx
, str
);
6159 equal
= isl_set_is_equal(set1
, set2
);
6165 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6167 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6168 set
= isl_set_read_from_str(ctx
, str
);
6169 pwaff
= isl_set_dim_max(set
, 0);
6170 set1
= isl_set_from_pw_aff(pwaff
);
6171 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6172 set2
= isl_set_read_from_str(ctx
, str
);
6173 equal
= isl_set_is_equal(set1
, set2
);
6179 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6181 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6182 "0 <= i < N and 0 <= j < M }";
6183 map
= isl_map_read_from_str(ctx
, str
);
6184 set
= isl_map_range(map
);
6186 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
6187 set1
= isl_set_from_pw_aff(pwaff
);
6188 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6189 set2
= isl_set_read_from_str(ctx
, str
);
6190 equal
= isl_set_is_equal(set1
, set2
);
6194 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
6195 set1
= isl_set_from_pw_aff(pwaff
);
6196 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6197 set2
= isl_set_read_from_str(ctx
, str
);
6198 if (equal
>= 0 && equal
)
6199 equal
= isl_set_is_equal(set1
, set2
);
6208 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6210 /* Check that solutions are properly merged. */
6211 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
6212 "c <= -1 + n - 4a - 2b and c >= -2b and "
6213 "4a >= -4 + n and c >= 0 }";
6214 set
= isl_set_read_from_str(ctx
, str
);
6215 pwaff
= isl_set_dim_min(set
, 2);
6216 set1
= isl_set_from_pw_aff(pwaff
);
6217 str
= "[n] -> { [(0)] : n >= 1 }";
6218 set2
= isl_set_read_from_str(ctx
, str
);
6219 equal
= isl_set_is_equal(set1
, set2
);
6226 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6228 /* Check that empty solution lie in the right space. */
6229 str
= "[n] -> { [t,a] : 1 = 0 }";
6230 set
= isl_set_read_from_str(ctx
, str
);
6231 pwaff
= isl_set_dim_max(set
, 0);
6232 set1
= isl_set_from_pw_aff(pwaff
);
6233 str
= "[n] -> { [t] : 1 = 0 }";
6234 set2
= isl_set_read_from_str(ctx
, str
);
6235 equal
= isl_set_is_equal(set1
, set2
);
6242 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6247 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6249 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
6253 isl_pw_multi_aff
*pma2
;
6259 ctx
= isl_pw_multi_aff_get_ctx(pma
);
6260 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6261 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
6262 isl_pw_multi_aff_free(pma2
);
6267 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6268 * represented by "str".
6270 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
6275 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
6279 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
6280 "result not as expected", return -1);
6284 /* Basic test for isl_pw_multi_aff_product.
6286 * Check that multiple pieces are properly handled.
6288 static int test_product_pma(isl_ctx
*ctx
)
6292 isl_pw_multi_aff
*pma1
, *pma2
;
6294 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6295 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6296 str
= "{ C[] -> D[] }";
6297 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6298 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
6299 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6300 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6301 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
6302 isl_pw_multi_aff_free(pma1
);
6309 int test_product(isl_ctx
*ctx
)
6313 isl_union_set
*uset1
, *uset2
;
6317 set
= isl_set_read_from_str(ctx
, str
);
6318 set
= isl_set_product(set
, isl_set_copy(set
));
6319 ok
= isl_set_is_wrapping(set
);
6324 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6327 uset1
= isl_union_set_read_from_str(ctx
, str
);
6328 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
6329 str
= "{ [[] -> []] }";
6330 uset2
= isl_union_set_read_from_str(ctx
, str
);
6331 ok
= isl_union_set_is_equal(uset1
, uset2
);
6332 isl_union_set_free(uset1
);
6333 isl_union_set_free(uset2
);
6337 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6339 if (test_product_pma(ctx
) < 0)
6345 /* Check that two sets are not considered disjoint just because
6346 * they have a different set of (named) parameters.
6348 static int test_disjoint(isl_ctx
*ctx
)
6351 isl_set
*set
, *set2
;
6354 str
= "[n] -> { [[]->[]] }";
6355 set
= isl_set_read_from_str(ctx
, str
);
6356 str
= "{ [[]->[]] }";
6357 set2
= isl_set_read_from_str(ctx
, str
);
6358 disjoint
= isl_set_is_disjoint(set
, set2
);
6364 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6369 /* Inputs for isl_pw_multi_aff_is_equal tests.
6370 * "f1" and "f2" are the two function that need to be compared.
6371 * "equal" is the expected result.
6377 } pma_equal_tests
[] = {
6378 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6379 "[N] -> { [0] : 0 <= N <= 1 }" },
6380 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6381 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6382 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6383 "[N] -> { [0] : 0 <= N <= 1 }" },
6384 { 0, "{ [NaN] }", "{ [NaN] }" },
6387 int test_equal(isl_ctx
*ctx
)
6391 isl_set
*set
, *set2
;
6395 set
= isl_set_read_from_str(ctx
, str
);
6397 set2
= isl_set_read_from_str(ctx
, str
);
6398 equal
= isl_set_is_equal(set
, set2
);
6404 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6406 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
6407 int expected
= pma_equal_tests
[i
].equal
;
6408 isl_pw_multi_aff
*f1
, *f2
;
6410 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
6411 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
6412 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
6413 isl_pw_multi_aff_free(f1
);
6414 isl_pw_multi_aff_free(f2
);
6417 if (equal
!= expected
)
6418 isl_die(ctx
, isl_error_unknown
,
6419 "unexpected equality result", return -1);
6425 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
6426 enum isl_dim_type type
, unsigned pos
, int fixed
)
6430 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
6437 isl_die(ctx
, isl_error_unknown
,
6438 "map not detected as fixed", return -1);
6440 isl_die(ctx
, isl_error_unknown
,
6441 "map detected as fixed", return -1);
6444 int test_fixed(isl_ctx
*ctx
)
6449 str
= "{ [i] -> [i] }";
6450 map
= isl_map_read_from_str(ctx
, str
);
6451 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
6453 str
= "{ [i] -> [1] }";
6454 map
= isl_map_read_from_str(ctx
, str
);
6455 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6457 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6458 map
= isl_map_read_from_str(ctx
, str
);
6459 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6461 map
= isl_map_read_from_str(ctx
, str
);
6462 map
= isl_map_neg(map
);
6463 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6469 struct isl_vertices_test_data
{
6472 const char *vertex
[6];
6473 } vertices_tests
[] = {
6474 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6475 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6476 { "{ A[t, i] : t = 14 and i = 1 }",
6477 1, { "{ A[14, 1] }" } },
6478 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6479 "c <= m and m <= n and m > 0 }",
6481 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6482 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6483 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6484 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6485 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6486 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6490 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
6492 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
6494 struct isl_vertices_test_data
*data
= user
;
6497 isl_basic_set
*bset
;
6498 isl_pw_multi_aff
*pma
;
6502 ctx
= isl_vertex_get_ctx(vertex
);
6503 bset
= isl_vertex_get_domain(vertex
);
6504 ma
= isl_vertex_get_expr(vertex
);
6505 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
6507 for (i
= 0; i
< data
->n
; ++i
) {
6508 isl_pw_multi_aff
*pma_i
;
6510 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
6511 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
6512 isl_pw_multi_aff_free(pma_i
);
6514 if (equal
< 0 || equal
)
6518 isl_pw_multi_aff_free(pma
);
6519 isl_vertex_free(vertex
);
6522 return isl_stat_error
;
6524 return equal
? isl_stat_ok
: isl_stat_error
;
6527 int test_vertices(isl_ctx
*ctx
)
6531 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
6532 isl_basic_set
*bset
;
6533 isl_vertices
*vertices
;
6537 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
6538 vertices
= isl_basic_set_compute_vertices(bset
);
6539 n
= isl_vertices_get_n_vertices(vertices
);
6540 if (vertices_tests
[i
].n
!= n
)
6542 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
6543 &vertices_tests
[i
]) < 0)
6545 isl_vertices_free(vertices
);
6546 isl_basic_set_free(bset
);
6551 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
6558 int test_union_pw(isl_ctx
*ctx
)
6562 isl_union_set
*uset
;
6563 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
6565 str
= "{ [x] -> x^2 }";
6566 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6567 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
6568 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
6569 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
6570 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
6571 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
6572 isl_union_pw_qpolynomial_free(upwqp1
);
6573 isl_union_pw_qpolynomial_free(upwqp2
);
6577 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6582 /* Inputs for basic tests of functions that select
6583 * subparts of the domain of an isl_multi_union_pw_aff.
6584 * "fn" is the function that is tested.
6585 * "arg" is a string description of the input.
6586 * "res" is a string description of the expected result.
6589 __isl_give isl_union_set
*(*fn
)(
6590 __isl_take isl_multi_union_pw_aff
*mupa
);
6593 } un_locus_tests
[] = {
6594 { &isl_multi_union_pw_aff_zero_union_set
,
6595 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6596 "{ A[0,j]; B[0,j] }" },
6597 { &isl_multi_union_pw_aff_zero_union_set
,
6598 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
6599 "{ A[i,i]; B[i,i] : i >= 0 }" },
6600 { &isl_multi_union_pw_aff_zero_union_set
,
6601 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
6602 "{ A[i,j]; B[i,i] : i >= 0 }" },
6605 /* Perform some basic tests of functions that select
6606 * subparts of the domain of an isl_multi_union_pw_aff.
6608 static int test_un_locus(isl_ctx
*ctx
)
6612 isl_union_set
*uset
, *res
;
6613 isl_multi_union_pw_aff
*mupa
;
6615 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
6616 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6617 un_locus_tests
[i
].arg
);
6618 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
6619 uset
= un_locus_tests
[i
].fn(mupa
);
6620 ok
= isl_union_set_is_equal(uset
, res
);
6621 isl_union_set_free(uset
);
6622 isl_union_set_free(res
);
6626 isl_die(ctx
, isl_error_unknown
,
6627 "unexpected result", return -1);
6633 /* Inputs for basic tests of functions that select
6634 * subparts of an isl_union_map based on a relation
6635 * specified by an isl_multi_union_pw_aff.
6636 * "fn" is the function that is tested.
6637 * "arg1" and "arg2" are string descriptions of the inputs.
6638 * "res" is a string description of the expected result.
6641 __isl_give isl_union_map
*(*fn
)(
6642 __isl_take isl_union_map
*umap
,
6643 __isl_take isl_multi_union_pw_aff
*mupa
);
6647 } bin_locus_tests
[] = {
6648 { &isl_union_map_eq_at_multi_union_pw_aff
,
6649 "{ A[i,j] -> B[i',j'] }",
6650 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6651 "{ A[i,j] -> B[i,j'] }" },
6652 { &isl_union_map_eq_at_multi_union_pw_aff
,
6653 "{ A[i,j] -> B[i',j'] }",
6654 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6655 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6656 "{ A[i,j] -> B[i,j] }" },
6657 { &isl_union_map_eq_at_multi_union_pw_aff
,
6658 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6659 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6660 "{ A[i,j] -> B[i,j'] }" },
6661 { &isl_union_map_eq_at_multi_union_pw_aff
,
6662 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6663 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
6664 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
6665 { &isl_union_map_eq_at_multi_union_pw_aff
,
6666 "{ A[i,j] -> B[i',j'] }",
6667 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
6668 "{ A[i,j] -> B[i,j'] : i > j }" },
6669 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
6670 "{ A[i,j] -> B[i',j'] }",
6671 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6672 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6673 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
6674 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
6675 "{ A[i,j] -> B[i',j'] }",
6676 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6677 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6678 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
6679 { &isl_union_map_eq_at_multi_union_pw_aff
,
6680 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6681 "(F[] : { A[i,j]; B[i,j] })",
6682 "{ A[i,j] -> B[i',j'] }" },
6683 { &isl_union_map_eq_at_multi_union_pw_aff
,
6684 "{ A[i,j] -> B[i',j'] }",
6685 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6686 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
6687 { &isl_union_map_eq_at_multi_union_pw_aff
,
6688 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
6689 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6690 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
6691 { &isl_union_map_eq_at_multi_union_pw_aff
,
6692 "{ A[i,j] -> B[i',j'] }",
6693 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
6694 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
6695 { &isl_union_map_eq_at_multi_union_pw_aff
,
6696 "{ A[i,j] -> B[i',j'] }",
6697 "[N] -> (F[] : { : N >= 0 })",
6698 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
6701 /* Perform some basic tests of functions that select
6702 * subparts of an isl_union_map based on a relation
6703 * specified by an isl_multi_union_pw_aff.
6705 static int test_bin_locus(isl_ctx
*ctx
)
6709 isl_union_map
*umap
, *res
;
6710 isl_multi_union_pw_aff
*mupa
;
6712 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
6713 umap
= isl_union_map_read_from_str(ctx
,
6714 bin_locus_tests
[i
].arg1
);
6715 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6716 bin_locus_tests
[i
].arg2
);
6717 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
6718 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
6719 ok
= isl_union_map_is_equal(umap
, res
);
6720 isl_union_map_free(umap
);
6721 isl_union_map_free(res
);
6725 isl_die(ctx
, isl_error_unknown
,
6726 "unexpected result", return -1);
6732 /* Perform basic locus tests.
6734 static int test_locus(isl_ctx
*ctx
)
6736 if (test_un_locus(ctx
) < 0)
6738 if (test_bin_locus(ctx
) < 0)
6743 /* Test that isl_union_pw_qpolynomial_eval picks up the function
6744 * defined over the correct domain space.
6746 static int test_eval_1(isl_ctx
*ctx
)
6751 isl_union_pw_qpolynomial
*upwqp
;
6755 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
6756 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6758 set
= isl_set_read_from_str(ctx
, str
);
6759 pnt
= isl_set_sample_point(set
);
6760 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
6761 cmp
= isl_val_cmp_si(v
, 36);
6767 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
6772 /* Check that isl_qpolynomial_eval handles getting called on a void point.
6774 static int test_eval_2(isl_ctx
*ctx
)
6779 isl_qpolynomial
*qp
;
6783 str
= "{ A[x] -> [x] }";
6784 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
6785 str
= "{ A[x] : false }";
6786 set
= isl_set_read_from_str(ctx
, str
);
6787 pnt
= isl_set_sample_point(set
);
6788 v
= isl_qpolynomial_eval(qp
, pnt
);
6789 ok
= isl_val_is_nan(v
);
6795 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
6800 /* Perform basic polynomial evaluation tests.
6802 static int test_eval(isl_ctx
*ctx
)
6804 if (test_eval_1(ctx
) < 0)
6806 if (test_eval_2(ctx
) < 0)
6811 /* Descriptions of sets that are tested for reparsing after printing.
6813 const char *output_tests
[] = {
6814 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
6817 "{ [x] : x mod 2 = 0 }",
6818 "{ [x] : x mod 2 = 1 }",
6819 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
6820 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
6821 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
6822 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
6823 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
6824 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
6827 /* Check that printing a set and reparsing a set from the printed output
6828 * results in the same set.
6830 static int test_output_set(isl_ctx
*ctx
)
6834 isl_set
*set1
, *set2
;
6837 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
6838 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
6839 str
= isl_set_to_str(set1
);
6840 set2
= isl_set_read_from_str(ctx
, str
);
6842 equal
= isl_set_is_equal(set1
, set2
);
6848 isl_die(ctx
, isl_error_unknown
,
6849 "parsed output not the same", return -1);
6855 int test_output(isl_ctx
*ctx
)
6863 if (test_output_set(ctx
) < 0)
6866 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
6867 pa
= isl_pw_aff_read_from_str(ctx
, str
);
6869 p
= isl_printer_to_str(ctx
);
6870 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
6871 p
= isl_printer_print_pw_aff(p
, pa
);
6872 s
= isl_printer_get_str(p
);
6873 isl_printer_free(p
);
6874 isl_pw_aff_free(pa
);
6878 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
6883 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6888 int test_sample(isl_ctx
*ctx
)
6891 isl_basic_set
*bset1
, *bset2
;
6894 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
6895 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
6896 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
6897 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
6898 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
6899 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
6900 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
6901 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
6902 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
6903 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
6904 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
6905 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
6906 "d - 1073741821e and "
6907 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
6908 "3j >= 1 - a + b + 2e and "
6909 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
6910 "3i <= 4 - a + 4b - e and "
6911 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
6912 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
6913 "c <= -1 + a and 3i >= -2 - a + 3e and "
6914 "1073741822e <= 1073741823 - a + 1073741822b + c and "
6915 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
6916 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
6917 "1073741823e >= 1 + 1073741823b - d and "
6918 "3i >= 1073741823b + c - 1073741823e - f and "
6919 "3i >= 1 + 2b + e + 3g }";
6920 bset1
= isl_basic_set_read_from_str(ctx
, str
);
6921 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
6922 empty
= isl_basic_set_is_empty(bset2
);
6923 subset
= isl_basic_set_is_subset(bset2
, bset1
);
6924 isl_basic_set_free(bset1
);
6925 isl_basic_set_free(bset2
);
6926 if (empty
< 0 || subset
< 0)
6929 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
6931 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
6936 int test_fixed_power(isl_ctx
*ctx
)
6943 str
= "{ [i] -> [i + 1] }";
6944 map
= isl_map_read_from_str(ctx
, str
);
6945 exp
= isl_val_int_from_si(ctx
, 23);
6946 map
= isl_map_fixed_power_val(map
, exp
);
6947 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
6955 int test_slice(isl_ctx
*ctx
)
6961 str
= "{ [i] -> [j] }";
6962 map
= isl_map_read_from_str(ctx
, str
);
6963 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
6964 equal
= map_check_equal(map
, "{ [i] -> [i] }");
6969 str
= "{ [i] -> [j] }";
6970 map
= isl_map_read_from_str(ctx
, str
);
6971 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
6972 equal
= map_check_equal(map
, "{ [i] -> [j] }");
6977 str
= "{ [i] -> [j] }";
6978 map
= isl_map_read_from_str(ctx
, str
);
6979 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
6980 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
6985 str
= "{ [i] -> [j] }";
6986 map
= isl_map_read_from_str(ctx
, str
);
6987 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
6988 equal
= map_check_equal(map
, "{ [0] -> [j] }");
6993 str
= "{ [i] -> [j] }";
6994 map
= isl_map_read_from_str(ctx
, str
);
6995 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
6996 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
7001 str
= "{ [i] -> [j] }";
7002 map
= isl_map_read_from_str(ctx
, str
);
7003 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7004 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
7012 int test_eliminate(isl_ctx
*ctx
)
7018 str
= "{ [i] -> [j] : i = 2j }";
7019 map
= isl_map_read_from_str(ctx
, str
);
7020 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
7021 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
7029 /* Check that isl_set_dim_residue_class detects that the values of j
7030 * in the set below are all odd and that it does not detect any spurious
7033 static int test_residue_class(isl_ctx
*ctx
)
7040 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7041 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7042 set
= isl_set_read_from_str(ctx
, str
);
7045 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
7047 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
7048 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
7049 res
= isl_stat_error
);
7057 int test_align_parameters(isl_ctx
*ctx
)
7061 isl_multi_aff
*ma1
, *ma2
;
7064 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7065 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
7067 space
= isl_space_params_alloc(ctx
, 1);
7068 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
7069 ma1
= isl_multi_aff_align_params(ma1
, space
);
7071 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7072 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7074 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7076 isl_multi_aff_free(ma1
);
7077 isl_multi_aff_free(ma2
);
7082 isl_die(ctx
, isl_error_unknown
,
7083 "result not as expected", return -1);
7088 static int test_list(isl_ctx
*ctx
)
7090 isl_id
*a
, *b
, *c
, *d
, *id
;
7094 a
= isl_id_alloc(ctx
, "a", NULL
);
7095 b
= isl_id_alloc(ctx
, "b", NULL
);
7096 c
= isl_id_alloc(ctx
, "c", NULL
);
7097 d
= isl_id_alloc(ctx
, "d", NULL
);
7099 list
= isl_id_list_alloc(ctx
, 4);
7100 list
= isl_id_list_add(list
, b
);
7101 list
= isl_id_list_insert(list
, 0, a
);
7102 list
= isl_id_list_add(list
, c
);
7103 list
= isl_id_list_add(list
, d
);
7104 list
= isl_id_list_drop(list
, 1, 1);
7108 if (isl_id_list_n_id(list
) != 3) {
7109 isl_id_list_free(list
);
7110 isl_die(ctx
, isl_error_unknown
,
7111 "unexpected number of elements in list", return -1);
7114 id
= isl_id_list_get_id(list
, 0);
7117 id
= isl_id_list_get_id(list
, 1);
7120 id
= isl_id_list_get_id(list
, 2);
7124 isl_id_list_free(list
);
7127 isl_die(ctx
, isl_error_unknown
,
7128 "unexpected elements in list", return -1);
7133 const char *set_conversion_tests
[] = {
7134 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7135 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7136 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7137 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7138 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7139 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7140 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7141 "-3 + c <= d <= 28 + c) }",
7144 /* Check that converting from isl_set to isl_pw_multi_aff and back
7145 * to isl_set produces the original isl_set.
7147 static int test_set_conversion(isl_ctx
*ctx
)
7151 isl_set
*set1
, *set2
;
7152 isl_pw_multi_aff
*pma
;
7155 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
7156 str
= set_conversion_tests
[i
];
7157 set1
= isl_set_read_from_str(ctx
, str
);
7158 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
7159 set2
= isl_set_from_pw_multi_aff(pma
);
7160 equal
= isl_set_is_equal(set1
, set2
);
7167 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7174 const char *conversion_tests
[] = {
7175 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7176 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7177 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7178 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7180 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7181 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7182 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7185 /* Check that converting from isl_map to isl_pw_multi_aff and back
7186 * to isl_map produces the original isl_map.
7188 static int test_map_conversion(isl_ctx
*ctx
)
7191 isl_map
*map1
, *map2
;
7192 isl_pw_multi_aff
*pma
;
7195 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
7196 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
7197 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
7198 map2
= isl_map_from_pw_multi_aff(pma
);
7199 equal
= isl_map_is_equal(map1
, map2
);
7206 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7213 /* Descriptions of isl_pw_multi_aff objects for testing conversion
7214 * to isl_multi_pw_aff and back.
7216 const char *mpa_conversion_tests
[] = {
7218 "{ [x] -> A[x] : x >= 0 }",
7219 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
7220 "{ [x] -> A[x, x + 1] }",
7222 "{ [x] -> A[] : x >= 0 }",
7225 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
7226 * back to isl_pw_multi_aff preserves the original meaning.
7228 static int test_mpa_conversion(isl_ctx
*ctx
)
7231 isl_pw_multi_aff
*pma1
, *pma2
;
7232 isl_multi_pw_aff
*mpa
;
7235 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
7237 str
= mpa_conversion_tests
[i
];
7238 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7239 pma2
= isl_pw_multi_aff_copy(pma1
);
7240 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
7241 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
7242 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
7243 isl_pw_multi_aff_free(pma1
);
7244 isl_pw_multi_aff_free(pma2
);
7249 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7256 /* Descriptions of union maps that should be convertible
7257 * to an isl_multi_union_pw_aff.
7259 const char *umap_mupa_conversion_tests
[] = {
7260 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7261 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7262 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7263 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7265 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7266 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7267 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7268 "{ A[] -> B[0]; C[] -> B[1] }",
7269 "{ A[] -> B[]; C[] -> B[] }",
7272 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
7273 * to isl_union_map produces the original isl_union_map.
7275 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
7278 isl_union_map
*umap1
, *umap2
;
7279 isl_multi_union_pw_aff
*mupa
;
7282 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
7284 str
= umap_mupa_conversion_tests
[i
];
7285 umap1
= isl_union_map_read_from_str(ctx
, str
);
7286 umap2
= isl_union_map_copy(umap1
);
7287 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
7288 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
7289 equal
= isl_union_map_is_equal(umap1
, umap2
);
7290 isl_union_map_free(umap1
);
7291 isl_union_map_free(umap2
);
7296 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7303 static int test_conversion(isl_ctx
*ctx
)
7305 if (test_set_conversion(ctx
) < 0)
7307 if (test_map_conversion(ctx
) < 0)
7309 if (test_mpa_conversion(ctx
) < 0)
7311 if (test_union_map_mupa_conversion(ctx
) < 0)
7316 /* Check that isl_basic_map_curry does not modify input.
7318 static int test_curry(isl_ctx
*ctx
)
7321 isl_basic_map
*bmap1
, *bmap2
;
7324 str
= "{ [A[] -> B[]] -> C[] }";
7325 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
7326 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
7327 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
7328 isl_basic_map_free(bmap1
);
7329 isl_basic_map_free(bmap2
);
7334 isl_die(ctx
, isl_error_unknown
,
7335 "curried map should not be equal to original",
7345 } preimage_tests
[] = {
7346 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
7347 "{ A[j,i] -> B[i,j] }",
7348 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
7349 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7350 "{ A[a,b] -> B[a/2,b/6] }",
7351 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
7352 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7353 "{ A[a,b] -> B[a/2,b/6] }",
7354 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
7355 "exists i,j : a = 2 i and b = 6 j }" },
7356 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
7357 "[n] -> { : 0 <= n <= 100 }" },
7358 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7359 "{ A[a] -> B[2a] }",
7360 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
7361 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7362 "{ A[a] -> B[([a/2])] }",
7363 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
7364 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
7365 "{ A[a] -> B[a,a,a/3] }",
7366 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
7367 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
7368 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
7371 static int test_preimage_basic_set(isl_ctx
*ctx
)
7374 isl_basic_set
*bset1
, *bset2
;
7378 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
7379 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
7380 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
7381 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
7382 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
7383 equal
= isl_basic_set_is_equal(bset1
, bset2
);
7384 isl_basic_set_free(bset1
);
7385 isl_basic_set_free(bset2
);
7389 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7400 } preimage_domain_tests
[] = {
7401 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
7402 "{ A[j,i] -> B[i,j] }",
7403 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
7404 { "{ B[i] -> C[i]; D[i] -> E[i] }",
7405 "{ A[i] -> B[i + 1] }",
7406 "{ A[i] -> C[i + 1] }" },
7407 { "{ B[i] -> C[i]; B[i] -> E[i] }",
7408 "{ A[i] -> B[i + 1] }",
7409 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
7410 { "{ B[i] -> C[([i/2])] }",
7411 "{ A[i] -> B[2i] }",
7412 "{ A[i] -> C[i] }" },
7413 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
7414 "{ A[i] -> B[([i/5]), ([i/7])] }",
7415 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
7416 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
7417 "[N] -> { A[] -> B[([N/5])] }",
7418 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
7419 { "{ B[i] -> C[i] : exists a : i = 5 a }",
7420 "{ A[i] -> B[2i] }",
7421 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
7422 { "{ B[i] -> C[i] : exists a : i = 2 a; "
7423 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
7424 "{ A[i] -> B[2i] }",
7425 "{ A[i] -> C[2i] }" },
7426 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
7427 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
7430 static int test_preimage_union_map(isl_ctx
*ctx
)
7433 isl_union_map
*umap1
, *umap2
;
7437 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
7438 umap1
= isl_union_map_read_from_str(ctx
,
7439 preimage_domain_tests
[i
].map
);
7440 ma
= isl_multi_aff_read_from_str(ctx
,
7441 preimage_domain_tests
[i
].ma
);
7442 umap2
= isl_union_map_read_from_str(ctx
,
7443 preimage_domain_tests
[i
].res
);
7444 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
7445 equal
= isl_union_map_is_equal(umap1
, umap2
);
7446 isl_union_map_free(umap1
);
7447 isl_union_map_free(umap2
);
7451 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7458 static int test_preimage(isl_ctx
*ctx
)
7460 if (test_preimage_basic_set(ctx
) < 0)
7462 if (test_preimage_union_map(ctx
) < 0)
7472 } pullback_tests
[] = {
7473 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
7474 "{ A[a,b] -> C[b + 2a] }" },
7475 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
7476 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
7477 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
7478 "{ A[a] -> C[(a)/6] }" },
7479 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
7480 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
7481 "{ A[a] -> C[(2a)/3] }" },
7482 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
7483 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
7484 "{ A[i,j] -> C[i + j, i + j] }"},
7485 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
7486 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
7487 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
7488 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
7489 "{ [i, j] -> [floor((i)/3), j] }",
7490 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
7493 static int test_pullback(isl_ctx
*ctx
)
7496 isl_multi_aff
*ma1
, *ma2
;
7500 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
7501 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
7502 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
7503 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
7504 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
7505 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7506 isl_multi_aff_free(ma1
);
7507 isl_multi_aff_free(ma2
);
7511 isl_die(ctx
, isl_error_unknown
, "bad pullback",
7518 /* Check that negation is printed correctly and that equal expressions
7519 * are correctly identified.
7521 static int test_ast(isl_ctx
*ctx
)
7523 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
7527 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
7528 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
7529 expr
= isl_ast_expr_add(expr1
, expr2
);
7530 expr2
= isl_ast_expr_copy(expr
);
7531 expr
= isl_ast_expr_neg(expr
);
7532 expr2
= isl_ast_expr_neg(expr2
);
7533 equal
= isl_ast_expr_is_equal(expr
, expr2
);
7534 str
= isl_ast_expr_to_C_str(expr
);
7535 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
7537 isl_ast_expr_free(expr
);
7538 isl_ast_expr_free(expr2
);
7540 if (ok
< 0 || equal
< 0)
7543 isl_die(ctx
, isl_error_unknown
,
7544 "equal expressions not considered equal", return -1);
7546 isl_die(ctx
, isl_error_unknown
,
7547 "isl_ast_expr printed incorrectly", return -1);
7549 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
7550 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
7551 expr
= isl_ast_expr_add(expr1
, expr2
);
7552 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
7553 expr
= isl_ast_expr_sub(expr3
, expr
);
7554 str
= isl_ast_expr_to_C_str(expr
);
7555 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
7557 isl_ast_expr_free(expr
);
7562 isl_die(ctx
, isl_error_unknown
,
7563 "isl_ast_expr printed incorrectly", return -1);
7568 /* Check that isl_ast_build_expr_from_set returns a valid expression
7569 * for an empty set. Note that isl_ast_build_expr_from_set getting
7570 * called on an empty set probably indicates a bug in the caller.
7572 static int test_ast_build(isl_ctx
*ctx
)
7575 isl_ast_build
*build
;
7578 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7579 build
= isl_ast_build_from_context(set
);
7581 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
7582 expr
= isl_ast_build_expr_from_set(build
, set
);
7584 isl_ast_expr_free(expr
);
7585 isl_ast_build_free(build
);
7593 /* Internal data structure for before_for and after_for callbacks.
7595 * depth is the current depth
7596 * before is the number of times before_for has been called
7597 * after is the number of times after_for has been called
7599 struct isl_test_codegen_data
{
7605 /* This function is called before each for loop in the AST generated
7606 * from test_ast_gen1.
7608 * Increment the number of calls and the depth.
7609 * Check that the space returned by isl_ast_build_get_schedule_space
7610 * matches the target space of the schedule returned by
7611 * isl_ast_build_get_schedule.
7612 * Return an isl_id that is checked by the corresponding call
7615 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
7618 struct isl_test_codegen_data
*data
= user
;
7621 isl_union_map
*schedule
;
7622 isl_union_set
*uset
;
7627 ctx
= isl_ast_build_get_ctx(build
);
7629 if (data
->before
>= 3)
7630 isl_die(ctx
, isl_error_unknown
,
7631 "unexpected number of for nodes", return NULL
);
7632 if (data
->depth
>= 2)
7633 isl_die(ctx
, isl_error_unknown
,
7634 "unexpected depth", return NULL
);
7636 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
7640 schedule
= isl_ast_build_get_schedule(build
);
7641 uset
= isl_union_map_range(schedule
);
7644 if (isl_union_set_n_set(uset
) != 1) {
7645 isl_union_set_free(uset
);
7646 isl_die(ctx
, isl_error_unknown
,
7647 "expecting single range space", return NULL
);
7650 space
= isl_ast_build_get_schedule_space(build
);
7651 set
= isl_union_set_extract_set(uset
, space
);
7652 isl_union_set_free(uset
);
7653 empty
= isl_set_is_empty(set
);
7659 isl_die(ctx
, isl_error_unknown
,
7660 "spaces don't match", return NULL
);
7662 return isl_id_alloc(ctx
, name
, NULL
);
7665 /* This function is called after each for loop in the AST generated
7666 * from test_ast_gen1.
7668 * Increment the number of calls and decrement the depth.
7669 * Check that the annotation attached to the node matches
7670 * the isl_id returned by the corresponding call to before_for.
7672 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
7673 __isl_keep isl_ast_build
*build
, void *user
)
7675 struct isl_test_codegen_data
*data
= user
;
7683 if (data
->after
> data
->before
)
7684 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
7685 "mismatch in number of for nodes",
7686 return isl_ast_node_free(node
));
7688 id
= isl_ast_node_get_annotation(node
);
7690 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
7691 "missing annotation", return isl_ast_node_free(node
));
7693 name
= isl_id_get_name(id
);
7694 valid
= name
&& atoi(name
+ 1) == data
->depth
;
7698 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
7699 "wrong annotation", return isl_ast_node_free(node
));
7704 /* Check that the before_each_for and after_each_for callbacks
7705 * are called for each for loop in the generated code,
7706 * that they are called in the right order and that the isl_id
7707 * returned from the before_each_for callback is attached to
7708 * the isl_ast_node passed to the corresponding after_each_for call.
7710 static int test_ast_gen1(isl_ctx
*ctx
)
7714 isl_union_map
*schedule
;
7715 isl_ast_build
*build
;
7717 struct isl_test_codegen_data data
;
7719 str
= "[N] -> { : N >= 10 }";
7720 set
= isl_set_read_from_str(ctx
, str
);
7721 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
7722 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
7723 schedule
= isl_union_map_read_from_str(ctx
, str
);
7728 build
= isl_ast_build_from_context(set
);
7729 build
= isl_ast_build_set_before_each_for(build
,
7730 &before_for
, &data
);
7731 build
= isl_ast_build_set_after_each_for(build
,
7733 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7734 isl_ast_build_free(build
);
7738 isl_ast_node_free(tree
);
7740 if (data
.before
!= 3 || data
.after
!= 3)
7741 isl_die(ctx
, isl_error_unknown
,
7742 "unexpected number of for nodes", return -1);
7747 /* Check that the AST generator handles domains that are integrally disjoint
7748 * but not rationally disjoint.
7750 static int test_ast_gen2(isl_ctx
*ctx
)
7754 isl_union_map
*schedule
;
7755 isl_union_map
*options
;
7756 isl_ast_build
*build
;
7759 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
7760 schedule
= isl_union_map_read_from_str(ctx
, str
);
7761 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7762 build
= isl_ast_build_from_context(set
);
7764 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
7765 options
= isl_union_map_read_from_str(ctx
, str
);
7766 build
= isl_ast_build_set_options(build
, options
);
7767 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7768 isl_ast_build_free(build
);
7771 isl_ast_node_free(tree
);
7776 /* Increment *user on each call.
7778 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
7779 __isl_keep isl_ast_build
*build
, void *user
)
7788 /* Test that unrolling tries to minimize the number of instances.
7789 * In particular, for the schedule given below, make sure it generates
7790 * 3 nodes (rather than 101).
7792 static int test_ast_gen3(isl_ctx
*ctx
)
7796 isl_union_map
*schedule
;
7797 isl_union_map
*options
;
7798 isl_ast_build
*build
;
7802 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
7803 schedule
= isl_union_map_read_from_str(ctx
, str
);
7804 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7806 str
= "{ [i] -> unroll[0] }";
7807 options
= isl_union_map_read_from_str(ctx
, str
);
7809 build
= isl_ast_build_from_context(set
);
7810 build
= isl_ast_build_set_options(build
, options
);
7811 build
= isl_ast_build_set_at_each_domain(build
,
7812 &count_domains
, &n_domain
);
7813 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7814 isl_ast_build_free(build
);
7818 isl_ast_node_free(tree
);
7821 isl_die(ctx
, isl_error_unknown
,
7822 "unexpected number of for nodes", return -1);
7827 /* Check that if the ast_build_exploit_nested_bounds options is set,
7828 * we do not get an outer if node in the generated AST,
7829 * while we do get such an outer if node if the options is not set.
7831 static int test_ast_gen4(isl_ctx
*ctx
)
7835 isl_union_map
*schedule
;
7836 isl_ast_build
*build
;
7838 enum isl_ast_node_type type
;
7841 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
7842 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
7844 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
7846 schedule
= isl_union_map_read_from_str(ctx
, str
);
7847 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7848 build
= isl_ast_build_from_context(set
);
7849 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7850 isl_ast_build_free(build
);
7854 type
= isl_ast_node_get_type(tree
);
7855 isl_ast_node_free(tree
);
7857 if (type
== isl_ast_node_if
)
7858 isl_die(ctx
, isl_error_unknown
,
7859 "not expecting if node", return -1);
7861 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
7863 schedule
= isl_union_map_read_from_str(ctx
, str
);
7864 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7865 build
= isl_ast_build_from_context(set
);
7866 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7867 isl_ast_build_free(build
);
7871 type
= isl_ast_node_get_type(tree
);
7872 isl_ast_node_free(tree
);
7874 if (type
!= isl_ast_node_if
)
7875 isl_die(ctx
, isl_error_unknown
,
7876 "expecting if node", return -1);
7878 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
7883 /* This function is called for each leaf in the AST generated
7884 * from test_ast_gen5.
7886 * We finalize the AST generation by extending the outer schedule
7887 * with a zero-dimensional schedule. If this results in any for loops,
7888 * then this means that we did not pass along enough information
7889 * about the outer schedule to the inner AST generation.
7891 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
7894 isl_union_map
*schedule
, *extra
;
7897 schedule
= isl_ast_build_get_schedule(build
);
7898 extra
= isl_union_map_copy(schedule
);
7899 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
7900 schedule
= isl_union_map_range_product(schedule
, extra
);
7901 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7902 isl_ast_build_free(build
);
7907 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
7908 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
7909 "code should not contain any for loop",
7910 return isl_ast_node_free(tree
));
7915 /* Check that we do not lose any information when going back and
7916 * forth between internal and external schedule.
7918 * In particular, we create an AST where we unroll the only
7919 * non-constant dimension in the schedule. We therefore do
7920 * not expect any for loops in the AST. However, older versions
7921 * of isl would not pass along enough information about the outer
7922 * schedule when performing an inner code generation from a create_leaf
7923 * callback, resulting in the inner code generation producing a for loop.
7925 static int test_ast_gen5(isl_ctx
*ctx
)
7929 isl_union_map
*schedule
, *options
;
7930 isl_ast_build
*build
;
7933 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
7934 schedule
= isl_union_map_read_from_str(ctx
, str
);
7936 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
7937 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
7938 options
= isl_union_map_read_from_str(ctx
, str
);
7940 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7941 build
= isl_ast_build_from_context(set
);
7942 build
= isl_ast_build_set_options(build
, options
);
7943 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
7944 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7945 isl_ast_build_free(build
);
7946 isl_ast_node_free(tree
);
7953 /* Check that the expression
7955 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
7957 * is not combined into
7961 * as this would result in n/2 being evaluated in parts of
7962 * the definition domain where n is not a multiple of 2.
7964 static int test_ast_expr(isl_ctx
*ctx
)
7968 isl_ast_build
*build
;
7973 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
7974 isl_options_set_ast_build_detect_min_max(ctx
, 1);
7976 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
7977 pa
= isl_pw_aff_read_from_str(ctx
, str
);
7978 build
= isl_ast_build_alloc(ctx
);
7979 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
7980 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
7981 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
7982 isl_ast_build_free(build
);
7983 isl_ast_expr_free(expr
);
7985 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
7990 isl_die(ctx
, isl_error_unknown
,
7991 "expressions should not be combined", return -1);
7996 static int test_ast_gen(isl_ctx
*ctx
)
7998 if (test_ast_gen1(ctx
) < 0)
8000 if (test_ast_gen2(ctx
) < 0)
8002 if (test_ast_gen3(ctx
) < 0)
8004 if (test_ast_gen4(ctx
) < 0)
8006 if (test_ast_gen5(ctx
) < 0)
8008 if (test_ast_expr(ctx
) < 0)
8013 /* Check if dropping output dimensions from an isl_pw_multi_aff
8016 static int test_pw_multi_aff(isl_ctx
*ctx
)
8019 isl_pw_multi_aff
*pma1
, *pma2
;
8022 str
= "{ [i,j] -> [i+j, 4i-j] }";
8023 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8024 str
= "{ [i,j] -> [4i-j] }";
8025 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8027 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
8029 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8031 isl_pw_multi_aff_free(pma1
);
8032 isl_pw_multi_aff_free(pma2
);
8036 isl_die(ctx
, isl_error_unknown
,
8037 "expressions not equal", return -1);
8042 /* Check that we can properly parse multi piecewise affine expressions
8043 * where the piecewise affine expressions have different domains.
8045 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
8048 isl_set
*dom
, *dom2
;
8049 isl_multi_pw_aff
*mpa1
, *mpa2
;
8054 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
8055 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
8056 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
8057 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
8058 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
8059 str
= "{ [i] -> [(i : i > 0), 2i] }";
8060 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8062 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
8064 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
8065 dom
= isl_pw_aff_domain(pa
);
8066 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
8067 dom2
= isl_pw_aff_domain(pa
);
8068 equal_domain
= isl_set_is_equal(dom
, dom2
);
8072 isl_multi_pw_aff_free(mpa1
);
8073 isl_multi_pw_aff_free(mpa2
);
8078 isl_die(ctx
, isl_error_unknown
,
8079 "expressions not equal", return -1);
8081 if (equal_domain
< 0)
8084 isl_die(ctx
, isl_error_unknown
,
8085 "domains unexpectedly equal", return -1);
8090 /* Check that the dimensions in the explicit domain
8091 * of a multi piecewise affine expression are properly
8092 * taken into account.
8094 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
8097 isl_bool involves1
, involves2
, involves3
, equal
;
8098 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
8100 str
= "{ A[x,y] -> B[] : x >= y }";
8101 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8102 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
8103 mpa1
= isl_multi_pw_aff_copy(mpa
);
8105 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
8106 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
8107 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
8108 str
= "{ [a,x,y] -> B[] : x >= y }";
8109 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8110 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8111 isl_multi_pw_aff_free(mpa2
);
8113 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
8114 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
8115 if (equal
>= 0 && equal
)
8116 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
8117 isl_multi_pw_aff_free(mpa1
);
8118 isl_multi_pw_aff_free(mpa
);
8120 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
8123 isl_die(ctx
, isl_error_unknown
,
8124 "incorrect result of dimension insertion/removal",
8125 return isl_stat_error
);
8126 if (!involves1
|| involves2
|| !involves3
)
8127 isl_die(ctx
, isl_error_unknown
,
8128 "incorrect characterization of involved dimensions",
8129 return isl_stat_error
);
8134 /* Perform some tests on multi piecewise affine expressions.
8136 static int test_multi_pw_aff(isl_ctx
*ctx
)
8138 if (test_multi_pw_aff_1(ctx
) < 0)
8140 if (test_multi_pw_aff_2(ctx
) < 0)
8145 /* This is a regression test for a bug where isl_basic_map_simplify
8146 * would end up in an infinite loop. In particular, we construct
8147 * an empty basic set that is not obviously empty.
8148 * isl_basic_set_is_empty marks the basic set as empty.
8149 * After projecting out i3, the variable can be dropped completely,
8150 * but isl_basic_map_simplify refrains from doing so if the basic set
8151 * is empty and would end up in an infinite loop if it didn't test
8152 * explicitly for empty basic maps in the outer loop.
8154 static int test_simplify_1(isl_ctx
*ctx
)
8157 isl_basic_set
*bset
;
8160 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8161 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8162 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8164 bset
= isl_basic_set_read_from_str(ctx
, str
);
8165 empty
= isl_basic_set_is_empty(bset
);
8166 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
8167 isl_basic_set_free(bset
);
8171 isl_die(ctx
, isl_error_unknown
,
8172 "basic set should be empty", return -1);
8177 /* Check that the equality in the set description below
8178 * is simplified away.
8180 static int test_simplify_2(isl_ctx
*ctx
)
8183 isl_basic_set
*bset
;
8186 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
8187 bset
= isl_basic_set_read_from_str(ctx
, str
);
8188 universe
= isl_basic_set_plain_is_universe(bset
);
8189 isl_basic_set_free(bset
);
8194 isl_die(ctx
, isl_error_unknown
,
8195 "equality not simplified away", return -1);
8199 /* Some simplification tests.
8201 static int test_simplify(isl_ctx
*ctx
)
8203 if (test_simplify_1(ctx
) < 0)
8205 if (test_simplify_2(ctx
) < 0)
8210 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
8211 * with gbr context would fail to disable the use of the shifted tableau
8212 * when transferring equalities for the input to the context, resulting
8213 * in invalid sample values.
8215 static int test_partial_lexmin(isl_ctx
*ctx
)
8218 isl_basic_set
*bset
;
8219 isl_basic_map
*bmap
;
8222 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
8223 bmap
= isl_basic_map_read_from_str(ctx
, str
);
8224 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
8225 bset
= isl_basic_set_read_from_str(ctx
, str
);
8226 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
8235 /* Check that the variable compression performed on the existentially
8236 * quantified variables inside isl_basic_set_compute_divs is not confused
8237 * by the implicit equalities among the parameters.
8239 static int test_compute_divs(isl_ctx
*ctx
)
8242 isl_basic_set
*bset
;
8245 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
8246 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
8247 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
8248 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
8249 bset
= isl_basic_set_read_from_str(ctx
, str
);
8250 set
= isl_basic_set_compute_divs(bset
);
8258 /* Check that isl_schedule_get_map is not confused by a schedule tree
8259 * with divergent filter node parameters, as can result from a call
8260 * to isl_schedule_intersect_domain.
8262 static int test_schedule_tree(isl_ctx
*ctx
)
8265 isl_union_set
*uset
;
8266 isl_schedule
*sched1
, *sched2
;
8267 isl_union_map
*umap
;
8269 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
8270 sched1
= isl_schedule_from_domain(uset
);
8271 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
8272 sched2
= isl_schedule_from_domain(uset
);
8274 sched1
= isl_schedule_sequence(sched1
, sched2
);
8275 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
8276 uset
= isl_union_set_read_from_str(ctx
, str
);
8277 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
8278 umap
= isl_schedule_get_map(sched1
);
8279 isl_schedule_free(sched1
);
8280 isl_union_map_free(umap
);
8287 /* Check that a zero-dimensional prefix schedule keeps track
8288 * of the domain and outer filters.
8290 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
8294 isl_union_set
*uset
;
8295 isl_union_set_list
*filters
;
8296 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8297 isl_schedule_node
*node
;
8299 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8300 uset
= isl_union_set_read_from_str(ctx
, str
);
8301 node
= isl_schedule_node_from_domain(uset
);
8302 node
= isl_schedule_node_child(node
, 0);
8304 str
= "{ S1[i,j] : i > j }";
8305 uset
= isl_union_set_read_from_str(ctx
, str
);
8306 filters
= isl_union_set_list_from_union_set(uset
);
8307 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
8308 uset
= isl_union_set_read_from_str(ctx
, str
);
8309 filters
= isl_union_set_list_add(filters
, uset
);
8310 node
= isl_schedule_node_insert_sequence(node
, filters
);
8312 node
= isl_schedule_node_child(node
, 0);
8313 node
= isl_schedule_node_child(node
, 0);
8314 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
8315 str
= "([] : { S1[i,j] : i > j })";
8316 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8317 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8318 isl_multi_union_pw_aff_free(mupa2
);
8319 isl_multi_union_pw_aff_free(mupa
);
8320 isl_schedule_node_free(node
);
8325 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
8331 /* Check that the reaching domain elements and the prefix schedule
8332 * at a leaf node are the same before and after grouping.
8334 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
8339 isl_union_set
*uset
;
8340 isl_multi_union_pw_aff
*mupa
;
8341 isl_union_pw_multi_aff
*upma1
, *upma2
;
8342 isl_union_set
*domain1
, *domain2
;
8343 isl_union_map
*umap1
, *umap2
;
8344 isl_schedule_node
*node
;
8346 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8347 uset
= isl_union_set_read_from_str(ctx
, str
);
8348 node
= isl_schedule_node_from_domain(uset
);
8349 node
= isl_schedule_node_child(node
, 0);
8350 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
8351 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8352 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8353 node
= isl_schedule_node_child(node
, 0);
8354 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
8355 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8356 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8357 node
= isl_schedule_node_child(node
, 0);
8358 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8359 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8360 domain1
= isl_schedule_node_get_domain(node
);
8361 id
= isl_id_alloc(ctx
, "group", NULL
);
8362 node
= isl_schedule_node_parent(node
);
8363 node
= isl_schedule_node_group(node
, id
);
8364 node
= isl_schedule_node_child(node
, 0);
8365 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8366 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8367 domain2
= isl_schedule_node_get_domain(node
);
8368 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
8369 if (equal
>= 0 && equal
)
8370 equal
= isl_union_set_is_equal(domain1
, domain2
);
8371 if (equal
>= 0 && equal
)
8372 equal
= isl_union_map_is_equal(umap1
, umap2
);
8373 isl_union_map_free(umap1
);
8374 isl_union_map_free(umap2
);
8375 isl_union_set_free(domain1
);
8376 isl_union_set_free(domain2
);
8377 isl_union_pw_multi_aff_free(upma1
);
8378 isl_union_pw_multi_aff_free(upma2
);
8379 isl_schedule_node_free(node
);
8384 isl_die(ctx
, isl_error_unknown
,
8385 "expressions not equal", return -1);
8390 /* Check that we can have nested groupings and that the union map
8391 * schedule representation is the same before and after the grouping.
8392 * Note that after the grouping, the union map representation contains
8393 * the domain constraints from the ranges of the expansion nodes,
8394 * while they are missing from the union map representation of
8395 * the tree without expansion nodes.
8397 * Also check that the global expansion is as expected.
8399 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
8401 int equal
, equal_expansion
;
8404 isl_union_set
*uset
;
8405 isl_union_map
*umap1
, *umap2
;
8406 isl_union_map
*expansion1
, *expansion2
;
8407 isl_union_set_list
*filters
;
8408 isl_multi_union_pw_aff
*mupa
;
8409 isl_schedule
*schedule
;
8410 isl_schedule_node
*node
;
8412 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
8413 "S3[i,j] : 0 <= i,j < 10 }";
8414 uset
= isl_union_set_read_from_str(ctx
, str
);
8415 node
= isl_schedule_node_from_domain(uset
);
8416 node
= isl_schedule_node_child(node
, 0);
8417 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
8418 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8419 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8420 node
= isl_schedule_node_child(node
, 0);
8421 str
= "{ S1[i,j] }";
8422 uset
= isl_union_set_read_from_str(ctx
, str
);
8423 filters
= isl_union_set_list_from_union_set(uset
);
8424 str
= "{ S2[i,j]; S3[i,j] }";
8425 uset
= isl_union_set_read_from_str(ctx
, str
);
8426 filters
= isl_union_set_list_add(filters
, uset
);
8427 node
= isl_schedule_node_insert_sequence(node
, filters
);
8428 node
= isl_schedule_node_child(node
, 1);
8429 node
= isl_schedule_node_child(node
, 0);
8430 str
= "{ S2[i,j] }";
8431 uset
= isl_union_set_read_from_str(ctx
, str
);
8432 filters
= isl_union_set_list_from_union_set(uset
);
8433 str
= "{ S3[i,j] }";
8434 uset
= isl_union_set_read_from_str(ctx
, str
);
8435 filters
= isl_union_set_list_add(filters
, uset
);
8436 node
= isl_schedule_node_insert_sequence(node
, filters
);
8438 schedule
= isl_schedule_node_get_schedule(node
);
8439 umap1
= isl_schedule_get_map(schedule
);
8440 uset
= isl_schedule_get_domain(schedule
);
8441 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
8442 isl_schedule_free(schedule
);
8444 node
= isl_schedule_node_parent(node
);
8445 node
= isl_schedule_node_parent(node
);
8446 id
= isl_id_alloc(ctx
, "group1", NULL
);
8447 node
= isl_schedule_node_group(node
, id
);
8448 node
= isl_schedule_node_child(node
, 1);
8449 node
= isl_schedule_node_child(node
, 0);
8450 id
= isl_id_alloc(ctx
, "group2", NULL
);
8451 node
= isl_schedule_node_group(node
, id
);
8453 schedule
= isl_schedule_node_get_schedule(node
);
8454 umap2
= isl_schedule_get_map(schedule
);
8455 isl_schedule_free(schedule
);
8457 node
= isl_schedule_node_root(node
);
8458 node
= isl_schedule_node_child(node
, 0);
8459 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
8460 isl_schedule_node_free(node
);
8462 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
8463 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
8464 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
8466 expansion2
= isl_union_map_read_from_str(ctx
, str
);
8468 equal
= isl_union_map_is_equal(umap1
, umap2
);
8469 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
8471 isl_union_map_free(umap1
);
8472 isl_union_map_free(umap2
);
8473 isl_union_map_free(expansion1
);
8474 isl_union_map_free(expansion2
);
8476 if (equal
< 0 || equal_expansion
< 0)
8479 isl_die(ctx
, isl_error_unknown
,
8480 "expressions not equal", return -1);
8481 if (!equal_expansion
)
8482 isl_die(ctx
, isl_error_unknown
,
8483 "unexpected expansion", return -1);
8488 /* Some tests for the isl_schedule_node_group function.
8490 static int test_schedule_tree_group(isl_ctx
*ctx
)
8492 if (test_schedule_tree_group_1(ctx
) < 0)
8494 if (test_schedule_tree_group_2(ctx
) < 0)
8503 { "{ rat: [i] : 0 <= i <= 10 }",
8504 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
8505 { "{ rat: [i] : FALSE }",
8506 "{ rat: coefficients[[cst] -> [a]] }" },
8508 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
8515 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
8516 "{ rat: [i] : 0 <= i <= 10 }" },
8517 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
8519 { "{ rat: coefficients[[cst] -> [a]] }",
8520 "{ rat: [i] : FALSE }" },
8523 /* Test the basic functionality of isl_basic_set_coefficients and
8524 * isl_basic_set_solutions.
8526 static int test_dual(isl_ctx
*ctx
)
8530 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
8532 isl_basic_set
*bset1
, *bset2
;
8534 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
8535 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
8536 bset1
= isl_basic_set_coefficients(bset1
);
8537 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8538 isl_basic_set_free(bset1
);
8539 isl_basic_set_free(bset2
);
8543 isl_die(ctx
, isl_error_unknown
,
8544 "incorrect dual", return -1);
8547 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
8549 isl_basic_set
*bset1
, *bset2
;
8551 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
8552 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
8553 bset1
= isl_basic_set_solutions(bset1
);
8554 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8555 isl_basic_set_free(bset1
);
8556 isl_basic_set_free(bset2
);
8560 isl_die(ctx
, isl_error_unknown
,
8561 "incorrect dual", return -1);
8571 const char *schedule
;
8576 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
8577 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8579 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
8580 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8582 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
8583 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8585 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
8586 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8588 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
8589 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8591 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
8592 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
8594 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
8595 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8597 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
8598 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
8602 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
8603 * tile the band and then check if the tile and point bands have the
8604 * expected partial schedule.
8606 static int test_tile(isl_ctx
*ctx
)
8612 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
8613 shift
= isl_options_get_tile_shift_point_loops(ctx
);
8615 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
8619 isl_union_set
*domain
;
8620 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8621 isl_schedule_node
*node
;
8622 isl_multi_val
*sizes
;
8624 opt
= tile_tests
[i
].scale_tile
;
8625 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
8626 opt
= tile_tests
[i
].shift_point
;
8627 isl_options_set_tile_shift_point_loops(ctx
, opt
);
8629 str
= tile_tests
[i
].domain
;
8630 domain
= isl_union_set_read_from_str(ctx
, str
);
8631 node
= isl_schedule_node_from_domain(domain
);
8632 node
= isl_schedule_node_child(node
, 0);
8633 str
= tile_tests
[i
].schedule
;
8634 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8635 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8636 str
= tile_tests
[i
].sizes
;
8637 sizes
= isl_multi_val_read_from_str(ctx
, str
);
8638 node
= isl_schedule_node_band_tile(node
, sizes
);
8640 str
= tile_tests
[i
].tile
;
8641 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8642 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
8643 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8644 isl_multi_union_pw_aff_free(mupa
);
8645 isl_multi_union_pw_aff_free(mupa2
);
8647 node
= isl_schedule_node_child(node
, 0);
8649 str
= tile_tests
[i
].point
;
8650 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8651 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
8652 if (equal
>= 0 && equal
)
8653 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
8655 isl_multi_union_pw_aff_free(mupa
);
8656 isl_multi_union_pw_aff_free(mupa2
);
8658 isl_schedule_node_free(node
);
8663 isl_die(ctx
, isl_error_unknown
,
8664 "unexpected result", return -1);
8667 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
8668 isl_options_set_tile_shift_point_loops(ctx
, shift
);
8673 /* Check that the domain hash of a space is equal to the hash
8674 * of the domain of the space.
8676 static int test_domain_hash(isl_ctx
*ctx
)
8680 uint32_t hash1
, hash2
;
8682 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
8683 space
= isl_map_get_space(map
);
8685 hash1
= isl_space_get_domain_hash(space
);
8686 space
= isl_space_domain(space
);
8687 hash2
= isl_space_get_hash(space
);
8688 isl_space_free(space
);
8693 isl_die(ctx
, isl_error_unknown
,
8694 "domain hash not equal to hash of domain", return -1);
8699 /* Check that a universe basic set that is not obviously equal to the universe
8700 * is still recognized as being equal to the universe.
8702 static int test_universe(isl_ctx
*ctx
)
8705 isl_basic_set
*bset
;
8708 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
8709 bset
= isl_basic_set_read_from_str(ctx
, s
);
8710 is_univ
= isl_basic_set_is_universe(bset
);
8711 isl_basic_set_free(bset
);
8716 isl_die(ctx
, isl_error_unknown
,
8717 "not recognized as universe set", return -1);
8722 /* Sets for which chambers are computed and checked.
8724 const char *chambers_tests
[] = {
8725 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
8726 "z >= 0 and z <= C - y and z <= B - x - y }",
8729 /* Add the domain of "cell" to "cells".
8731 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
8733 isl_basic_set_list
**cells
= user
;
8736 dom
= isl_cell_get_domain(cell
);
8737 isl_cell_free(cell
);
8738 *cells
= isl_basic_set_list_add(*cells
, dom
);
8740 return *cells
? isl_stat_ok
: isl_stat_error
;
8743 /* Check that the elements of "list" are pairwise disjoint.
8745 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
8750 return isl_stat_error
;
8752 n
= isl_basic_set_list_n_basic_set(list
);
8753 for (i
= 0; i
< n
; ++i
) {
8754 isl_basic_set
*bset_i
;
8756 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
8757 for (j
= i
+ 1; j
< n
; ++j
) {
8758 isl_basic_set
*bset_j
;
8761 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
8762 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
8763 isl_basic_set_free(bset_j
);
8765 isl_die(isl_basic_set_list_get_ctx(list
),
8766 isl_error_unknown
, "not disjoint",
8768 if (disjoint
< 0 || !disjoint
)
8771 isl_basic_set_free(bset_i
);
8773 return isl_stat_error
;
8779 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
8780 * are pairwise disjoint.
8782 static int test_chambers(isl_ctx
*ctx
)
8786 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
8787 isl_basic_set
*bset
;
8788 isl_vertices
*vertices
;
8789 isl_basic_set_list
*cells
;
8792 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
8793 vertices
= isl_basic_set_compute_vertices(bset
);
8794 cells
= isl_basic_set_list_alloc(ctx
, 0);
8795 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
8797 cells
= isl_basic_set_list_free(cells
);
8798 ok
= check_pairwise_disjoint(cells
);
8799 isl_basic_set_list_free(cells
);
8800 isl_vertices_free(vertices
);
8801 isl_basic_set_free(bset
);
8812 int (*fn
)(isl_ctx
*ctx
);
8814 { "universe", &test_universe
},
8815 { "domain hash", &test_domain_hash
},
8816 { "dual", &test_dual
},
8817 { "dependence analysis", &test_flow
},
8818 { "val", &test_val
},
8819 { "compute divs", &test_compute_divs
},
8820 { "partial lexmin", &test_partial_lexmin
},
8821 { "simplify", &test_simplify
},
8822 { "curry", &test_curry
},
8823 { "piecewise multi affine expressions", &test_pw_multi_aff
},
8824 { "multi piecewise affine expressions", &test_multi_pw_aff
},
8825 { "conversion", &test_conversion
},
8826 { "list", &test_list
},
8827 { "align parameters", &test_align_parameters
},
8828 { "preimage", &test_preimage
},
8829 { "pullback", &test_pullback
},
8830 { "AST", &test_ast
},
8831 { "AST build", &test_ast_build
},
8832 { "AST generation", &test_ast_gen
},
8833 { "eliminate", &test_eliminate
},
8834 { "residue class", &test_residue_class
},
8835 { "div", &test_div
},
8836 { "slice", &test_slice
},
8837 { "fixed power", &test_fixed_power
},
8838 { "sample", &test_sample
},
8839 { "output", &test_output
},
8840 { "vertices", &test_vertices
},
8841 { "chambers", &test_chambers
},
8842 { "fixed", &test_fixed
},
8843 { "equal", &test_equal
},
8844 { "disjoint", &test_disjoint
},
8845 { "product", &test_product
},
8846 { "dim_max", &test_dim_max
},
8847 { "affine", &test_aff
},
8848 { "injective", &test_injective
},
8849 { "schedule (whole component)", &test_schedule_whole
},
8850 { "schedule (incremental)", &test_schedule_incremental
},
8851 { "schedule tree", &test_schedule_tree
},
8852 { "schedule tree prefix", &test_schedule_tree_prefix
},
8853 { "schedule tree grouping", &test_schedule_tree_group
},
8854 { "tile", &test_tile
},
8855 { "union_pw", &test_union_pw
},
8856 { "locus", &test_locus
},
8857 { "eval", &test_eval
},
8858 { "parse", &test_parse
},
8859 { "single-valued", &test_sv
},
8860 { "affine hull", &test_affine_hull
},
8861 { "simple_hull", &test_simple_hull
},
8862 { "coalesce", &test_coalesce
},
8863 { "factorize", &test_factorize
},
8864 { "subset", &test_subset
},
8865 { "subtract", &test_subtract
},
8866 { "intersect", &test_intersect
},
8867 { "lexmin", &test_lexmin
},
8868 { "min", &test_min
},
8869 { "gist", &test_gist
},
8870 { "piecewise quasi-polynomials", &test_pwqp
},
8871 { "lift", &test_lift
},
8872 { "bound", &test_bound
},
8873 { "union", &test_union
},
8874 { "split periods", &test_split_periods
},
8875 { "lexicographic order", &test_lex
},
8876 { "bijectivity", &test_bijective
},
8877 { "dataflow analysis", &test_dep
},
8878 { "reading", &test_read
},
8879 { "bounded", &test_bounded
},
8880 { "construction", &test_construction
},
8881 { "dimension manipulation", &test_dim
},
8882 { "map application", &test_application
},
8883 { "convex hull", &test_convex_hull
},
8884 { "transitive closure", &test_closure
},
8887 int main(int argc
, char **argv
)
8890 struct isl_ctx
*ctx
;
8891 struct isl_options
*options
;
8893 options
= isl_options_new_with_defaults();
8895 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
8897 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
8898 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
8899 printf("%s\n", tests
[i
].name
);
8900 if (tests
[i
].fn(ctx
) < 0)