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>
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>
26 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
29 char *pattern
= "%s/test_inputs/%s.%s";
31 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
33 filename
= isl_alloc_array(ctx
, char, length
);
38 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
43 void test_parse_map(isl_ctx
*ctx
, const char *str
)
47 map
= isl_map_read_from_str(ctx
, str
, -1);
52 void test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
56 map
= isl_map_read_from_str(ctx
, str
, -1);
57 map2
= isl_map_read_from_str(ctx
, str2
, -1);
58 assert(map
&& map2
&& isl_map_is_equal(map
, map2
));
63 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
65 isl_pw_qpolynomial
*pwqp
;
67 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
69 isl_pw_qpolynomial_free(pwqp
);
72 void test_parse(struct isl_ctx
*ctx
)
75 const char *str
, *str2
;
77 str
= "{ [i] -> [-i] }";
78 map
= isl_map_read_from_str(ctx
, str
, -1);
82 str
= "{ A[i] -> L[([i/3])] }";
83 map
= isl_map_read_from_str(ctx
, str
, -1);
87 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
88 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
89 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
91 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
92 str2
= "{ [x, y] : 2y >= 6 - x }";
93 test_parse_map_equal(ctx
, str
, str2
);
95 test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
96 "{ [x,y] : x <= y, 2*y + 3 }");
97 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
98 test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }", str
);
100 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
101 map
= isl_map_read_from_str(ctx
, str
, -1);
102 str
= "{ [new, old] -> [o0, o1] : "
103 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
104 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
105 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
106 map2
= isl_map_read_from_str(ctx
, str
, -1);
107 assert(isl_map_is_equal(map
, map2
));
111 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
112 map
= isl_map_read_from_str(ctx
, str
, -1);
113 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
114 map2
= isl_map_read_from_str(ctx
, str
, -1);
115 assert(isl_map_is_equal(map
, map2
));
119 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
120 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
121 test_parse_map_equal(ctx
, str
, str2
);
123 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
124 str2
= "{ [i,j] -> [min(i,j)] }";
125 test_parse_map_equal(ctx
, str
, str2
);
127 str
= "{ [i,j] : i != j }";
128 str2
= "{ [i,j] : i < j or i > j }";
129 test_parse_map_equal(ctx
, str
, str2
);
131 str
= "{ [i,j] : (i+1)*2 >= j }";
132 str2
= "{ [i, j] : j <= 2 + 2i }";
133 test_parse_map_equal(ctx
, str
, str2
);
135 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
136 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
139 void test_read(struct isl_ctx
*ctx
)
143 struct isl_basic_set
*bset1
, *bset2
;
144 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
146 filename
= get_filename(ctx
, "set", "omega");
148 input
= fopen(filename
, "r");
151 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
152 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
154 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
156 isl_basic_set_free(bset1
);
157 isl_basic_set_free(bset2
);
163 void test_bounded(struct isl_ctx
*ctx
)
168 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }", -1);
169 bounded
= isl_set_is_bounded(set
);
173 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }", -1);
174 bounded
= isl_set_is_bounded(set
);
178 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }", -1);
179 bounded
= isl_set_is_bounded(set
);
184 /* Construct the basic set { [i] : 5 <= i <= N } */
185 void test_construction(struct isl_ctx
*ctx
)
189 struct isl_basic_set
*bset
;
190 struct isl_constraint
*c
;
194 dim
= isl_dim_set_alloc(ctx
, 1, 1);
195 bset
= isl_basic_set_universe(dim
);
197 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
198 isl_int_set_si(v
, -1);
199 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
200 isl_int_set_si(v
, 1);
201 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
202 bset
= isl_basic_set_add_constraint(bset
, c
);
204 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
205 isl_int_set_si(v
, 1);
206 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
207 isl_int_set_si(v
, -5);
208 isl_constraint_set_constant(c
, v
);
209 bset
= isl_basic_set_add_constraint(bset
, c
);
211 isl_basic_set_free(bset
);
216 void test_dim(struct isl_ctx
*ctx
)
219 isl_map
*map1
, *map2
;
221 map1
= isl_map_read_from_str(ctx
,
222 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
223 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
224 map2
= isl_map_read_from_str(ctx
,
225 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
226 assert(isl_map_is_equal(map1
, map2
));
229 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
230 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
231 assert(isl_map_is_equal(map1
, map2
));
236 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
237 map1
= isl_map_read_from_str(ctx
, str
, -1);
238 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
239 map2
= isl_map_read_from_str(ctx
, str
, -1);
240 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
241 assert(isl_map_is_equal(map1
, map2
));
247 void test_div(struct isl_ctx
*ctx
)
251 struct isl_basic_set
*bset
;
252 struct isl_constraint
*c
;
257 dim
= isl_dim_set_alloc(ctx
, 0, 3);
258 bset
= isl_basic_set_universe(dim
);
260 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
261 isl_int_set_si(v
, -1);
262 isl_constraint_set_constant(c
, v
);
263 isl_int_set_si(v
, 1);
264 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
265 isl_int_set_si(v
, 3);
266 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
267 bset
= isl_basic_set_add_constraint(bset
, c
);
269 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
270 isl_int_set_si(v
, 1);
271 isl_constraint_set_constant(c
, v
);
272 isl_int_set_si(v
, -1);
273 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
274 isl_int_set_si(v
, 3);
275 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
276 bset
= isl_basic_set_add_constraint(bset
, c
);
278 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
280 assert(bset
&& bset
->n_div
== 1);
281 isl_basic_set_free(bset
);
284 dim
= isl_dim_set_alloc(ctx
, 0, 3);
285 bset
= isl_basic_set_universe(dim
);
287 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
288 isl_int_set_si(v
, 1);
289 isl_constraint_set_constant(c
, v
);
290 isl_int_set_si(v
, -1);
291 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
292 isl_int_set_si(v
, 3);
293 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
294 bset
= isl_basic_set_add_constraint(bset
, c
);
296 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
297 isl_int_set_si(v
, -1);
298 isl_constraint_set_constant(c
, v
);
299 isl_int_set_si(v
, 1);
300 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
301 isl_int_set_si(v
, 3);
302 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
303 bset
= isl_basic_set_add_constraint(bset
, c
);
305 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
307 assert(bset
&& bset
->n_div
== 1);
308 isl_basic_set_free(bset
);
311 dim
= isl_dim_set_alloc(ctx
, 0, 3);
312 bset
= isl_basic_set_universe(dim
);
314 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
315 isl_int_set_si(v
, 1);
316 isl_constraint_set_constant(c
, v
);
317 isl_int_set_si(v
, -1);
318 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
319 isl_int_set_si(v
, 3);
320 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
321 bset
= isl_basic_set_add_constraint(bset
, c
);
323 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
324 isl_int_set_si(v
, -3);
325 isl_constraint_set_constant(c
, v
);
326 isl_int_set_si(v
, 1);
327 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
328 isl_int_set_si(v
, 4);
329 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
330 bset
= isl_basic_set_add_constraint(bset
, c
);
332 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
334 assert(bset
&& bset
->n_div
== 1);
335 isl_basic_set_free(bset
);
338 dim
= isl_dim_set_alloc(ctx
, 0, 3);
339 bset
= isl_basic_set_universe(dim
);
341 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
342 isl_int_set_si(v
, 2);
343 isl_constraint_set_constant(c
, v
);
344 isl_int_set_si(v
, -1);
345 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
346 isl_int_set_si(v
, 3);
347 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
348 bset
= isl_basic_set_add_constraint(bset
, c
);
350 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
351 isl_int_set_si(v
, -1);
352 isl_constraint_set_constant(c
, v
);
353 isl_int_set_si(v
, 1);
354 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
355 isl_int_set_si(v
, 6);
356 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
357 bset
= isl_basic_set_add_constraint(bset
, c
);
359 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
361 assert(isl_basic_set_is_empty(bset
));
362 isl_basic_set_free(bset
);
365 dim
= isl_dim_set_alloc(ctx
, 0, 3);
366 bset
= isl_basic_set_universe(dim
);
368 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
369 isl_int_set_si(v
, -1);
370 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
371 isl_int_set_si(v
, 3);
372 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
373 bset
= isl_basic_set_add_constraint(bset
, c
);
375 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
376 isl_int_set_si(v
, 1);
377 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
378 isl_int_set_si(v
, -3);
379 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
380 bset
= isl_basic_set_add_constraint(bset
, c
);
382 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
384 assert(bset
&& bset
->n_div
== 0);
385 isl_basic_set_free(bset
);
388 dim
= isl_dim_set_alloc(ctx
, 0, 3);
389 bset
= isl_basic_set_universe(dim
);
391 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
392 isl_int_set_si(v
, -1);
393 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
394 isl_int_set_si(v
, 6);
395 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
396 bset
= isl_basic_set_add_constraint(bset
, c
);
398 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
399 isl_int_set_si(v
, 1);
400 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
401 isl_int_set_si(v
, -3);
402 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
403 bset
= isl_basic_set_add_constraint(bset
, c
);
405 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
407 assert(bset
&& bset
->n_div
== 1);
408 isl_basic_set_free(bset
);
411 /* This test is a bit tricky. We set up an equality
413 * Normalization of divs creates _two_ divs
416 * Afterwards e0 is removed again because it has coefficient -1
417 * and we end up with the original equality and div again.
418 * Perhaps we can avoid the introduction of this temporary div.
420 dim
= isl_dim_set_alloc(ctx
, 0, 4);
421 bset
= isl_basic_set_universe(dim
);
423 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
424 isl_int_set_si(v
, -1);
425 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
426 isl_int_set_si(v
, -3);
427 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
428 isl_int_set_si(v
, -3);
429 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
430 isl_int_set_si(v
, 6);
431 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
432 bset
= isl_basic_set_add_constraint(bset
, c
);
434 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
436 /* Test disabled for now */
438 assert(bset && bset->n_div == 1);
440 isl_basic_set_free(bset
);
443 dim
= isl_dim_set_alloc(ctx
, 0, 5);
444 bset
= isl_basic_set_universe(dim
);
446 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
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
, 1, v
);
451 isl_int_set_si(v
, -3);
452 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
453 isl_int_set_si(v
, 6);
454 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
455 bset
= isl_basic_set_add_constraint(bset
, c
);
457 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
458 isl_int_set_si(v
, -1);
459 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
460 isl_int_set_si(v
, 1);
461 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
462 isl_int_set_si(v
, 1);
463 isl_constraint_set_constant(c
, v
);
464 bset
= isl_basic_set_add_constraint(bset
, c
);
466 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
468 /* Test disabled for now */
470 assert(bset && bset->n_div == 1);
472 isl_basic_set_free(bset
);
475 dim
= isl_dim_set_alloc(ctx
, 0, 4);
476 bset
= isl_basic_set_universe(dim
);
478 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
479 isl_int_set_si(v
, 1);
480 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
481 isl_int_set_si(v
, -1);
482 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
483 isl_int_set_si(v
, -2);
484 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
485 bset
= isl_basic_set_add_constraint(bset
, c
);
487 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
488 isl_int_set_si(v
, -1);
489 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
490 isl_int_set_si(v
, 3);
491 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
492 isl_int_set_si(v
, 2);
493 isl_constraint_set_constant(c
, v
);
494 bset
= isl_basic_set_add_constraint(bset
, c
);
496 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
498 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
500 assert(!isl_basic_set_is_empty(bset
));
502 isl_basic_set_free(bset
);
505 dim
= isl_dim_set_alloc(ctx
, 0, 3);
506 bset
= isl_basic_set_universe(dim
);
508 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
509 isl_int_set_si(v
, 1);
510 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
511 isl_int_set_si(v
, -2);
512 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
513 bset
= isl_basic_set_add_constraint(bset
, c
);
515 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
517 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
519 isl_basic_set_free(bset
);
524 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
528 struct isl_basic_set
*bset1
, *bset2
;
529 struct isl_basic_map
*bmap
;
531 filename
= get_filename(ctx
, name
, "omega");
533 input
= fopen(filename
, "r");
536 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
537 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
539 bset1
= isl_basic_set_apply(bset1
, bmap
);
541 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
543 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
545 isl_basic_set_free(bset1
);
546 isl_basic_set_free(bset2
);
552 void test_application(struct isl_ctx
*ctx
)
554 test_application_case(ctx
, "application");
555 test_application_case(ctx
, "application2");
558 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
562 struct isl_basic_set
*bset1
, *bset2
;
564 filename
= get_filename(ctx
, name
, "polylib");
566 input
= fopen(filename
, "r");
569 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
570 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
572 bset1
= isl_basic_set_affine_hull(bset1
);
574 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
576 isl_basic_set_free(bset1
);
577 isl_basic_set_free(bset2
);
583 void test_affine_hull(struct isl_ctx
*ctx
)
585 test_affine_hull_case(ctx
, "affine2");
586 test_affine_hull_case(ctx
, "affine");
587 test_affine_hull_case(ctx
, "affine3");
590 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
594 struct isl_basic_set
*bset1
, *bset2
;
597 filename
= get_filename(ctx
, name
, "polylib");
599 input
= fopen(filename
, "r");
602 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
603 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
605 set
= isl_basic_set_union(bset1
, bset2
);
606 bset1
= isl_set_convex_hull(set
);
608 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
610 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
612 isl_basic_set_free(bset1
);
613 isl_basic_set_free(bset2
);
619 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
621 const char *str1
, *str2
;
622 isl_set
*set1
, *set2
;
623 int orig_convex
= ctx
->opt
->convex
;
624 ctx
->opt
->convex
= convex
;
626 test_convex_hull_case(ctx
, "convex0");
627 test_convex_hull_case(ctx
, "convex1");
628 test_convex_hull_case(ctx
, "convex2");
629 test_convex_hull_case(ctx
, "convex3");
630 test_convex_hull_case(ctx
, "convex4");
631 test_convex_hull_case(ctx
, "convex5");
632 test_convex_hull_case(ctx
, "convex6");
633 test_convex_hull_case(ctx
, "convex7");
634 test_convex_hull_case(ctx
, "convex8");
635 test_convex_hull_case(ctx
, "convex9");
636 test_convex_hull_case(ctx
, "convex10");
637 test_convex_hull_case(ctx
, "convex11");
638 test_convex_hull_case(ctx
, "convex12");
639 test_convex_hull_case(ctx
, "convex13");
640 test_convex_hull_case(ctx
, "convex14");
641 test_convex_hull_case(ctx
, "convex15");
643 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
644 "(i0 = 1 and i1 = 0 and i2 = 1) or "
645 "(i0 = 0 and i1 = 0 and i2 = 0) }";
646 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
647 set1
= isl_set_read_from_str(ctx
, str1
, -1);
648 set2
= isl_set_read_from_str(ctx
, str2
, -1);
649 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
650 assert(isl_set_is_equal(set1
, set2
));
654 ctx
->opt
->convex
= orig_convex
;
657 void test_convex_hull(struct isl_ctx
*ctx
)
659 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
660 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
663 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
667 struct isl_basic_set
*bset1
, *bset2
;
669 filename
= get_filename(ctx
, name
, "polylib");
671 input
= fopen(filename
, "r");
674 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
675 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
677 bset1
= isl_basic_set_gist(bset1
, bset2
);
679 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
681 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
683 isl_basic_set_free(bset1
);
684 isl_basic_set_free(bset2
);
690 void test_gist(struct isl_ctx
*ctx
)
693 isl_basic_set
*bset1
, *bset2
;
695 test_gist_case(ctx
, "gist1");
697 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
698 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
699 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
700 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
701 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
702 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
703 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
704 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
705 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
706 bset1
= isl_basic_set_read_from_str(ctx
, str
, -1);
707 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
708 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
709 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
710 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
711 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
712 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
713 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
714 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
715 bset2
= isl_basic_set_read_from_str(ctx
, str
, -1);
716 bset1
= isl_basic_set_gist(bset1
, bset2
);
717 assert(bset1
&& bset1
->n_div
== 0);
718 isl_basic_set_free(bset1
);
721 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
725 set
= isl_set_read_from_str(ctx
, str
, -1);
726 set
= isl_set_coalesce(set
);
727 set2
= isl_set_read_from_str(ctx
, str
, -1);
728 assert(isl_set_is_equal(set
, set2
));
730 assert(set
&& set
->n
== 1);
735 void test_coalesce(struct isl_ctx
*ctx
)
738 struct isl_set
*set
, *set2
;
739 struct isl_map
*map
, *map2
;
741 set
= isl_set_read_from_str(ctx
,
742 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
743 "y >= x & x >= 2 & 5 >= y }", -1);
744 set
= isl_set_coalesce(set
);
745 assert(set
&& set
->n
== 1);
748 set
= isl_set_read_from_str(ctx
,
749 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
750 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
751 set
= isl_set_coalesce(set
);
752 assert(set
&& set
->n
== 1);
755 set
= isl_set_read_from_str(ctx
,
756 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
757 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
758 set
= isl_set_coalesce(set
);
759 assert(set
&& set
->n
== 2);
762 set
= isl_set_read_from_str(ctx
,
763 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
764 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
765 set
= isl_set_coalesce(set
);
766 assert(set
&& set
->n
== 1);
769 set
= isl_set_read_from_str(ctx
,
770 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
771 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
772 set
= isl_set_coalesce(set
);
773 assert(set
&& set
->n
== 2);
776 set
= isl_set_read_from_str(ctx
,
777 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
778 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
779 set
= isl_set_coalesce(set
);
780 assert(set
&& set
->n
== 2);
783 set
= isl_set_read_from_str(ctx
,
784 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
785 "y >= 0 & x = 6 & y <= 6}", -1);
786 set
= isl_set_coalesce(set
);
787 assert(set
&& set
->n
== 1);
790 set
= isl_set_read_from_str(ctx
,
791 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
792 "y >= 0 & x = 7 & y <= 6}", -1);
793 set
= isl_set_coalesce(set
);
794 assert(set
&& set
->n
== 2);
797 set
= isl_set_read_from_str(ctx
,
798 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
799 "y >= 0 & x = 6 & y <= 5}", -1);
800 set
= isl_set_coalesce(set
);
801 assert(set
&& set
->n
== 1);
802 set2
= isl_set_read_from_str(ctx
,
803 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
804 "y >= 0 & x = 6 & y <= 5}", -1);
805 assert(isl_set_is_equal(set
, set2
));
809 set
= isl_set_read_from_str(ctx
,
810 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
811 "y >= 0 & x = 6 & y <= 7}", -1);
812 set
= isl_set_coalesce(set
);
813 assert(set
&& set
->n
== 2);
816 set
= isl_set_read_from_str(ctx
,
817 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
818 set
= isl_set_coalesce(set
);
819 assert(set
&& set
->n
== 1);
820 set2
= isl_set_read_from_str(ctx
,
821 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
822 assert(isl_set_is_equal(set
, set2
));
826 set
= isl_set_read_from_str(ctx
,
827 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
828 set
= isl_set_coalesce(set
);
829 set2
= isl_set_read_from_str(ctx
,
830 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
831 assert(isl_set_is_equal(set
, set2
));
835 set
= isl_set_read_from_str(ctx
,
836 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
837 "2 <= i and i <= n }", -1);
838 set
= isl_set_coalesce(set
);
839 assert(set
&& set
->n
== 1);
840 set2
= isl_set_read_from_str(ctx
,
841 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
842 "2 <= i and i <= n }", -1);
843 assert(isl_set_is_equal(set
, set2
));
847 map
= isl_map_read_from_str(ctx
,
848 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
849 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
850 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
851 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
852 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
853 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
854 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
855 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
856 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
857 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
858 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
859 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
860 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
861 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
862 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
863 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
864 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
865 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
866 map
= isl_map_coalesce(map
);
867 map2
= isl_map_read_from_str(ctx
,
868 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
869 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
870 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
871 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
872 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
873 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
874 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
875 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
876 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
877 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
878 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
879 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
880 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
881 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
882 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
883 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
884 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
885 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
886 assert(isl_map_is_equal(map
, map2
));
890 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
891 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
892 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
893 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
894 map
= isl_map_read_from_str(ctx
, str
, -1);
895 map
= isl_map_coalesce(map
);
896 map2
= isl_map_read_from_str(ctx
, str
, -1);
897 assert(isl_map_is_equal(map
, map2
));
901 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
902 "[o0, o1, o2, o3, o4, o5, o6] : "
903 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
904 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
905 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
906 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
907 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
908 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
909 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
910 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
911 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
912 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
913 "o6 >= i3 + i6 - o3 and M >= 0 and "
914 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
915 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
916 map
= isl_map_read_from_str(ctx
, str
, -1);
917 map
= isl_map_coalesce(map
);
918 map2
= isl_map_read_from_str(ctx
, str
, -1);
919 assert(isl_map_is_equal(map
, map2
));
923 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
924 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
925 "(o0 = 0 and M >= 2 and N >= 3) or "
926 "(M = 0 and o0 = 0 and N >= 3) }";
927 map
= isl_map_read_from_str(ctx
, str
, -1);
928 map
= isl_map_coalesce(map
);
929 map2
= isl_map_read_from_str(ctx
, str
, -1);
930 assert(isl_map_is_equal(map
, map2
));
934 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
935 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
936 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
937 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
938 map
= isl_map_read_from_str(ctx
, str
, -1);
939 map
= isl_map_coalesce(map
);
940 map2
= isl_map_read_from_str(ctx
, str
, -1);
941 assert(isl_map_is_equal(map
, map2
));
945 test_coalesce_set(ctx
,
946 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
947 "(i1 = M and M >= 1) }", 0);
948 test_coalesce_set(ctx
,
949 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
950 test_coalesce_set(ctx
,
951 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
952 "(y = 3 and x = 1) }", 1);
953 test_coalesce_set(ctx
,
954 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
955 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
956 "i1 <= M and i3 <= M and i4 <= M) or "
957 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
958 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
959 "i4 <= -1 + M) }", 1);
960 test_coalesce_set(ctx
,
961 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
962 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
963 test_coalesce_set(ctx
,
964 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
965 "-x - y + 1 >= 0 and -3 <= z <= 3;"
966 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
967 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
968 test_coalesce_set(ctx
,
969 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
970 test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
971 test_coalesce_set(ctx
,
972 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
973 test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
974 test_coalesce_set(ctx
, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
975 test_coalesce_set(ctx
, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
976 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
977 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
978 test_coalesce_set(ctx
, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
979 test_coalesce_set(ctx
, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
982 void test_closure(struct isl_ctx
*ctx
)
990 /* COCOA example 1 */
991 map
= isl_map_read_from_str(ctx
,
992 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
993 "1 <= i and i < n and 1 <= j and j < n or "
994 "i2 = i + 1 and j2 = j - 1 and "
995 "1 <= i and i < n and 2 <= j and j <= n }", -1);
996 map
= isl_map_power(map
, &exact
);
1000 /* COCOA example 1 */
1001 map
= isl_map_read_from_str(ctx
,
1002 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1003 "1 <= i and i < n and 1 <= j and j < n or "
1004 "i2 = i + 1 and j2 = j - 1 and "
1005 "1 <= i and i < n and 2 <= j and j <= n }", -1);
1006 map
= isl_map_transitive_closure(map
, &exact
);
1008 map2
= isl_map_read_from_str(ctx
,
1009 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1010 "1 <= i and i < n and 1 <= j and j <= n and "
1011 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1012 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1013 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
1014 assert(isl_map_is_equal(map
, map2
));
1018 map
= isl_map_read_from_str(ctx
,
1019 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1020 " 0 <= y and y <= n }", -1);
1021 map
= isl_map_transitive_closure(map
, &exact
);
1022 map2
= isl_map_read_from_str(ctx
,
1023 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1024 " 0 <= y and y <= n }", -1);
1025 assert(isl_map_is_equal(map
, map2
));
1029 /* COCOA example 2 */
1030 map
= isl_map_read_from_str(ctx
,
1031 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1032 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1033 "i2 = i + 2 and j2 = j - 2 and "
1034 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
1035 map
= isl_map_transitive_closure(map
, &exact
);
1037 map2
= isl_map_read_from_str(ctx
,
1038 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1039 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1040 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1041 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1042 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
1043 assert(isl_map_is_equal(map
, map2
));
1047 /* COCOA Fig.2 left */
1048 map
= isl_map_read_from_str(ctx
,
1049 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1050 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1052 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1053 "j <= 2 i - 3 and j <= n - 2 or "
1054 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1055 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1056 map
= isl_map_transitive_closure(map
, &exact
);
1060 /* COCOA Fig.2 right */
1061 map
= isl_map_read_from_str(ctx
,
1062 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1063 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1065 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1066 "j <= 2 i - 4 and j <= n - 3 or "
1067 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1068 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1069 map
= isl_map_power(map
, &exact
);
1073 /* COCOA Fig.2 right */
1074 map
= isl_map_read_from_str(ctx
,
1075 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1076 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1078 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1079 "j <= 2 i - 4 and j <= n - 3 or "
1080 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1081 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1082 map
= isl_map_transitive_closure(map
, &exact
);
1084 map2
= isl_map_read_from_str(ctx
,
1085 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1086 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1087 "j <= n and 3 + i + 2 j <= 3 n and "
1088 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1089 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1090 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1091 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1092 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1093 assert(isl_map_is_equal(map
, map2
));
1097 /* COCOA Fig.1 right */
1098 dom
= isl_set_read_from_str(ctx
,
1099 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1100 "2 x - 3 y + 3 >= 0 }", -1);
1101 right
= isl_map_read_from_str(ctx
,
1102 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1103 up
= isl_map_read_from_str(ctx
,
1104 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1105 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1106 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1107 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1108 up
= isl_map_intersect_range(up
, dom
);
1109 map
= isl_map_union(up
, right
);
1110 map
= isl_map_transitive_closure(map
, &exact
);
1112 map2
= isl_map_read_from_str(ctx
,
1113 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1114 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1115 assert(isl_map_is_equal(map
, map2
));
1119 /* COCOA Theorem 1 counter example */
1120 map
= isl_map_read_from_str(ctx
,
1121 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1122 "i2 = 1 and j2 = j or "
1123 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1124 map
= isl_map_transitive_closure(map
, &exact
);
1128 map
= isl_map_read_from_str(ctx
,
1129 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1130 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1131 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1132 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1133 map
= isl_map_transitive_closure(map
, &exact
);
1137 /* Kelly et al 1996, fig 12 */
1138 map
= isl_map_read_from_str(ctx
,
1139 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1140 "1 <= i,j,j+1 <= n or "
1141 "j = n and j2 = 1 and i2 = i + 1 and "
1142 "1 <= i,i+1 <= n }", -1);
1143 map
= isl_map_transitive_closure(map
, &exact
);
1145 map2
= isl_map_read_from_str(ctx
,
1146 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1147 "1 <= i <= n and i = i2 or "
1148 "1 <= i < i2 <= n and 1 <= j <= n and "
1149 "1 <= j2 <= n }", -1);
1150 assert(isl_map_is_equal(map
, map2
));
1154 /* Omega's closure4 */
1155 map
= isl_map_read_from_str(ctx
,
1156 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1157 "1 <= x,y <= 10 or "
1158 "x2 = x + 1 and y2 = y and "
1159 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1160 map
= isl_map_transitive_closure(map
, &exact
);
1164 map
= isl_map_read_from_str(ctx
,
1165 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1166 map
= isl_map_transitive_closure(map
, &exact
);
1168 map2
= isl_map_read_from_str(ctx
,
1169 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1170 assert(isl_map_is_equal(map
, map2
));
1174 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1175 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1176 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1177 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1178 map
= isl_map_read_from_str(ctx
, str
, -1);
1179 map
= isl_map_transitive_closure(map
, &exact
);
1181 map2
= isl_map_read_from_str(ctx
, str
, -1);
1182 assert(isl_map_is_equal(map
, map2
));
1186 str
= "{[0] -> [1]; [2] -> [3]}";
1187 map
= isl_map_read_from_str(ctx
, str
, -1);
1188 map
= isl_map_transitive_closure(map
, &exact
);
1190 map2
= isl_map_read_from_str(ctx
, str
, -1);
1191 assert(isl_map_is_equal(map
, map2
));
1195 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1196 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1197 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1198 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1199 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1200 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1201 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1202 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1203 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1204 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1205 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1206 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1207 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1208 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1209 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1210 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1211 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1212 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1213 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1214 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1215 map
= isl_map_read_from_str(ctx
, str
, -1);
1216 map
= isl_map_transitive_closure(map
, NULL
);
1221 void test_lex(struct isl_ctx
*ctx
)
1226 dim
= isl_dim_alloc(ctx
, 0, 0, 0);
1227 map
= isl_map_lex_le(dim
);
1228 assert(!isl_map_is_empty(map
));
1232 static int consume_lexmin(__isl_take isl_basic_set
*dom
,
1233 __isl_take isl_aff_list
*list
, void *user
)
1236 isl_basic_map
*bmap
;
1237 isl_map
**map
= user
;
1239 dim
= isl_basic_set_get_dim(dom
);
1240 bmap
= isl_basic_map_from_aff_list(dim
, list
);
1241 bmap
= isl_basic_map_intersect_domain(bmap
, dom
);
1243 *map
= isl_map_union(*map
, isl_map_from_basic_map(bmap
));
1248 void test_lexmin(struct isl_ctx
*ctx
)
1251 isl_basic_map
*bmap
;
1252 isl_map
*map
, *map2
;
1256 str
= "[p0, p1] -> { [] -> [] : "
1257 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1258 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1259 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1260 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1261 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1262 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1263 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1264 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1265 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1266 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1267 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1268 map
= isl_map_read_from_str(ctx
, str
, -1);
1269 map
= isl_map_lexmin(map
);
1272 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1273 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1274 set
= isl_set_read_from_str(ctx
, str
, -1);
1275 set
= isl_set_lexmax(set
);
1276 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1277 set2
= isl_set_read_from_str(ctx
, str
, -1);
1278 set
= isl_set_intersect(set
, set2
);
1279 assert(!isl_set_is_empty(set
));
1282 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1283 map
= isl_map_read_from_str(ctx
, str
, -1);
1284 map
= isl_map_lexmin(map
);
1285 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1286 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1287 map2
= isl_map_read_from_str(ctx
, str
, -1);
1288 assert(isl_map_is_equal(map
, map2
));
1292 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1293 map
= isl_map_read_from_str(ctx
, str
, -1);
1294 map2
= isl_map_copy(map
);
1295 map
= isl_map_lexmin(map
);
1296 assert(isl_map_is_equal(map
, map2
));
1300 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1301 map
= isl_map_read_from_str(ctx
, str
, -1);
1302 map
= isl_map_lexmin(map
);
1303 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1304 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1305 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1306 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1307 map2
= isl_map_read_from_str(ctx
, str
, -1);
1308 assert(isl_map_is_equal(map
, map2
));
1312 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1313 " 8i' <= i and 8i' >= -7 + i }";
1314 bmap
= isl_basic_map_read_from_str(ctx
, str
, -1);
1315 map2
= isl_map_empty(isl_basic_map_get_dim(bmap
));
1316 isl_basic_map_foreach_lexmin(bmap
, &consume_lexmin
, &map2
);
1317 map
= isl_map_from_basic_map(bmap
);
1318 assert(isl_map_is_equal(map
, map2
));
1328 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1329 void *dep_user
, void *user
)
1331 struct must_may
*mm
= (struct must_may
*)user
;
1334 mm
->must
= isl_map_union(mm
->must
, dep
);
1336 mm
->may
= isl_map_union(mm
->may
, dep
);
1341 static int common_space(void *first
, void *second
)
1343 int depth
= *(int *)first
;
1347 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1355 map2
= isl_map_read_from_str(map
->ctx
, str
, -1);
1356 equal
= isl_map_is_equal(map
, map2
);
1362 void test_dep(struct isl_ctx
*ctx
)
1367 isl_access_info
*ai
;
1374 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1375 map
= isl_map_read_from_str(ctx
, str
, -1);
1376 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1378 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1379 map
= isl_map_read_from_str(ctx
, str
, -1);
1380 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1382 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1383 map
= isl_map_read_from_str(ctx
, str
, -1);
1384 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1386 flow
= isl_access_info_compute_flow(ai
);
1387 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1388 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1389 mm
.may
= isl_map_empty(dim
);
1391 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1393 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1394 " [1,10,0] -> [2,5,0] }";
1395 assert(map_is_equal(mm
.must
, str
));
1396 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1397 assert(map_is_equal(mm
.may
, str
));
1399 isl_map_free(mm
.must
);
1400 isl_map_free(mm
.may
);
1401 isl_flow_free(flow
);
1404 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1405 map
= isl_map_read_from_str(ctx
, str
, -1);
1406 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1408 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1409 map
= isl_map_read_from_str(ctx
, str
, -1);
1410 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1412 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1413 map
= isl_map_read_from_str(ctx
, str
, -1);
1414 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1416 flow
= isl_access_info_compute_flow(ai
);
1417 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1418 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1419 mm
.may
= isl_map_empty(dim
);
1421 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1423 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1424 assert(map_is_equal(mm
.must
, str
));
1425 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1426 assert(map_is_equal(mm
.may
, str
));
1428 isl_map_free(mm
.must
);
1429 isl_map_free(mm
.may
);
1430 isl_flow_free(flow
);
1433 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1434 map
= isl_map_read_from_str(ctx
, str
, -1);
1435 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1437 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1438 map
= isl_map_read_from_str(ctx
, str
, -1);
1439 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1441 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1442 map
= isl_map_read_from_str(ctx
, str
, -1);
1443 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1445 flow
= isl_access_info_compute_flow(ai
);
1446 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1447 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1448 mm
.may
= isl_map_empty(dim
);
1450 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1452 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1453 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1454 assert(map_is_equal(mm
.may
, str
));
1455 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1456 assert(map_is_equal(mm
.must
, str
));
1458 isl_map_free(mm
.must
);
1459 isl_map_free(mm
.may
);
1460 isl_flow_free(flow
);
1463 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1464 map
= isl_map_read_from_str(ctx
, str
, -1);
1465 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1467 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1468 map
= isl_map_read_from_str(ctx
, str
, -1);
1469 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1471 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1472 map
= isl_map_read_from_str(ctx
, str
, -1);
1473 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1475 flow
= isl_access_info_compute_flow(ai
);
1476 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1477 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1478 mm
.may
= isl_map_empty(dim
);
1480 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1482 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1483 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1484 assert(map_is_equal(mm
.may
, str
));
1485 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1486 assert(map_is_equal(mm
.must
, str
));
1488 isl_map_free(mm
.must
);
1489 isl_map_free(mm
.may
);
1490 isl_flow_free(flow
);
1493 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1494 map
= isl_map_read_from_str(ctx
, str
, -1);
1495 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1497 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1498 map
= isl_map_read_from_str(ctx
, str
, -1);
1499 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1501 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1502 map
= isl_map_read_from_str(ctx
, str
, -1);
1503 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1505 flow
= isl_access_info_compute_flow(ai
);
1506 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1507 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1508 mm
.may
= isl_map_empty(dim
);
1510 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1512 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1513 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1514 assert(map_is_equal(mm
.may
, str
));
1515 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1516 assert(map_is_equal(mm
.must
, str
));
1518 isl_map_free(mm
.must
);
1519 isl_map_free(mm
.may
);
1520 isl_flow_free(flow
);
1525 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1526 map
= isl_map_read_from_str(ctx
, str
, -1);
1527 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1529 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1530 map
= isl_map_read_from_str(ctx
, str
, -1);
1531 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1533 flow
= isl_access_info_compute_flow(ai
);
1534 dim
= isl_dim_alloc(ctx
, 0, 5, 5);
1535 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1536 mm
.may
= isl_map_empty(dim
);
1538 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1540 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1541 assert(map_is_equal(mm
.must
, str
));
1542 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1543 assert(map_is_equal(mm
.may
, str
));
1545 isl_map_free(mm
.must
);
1546 isl_map_free(mm
.may
);
1547 isl_flow_free(flow
);
1550 int test_sv(isl_ctx
*ctx
)
1554 isl_union_map
*umap
;
1557 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1558 map
= isl_map_read_from_str(ctx
, str
, -1);
1559 sv
= isl_map_is_single_valued(map
);
1564 isl_die(ctx
, isl_error_internal
,
1565 "map not detected as single valued", return -1);
1567 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1568 map
= isl_map_read_from_str(ctx
, str
, -1);
1569 sv
= isl_map_is_single_valued(map
);
1574 isl_die(ctx
, isl_error_internal
,
1575 "map detected as single valued", return -1);
1577 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1578 umap
= isl_union_map_read_from_str(ctx
, str
);
1579 sv
= isl_union_map_is_single_valued(umap
);
1580 isl_union_map_free(umap
);
1584 isl_die(ctx
, isl_error_internal
,
1585 "map not detected as single valued", return -1);
1587 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1588 umap
= isl_union_map_read_from_str(ctx
, str
);
1589 sv
= isl_union_map_is_single_valued(umap
);
1590 isl_union_map_free(umap
);
1594 isl_die(ctx
, isl_error_internal
,
1595 "map detected as single valued", return -1);
1600 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1604 map
= isl_map_read_from_str(ctx
, str
, -1);
1606 assert(isl_map_is_bijective(map
));
1608 assert(!isl_map_is_bijective(map
));
1612 void test_bijective(struct isl_ctx
*ctx
)
1614 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1615 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1616 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1617 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1618 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1619 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1620 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1621 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1622 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1623 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1624 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1625 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1626 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1629 void test_pwqp(struct isl_ctx
*ctx
)
1633 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1635 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1636 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1638 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1641 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1642 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1644 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1646 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1648 isl_pw_qpolynomial_free(pwqp1
);
1650 str
= "{ [i] -> i }";
1651 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1652 str
= "{ [k] : exists a : k = 2a }";
1653 set
= isl_set_read_from_str(ctx
, str
, 0);
1654 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1655 str
= "{ [i] -> i }";
1656 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1658 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1660 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1662 isl_pw_qpolynomial_free(pwqp1
);
1664 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
1665 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1667 set
= isl_set_read_from_str(ctx
, str
, 0);
1668 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1669 str
= "{ [i] -> 16 }";
1670 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1672 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1674 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1676 isl_pw_qpolynomial_free(pwqp1
);
1678 str
= "{ [i] -> ([(i)/2]) }";
1679 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1680 str
= "{ [k] : exists a : k = 2a+1 }";
1681 set
= isl_set_read_from_str(ctx
, str
, 0);
1682 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1683 str
= "{ [i] -> -1/2 + 1/2 * i }";
1684 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1686 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1688 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1690 isl_pw_qpolynomial_free(pwqp1
);
1692 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
1693 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1694 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
1695 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1697 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1699 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1701 isl_pw_qpolynomial_free(pwqp1
);
1703 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
1704 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1705 str
= "{ [x] -> x }";
1706 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1708 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1710 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1712 isl_pw_qpolynomial_free(pwqp1
);
1714 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1715 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1716 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1717 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
1718 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1719 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1720 isl_pw_qpolynomial_free(pwqp1
);
1723 void test_split_periods(isl_ctx
*ctx
)
1726 isl_pw_qpolynomial
*pwqp
;
1728 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1729 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1730 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1731 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1733 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1736 isl_pw_qpolynomial_free(pwqp
);
1739 void test_union(isl_ctx
*ctx
)
1742 isl_union_set
*uset1
, *uset2
;
1743 isl_union_map
*umap1
, *umap2
;
1745 str
= "{ [i] : 0 <= i <= 1 }";
1746 uset1
= isl_union_set_read_from_str(ctx
, str
);
1747 str
= "{ [1] -> [0] }";
1748 umap1
= isl_union_map_read_from_str(ctx
, str
);
1750 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
1751 assert(isl_union_map_is_equal(umap1
, umap2
));
1753 isl_union_map_free(umap1
);
1754 isl_union_map_free(umap2
);
1756 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1757 umap1
= isl_union_map_read_from_str(ctx
, str
);
1758 str
= "{ A[i]; B[i] }";
1759 uset1
= isl_union_set_read_from_str(ctx
, str
);
1761 uset2
= isl_union_map_domain(umap1
);
1763 assert(isl_union_set_is_equal(uset1
, uset2
));
1765 isl_union_set_free(uset1
);
1766 isl_union_set_free(uset2
);
1769 void test_bound(isl_ctx
*ctx
)
1772 isl_pw_qpolynomial
*pwqp
;
1773 isl_pw_qpolynomial_fold
*pwf
;
1775 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
1776 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1777 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1778 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_set
) == 4);
1779 isl_pw_qpolynomial_fold_free(pwf
);
1781 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1782 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1783 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1784 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_set
) == 1);
1785 isl_pw_qpolynomial_fold_free(pwf
);
1788 void test_lift(isl_ctx
*ctx
)
1791 isl_basic_map
*bmap
;
1792 isl_basic_set
*bset
;
1794 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
1795 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1796 bset
= isl_basic_set_lift(bset
);
1797 bmap
= isl_basic_map_from_range(bset
);
1798 bset
= isl_basic_map_domain(bmap
);
1799 isl_basic_set_free(bset
);
1802 void test_subset(isl_ctx
*ctx
)
1805 isl_set
*set1
, *set2
;
1807 str
= "{ [112, 0] }";
1808 set1
= isl_set_read_from_str(ctx
, str
, 0);
1809 str
= "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1810 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1811 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1812 set2
= isl_set_read_from_str(ctx
, str
, 0);
1813 assert(isl_set_is_subset(set1
, set2
));
1818 void test_factorize(isl_ctx
*ctx
)
1821 isl_basic_set
*bset
;
1824 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1825 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1826 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1827 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1828 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1829 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1830 "3i5 >= -2i0 - i2 + 3i4 }";
1831 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1832 f
= isl_basic_set_factorizer(bset
);
1834 isl_basic_set_free(bset
);
1835 isl_factorizer_free(f
);
1837 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1838 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1839 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1840 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1841 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1842 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1843 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1844 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1845 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1846 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1847 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1848 f
= isl_basic_set_factorizer(bset
);
1850 isl_basic_set_free(bset
);
1851 isl_factorizer_free(f
);
1854 static int check_injective(__isl_take isl_map
*map
, void *user
)
1856 int *injective
= user
;
1858 *injective
= isl_map_is_injective(map
);
1861 if (*injective
< 0 || !*injective
)
1867 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
1868 const char *r
, const char *s
, int tilable
, int parallel
)
1872 isl_union_map
*W
, *R
, *S
;
1873 isl_union_map
*empty
;
1874 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
1875 isl_union_map
*validity
, *proximity
;
1876 isl_union_map
*schedule
;
1877 isl_union_map
*test
;
1878 isl_union_set
*delta
;
1879 isl_union_set
*domain
;
1883 isl_schedule
*sched
;
1884 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
1886 D
= isl_union_set_read_from_str(ctx
, d
);
1887 W
= isl_union_map_read_from_str(ctx
, w
);
1888 R
= isl_union_map_read_from_str(ctx
, r
);
1889 S
= isl_union_map_read_from_str(ctx
, s
);
1891 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
1892 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
1894 empty
= isl_union_map_empty(isl_union_map_get_dim(S
));
1895 isl_union_map_compute_flow(isl_union_map_copy(R
),
1896 isl_union_map_copy(W
), empty
,
1897 isl_union_map_copy(S
),
1898 &dep_raw
, NULL
, NULL
, NULL
);
1899 isl_union_map_compute_flow(isl_union_map_copy(W
),
1900 isl_union_map_copy(W
),
1901 isl_union_map_copy(R
),
1902 isl_union_map_copy(S
),
1903 &dep_waw
, &dep_war
, NULL
, NULL
);
1905 dep
= isl_union_map_union(dep_waw
, dep_war
);
1906 dep
= isl_union_map_union(dep
, dep_raw
);
1907 validity
= isl_union_map_copy(dep
);
1908 proximity
= isl_union_map_copy(dep
);
1910 sched
= isl_union_set_compute_schedule(isl_union_set_copy(D
),
1911 validity
, proximity
);
1912 schedule
= isl_schedule_get_map(sched
);
1913 isl_schedule_free(sched
);
1914 isl_union_map_free(W
);
1915 isl_union_map_free(R
);
1916 isl_union_map_free(S
);
1919 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
1921 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
1922 is_complete
= isl_union_set_is_subset(D
, domain
);
1923 isl_union_set_free(D
);
1924 isl_union_set_free(domain
);
1926 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
1927 test
= isl_union_map_apply_range(test
, dep
);
1928 test
= isl_union_map_apply_range(test
, schedule
);
1930 delta
= isl_union_map_deltas(test
);
1931 if (isl_union_set_n_set(delta
) == 0) {
1935 isl_union_set_free(delta
);
1937 delta_set
= isl_set_from_union_set(delta
);
1939 slice
= isl_set_universe(isl_set_get_dim(delta_set
));
1940 for (i
= 0; i
< tilable
; ++i
)
1941 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
1942 is_tilable
= isl_set_is_subset(delta_set
, slice
);
1943 isl_set_free(slice
);
1945 slice
= isl_set_universe(isl_set_get_dim(delta_set
));
1946 for (i
= 0; i
< parallel
; ++i
)
1947 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
1948 is_parallel
= isl_set_is_subset(delta_set
, slice
);
1949 isl_set_free(slice
);
1951 origin
= isl_set_universe(isl_set_get_dim(delta_set
));
1952 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
1953 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
1955 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
1956 delta_set
= isl_set_lexmin(delta_set
);
1958 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
1960 isl_set_free(origin
);
1961 isl_set_free(delta_set
);
1964 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
1965 is_injection
< 0 || is_complete
< 0)
1968 isl_die(ctx
, isl_error_unknown
,
1969 "generated schedule incomplete", return -1);
1971 isl_die(ctx
, isl_error_unknown
,
1972 "generated schedule not injective on each statement",
1975 isl_die(ctx
, isl_error_unknown
,
1976 "negative dependences in generated schedule",
1979 isl_die(ctx
, isl_error_unknown
,
1980 "generated schedule not as tilable as expected",
1983 isl_die(ctx
, isl_error_unknown
,
1984 "generated schedule not as parallel as expected",
1990 int test_special_schedule(isl_ctx
*ctx
)
1994 isl_union_map
*empty
;
1996 isl_union_map
*sched1
, *sched2
;
1997 isl_schedule
*schedule
;
2000 str
= "{ S[i,j] : 0 <= i <= 10 }";
2001 dom
= isl_union_set_read_from_str(ctx
, str
);
2002 str
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2003 dep
= isl_union_map_read_from_str(ctx
, str
);
2004 empty
= isl_union_map_read_from_str(ctx
, "{}");
2005 schedule
= isl_union_set_compute_schedule(dom
, empty
, dep
);
2006 sched1
= isl_schedule_get_map(schedule
);
2007 isl_schedule_free(schedule
);
2009 str
= "{ S[i, j] -> [j, i] }";
2010 sched2
= isl_union_map_read_from_str(ctx
, str
);
2012 equal
= isl_union_map_is_equal(sched1
, sched2
);
2013 isl_union_map_free(sched1
);
2014 isl_union_map_free(sched2
);
2019 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2025 int test_schedule(isl_ctx
*ctx
)
2027 const char *D
, *W
, *R
, *S
;
2030 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2031 W
= "{ S1[t,i] -> a[t,i] }";
2032 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2033 "S1[t,i] -> a[t-1,i+1] }";
2034 S
= "{ S1[t,i] -> [t,i] }";
2035 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2038 /* Fig. 5 of CC2008 */
2039 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2041 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2042 "j >= 2 and j <= -1 + N }";
2043 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2044 "j >= 2 and j <= -1 + N; "
2045 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2046 "j >= 2 and j <= -1 + N }";
2047 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2048 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2051 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2052 W
= "{ S1[i] -> a[i] }";
2053 R
= "{ S2[i] -> a[i+1] }";
2054 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2055 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2058 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2059 W
= "{ S1[i] -> a[i] }";
2060 R
= "{ S2[i] -> a[9-i] }";
2061 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2062 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2065 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2066 W
= "{ S1[i] -> a[i] }";
2067 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2068 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2069 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2072 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2073 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2074 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2075 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2076 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2079 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2080 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2081 R
= "{ S2[i,j] -> a[i-1,j] }";
2082 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2083 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2086 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2087 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2088 R
= "{ S2[i,j] -> a[i,j-1] }";
2089 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2090 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2093 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2094 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2095 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2096 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2097 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2098 "S_0[] -> [0, 0, 0] }";
2099 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2101 ctx
->opt
->schedule_parametric
= 0;
2102 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2104 ctx
->opt
->schedule_parametric
= 1;
2106 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2107 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2108 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2109 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2110 "S4[i] -> a[i,N] }";
2111 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2112 "S4[i] -> [4,i,0] }";
2113 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2116 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2117 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2119 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2121 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2123 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2124 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2127 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2128 " S_2[t] : t >= 0 and t <= -1 + N; "
2129 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2131 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2132 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2133 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2134 "i >= 0 and i <= -1 + N }";
2135 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2136 "i >= 0 and i <= -1 + N; "
2137 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2138 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2139 " S_0[t] -> [0, t, 0] }";
2141 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2143 ctx
->opt
->schedule_parametric
= 0;
2144 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2146 ctx
->opt
->schedule_parametric
= 1;
2148 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2149 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2150 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
2153 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2154 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2155 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2156 "j >= 0 and j <= -1 + N; "
2157 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2158 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2159 "j >= 0 and j <= -1 + N; "
2160 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2161 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2162 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2165 D
= "{ S_0[i] : i >= 0 }";
2166 W
= "{ S_0[i] -> a[i] : i >= 0 }";
2167 R
= "{ S_0[i] -> a[0] : i >= 0 }";
2168 S
= "{ S_0[i] -> [0, i, 0] }";
2169 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2172 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2173 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2174 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2175 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2176 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2179 return test_special_schedule(ctx
);
2182 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
2184 isl_union_map
*umap
;
2187 umap
= isl_union_map_read_from_str(ctx
, str
);
2188 test
= isl_union_map_plain_is_injective(umap
);
2189 isl_union_map_free(umap
);
2192 if (test
== injective
)
2195 isl_die(ctx
, isl_error_unknown
,
2196 "map not detected as injective", return -1);
2198 isl_die(ctx
, isl_error_unknown
,
2199 "map detected as injective", return -1);
2202 int test_injective(isl_ctx
*ctx
)
2206 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2208 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
2210 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
2212 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
2214 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2216 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2218 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2220 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2223 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2224 if (test_plain_injective(ctx
, str
, 1))
2226 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2227 if (test_plain_injective(ctx
, str
, 0))
2233 int test_aff(isl_ctx
*ctx
)
2238 isl_local_space
*ls
;
2242 dim
= isl_dim_set_alloc(ctx
, 0, 1);
2243 ls
= isl_local_space_from_dim(dim
);
2244 aff
= isl_aff_zero(ls
);
2246 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_set
, 0, 1);
2247 aff
= isl_aff_scale_down_ui(aff
, 3);
2248 aff
= isl_aff_floor(aff
);
2249 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_set
, 0, 1);
2250 aff
= isl_aff_scale_down_ui(aff
, 2);
2251 aff
= isl_aff_floor(aff
);
2252 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_set
, 0, 1);
2255 set
= isl_set_read_from_str(ctx
, str
, 0);
2256 aff
= isl_aff_gist(aff
, set
);
2258 aff
= isl_aff_add_constant_si(aff
, -16);
2259 zero
= isl_aff_plain_is_zero(aff
);
2265 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2270 int test_dim_max(isl_ctx
*ctx
)
2274 isl_map
*map
, *map2
;
2278 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
2279 set
= isl_set_read_from_str(ctx
, str
, -1);
2280 pwaff
= isl_set_dim_max(set
, 0);
2281 map
= isl_map_from_pw_aff(pwaff
);
2282 str
= "[N] -> { [] -> [10] : N >= 10; [] -> [N] : N <= 9 and N >= 0 }";
2283 map2
= isl_map_read_from_str(ctx
, str
, -1);
2284 equal
= isl_map_is_equal(map
, map2
);
2290 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2292 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2293 set
= isl_set_read_from_str(ctx
, str
, -1);
2294 pwaff
= isl_set_dim_max(set
, 0);
2295 map
= isl_map_from_pw_aff(pwaff
);
2296 str
= "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
2297 map2
= isl_map_read_from_str(ctx
, str
, -1);
2298 equal
= isl_map_is_equal(map
, map2
);
2304 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2306 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2307 set
= isl_set_read_from_str(ctx
, str
, -1);
2308 pwaff
= isl_set_dim_max(set
, 0);
2309 map
= isl_map_from_pw_aff(pwaff
);
2310 str
= "[N] -> { [] -> [6 + N] : -6 <= N <= 5; [] -> [2N] : N >= 6 }";
2311 map2
= isl_map_read_from_str(ctx
, str
, -1);
2312 equal
= isl_map_is_equal(map
, map2
);
2318 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2320 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2321 "0 <= i < N and 0 <= j < M }";
2322 map
= isl_map_read_from_str(ctx
, str
, -1);
2323 set
= isl_map_range(map
);
2325 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
2326 map
= isl_map_from_pw_aff(pwaff
);
2327 str
= "[N,M] -> { [] -> [([(N-1)/16])] : M,N > 0 }";
2328 map2
= isl_map_read_from_str(ctx
, str
, -1);
2329 equal
= isl_map_is_equal(map
, map2
);
2333 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
2334 map
= isl_map_from_pw_aff(pwaff
);
2335 str
= "[N,M] -> { [] -> [t] : t = min(M-1,15) and M,N > 0 }";
2336 map2
= isl_map_read_from_str(ctx
, str
, -1);
2337 if (equal
>= 0 && equal
)
2338 equal
= isl_map_is_equal(map
, map2
);
2347 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2354 struct isl_ctx
*ctx
;
2356 srcdir
= getenv("srcdir");
2359 ctx
= isl_ctx_alloc();
2360 if (test_dim_max(ctx
) < 0)
2362 if (test_aff(ctx
) < 0)
2364 if (test_injective(ctx
) < 0)
2366 if (test_schedule(ctx
) < 0)
2368 test_factorize(ctx
);
2373 test_split_periods(ctx
);
2377 if (test_sv(ctx
) < 0)
2379 test_bijective(ctx
);
2383 test_construction(ctx
);
2386 test_application(ctx
);
2387 test_affine_hull(ctx
);
2388 test_convex_hull(ctx
);