2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
13 #include <isl_ctx_private.h>
14 #include <isl_map_private.h>
15 #include <isl_aff_private.h>
18 #include <isl/constraint.h>
19 #include <isl/polynomial.h>
20 #include <isl/union_map.h>
21 #include <isl_factorization.h>
22 #include <isl/schedule.h>
23 #include <isl_options_private.h>
24 #include <isl/vertices.h>
26 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
30 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
33 char *pattern
= "%s/test_inputs/%s.%s";
35 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
37 filename
= isl_alloc_array(ctx
, char, length
);
42 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
47 void test_parse_map(isl_ctx
*ctx
, const char *str
)
51 map
= isl_map_read_from_str(ctx
, str
);
56 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
61 map
= isl_map_read_from_str(ctx
, str
);
62 map2
= isl_map_read_from_str(ctx
, str2
);
63 equal
= isl_map_is_equal(map
, map2
);
70 isl_die(ctx
, isl_error_unknown
, "maps not equal",
76 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
78 isl_pw_qpolynomial
*pwqp
;
80 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
82 isl_pw_qpolynomial_free(pwqp
);
85 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
89 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
91 isl_pw_aff_free(pwaff
);
94 int test_parse(struct isl_ctx
*ctx
)
97 const char *str
, *str2
;
99 str
= "{ [i] -> [-i] }";
100 map
= isl_map_read_from_str(ctx
, str
);
104 str
= "{ A[i] -> L[([i/3])] }";
105 map
= isl_map_read_from_str(ctx
, str
);
109 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
110 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
111 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
113 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
114 str2
= "{ [x, y] : 2y >= 6 - x }";
115 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
118 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
119 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
121 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
122 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
126 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
127 map
= isl_map_read_from_str(ctx
, str
);
128 str
= "{ [new, old] -> [o0, o1] : "
129 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
130 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
131 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
132 map2
= isl_map_read_from_str(ctx
, str
);
133 assert(isl_map_is_equal(map
, map2
));
137 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
138 map
= isl_map_read_from_str(ctx
, str
);
139 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
140 map2
= isl_map_read_from_str(ctx
, str
);
141 assert(isl_map_is_equal(map
, map2
));
145 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
146 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
147 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
150 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
151 str2
= "{ [i,j] -> [min(i,j)] }";
152 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
155 str
= "{ [i,j] : i != j }";
156 str2
= "{ [i,j] : i < j or i > j }";
157 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
160 str
= "{ [i,j] : (i+1)*2 >= j }";
161 str2
= "{ [i, j] : j <= 2 + 2i }";
162 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
165 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
166 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
167 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
170 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
171 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
172 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
175 str
= "{ [x] : x >= 0 }";
176 str2
= "{ [x] : x-0 >= 0 }";
177 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
180 str
= "{ [i] : ((i > 10)) }";
181 str2
= "{ [i] : i >= 11 }";
182 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
185 str
= "{ [i] -> [0] }";
186 str2
= "{ [i] -> [0 * i] }";
187 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
190 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
191 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
192 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
193 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
195 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
196 "{ [a] -> [b] : true }") < 0)
202 void test_read(struct isl_ctx
*ctx
)
206 struct isl_basic_set
*bset1
, *bset2
;
207 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
209 filename
= get_filename(ctx
, "set", "omega");
211 input
= fopen(filename
, "r");
214 bset1
= isl_basic_set_read_from_file(ctx
, input
);
215 bset2
= isl_basic_set_read_from_str(ctx
, str
);
217 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
219 isl_basic_set_free(bset1
);
220 isl_basic_set_free(bset2
);
226 void test_bounded(struct isl_ctx
*ctx
)
231 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
232 bounded
= isl_set_is_bounded(set
);
236 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
237 bounded
= isl_set_is_bounded(set
);
241 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
242 bounded
= isl_set_is_bounded(set
);
247 /* Construct the basic set { [i] : 5 <= i <= N } */
248 void test_construction(struct isl_ctx
*ctx
)
253 struct isl_basic_set
*bset
;
254 struct isl_constraint
*c
;
258 dim
= isl_space_set_alloc(ctx
, 1, 1);
259 bset
= isl_basic_set_universe(isl_space_copy(dim
));
260 ls
= isl_local_space_from_space(dim
);
262 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
263 isl_int_set_si(v
, -1);
264 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
265 isl_int_set_si(v
, 1);
266 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
267 bset
= isl_basic_set_add_constraint(bset
, c
);
269 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
270 isl_int_set_si(v
, 1);
271 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
272 isl_int_set_si(v
, -5);
273 isl_constraint_set_constant(c
, v
);
274 bset
= isl_basic_set_add_constraint(bset
, c
);
276 isl_local_space_free(ls
);
277 isl_basic_set_free(bset
);
282 void test_dim(struct isl_ctx
*ctx
)
285 isl_map
*map1
, *map2
;
287 map1
= isl_map_read_from_str(ctx
,
288 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
289 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
290 map2
= isl_map_read_from_str(ctx
,
291 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
292 assert(isl_map_is_equal(map1
, map2
));
295 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
296 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
297 assert(isl_map_is_equal(map1
, map2
));
302 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
303 map1
= isl_map_read_from_str(ctx
, str
);
304 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
305 map2
= isl_map_read_from_str(ctx
, str
);
306 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
307 assert(isl_map_is_equal(map1
, map2
));
313 static int test_div(isl_ctx
*ctx
)
320 struct isl_basic_set
*bset
;
321 struct isl_constraint
*c
;
326 dim
= isl_space_set_alloc(ctx
, 0, 3);
327 bset
= isl_basic_set_universe(isl_space_copy(dim
));
328 ls
= isl_local_space_from_space(dim
);
330 c
= isl_equality_alloc(isl_local_space_copy(ls
));
331 isl_int_set_si(v
, -1);
332 isl_constraint_set_constant(c
, v
);
333 isl_int_set_si(v
, 1);
334 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
335 isl_int_set_si(v
, 3);
336 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
337 bset
= isl_basic_set_add_constraint(bset
, c
);
339 c
= isl_equality_alloc(isl_local_space_copy(ls
));
340 isl_int_set_si(v
, 1);
341 isl_constraint_set_constant(c
, v
);
342 isl_int_set_si(v
, -1);
343 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
344 isl_int_set_si(v
, 3);
345 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
346 bset
= isl_basic_set_add_constraint(bset
, c
);
348 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
350 assert(bset
&& bset
->n_div
== 1);
351 isl_local_space_free(ls
);
352 isl_basic_set_free(bset
);
355 dim
= isl_space_set_alloc(ctx
, 0, 3);
356 bset
= isl_basic_set_universe(isl_space_copy(dim
));
357 ls
= isl_local_space_from_space(dim
);
359 c
= isl_equality_alloc(isl_local_space_copy(ls
));
360 isl_int_set_si(v
, 1);
361 isl_constraint_set_constant(c
, v
);
362 isl_int_set_si(v
, -1);
363 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
364 isl_int_set_si(v
, 3);
365 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
366 bset
= isl_basic_set_add_constraint(bset
, c
);
368 c
= isl_equality_alloc(isl_local_space_copy(ls
));
369 isl_int_set_si(v
, -1);
370 isl_constraint_set_constant(c
, v
);
371 isl_int_set_si(v
, 1);
372 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
373 isl_int_set_si(v
, 3);
374 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
375 bset
= isl_basic_set_add_constraint(bset
, c
);
377 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
379 assert(bset
&& bset
->n_div
== 1);
380 isl_local_space_free(ls
);
381 isl_basic_set_free(bset
);
384 dim
= isl_space_set_alloc(ctx
, 0, 3);
385 bset
= isl_basic_set_universe(isl_space_copy(dim
));
386 ls
= isl_local_space_from_space(dim
);
388 c
= isl_equality_alloc(isl_local_space_copy(ls
));
389 isl_int_set_si(v
, 1);
390 isl_constraint_set_constant(c
, v
);
391 isl_int_set_si(v
, -1);
392 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
393 isl_int_set_si(v
, 3);
394 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
395 bset
= isl_basic_set_add_constraint(bset
, c
);
397 c
= isl_equality_alloc(isl_local_space_copy(ls
));
398 isl_int_set_si(v
, -3);
399 isl_constraint_set_constant(c
, v
);
400 isl_int_set_si(v
, 1);
401 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
402 isl_int_set_si(v
, 4);
403 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
404 bset
= isl_basic_set_add_constraint(bset
, c
);
406 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
408 assert(bset
&& bset
->n_div
== 1);
409 isl_local_space_free(ls
);
410 isl_basic_set_free(bset
);
413 dim
= isl_space_set_alloc(ctx
, 0, 3);
414 bset
= isl_basic_set_universe(isl_space_copy(dim
));
415 ls
= isl_local_space_from_space(dim
);
417 c
= isl_equality_alloc(isl_local_space_copy(ls
));
418 isl_int_set_si(v
, 2);
419 isl_constraint_set_constant(c
, v
);
420 isl_int_set_si(v
, -1);
421 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
422 isl_int_set_si(v
, 3);
423 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
424 bset
= isl_basic_set_add_constraint(bset
, c
);
426 c
= isl_equality_alloc(isl_local_space_copy(ls
));
427 isl_int_set_si(v
, -1);
428 isl_constraint_set_constant(c
, v
);
429 isl_int_set_si(v
, 1);
430 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
431 isl_int_set_si(v
, 6);
432 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
433 bset
= isl_basic_set_add_constraint(bset
, c
);
435 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
437 assert(isl_basic_set_is_empty(bset
));
438 isl_local_space_free(ls
);
439 isl_basic_set_free(bset
);
442 dim
= isl_space_set_alloc(ctx
, 0, 3);
443 bset
= isl_basic_set_universe(isl_space_copy(dim
));
444 ls
= isl_local_space_from_space(dim
);
446 c
= isl_equality_alloc(isl_local_space_copy(ls
));
447 isl_int_set_si(v
, -1);
448 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
449 isl_int_set_si(v
, 3);
450 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
451 bset
= isl_basic_set_add_constraint(bset
, c
);
453 c
= isl_equality_alloc(isl_local_space_copy(ls
));
454 isl_int_set_si(v
, 1);
455 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
456 isl_int_set_si(v
, -3);
457 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
458 bset
= isl_basic_set_add_constraint(bset
, c
);
460 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
462 assert(bset
&& bset
->n_div
== 0);
463 isl_basic_set_free(bset
);
464 isl_local_space_free(ls
);
467 dim
= isl_space_set_alloc(ctx
, 0, 3);
468 bset
= isl_basic_set_universe(isl_space_copy(dim
));
469 ls
= isl_local_space_from_space(dim
);
471 c
= isl_equality_alloc(isl_local_space_copy(ls
));
472 isl_int_set_si(v
, -1);
473 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
474 isl_int_set_si(v
, 6);
475 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
476 bset
= isl_basic_set_add_constraint(bset
, c
);
478 c
= isl_equality_alloc(isl_local_space_copy(ls
));
479 isl_int_set_si(v
, 1);
480 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
481 isl_int_set_si(v
, -3);
482 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
483 bset
= isl_basic_set_add_constraint(bset
, c
);
485 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
487 assert(bset
&& bset
->n_div
== 1);
488 isl_basic_set_free(bset
);
489 isl_local_space_free(ls
);
492 /* This test is a bit tricky. We set up an equality
494 * Normalization of divs creates _two_ divs
497 * Afterwards e0 is removed again because it has coefficient -1
498 * and we end up with the original equality and div again.
499 * Perhaps we can avoid the introduction of this temporary div.
501 dim
= isl_space_set_alloc(ctx
, 0, 4);
502 bset
= isl_basic_set_universe(isl_space_copy(dim
));
503 ls
= isl_local_space_from_space(dim
);
505 c
= isl_equality_alloc(isl_local_space_copy(ls
));
506 isl_int_set_si(v
, -1);
507 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
508 isl_int_set_si(v
, -3);
509 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
510 isl_int_set_si(v
, -3);
511 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
512 isl_int_set_si(v
, 6);
513 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
514 bset
= isl_basic_set_add_constraint(bset
, c
);
516 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
518 /* Test disabled for now */
520 assert(bset && bset->n_div == 1);
522 isl_local_space_free(ls
);
523 isl_basic_set_free(bset
);
526 dim
= isl_space_set_alloc(ctx
, 0, 5);
527 bset
= isl_basic_set_universe(isl_space_copy(dim
));
528 ls
= isl_local_space_from_space(dim
);
530 c
= isl_equality_alloc(isl_local_space_copy(ls
));
531 isl_int_set_si(v
, -1);
532 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
533 isl_int_set_si(v
, -3);
534 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
535 isl_int_set_si(v
, -3);
536 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
537 isl_int_set_si(v
, 6);
538 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
539 bset
= isl_basic_set_add_constraint(bset
, c
);
541 c
= isl_equality_alloc(isl_local_space_copy(ls
));
542 isl_int_set_si(v
, -1);
543 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
544 isl_int_set_si(v
, 1);
545 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
546 isl_int_set_si(v
, 1);
547 isl_constraint_set_constant(c
, v
);
548 bset
= isl_basic_set_add_constraint(bset
, c
);
550 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
552 /* Test disabled for now */
554 assert(bset && bset->n_div == 1);
556 isl_local_space_free(ls
);
557 isl_basic_set_free(bset
);
560 dim
= isl_space_set_alloc(ctx
, 0, 4);
561 bset
= isl_basic_set_universe(isl_space_copy(dim
));
562 ls
= isl_local_space_from_space(dim
);
564 c
= isl_equality_alloc(isl_local_space_copy(ls
));
565 isl_int_set_si(v
, 1);
566 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
567 isl_int_set_si(v
, -1);
568 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
569 isl_int_set_si(v
, -2);
570 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
571 bset
= isl_basic_set_add_constraint(bset
, c
);
573 c
= isl_equality_alloc(isl_local_space_copy(ls
));
574 isl_int_set_si(v
, -1);
575 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
576 isl_int_set_si(v
, 3);
577 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
578 isl_int_set_si(v
, 2);
579 isl_constraint_set_constant(c
, v
);
580 bset
= isl_basic_set_add_constraint(bset
, c
);
582 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
584 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
586 assert(!isl_basic_set_is_empty(bset
));
588 isl_local_space_free(ls
);
589 isl_basic_set_free(bset
);
592 dim
= isl_space_set_alloc(ctx
, 0, 3);
593 bset
= isl_basic_set_universe(isl_space_copy(dim
));
594 ls
= isl_local_space_from_space(dim
);
596 c
= isl_equality_alloc(isl_local_space_copy(ls
));
597 isl_int_set_si(v
, 1);
598 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
599 isl_int_set_si(v
, -2);
600 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
601 bset
= isl_basic_set_add_constraint(bset
, c
);
603 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
605 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
607 isl_local_space_free(ls
);
608 isl_basic_set_free(bset
);
612 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
613 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
614 set
= isl_set_read_from_str(ctx
, str
);
615 set
= isl_set_compute_divs(set
);
623 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
627 struct isl_basic_set
*bset1
, *bset2
;
628 struct isl_basic_map
*bmap
;
630 filename
= get_filename(ctx
, name
, "omega");
632 input
= fopen(filename
, "r");
635 bset1
= isl_basic_set_read_from_file(ctx
, input
);
636 bmap
= isl_basic_map_read_from_file(ctx
, input
);
638 bset1
= isl_basic_set_apply(bset1
, bmap
);
640 bset2
= isl_basic_set_read_from_file(ctx
, input
);
642 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
644 isl_basic_set_free(bset1
);
645 isl_basic_set_free(bset2
);
651 void test_application(struct isl_ctx
*ctx
)
653 test_application_case(ctx
, "application");
654 test_application_case(ctx
, "application2");
657 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
661 struct isl_basic_set
*bset1
, *bset2
;
663 filename
= get_filename(ctx
, name
, "polylib");
665 input
= fopen(filename
, "r");
668 bset1
= isl_basic_set_read_from_file(ctx
, input
);
669 bset2
= isl_basic_set_read_from_file(ctx
, input
);
671 bset1
= isl_basic_set_affine_hull(bset1
);
673 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
675 isl_basic_set_free(bset1
);
676 isl_basic_set_free(bset2
);
682 int test_affine_hull(struct isl_ctx
*ctx
)
689 test_affine_hull_case(ctx
, "affine2");
690 test_affine_hull_case(ctx
, "affine");
691 test_affine_hull_case(ctx
, "affine3");
693 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
694 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
695 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
696 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
697 set
= isl_set_read_from_str(ctx
, str
);
698 bset
= isl_set_affine_hull(set
);
699 n
= isl_basic_set_dim(bset
, isl_dim_div
);
700 isl_basic_set_free(bset
);
702 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
708 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
712 struct isl_basic_set
*bset1
, *bset2
;
715 filename
= get_filename(ctx
, name
, "polylib");
717 input
= fopen(filename
, "r");
720 bset1
= isl_basic_set_read_from_file(ctx
, input
);
721 bset2
= isl_basic_set_read_from_file(ctx
, input
);
723 set
= isl_basic_set_union(bset1
, bset2
);
724 bset1
= isl_set_convex_hull(set
);
726 bset2
= isl_basic_set_read_from_file(ctx
, input
);
728 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
730 isl_basic_set_free(bset1
);
731 isl_basic_set_free(bset2
);
737 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
739 const char *str1
, *str2
;
740 isl_set
*set1
, *set2
;
741 int orig_convex
= ctx
->opt
->convex
;
742 ctx
->opt
->convex
= convex
;
744 test_convex_hull_case(ctx
, "convex0");
745 test_convex_hull_case(ctx
, "convex1");
746 test_convex_hull_case(ctx
, "convex2");
747 test_convex_hull_case(ctx
, "convex3");
748 test_convex_hull_case(ctx
, "convex4");
749 test_convex_hull_case(ctx
, "convex5");
750 test_convex_hull_case(ctx
, "convex6");
751 test_convex_hull_case(ctx
, "convex7");
752 test_convex_hull_case(ctx
, "convex8");
753 test_convex_hull_case(ctx
, "convex9");
754 test_convex_hull_case(ctx
, "convex10");
755 test_convex_hull_case(ctx
, "convex11");
756 test_convex_hull_case(ctx
, "convex12");
757 test_convex_hull_case(ctx
, "convex13");
758 test_convex_hull_case(ctx
, "convex14");
759 test_convex_hull_case(ctx
, "convex15");
761 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
762 "(i0 = 1 and i1 = 0 and i2 = 1) or "
763 "(i0 = 0 and i1 = 0 and i2 = 0) }";
764 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
765 set1
= isl_set_read_from_str(ctx
, str1
);
766 set2
= isl_set_read_from_str(ctx
, str2
);
767 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
768 assert(isl_set_is_equal(set1
, set2
));
772 ctx
->opt
->convex
= orig_convex
;
775 void test_convex_hull(struct isl_ctx
*ctx
)
777 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
778 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
781 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
785 struct isl_basic_set
*bset1
, *bset2
;
787 filename
= get_filename(ctx
, name
, "polylib");
789 input
= fopen(filename
, "r");
792 bset1
= isl_basic_set_read_from_file(ctx
, input
);
793 bset2
= isl_basic_set_read_from_file(ctx
, input
);
795 bset1
= isl_basic_set_gist(bset1
, bset2
);
797 bset2
= isl_basic_set_read_from_file(ctx
, input
);
799 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
801 isl_basic_set_free(bset1
);
802 isl_basic_set_free(bset2
);
808 void test_gist(struct isl_ctx
*ctx
)
811 isl_basic_set
*bset1
, *bset2
;
813 test_gist_case(ctx
, "gist1");
815 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
816 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
817 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
818 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
819 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
820 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
821 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
822 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
823 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
824 bset1
= isl_basic_set_read_from_str(ctx
, str
);
825 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
826 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
827 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
828 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
829 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
830 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
831 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
832 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
833 bset2
= isl_basic_set_read_from_str(ctx
, str
);
834 bset1
= isl_basic_set_gist(bset1
, bset2
);
835 assert(bset1
&& bset1
->n_div
== 0);
836 isl_basic_set_free(bset1
);
839 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
845 set
= isl_set_read_from_str(ctx
, str
);
846 set
= isl_set_coalesce(set
);
847 set2
= isl_set_read_from_str(ctx
, str
);
848 equal
= isl_set_is_equal(set
, set2
);
849 one
= set
&& set
->n
== 1;
856 isl_die(ctx
, isl_error_unknown
,
857 "coalesced set not equal to input", return -1);
858 if (check_one
&& !one
)
859 isl_die(ctx
, isl_error_unknown
,
860 "coalesced set should not be a union", return -1);
865 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
870 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
871 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
873 if (test_coalesce_set(ctx
,
874 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
875 "-x - y + 1 >= 0 and -3 <= z <= 3;"
876 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
877 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
878 "-10 <= y <= 0}", 1) < 0)
880 if (test_coalesce_set(ctx
,
881 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
883 if (test_coalesce_set(ctx
,
884 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
892 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
897 int test_coalesce(struct isl_ctx
*ctx
)
900 struct isl_set
*set
, *set2
;
901 struct isl_map
*map
, *map2
;
903 set
= isl_set_read_from_str(ctx
,
904 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
905 "y >= x & x >= 2 & 5 >= y }");
906 set
= isl_set_coalesce(set
);
907 assert(set
&& set
->n
== 1);
910 set
= isl_set_read_from_str(ctx
,
911 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
912 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}");
913 set
= isl_set_coalesce(set
);
914 assert(set
&& set
->n
== 1);
917 set
= isl_set_read_from_str(ctx
,
918 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
919 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}");
920 set
= isl_set_coalesce(set
);
921 assert(set
&& set
->n
== 2);
924 set
= isl_set_read_from_str(ctx
,
925 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
926 "y >= 0 & x >= 6 & x <= 10 & y <= x}");
927 set
= isl_set_coalesce(set
);
928 assert(set
&& set
->n
== 1);
931 set
= isl_set_read_from_str(ctx
,
932 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
933 "y >= 0 & x >= 7 & x <= 10 & y <= x}");
934 set
= isl_set_coalesce(set
);
935 assert(set
&& set
->n
== 2);
938 set
= isl_set_read_from_str(ctx
,
939 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
940 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}");
941 set
= isl_set_coalesce(set
);
942 assert(set
&& set
->n
== 2);
945 set
= isl_set_read_from_str(ctx
,
946 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
947 "y >= 0 & x = 6 & y <= 6}");
948 set
= isl_set_coalesce(set
);
949 assert(set
&& set
->n
== 1);
952 set
= isl_set_read_from_str(ctx
,
953 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
954 "y >= 0 & x = 7 & y <= 6}");
955 set
= isl_set_coalesce(set
);
956 assert(set
&& set
->n
== 2);
959 set
= isl_set_read_from_str(ctx
,
960 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
961 "y >= 0 & x = 6 & y <= 5}");
962 set
= isl_set_coalesce(set
);
963 assert(set
&& set
->n
== 1);
964 set2
= isl_set_read_from_str(ctx
,
965 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
966 "y >= 0 & x = 6 & y <= 5}");
967 assert(isl_set_is_equal(set
, set2
));
971 set
= isl_set_read_from_str(ctx
,
972 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
973 "y >= 0 & x = 6 & y <= 7}");
974 set
= isl_set_coalesce(set
);
975 assert(set
&& set
->n
== 2);
978 set
= isl_set_read_from_str(ctx
,
979 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
980 set
= isl_set_coalesce(set
);
981 assert(set
&& set
->n
== 1);
982 set2
= isl_set_read_from_str(ctx
,
983 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
984 assert(isl_set_is_equal(set
, set2
));
988 set
= isl_set_read_from_str(ctx
,
989 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
990 set
= isl_set_coalesce(set
);
991 set2
= isl_set_read_from_str(ctx
,
992 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
993 assert(isl_set_is_equal(set
, set2
));
997 set
= isl_set_read_from_str(ctx
,
998 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
999 "2 <= i and i <= n }");
1000 set
= isl_set_coalesce(set
);
1001 assert(set
&& set
->n
== 1);
1002 set2
= isl_set_read_from_str(ctx
,
1003 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
1004 "2 <= i and i <= n }");
1005 assert(isl_set_is_equal(set
, set2
));
1009 map
= isl_map_read_from_str(ctx
,
1010 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1011 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1012 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1013 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1014 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1015 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1016 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1017 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1018 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1019 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1020 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1021 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1022 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1023 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1024 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1025 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1026 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1027 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
1028 map
= isl_map_coalesce(map
);
1029 map2
= isl_map_read_from_str(ctx
,
1030 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1031 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1032 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1033 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1034 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1035 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1036 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1037 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1038 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1039 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1040 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1041 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1042 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1043 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1044 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1045 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1046 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1047 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
1048 assert(isl_map_is_equal(map
, map2
));
1052 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1053 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1054 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1055 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
1056 map
= isl_map_read_from_str(ctx
, str
);
1057 map
= isl_map_coalesce(map
);
1058 map2
= isl_map_read_from_str(ctx
, str
);
1059 assert(isl_map_is_equal(map
, map2
));
1063 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
1064 "[o0, o1, o2, o3, o4, o5, o6] : "
1065 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1066 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1067 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1068 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1069 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1070 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1071 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1072 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1073 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1074 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1075 "o6 >= i3 + i6 - o3 and M >= 0 and "
1076 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1077 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
1078 map
= isl_map_read_from_str(ctx
, str
);
1079 map
= isl_map_coalesce(map
);
1080 map2
= isl_map_read_from_str(ctx
, str
);
1081 assert(isl_map_is_equal(map
, map2
));
1085 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1086 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1087 "(o0 = 0 and M >= 2 and N >= 3) or "
1088 "(M = 0 and o0 = 0 and N >= 3) }";
1089 map
= isl_map_read_from_str(ctx
, str
);
1090 map
= isl_map_coalesce(map
);
1091 map2
= isl_map_read_from_str(ctx
, str
);
1092 assert(isl_map_is_equal(map
, map2
));
1096 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1097 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1098 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1099 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
1100 map
= isl_map_read_from_str(ctx
, str
);
1101 map
= isl_map_coalesce(map
);
1102 map2
= isl_map_read_from_str(ctx
, str
);
1103 assert(isl_map_is_equal(map
, map2
));
1107 test_coalesce_set(ctx
,
1108 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
1109 "(i1 = M and M >= 1) }", 0);
1110 test_coalesce_set(ctx
,
1111 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
1112 test_coalesce_set(ctx
,
1113 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1114 "(y = 3 and x = 1) }", 1);
1115 test_coalesce_set(ctx
,
1116 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1117 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1118 "i1 <= M and i3 <= M and i4 <= M) or "
1119 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1120 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1121 "i4 <= -1 + M) }", 1);
1122 test_coalesce_set(ctx
,
1123 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1124 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
1125 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1127 if (test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0) < 0)
1129 if (test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1) < 0)
1131 if (test_coalesce_set(ctx
, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1) < 0)
1133 if (test_coalesce_set(ctx
, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0) < 0)
1135 if (test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1) < 0)
1137 if (test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0) < 0)
1139 if (test_coalesce_set(ctx
, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1141 if (test_coalesce_set(ctx
, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1143 if (test_coalesce_set(ctx
, "{ [a, b] : exists e : 2e = a and "
1144 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }", 0) < 0)
1146 if (test_coalesce_set(ctx
,
1147 "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1148 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1149 "j >= 1 and j' <= i + j - i' and i >= 1; "
1150 "[1, 1, 1, 1] }", 0) < 0)
1152 if (test_coalesce_set(ctx
, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1153 "[i,j] : exists a : j = 3a }", 1) < 0)
1158 void test_closure(struct isl_ctx
*ctx
)
1162 isl_map
*up
, *right
;
1163 isl_map
*map
, *map2
;
1166 /* COCOA example 1 */
1167 map
= isl_map_read_from_str(ctx
,
1168 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1169 "1 <= i and i < n and 1 <= j and j < n or "
1170 "i2 = i + 1 and j2 = j - 1 and "
1171 "1 <= i and i < n and 2 <= j and j <= n }");
1172 map
= isl_map_power(map
, &exact
);
1176 /* COCOA example 1 */
1177 map
= isl_map_read_from_str(ctx
,
1178 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1179 "1 <= i and i < n and 1 <= j and j < n or "
1180 "i2 = i + 1 and j2 = j - 1 and "
1181 "1 <= i and i < n and 2 <= j and j <= n }");
1182 map
= isl_map_transitive_closure(map
, &exact
);
1184 map2
= isl_map_read_from_str(ctx
,
1185 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1186 "1 <= i and i < n and 1 <= j and j <= n and "
1187 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1188 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1189 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1190 assert(isl_map_is_equal(map
, map2
));
1194 map
= isl_map_read_from_str(ctx
,
1195 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1196 " 0 <= y and y <= n }");
1197 map
= isl_map_transitive_closure(map
, &exact
);
1198 map2
= isl_map_read_from_str(ctx
,
1199 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1200 " 0 <= y and y <= n }");
1201 assert(isl_map_is_equal(map
, map2
));
1205 /* COCOA example 2 */
1206 map
= isl_map_read_from_str(ctx
,
1207 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1208 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1209 "i2 = i + 2 and j2 = j - 2 and "
1210 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1211 map
= isl_map_transitive_closure(map
, &exact
);
1213 map2
= isl_map_read_from_str(ctx
,
1214 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1215 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1216 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1217 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1218 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1219 assert(isl_map_is_equal(map
, map2
));
1223 /* COCOA Fig.2 left */
1224 map
= isl_map_read_from_str(ctx
,
1225 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1226 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1228 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1229 "j <= 2 i - 3 and j <= n - 2 or "
1230 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1231 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1232 map
= isl_map_transitive_closure(map
, &exact
);
1236 /* COCOA Fig.2 right */
1237 map
= isl_map_read_from_str(ctx
,
1238 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1239 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1241 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1242 "j <= 2 i - 4 and j <= n - 3 or "
1243 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1244 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1245 map
= isl_map_power(map
, &exact
);
1249 /* COCOA Fig.2 right */
1250 map
= isl_map_read_from_str(ctx
,
1251 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1252 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1254 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1255 "j <= 2 i - 4 and j <= n - 3 or "
1256 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1257 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1258 map
= isl_map_transitive_closure(map
, &exact
);
1260 map2
= isl_map_read_from_str(ctx
,
1261 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1262 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1263 "j <= n and 3 + i + 2 j <= 3 n and "
1264 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1265 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1266 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1267 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1268 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1269 assert(isl_map_is_equal(map
, map2
));
1273 /* COCOA Fig.1 right */
1274 dom
= isl_set_read_from_str(ctx
,
1275 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1276 "2 x - 3 y + 3 >= 0 }");
1277 right
= isl_map_read_from_str(ctx
,
1278 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1279 up
= isl_map_read_from_str(ctx
,
1280 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1281 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1282 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1283 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1284 up
= isl_map_intersect_range(up
, dom
);
1285 map
= isl_map_union(up
, right
);
1286 map
= isl_map_transitive_closure(map
, &exact
);
1288 map2
= isl_map_read_from_str(ctx
,
1289 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1290 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1291 assert(isl_map_is_equal(map
, map2
));
1295 /* COCOA Theorem 1 counter example */
1296 map
= isl_map_read_from_str(ctx
,
1297 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1298 "i2 = 1 and j2 = j or "
1299 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1300 map
= isl_map_transitive_closure(map
, &exact
);
1304 map
= isl_map_read_from_str(ctx
,
1305 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1306 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1307 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1308 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1309 map
= isl_map_transitive_closure(map
, &exact
);
1313 /* Kelly et al 1996, fig 12 */
1314 map
= isl_map_read_from_str(ctx
,
1315 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1316 "1 <= i,j,j+1 <= n or "
1317 "j = n and j2 = 1 and i2 = i + 1 and "
1318 "1 <= i,i+1 <= n }");
1319 map
= isl_map_transitive_closure(map
, &exact
);
1321 map2
= isl_map_read_from_str(ctx
,
1322 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1323 "1 <= i <= n and i = i2 or "
1324 "1 <= i < i2 <= n and 1 <= j <= n and "
1326 assert(isl_map_is_equal(map
, map2
));
1330 /* Omega's closure4 */
1331 map
= isl_map_read_from_str(ctx
,
1332 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1333 "1 <= x,y <= 10 or "
1334 "x2 = x + 1 and y2 = y and "
1335 "1 <= x <= 20 && 5 <= y <= 15 }");
1336 map
= isl_map_transitive_closure(map
, &exact
);
1340 map
= isl_map_read_from_str(ctx
,
1341 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1342 map
= isl_map_transitive_closure(map
, &exact
);
1344 map2
= isl_map_read_from_str(ctx
,
1345 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1346 assert(isl_map_is_equal(map
, map2
));
1350 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1351 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1352 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1353 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1354 map
= isl_map_read_from_str(ctx
, str
);
1355 map
= isl_map_transitive_closure(map
, &exact
);
1357 map2
= isl_map_read_from_str(ctx
, str
);
1358 assert(isl_map_is_equal(map
, map2
));
1362 str
= "{[0] -> [1]; [2] -> [3]}";
1363 map
= isl_map_read_from_str(ctx
, str
);
1364 map
= isl_map_transitive_closure(map
, &exact
);
1366 map2
= isl_map_read_from_str(ctx
, str
);
1367 assert(isl_map_is_equal(map
, map2
));
1371 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1372 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1373 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1374 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1375 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1376 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1377 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1378 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1379 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1380 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1381 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1382 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1383 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1384 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1385 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1386 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1387 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1388 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1389 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1390 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1391 map
= isl_map_read_from_str(ctx
, str
);
1392 map
= isl_map_transitive_closure(map
, NULL
);
1397 void test_lex(struct isl_ctx
*ctx
)
1402 dim
= isl_space_set_alloc(ctx
, 0, 0);
1403 map
= isl_map_lex_le(dim
);
1404 assert(!isl_map_is_empty(map
));
1408 void test_lexmin(struct isl_ctx
*ctx
)
1411 isl_basic_map
*bmap
;
1412 isl_map
*map
, *map2
;
1415 isl_pw_multi_aff
*pma
;
1417 str
= "[p0, p1] -> { [] -> [] : "
1418 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1419 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1420 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1421 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1422 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1423 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1424 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1425 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1426 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1427 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1428 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1429 map
= isl_map_read_from_str(ctx
, str
);
1430 map
= isl_map_lexmin(map
);
1433 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1434 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1435 set
= isl_set_read_from_str(ctx
, str
);
1436 set
= isl_set_lexmax(set
);
1437 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1438 set2
= isl_set_read_from_str(ctx
, str
);
1439 set
= isl_set_intersect(set
, set2
);
1440 assert(!isl_set_is_empty(set
));
1443 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1444 map
= isl_map_read_from_str(ctx
, str
);
1445 map
= isl_map_lexmin(map
);
1446 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1447 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1448 map2
= isl_map_read_from_str(ctx
, str
);
1449 assert(isl_map_is_equal(map
, map2
));
1453 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1454 map
= isl_map_read_from_str(ctx
, str
);
1455 map2
= isl_map_copy(map
);
1456 map
= isl_map_lexmin(map
);
1457 assert(isl_map_is_equal(map
, map2
));
1461 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1462 map
= isl_map_read_from_str(ctx
, str
);
1463 map
= isl_map_lexmin(map
);
1464 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1465 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1466 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1467 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1468 map2
= isl_map_read_from_str(ctx
, str
);
1469 assert(isl_map_is_equal(map
, map2
));
1473 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1474 " 8i' <= i and 8i' >= -7 + i }";
1475 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1476 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1477 map2
= isl_map_from_pw_multi_aff(pma
);
1478 map
= isl_map_from_basic_map(bmap
);
1479 assert(isl_map_is_equal(map
, map2
));
1483 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1484 map
= isl_map_read_from_str(ctx
, str
);
1485 map
= isl_map_lexmin(map
);
1486 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1487 map2
= isl_map_read_from_str(ctx
, str
);
1488 assert(isl_map_is_equal(map
, map2
));
1498 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1499 void *dep_user
, void *user
)
1501 struct must_may
*mm
= (struct must_may
*)user
;
1504 mm
->must
= isl_map_union(mm
->must
, dep
);
1506 mm
->may
= isl_map_union(mm
->may
, dep
);
1511 static int common_space(void *first
, void *second
)
1513 int depth
= *(int *)first
;
1517 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1525 map2
= isl_map_read_from_str(map
->ctx
, str
);
1526 equal
= isl_map_is_equal(map
, map2
);
1532 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1536 equal
= map_is_equal(map
, str
);
1540 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1541 "result not as expected", return -1);
1545 void test_dep(struct isl_ctx
*ctx
)
1550 isl_access_info
*ai
;
1557 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1558 map
= isl_map_read_from_str(ctx
, str
);
1559 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1561 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1562 map
= isl_map_read_from_str(ctx
, str
);
1563 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1565 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1566 map
= isl_map_read_from_str(ctx
, str
);
1567 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1569 flow
= isl_access_info_compute_flow(ai
);
1570 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1571 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1572 mm
.may
= isl_map_empty(dim
);
1574 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1576 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1577 " [1,10,0] -> [2,5,0] }";
1578 assert(map_is_equal(mm
.must
, str
));
1579 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1580 assert(map_is_equal(mm
.may
, str
));
1582 isl_map_free(mm
.must
);
1583 isl_map_free(mm
.may
);
1584 isl_flow_free(flow
);
1587 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1588 map
= isl_map_read_from_str(ctx
, str
);
1589 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1591 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1592 map
= isl_map_read_from_str(ctx
, str
);
1593 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1595 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1596 map
= isl_map_read_from_str(ctx
, str
);
1597 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1599 flow
= isl_access_info_compute_flow(ai
);
1600 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1601 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1602 mm
.may
= isl_map_empty(dim
);
1604 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1606 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1607 assert(map_is_equal(mm
.must
, str
));
1608 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1609 assert(map_is_equal(mm
.may
, str
));
1611 isl_map_free(mm
.must
);
1612 isl_map_free(mm
.may
);
1613 isl_flow_free(flow
);
1616 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1617 map
= isl_map_read_from_str(ctx
, str
);
1618 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1620 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1621 map
= isl_map_read_from_str(ctx
, str
);
1622 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1624 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1625 map
= isl_map_read_from_str(ctx
, str
);
1626 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1628 flow
= isl_access_info_compute_flow(ai
);
1629 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1630 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1631 mm
.may
= isl_map_empty(dim
);
1633 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1635 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1636 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1637 assert(map_is_equal(mm
.may
, str
));
1638 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1639 assert(map_is_equal(mm
.must
, str
));
1641 isl_map_free(mm
.must
);
1642 isl_map_free(mm
.may
);
1643 isl_flow_free(flow
);
1646 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1647 map
= isl_map_read_from_str(ctx
, str
);
1648 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1650 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1651 map
= isl_map_read_from_str(ctx
, str
);
1652 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1654 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1655 map
= isl_map_read_from_str(ctx
, str
);
1656 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1658 flow
= isl_access_info_compute_flow(ai
);
1659 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1660 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1661 mm
.may
= isl_map_empty(dim
);
1663 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1665 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1666 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1667 assert(map_is_equal(mm
.may
, str
));
1668 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1669 assert(map_is_equal(mm
.must
, str
));
1671 isl_map_free(mm
.must
);
1672 isl_map_free(mm
.may
);
1673 isl_flow_free(flow
);
1676 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1677 map
= isl_map_read_from_str(ctx
, str
);
1678 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1680 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1681 map
= isl_map_read_from_str(ctx
, str
);
1682 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1684 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1685 map
= isl_map_read_from_str(ctx
, str
);
1686 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1688 flow
= isl_access_info_compute_flow(ai
);
1689 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1690 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1691 mm
.may
= isl_map_empty(dim
);
1693 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1695 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1696 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1697 assert(map_is_equal(mm
.may
, str
));
1698 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1699 assert(map_is_equal(mm
.must
, str
));
1701 isl_map_free(mm
.must
);
1702 isl_map_free(mm
.may
);
1703 isl_flow_free(flow
);
1708 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1709 map
= isl_map_read_from_str(ctx
, str
);
1710 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1712 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1713 map
= isl_map_read_from_str(ctx
, str
);
1714 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1716 flow
= isl_access_info_compute_flow(ai
);
1717 dim
= isl_space_alloc(ctx
, 0, 5, 5);
1718 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1719 mm
.may
= isl_map_empty(dim
);
1721 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1723 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1724 assert(map_is_equal(mm
.must
, str
));
1725 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1726 assert(map_is_equal(mm
.may
, str
));
1728 isl_map_free(mm
.must
);
1729 isl_map_free(mm
.may
);
1730 isl_flow_free(flow
);
1733 int test_sv(isl_ctx
*ctx
)
1737 isl_union_map
*umap
;
1740 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1741 map
= isl_map_read_from_str(ctx
, str
);
1742 sv
= isl_map_is_single_valued(map
);
1747 isl_die(ctx
, isl_error_internal
,
1748 "map not detected as single valued", return -1);
1750 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1751 map
= isl_map_read_from_str(ctx
, str
);
1752 sv
= isl_map_is_single_valued(map
);
1757 isl_die(ctx
, isl_error_internal
,
1758 "map detected as single valued", return -1);
1760 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1761 umap
= isl_union_map_read_from_str(ctx
, str
);
1762 sv
= isl_union_map_is_single_valued(umap
);
1763 isl_union_map_free(umap
);
1767 isl_die(ctx
, isl_error_internal
,
1768 "map not detected as single valued", return -1);
1770 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1771 umap
= isl_union_map_read_from_str(ctx
, str
);
1772 sv
= isl_union_map_is_single_valued(umap
);
1773 isl_union_map_free(umap
);
1777 isl_die(ctx
, isl_error_internal
,
1778 "map detected as single valued", return -1);
1783 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1787 map
= isl_map_read_from_str(ctx
, str
);
1789 assert(isl_map_is_bijective(map
));
1791 assert(!isl_map_is_bijective(map
));
1795 void test_bijective(struct isl_ctx
*ctx
)
1797 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1798 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1799 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1800 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1801 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1802 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1803 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1804 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1805 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1806 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1807 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1808 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1809 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1812 void test_pwqp(struct isl_ctx
*ctx
)
1816 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1818 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1819 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1821 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1824 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1825 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1827 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1829 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1831 isl_pw_qpolynomial_free(pwqp1
);
1833 str
= "{ [i] -> i }";
1834 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1835 str
= "{ [k] : exists a : k = 2a }";
1836 set
= isl_set_read_from_str(ctx
, str
);
1837 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1838 str
= "{ [i] -> i }";
1839 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1841 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1843 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1845 isl_pw_qpolynomial_free(pwqp1
);
1847 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
1848 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1850 set
= isl_set_read_from_str(ctx
, str
);
1851 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1852 str
= "{ [i] -> 16 }";
1853 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1855 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1857 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1859 isl_pw_qpolynomial_free(pwqp1
);
1861 str
= "{ [i] -> ([(i)/2]) }";
1862 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1863 str
= "{ [k] : exists a : k = 2a+1 }";
1864 set
= isl_set_read_from_str(ctx
, str
);
1865 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1866 str
= "{ [i] -> -1/2 + 1/2 * i }";
1867 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1869 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1871 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1873 isl_pw_qpolynomial_free(pwqp1
);
1875 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
1876 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1877 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
1878 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1880 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1882 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1884 isl_pw_qpolynomial_free(pwqp1
);
1886 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
1887 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1888 str
= "{ [x] -> x }";
1889 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1891 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1893 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1895 isl_pw_qpolynomial_free(pwqp1
);
1897 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1898 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1899 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1900 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
1901 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1902 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1903 isl_pw_qpolynomial_free(pwqp1
);
1906 void test_split_periods(isl_ctx
*ctx
)
1909 isl_pw_qpolynomial
*pwqp
;
1911 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1912 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1913 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1914 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1916 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1919 isl_pw_qpolynomial_free(pwqp
);
1922 void test_union(isl_ctx
*ctx
)
1925 isl_union_set
*uset1
, *uset2
;
1926 isl_union_map
*umap1
, *umap2
;
1928 str
= "{ [i] : 0 <= i <= 1 }";
1929 uset1
= isl_union_set_read_from_str(ctx
, str
);
1930 str
= "{ [1] -> [0] }";
1931 umap1
= isl_union_map_read_from_str(ctx
, str
);
1933 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
1934 assert(isl_union_map_is_equal(umap1
, umap2
));
1936 isl_union_map_free(umap1
);
1937 isl_union_map_free(umap2
);
1939 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1940 umap1
= isl_union_map_read_from_str(ctx
, str
);
1941 str
= "{ A[i]; B[i] }";
1942 uset1
= isl_union_set_read_from_str(ctx
, str
);
1944 uset2
= isl_union_map_domain(umap1
);
1946 assert(isl_union_set_is_equal(uset1
, uset2
));
1948 isl_union_set_free(uset1
);
1949 isl_union_set_free(uset2
);
1952 void test_bound(isl_ctx
*ctx
)
1955 isl_pw_qpolynomial
*pwqp
;
1956 isl_pw_qpolynomial_fold
*pwf
;
1958 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
1959 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1960 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1961 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
1962 isl_pw_qpolynomial_fold_free(pwf
);
1964 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1965 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1966 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1967 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
1968 isl_pw_qpolynomial_fold_free(pwf
);
1971 void test_lift(isl_ctx
*ctx
)
1974 isl_basic_map
*bmap
;
1975 isl_basic_set
*bset
;
1977 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
1978 bset
= isl_basic_set_read_from_str(ctx
, str
);
1979 bset
= isl_basic_set_lift(bset
);
1980 bmap
= isl_basic_map_from_range(bset
);
1981 bset
= isl_basic_map_domain(bmap
);
1982 isl_basic_set_free(bset
);
1985 void test_subset(isl_ctx
*ctx
)
1988 isl_set
*set1
, *set2
;
1990 str
= "{ [112, 0] }";
1991 set1
= isl_set_read_from_str(ctx
, str
);
1992 str
= "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1993 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1994 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1995 set2
= isl_set_read_from_str(ctx
, str
);
1996 assert(isl_set_is_subset(set1
, set2
));
2001 int test_factorize(isl_ctx
*ctx
)
2004 isl_basic_set
*bset
;
2007 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2008 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2009 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2010 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2011 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2012 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2013 "3i5 >= -2i0 - i2 + 3i4 }";
2014 bset
= isl_basic_set_read_from_str(ctx
, str
);
2015 f
= isl_basic_set_factorizer(bset
);
2016 isl_basic_set_free(bset
);
2017 isl_factorizer_free(f
);
2019 isl_die(ctx
, isl_error_unknown
,
2020 "failed to construct factorizer", return -1);
2022 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2023 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2024 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2025 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2026 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2027 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2028 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2029 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2030 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2031 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2032 bset
= isl_basic_set_read_from_str(ctx
, str
);
2033 f
= isl_basic_set_factorizer(bset
);
2034 isl_basic_set_free(bset
);
2035 isl_factorizer_free(f
);
2037 isl_die(ctx
, isl_error_unknown
,
2038 "failed to construct factorizer", return -1);
2043 static int check_injective(__isl_take isl_map
*map
, void *user
)
2045 int *injective
= user
;
2047 *injective
= isl_map_is_injective(map
);
2050 if (*injective
< 0 || !*injective
)
2056 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2057 const char *r
, const char *s
, int tilable
, int parallel
)
2061 isl_union_map
*W
, *R
, *S
;
2062 isl_union_map
*empty
;
2063 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2064 isl_union_map
*validity
, *proximity
;
2065 isl_union_map
*schedule
;
2066 isl_union_map
*test
;
2067 isl_union_set
*delta
;
2068 isl_union_set
*domain
;
2072 isl_schedule
*sched
;
2073 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2075 D
= isl_union_set_read_from_str(ctx
, d
);
2076 W
= isl_union_map_read_from_str(ctx
, w
);
2077 R
= isl_union_map_read_from_str(ctx
, r
);
2078 S
= isl_union_map_read_from_str(ctx
, s
);
2080 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2081 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2083 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2084 isl_union_map_compute_flow(isl_union_map_copy(R
),
2085 isl_union_map_copy(W
), empty
,
2086 isl_union_map_copy(S
),
2087 &dep_raw
, NULL
, NULL
, NULL
);
2088 isl_union_map_compute_flow(isl_union_map_copy(W
),
2089 isl_union_map_copy(W
),
2090 isl_union_map_copy(R
),
2091 isl_union_map_copy(S
),
2092 &dep_waw
, &dep_war
, NULL
, NULL
);
2094 dep
= isl_union_map_union(dep_waw
, dep_war
);
2095 dep
= isl_union_map_union(dep
, dep_raw
);
2096 validity
= isl_union_map_copy(dep
);
2097 proximity
= isl_union_map_copy(dep
);
2099 sched
= isl_union_set_compute_schedule(isl_union_set_copy(D
),
2100 validity
, proximity
);
2101 schedule
= isl_schedule_get_map(sched
);
2102 isl_schedule_free(sched
);
2103 isl_union_map_free(W
);
2104 isl_union_map_free(R
);
2105 isl_union_map_free(S
);
2108 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2110 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2111 is_complete
= isl_union_set_is_subset(D
, domain
);
2112 isl_union_set_free(D
);
2113 isl_union_set_free(domain
);
2115 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2116 test
= isl_union_map_apply_range(test
, dep
);
2117 test
= isl_union_map_apply_range(test
, schedule
);
2119 delta
= isl_union_map_deltas(test
);
2120 if (isl_union_set_n_set(delta
) == 0) {
2124 isl_union_set_free(delta
);
2126 delta_set
= isl_set_from_union_set(delta
);
2128 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2129 for (i
= 0; i
< tilable
; ++i
)
2130 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2131 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2132 isl_set_free(slice
);
2134 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2135 for (i
= 0; i
< parallel
; ++i
)
2136 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2137 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2138 isl_set_free(slice
);
2140 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2141 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2142 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2144 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2145 delta_set
= isl_set_lexmin(delta_set
);
2147 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2149 isl_set_free(origin
);
2150 isl_set_free(delta_set
);
2153 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2154 is_injection
< 0 || is_complete
< 0)
2157 isl_die(ctx
, isl_error_unknown
,
2158 "generated schedule incomplete", return -1);
2160 isl_die(ctx
, isl_error_unknown
,
2161 "generated schedule not injective on each statement",
2164 isl_die(ctx
, isl_error_unknown
,
2165 "negative dependences in generated schedule",
2168 isl_die(ctx
, isl_error_unknown
,
2169 "generated schedule not as tilable as expected",
2172 isl_die(ctx
, isl_error_unknown
,
2173 "generated schedule not as parallel as expected",
2179 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2180 const char *validity
, const char *proximity
, const char *expected_sched
)
2184 isl_union_map
*prox
;
2185 isl_union_map
*sched1
, *sched2
;
2186 isl_schedule
*schedule
;
2189 dom
= isl_union_set_read_from_str(ctx
, domain
);
2190 dep
= isl_union_map_read_from_str(ctx
, validity
);
2191 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2192 schedule
= isl_union_set_compute_schedule(dom
, dep
, prox
);
2193 sched1
= isl_schedule_get_map(schedule
);
2194 isl_schedule_free(schedule
);
2196 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2198 equal
= isl_union_map_is_equal(sched1
, sched2
);
2199 isl_union_map_free(sched1
);
2200 isl_union_map_free(sched2
);
2205 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2211 int test_schedule(isl_ctx
*ctx
)
2213 const char *D
, *W
, *R
, *V
, *P
, *S
;
2216 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2217 W
= "{ S1[t,i] -> a[t,i] }";
2218 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2219 "S1[t,i] -> a[t-1,i+1] }";
2220 S
= "{ S1[t,i] -> [t,i] }";
2221 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2224 /* Fig. 5 of CC2008 */
2225 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2227 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2228 "j >= 2 and j <= -1 + N }";
2229 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2230 "j >= 2 and j <= -1 + N; "
2231 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2232 "j >= 2 and j <= -1 + N }";
2233 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2234 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2237 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2238 W
= "{ S1[i] -> a[i] }";
2239 R
= "{ S2[i] -> a[i+1] }";
2240 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2241 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2244 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2245 W
= "{ S1[i] -> a[i] }";
2246 R
= "{ S2[i] -> a[9-i] }";
2247 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2248 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2251 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2252 W
= "{ S1[i] -> a[i] }";
2253 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2254 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2255 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2258 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2259 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2260 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2261 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2262 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2265 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2266 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2267 R
= "{ S2[i,j] -> a[i-1,j] }";
2268 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2269 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2272 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2273 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2274 R
= "{ S2[i,j] -> a[i,j-1] }";
2275 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2276 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2279 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2280 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2281 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2282 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2283 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2284 "S_0[] -> [0, 0, 0] }";
2285 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2287 ctx
->opt
->schedule_parametric
= 0;
2288 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2290 ctx
->opt
->schedule_parametric
= 1;
2292 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2293 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2294 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2295 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2296 "S4[i] -> a[i,N] }";
2297 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2298 "S4[i] -> [4,i,0] }";
2299 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2302 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2303 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2305 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2307 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2309 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2310 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2313 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2314 " S_2[t] : t >= 0 and t <= -1 + N; "
2315 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2317 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2318 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2319 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2320 "i >= 0 and i <= -1 + N }";
2321 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2322 "i >= 0 and i <= -1 + N; "
2323 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2324 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2325 " S_0[t] -> [0, t, 0] }";
2327 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2329 ctx
->opt
->schedule_parametric
= 0;
2330 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2332 ctx
->opt
->schedule_parametric
= 1;
2334 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2335 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2336 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
2339 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2340 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2341 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2342 "j >= 0 and j <= -1 + N; "
2343 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2344 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2345 "j >= 0 and j <= -1 + N; "
2346 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2347 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2348 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2351 D
= "{ S_0[i] : i >= 0 }";
2352 W
= "{ S_0[i] -> a[i] : i >= 0 }";
2353 R
= "{ S_0[i] -> a[0] : i >= 0 }";
2354 S
= "{ S_0[i] -> [0, i, 0] }";
2355 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2358 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2359 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2360 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2361 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2362 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2365 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2366 "k <= -1 + n and k >= 0 }";
2367 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2368 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2369 "k <= -1 + n and k >= 0; "
2370 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2371 "k <= -1 + n and k >= 0; "
2372 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2373 "k <= -1 + n and k >= 0 }";
2374 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
2375 ctx
->opt
->schedule_outer_zero_distance
= 1;
2376 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2378 ctx
->opt
->schedule_outer_zero_distance
= 0;
2380 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
2381 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2382 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2383 "Stmt_for_body24[i0, i1, 1, 0]:"
2384 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2385 "Stmt_for_body7[i0, i1, i2]:"
2386 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2389 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
2390 "Stmt_for_body24[1, i1, i2, i3]:"
2391 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2393 "Stmt_for_body24[0, i1, i2, i3] -> "
2394 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2395 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2397 "Stmt_for_body24[0, i1, i2, i3] ->"
2398 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2399 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2400 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2401 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2402 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2403 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2404 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2405 "i1 <= 6 and i1 >= 0;"
2406 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2407 "Stmt_for_body7[i0, i1, i2] -> "
2408 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2409 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2410 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2411 "Stmt_for_body7[i0, i1, i2] -> "
2412 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2413 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2414 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2416 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2417 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2418 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2420 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2423 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2424 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2425 "j >= 1 and j <= 7;"
2426 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2427 "j >= 1 and j <= 8 }";
2429 S
= "{ S_0[i, j] -> [i + j, j] }";
2430 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2431 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2433 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2435 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2436 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2437 "j >= 0 and j <= -1 + i }";
2438 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2439 "i <= -1 + N and j >= 0;"
2440 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2443 S
= "{ S_0[i, j] -> [i, j] }";
2444 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2445 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2447 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2449 /* Test both algorithms on a case with only proximity dependences. */
2450 D
= "{ S[i,j] : 0 <= i <= 10 }";
2452 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2453 S
= "{ S[i, j] -> [j, i] }";
2454 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2455 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2457 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2458 return test_special_schedule(ctx
, D
, V
, P
, S
);
2461 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
2463 isl_union_map
*umap
;
2466 umap
= isl_union_map_read_from_str(ctx
, str
);
2467 test
= isl_union_map_plain_is_injective(umap
);
2468 isl_union_map_free(umap
);
2471 if (test
== injective
)
2474 isl_die(ctx
, isl_error_unknown
,
2475 "map not detected as injective", return -1);
2477 isl_die(ctx
, isl_error_unknown
,
2478 "map detected as injective", return -1);
2481 int test_injective(isl_ctx
*ctx
)
2485 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2487 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
2489 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
2491 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
2493 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2495 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2497 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2499 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2502 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2503 if (test_plain_injective(ctx
, str
, 1))
2505 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2506 if (test_plain_injective(ctx
, str
, 0))
2512 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
2520 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
2521 equal
= isl_aff_plain_is_equal(aff
, aff2
);
2527 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
2531 equal
= aff_plain_is_equal(aff
, str
);
2535 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
2536 "result not as expected", return -1);
2540 int test_aff(isl_ctx
*ctx
)
2545 isl_local_space
*ls
;
2549 space
= isl_space_set_alloc(ctx
, 0, 1);
2550 ls
= isl_local_space_from_space(space
);
2551 aff
= isl_aff_zero_on_domain(ls
);
2553 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2554 aff
= isl_aff_scale_down_ui(aff
, 3);
2555 aff
= isl_aff_floor(aff
);
2556 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2557 aff
= isl_aff_scale_down_ui(aff
, 2);
2558 aff
= isl_aff_floor(aff
);
2559 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2562 set
= isl_set_read_from_str(ctx
, str
);
2563 aff
= isl_aff_gist(aff
, set
);
2565 aff
= isl_aff_add_constant_si(aff
, -16);
2566 zero
= isl_aff_plain_is_zero(aff
);
2572 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2574 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
2575 aff
= isl_aff_scale_down_ui(aff
, 64);
2576 aff
= isl_aff_floor(aff
);
2577 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
2585 int test_dim_max(isl_ctx
*ctx
)
2589 isl_set
*set1
, *set2
;
2594 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
2595 set
= isl_set_read_from_str(ctx
, str
);
2596 pwaff
= isl_set_dim_max(set
, 0);
2597 set1
= isl_set_from_pw_aff(pwaff
);
2598 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2599 set2
= isl_set_read_from_str(ctx
, str
);
2600 equal
= isl_set_is_equal(set1
, set2
);
2606 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2608 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2609 set
= isl_set_read_from_str(ctx
, str
);
2610 pwaff
= isl_set_dim_max(set
, 0);
2611 set1
= isl_set_from_pw_aff(pwaff
);
2612 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2613 set2
= isl_set_read_from_str(ctx
, str
);
2614 equal
= isl_set_is_equal(set1
, set2
);
2620 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2622 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2623 set
= isl_set_read_from_str(ctx
, str
);
2624 pwaff
= isl_set_dim_max(set
, 0);
2625 set1
= isl_set_from_pw_aff(pwaff
);
2626 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2627 set2
= isl_set_read_from_str(ctx
, str
);
2628 equal
= isl_set_is_equal(set1
, set2
);
2634 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2636 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2637 "0 <= i < N and 0 <= j < M }";
2638 map
= isl_map_read_from_str(ctx
, str
);
2639 set
= isl_map_range(map
);
2641 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
2642 set1
= isl_set_from_pw_aff(pwaff
);
2643 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
2644 set2
= isl_set_read_from_str(ctx
, str
);
2645 equal
= isl_set_is_equal(set1
, set2
);
2649 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
2650 set1
= isl_set_from_pw_aff(pwaff
);
2651 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
2652 set2
= isl_set_read_from_str(ctx
, str
);
2653 if (equal
>= 0 && equal
)
2654 equal
= isl_set_is_equal(set1
, set2
);
2663 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2668 int test_product(isl_ctx
*ctx
)
2672 isl_union_set
*uset1
, *uset2
;
2676 set
= isl_set_read_from_str(ctx
, str
);
2677 set
= isl_set_product(set
, isl_set_copy(set
));
2678 ok
= isl_set_is_wrapping(set
);
2683 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2686 uset1
= isl_union_set_read_from_str(ctx
, str
);
2687 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
2688 str
= "{ [[] -> []] }";
2689 uset2
= isl_union_set_read_from_str(ctx
, str
);
2690 ok
= isl_union_set_is_equal(uset1
, uset2
);
2691 isl_union_set_free(uset1
);
2692 isl_union_set_free(uset2
);
2696 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2701 int test_equal(isl_ctx
*ctx
)
2704 isl_set
*set
, *set2
;
2708 set
= isl_set_read_from_str(ctx
, str
);
2710 set2
= isl_set_read_from_str(ctx
, str
);
2711 equal
= isl_set_is_equal(set
, set2
);
2717 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2722 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
2723 enum isl_dim_type type
, unsigned pos
, int fixed
)
2727 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
2734 isl_die(ctx
, isl_error_unknown
,
2735 "map not detected as fixed", return -1);
2737 isl_die(ctx
, isl_error_unknown
,
2738 "map detected as fixed", return -1);
2741 int test_fixed(isl_ctx
*ctx
)
2746 str
= "{ [i] -> [i] }";
2747 map
= isl_map_read_from_str(ctx
, str
);
2748 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
2750 str
= "{ [i] -> [1] }";
2751 map
= isl_map_read_from_str(ctx
, str
);
2752 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2754 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
2755 map
= isl_map_read_from_str(ctx
, str
);
2756 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2758 map
= isl_map_read_from_str(ctx
, str
);
2759 map
= isl_map_neg(map
);
2760 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2766 int test_vertices(isl_ctx
*ctx
)
2769 isl_basic_set
*bset
;
2770 isl_vertices
*vertices
;
2772 str
= "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
2773 bset
= isl_basic_set_read_from_str(ctx
, str
);
2774 vertices
= isl_basic_set_compute_vertices(bset
);
2775 isl_basic_set_free(bset
);
2776 isl_vertices_free(vertices
);
2780 str
= "{ A[t, i] : t = 14 and i = 1 }";
2781 bset
= isl_basic_set_read_from_str(ctx
, str
);
2782 vertices
= isl_basic_set_compute_vertices(bset
);
2783 isl_basic_set_free(bset
);
2784 isl_vertices_free(vertices
);
2791 int test_union_pw(isl_ctx
*ctx
)
2795 isl_union_set
*uset
;
2796 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
2798 str
= "{ [x] -> x^2 }";
2799 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
2800 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
2801 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
2802 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
2803 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
2804 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
2805 isl_union_pw_qpolynomial_free(upwqp1
);
2806 isl_union_pw_qpolynomial_free(upwqp2
);
2810 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2815 int test_output(isl_ctx
*ctx
)
2823 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
2824 pa
= isl_pw_aff_read_from_str(ctx
, str
);
2826 p
= isl_printer_to_str(ctx
);
2827 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
2828 p
= isl_printer_print_pw_aff(p
, pa
);
2829 s
= isl_printer_get_str(p
);
2830 isl_printer_free(p
);
2831 isl_pw_aff_free(pa
);
2832 equal
= !strcmp(s
, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
2837 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2842 int test_sample(isl_ctx
*ctx
)
2845 isl_basic_set
*bset1
, *bset2
;
2848 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
2849 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
2850 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
2851 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
2852 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
2853 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
2854 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
2855 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
2856 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
2857 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
2858 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
2859 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
2860 "d - 1073741821e and "
2861 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
2862 "3j >= 1 - a + b + 2e and "
2863 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
2864 "3i <= 4 - a + 4b - e and "
2865 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
2866 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
2867 "c <= -1 + a and 3i >= -2 - a + 3e and "
2868 "1073741822e <= 1073741823 - a + 1073741822b + c and "
2869 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
2870 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
2871 "1073741823e >= 1 + 1073741823b - d and "
2872 "3i >= 1073741823b + c - 1073741823e - f and "
2873 "3i >= 1 + 2b + e + 3g }";
2874 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2875 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
2876 empty
= isl_basic_set_is_empty(bset2
);
2877 subset
= isl_basic_set_is_subset(bset2
, bset1
);
2878 isl_basic_set_free(bset1
);
2879 isl_basic_set_free(bset2
);
2881 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
2883 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
2888 int test_fixed_power(isl_ctx
*ctx
)
2896 str
= "{ [i] -> [i + 1] }";
2897 map
= isl_map_read_from_str(ctx
, str
);
2898 isl_int_set_si(exp
, 23);
2899 map
= isl_map_fixed_power(map
, exp
);
2900 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
2909 int test_slice(isl_ctx
*ctx
)
2915 str
= "{ [i] -> [j] }";
2916 map
= isl_map_read_from_str(ctx
, str
);
2917 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
2918 equal
= map_check_equal(map
, "{ [i] -> [i] }");
2923 str
= "{ [i] -> [j] }";
2924 map
= isl_map_read_from_str(ctx
, str
);
2925 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
2926 equal
= map_check_equal(map
, "{ [i] -> [j] }");
2931 str
= "{ [i] -> [j] }";
2932 map
= isl_map_read_from_str(ctx
, str
);
2933 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
2934 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
2939 str
= "{ [i] -> [j] }";
2940 map
= isl_map_read_from_str(ctx
, str
);
2941 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
2942 equal
= map_check_equal(map
, "{ [0] -> [j] }");
2947 str
= "{ [i] -> [j] }";
2948 map
= isl_map_read_from_str(ctx
, str
);
2949 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
2950 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
2955 str
= "{ [i] -> [j] }";
2956 map
= isl_map_read_from_str(ctx
, str
);
2957 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
2958 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
2966 int test_eliminate(isl_ctx
*ctx
)
2972 str
= "{ [i] -> [j] : i = 2j }";
2973 map
= isl_map_read_from_str(ctx
, str
);
2974 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
2975 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
2983 /* Check that isl_set_dim_residue_class detects that the values of j
2984 * in the set below are all odd and that it does not detect any spurious
2987 static int test_residue_class(isl_ctx
*ctx
)
2994 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
2995 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
2996 set
= isl_set_read_from_str(ctx
, str
);
2999 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
3001 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
3002 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
3011 int test_align_parameters(isl_ctx
*ctx
)
3015 isl_multi_aff
*ma1
, *ma2
;
3018 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3019 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
3021 space
= isl_space_params_alloc(ctx
, 1);
3022 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
3023 ma1
= isl_multi_aff_align_params(ma1
, space
);
3025 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3026 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
3028 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
3030 isl_multi_aff_free(ma1
);
3031 isl_multi_aff_free(ma2
);
3036 isl_die(ctx
, isl_error_unknown
,
3037 "result not as expected", return -1);
3044 int (*fn
)(isl_ctx
*ctx
);
3046 { "align parameters", &test_align_parameters
},
3047 { "eliminate", &test_eliminate
},
3048 { "reisdue class", &test_residue_class
},
3049 { "div", &test_div
},
3050 { "slice", &test_slice
},
3051 { "fixed power", &test_fixed_power
},
3052 { "sample", &test_sample
},
3053 { "output", &test_output
},
3054 { "vertices", &test_vertices
},
3055 { "fixed", &test_fixed
},
3056 { "equal", &test_equal
},
3057 { "product", &test_product
},
3058 { "dim_max", &test_dim_max
},
3059 { "affine", &test_aff
},
3060 { "injective", &test_injective
},
3061 { "schedule", &test_schedule
},
3062 { "union_pw", &test_union_pw
},
3063 { "parse", &test_parse
},
3064 { "single-valued", &test_sv
},
3065 { "affine hull", &test_affine_hull
},
3066 { "coalesce", &test_coalesce
},
3067 { "factorize", &test_factorize
},
3073 struct isl_ctx
*ctx
;
3075 srcdir
= getenv("srcdir");
3078 ctx
= isl_ctx_alloc();
3079 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
3080 printf("%s\n", tests
[i
].name
);
3081 if (tests
[i
].fn(ctx
) < 0)
3088 test_split_periods(ctx
);
3091 test_bijective(ctx
);
3095 test_construction(ctx
);
3097 test_application(ctx
);
3098 test_convex_hull(ctx
);