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>
23 #include <isl_options_private.h>
24 #include <isl/vertices.h>
28 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
31 char *pattern
= "%s/test_inputs/%s.%s";
33 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
35 filename
= isl_alloc_array(ctx
, char, length
);
40 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
45 void test_parse_map(isl_ctx
*ctx
, const char *str
)
49 map
= isl_map_read_from_str(ctx
, str
);
54 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
59 map
= isl_map_read_from_str(ctx
, str
);
60 map2
= isl_map_read_from_str(ctx
, str2
);
61 equal
= isl_map_is_equal(map
, map2
);
68 isl_die(ctx
, isl_error_unknown
, "maps not equal",
74 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
76 isl_pw_qpolynomial
*pwqp
;
78 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
80 isl_pw_qpolynomial_free(pwqp
);
83 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
87 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
89 isl_pw_aff_free(pwaff
);
92 int test_parse(struct isl_ctx
*ctx
)
95 const char *str
, *str2
;
97 str
= "{ [i] -> [-i] }";
98 map
= isl_map_read_from_str(ctx
, str
);
102 str
= "{ A[i] -> L[([i/3])] }";
103 map
= isl_map_read_from_str(ctx
, str
);
107 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
108 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
109 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
111 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
112 str2
= "{ [x, y] : 2y >= 6 - x }";
113 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
116 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
117 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
119 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
120 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
124 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
125 map
= isl_map_read_from_str(ctx
, str
);
126 str
= "{ [new, old] -> [o0, o1] : "
127 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
128 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
129 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
130 map2
= isl_map_read_from_str(ctx
, str
);
131 assert(isl_map_is_equal(map
, map2
));
135 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
136 map
= isl_map_read_from_str(ctx
, str
);
137 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
138 map2
= isl_map_read_from_str(ctx
, str
);
139 assert(isl_map_is_equal(map
, map2
));
143 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
144 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
145 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
148 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
149 str2
= "{ [i,j] -> [min(i,j)] }";
150 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
153 str
= "{ [i,j] : i != j }";
154 str2
= "{ [i,j] : i < j or i > j }";
155 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
158 str
= "{ [i,j] : (i+1)*2 >= j }";
159 str2
= "{ [i, j] : j <= 2 + 2i }";
160 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
163 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
164 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
165 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
168 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
169 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
170 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
173 str
= "{ [x] : x >= 0 }";
174 str2
= "{ [x] : x-0 >= 0 }";
175 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
178 str
= "{ [i] : ((i > 10)) }";
179 str2
= "{ [i] : i >= 11 }";
180 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
183 str
= "{ [i] -> [0] }";
184 str2
= "{ [i] -> [0 * i] }";
185 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
188 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
189 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
190 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
191 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
193 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
194 "{ [a] -> [b] : true }") < 0)
200 void test_read(struct isl_ctx
*ctx
)
204 struct isl_basic_set
*bset1
, *bset2
;
205 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
207 filename
= get_filename(ctx
, "set", "omega");
209 input
= fopen(filename
, "r");
212 bset1
= isl_basic_set_read_from_file(ctx
, input
);
213 bset2
= isl_basic_set_read_from_str(ctx
, str
);
215 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
217 isl_basic_set_free(bset1
);
218 isl_basic_set_free(bset2
);
224 void test_bounded(struct isl_ctx
*ctx
)
229 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
230 bounded
= isl_set_is_bounded(set
);
234 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
235 bounded
= isl_set_is_bounded(set
);
239 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
240 bounded
= isl_set_is_bounded(set
);
245 /* Construct the basic set { [i] : 5 <= i <= N } */
246 void test_construction(struct isl_ctx
*ctx
)
251 struct isl_basic_set
*bset
;
252 struct isl_constraint
*c
;
256 dim
= isl_space_set_alloc(ctx
, 1, 1);
257 bset
= isl_basic_set_universe(isl_space_copy(dim
));
258 ls
= isl_local_space_from_space(dim
);
260 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
261 isl_int_set_si(v
, -1);
262 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
263 isl_int_set_si(v
, 1);
264 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
265 bset
= isl_basic_set_add_constraint(bset
, c
);
267 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
268 isl_int_set_si(v
, 1);
269 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
270 isl_int_set_si(v
, -5);
271 isl_constraint_set_constant(c
, v
);
272 bset
= isl_basic_set_add_constraint(bset
, c
);
274 isl_local_space_free(ls
);
275 isl_basic_set_free(bset
);
280 void test_dim(struct isl_ctx
*ctx
)
283 isl_map
*map1
, *map2
;
285 map1
= isl_map_read_from_str(ctx
,
286 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
287 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
288 map2
= isl_map_read_from_str(ctx
,
289 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
290 assert(isl_map_is_equal(map1
, map2
));
293 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
294 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
295 assert(isl_map_is_equal(map1
, map2
));
300 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
301 map1
= isl_map_read_from_str(ctx
, str
);
302 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
303 map2
= isl_map_read_from_str(ctx
, str
);
304 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
305 assert(isl_map_is_equal(map1
, map2
));
311 void test_div(struct isl_ctx
*ctx
)
316 struct isl_basic_set
*bset
;
317 struct isl_constraint
*c
;
322 dim
= isl_space_set_alloc(ctx
, 0, 3);
323 bset
= isl_basic_set_universe(isl_space_copy(dim
));
324 ls
= isl_local_space_from_space(dim
);
326 c
= isl_equality_alloc(isl_local_space_copy(ls
));
327 isl_int_set_si(v
, -1);
328 isl_constraint_set_constant(c
, v
);
329 isl_int_set_si(v
, 1);
330 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
331 isl_int_set_si(v
, 3);
332 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
333 bset
= isl_basic_set_add_constraint(bset
, c
);
335 c
= isl_equality_alloc(isl_local_space_copy(ls
));
336 isl_int_set_si(v
, 1);
337 isl_constraint_set_constant(c
, v
);
338 isl_int_set_si(v
, -1);
339 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
340 isl_int_set_si(v
, 3);
341 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
342 bset
= isl_basic_set_add_constraint(bset
, c
);
344 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
346 assert(bset
&& bset
->n_div
== 1);
347 isl_local_space_free(ls
);
348 isl_basic_set_free(bset
);
351 dim
= isl_space_set_alloc(ctx
, 0, 3);
352 bset
= isl_basic_set_universe(isl_space_copy(dim
));
353 ls
= isl_local_space_from_space(dim
);
355 c
= isl_equality_alloc(isl_local_space_copy(ls
));
356 isl_int_set_si(v
, 1);
357 isl_constraint_set_constant(c
, v
);
358 isl_int_set_si(v
, -1);
359 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
360 isl_int_set_si(v
, 3);
361 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
362 bset
= isl_basic_set_add_constraint(bset
, c
);
364 c
= isl_equality_alloc(isl_local_space_copy(ls
));
365 isl_int_set_si(v
, -1);
366 isl_constraint_set_constant(c
, v
);
367 isl_int_set_si(v
, 1);
368 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
369 isl_int_set_si(v
, 3);
370 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
371 bset
= isl_basic_set_add_constraint(bset
, c
);
373 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
375 assert(bset
&& bset
->n_div
== 1);
376 isl_local_space_free(ls
);
377 isl_basic_set_free(bset
);
380 dim
= isl_space_set_alloc(ctx
, 0, 3);
381 bset
= isl_basic_set_universe(isl_space_copy(dim
));
382 ls
= isl_local_space_from_space(dim
);
384 c
= isl_equality_alloc(isl_local_space_copy(ls
));
385 isl_int_set_si(v
, 1);
386 isl_constraint_set_constant(c
, v
);
387 isl_int_set_si(v
, -1);
388 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
389 isl_int_set_si(v
, 3);
390 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
391 bset
= isl_basic_set_add_constraint(bset
, c
);
393 c
= isl_equality_alloc(isl_local_space_copy(ls
));
394 isl_int_set_si(v
, -3);
395 isl_constraint_set_constant(c
, v
);
396 isl_int_set_si(v
, 1);
397 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
398 isl_int_set_si(v
, 4);
399 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
400 bset
= isl_basic_set_add_constraint(bset
, c
);
402 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
404 assert(bset
&& bset
->n_div
== 1);
405 isl_local_space_free(ls
);
406 isl_basic_set_free(bset
);
409 dim
= isl_space_set_alloc(ctx
, 0, 3);
410 bset
= isl_basic_set_universe(isl_space_copy(dim
));
411 ls
= isl_local_space_from_space(dim
);
413 c
= isl_equality_alloc(isl_local_space_copy(ls
));
414 isl_int_set_si(v
, 2);
415 isl_constraint_set_constant(c
, v
);
416 isl_int_set_si(v
, -1);
417 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
418 isl_int_set_si(v
, 3);
419 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
420 bset
= isl_basic_set_add_constraint(bset
, c
);
422 c
= isl_equality_alloc(isl_local_space_copy(ls
));
423 isl_int_set_si(v
, -1);
424 isl_constraint_set_constant(c
, v
);
425 isl_int_set_si(v
, 1);
426 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
427 isl_int_set_si(v
, 6);
428 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
429 bset
= isl_basic_set_add_constraint(bset
, c
);
431 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
433 assert(isl_basic_set_is_empty(bset
));
434 isl_local_space_free(ls
);
435 isl_basic_set_free(bset
);
438 dim
= isl_space_set_alloc(ctx
, 0, 3);
439 bset
= isl_basic_set_universe(isl_space_copy(dim
));
440 ls
= isl_local_space_from_space(dim
);
442 c
= isl_equality_alloc(isl_local_space_copy(ls
));
443 isl_int_set_si(v
, -1);
444 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
445 isl_int_set_si(v
, 3);
446 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
447 bset
= isl_basic_set_add_constraint(bset
, c
);
449 c
= isl_equality_alloc(isl_local_space_copy(ls
));
450 isl_int_set_si(v
, 1);
451 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
452 isl_int_set_si(v
, -3);
453 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
454 bset
= isl_basic_set_add_constraint(bset
, c
);
456 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
458 assert(bset
&& bset
->n_div
== 0);
459 isl_basic_set_free(bset
);
460 isl_local_space_free(ls
);
463 dim
= isl_space_set_alloc(ctx
, 0, 3);
464 bset
= isl_basic_set_universe(isl_space_copy(dim
));
465 ls
= isl_local_space_from_space(dim
);
467 c
= isl_equality_alloc(isl_local_space_copy(ls
));
468 isl_int_set_si(v
, -1);
469 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
470 isl_int_set_si(v
, 6);
471 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
472 bset
= isl_basic_set_add_constraint(bset
, c
);
474 c
= isl_equality_alloc(isl_local_space_copy(ls
));
475 isl_int_set_si(v
, 1);
476 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
477 isl_int_set_si(v
, -3);
478 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
479 bset
= isl_basic_set_add_constraint(bset
, c
);
481 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
483 assert(bset
&& bset
->n_div
== 1);
484 isl_basic_set_free(bset
);
485 isl_local_space_free(ls
);
488 /* This test is a bit tricky. We set up an equality
490 * Normalization of divs creates _two_ divs
493 * Afterwards e0 is removed again because it has coefficient -1
494 * and we end up with the original equality and div again.
495 * Perhaps we can avoid the introduction of this temporary div.
497 dim
= isl_space_set_alloc(ctx
, 0, 4);
498 bset
= isl_basic_set_universe(isl_space_copy(dim
));
499 ls
= isl_local_space_from_space(dim
);
501 c
= isl_equality_alloc(isl_local_space_copy(ls
));
502 isl_int_set_si(v
, -1);
503 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
504 isl_int_set_si(v
, -3);
505 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
506 isl_int_set_si(v
, -3);
507 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
508 isl_int_set_si(v
, 6);
509 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
510 bset
= isl_basic_set_add_constraint(bset
, c
);
512 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
514 /* Test disabled for now */
516 assert(bset && bset->n_div == 1);
518 isl_local_space_free(ls
);
519 isl_basic_set_free(bset
);
522 dim
= isl_space_set_alloc(ctx
, 0, 5);
523 bset
= isl_basic_set_universe(isl_space_copy(dim
));
524 ls
= isl_local_space_from_space(dim
);
526 c
= isl_equality_alloc(isl_local_space_copy(ls
));
527 isl_int_set_si(v
, -1);
528 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
529 isl_int_set_si(v
, -3);
530 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
531 isl_int_set_si(v
, -3);
532 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
533 isl_int_set_si(v
, 6);
534 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
535 bset
= isl_basic_set_add_constraint(bset
, c
);
537 c
= isl_equality_alloc(isl_local_space_copy(ls
));
538 isl_int_set_si(v
, -1);
539 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
540 isl_int_set_si(v
, 1);
541 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
542 isl_int_set_si(v
, 1);
543 isl_constraint_set_constant(c
, v
);
544 bset
= isl_basic_set_add_constraint(bset
, c
);
546 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
548 /* Test disabled for now */
550 assert(bset && bset->n_div == 1);
552 isl_local_space_free(ls
);
553 isl_basic_set_free(bset
);
556 dim
= isl_space_set_alloc(ctx
, 0, 4);
557 bset
= isl_basic_set_universe(isl_space_copy(dim
));
558 ls
= isl_local_space_from_space(dim
);
560 c
= isl_equality_alloc(isl_local_space_copy(ls
));
561 isl_int_set_si(v
, 1);
562 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
563 isl_int_set_si(v
, -1);
564 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
565 isl_int_set_si(v
, -2);
566 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
567 bset
= isl_basic_set_add_constraint(bset
, c
);
569 c
= isl_equality_alloc(isl_local_space_copy(ls
));
570 isl_int_set_si(v
, -1);
571 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
572 isl_int_set_si(v
, 3);
573 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
574 isl_int_set_si(v
, 2);
575 isl_constraint_set_constant(c
, v
);
576 bset
= isl_basic_set_add_constraint(bset
, c
);
578 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
580 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
582 assert(!isl_basic_set_is_empty(bset
));
584 isl_local_space_free(ls
);
585 isl_basic_set_free(bset
);
588 dim
= isl_space_set_alloc(ctx
, 0, 3);
589 bset
= isl_basic_set_universe(isl_space_copy(dim
));
590 ls
= isl_local_space_from_space(dim
);
592 c
= isl_equality_alloc(isl_local_space_copy(ls
));
593 isl_int_set_si(v
, 1);
594 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
595 isl_int_set_si(v
, -2);
596 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
597 bset
= isl_basic_set_add_constraint(bset
, c
);
599 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
601 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
603 isl_local_space_free(ls
);
604 isl_basic_set_free(bset
);
609 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
613 struct isl_basic_set
*bset1
, *bset2
;
614 struct isl_basic_map
*bmap
;
616 filename
= get_filename(ctx
, name
, "omega");
618 input
= fopen(filename
, "r");
621 bset1
= isl_basic_set_read_from_file(ctx
, input
);
622 bmap
= isl_basic_map_read_from_file(ctx
, input
);
624 bset1
= isl_basic_set_apply(bset1
, bmap
);
626 bset2
= isl_basic_set_read_from_file(ctx
, input
);
628 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
630 isl_basic_set_free(bset1
);
631 isl_basic_set_free(bset2
);
637 void test_application(struct isl_ctx
*ctx
)
639 test_application_case(ctx
, "application");
640 test_application_case(ctx
, "application2");
643 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
647 struct isl_basic_set
*bset1
, *bset2
;
649 filename
= get_filename(ctx
, name
, "polylib");
651 input
= fopen(filename
, "r");
654 bset1
= isl_basic_set_read_from_file(ctx
, input
);
655 bset2
= isl_basic_set_read_from_file(ctx
, input
);
657 bset1
= isl_basic_set_affine_hull(bset1
);
659 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
661 isl_basic_set_free(bset1
);
662 isl_basic_set_free(bset2
);
668 int test_affine_hull(struct isl_ctx
*ctx
)
675 test_affine_hull_case(ctx
, "affine2");
676 test_affine_hull_case(ctx
, "affine");
677 test_affine_hull_case(ctx
, "affine3");
679 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
680 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
681 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
682 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
683 set
= isl_set_read_from_str(ctx
, str
);
684 bset
= isl_set_affine_hull(set
);
685 n
= isl_basic_set_dim(bset
, isl_dim_div
);
686 isl_basic_set_free(bset
);
688 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
694 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
698 struct isl_basic_set
*bset1
, *bset2
;
701 filename
= get_filename(ctx
, name
, "polylib");
703 input
= fopen(filename
, "r");
706 bset1
= isl_basic_set_read_from_file(ctx
, input
);
707 bset2
= isl_basic_set_read_from_file(ctx
, input
);
709 set
= isl_basic_set_union(bset1
, bset2
);
710 bset1
= isl_set_convex_hull(set
);
712 bset2
= isl_basic_set_read_from_file(ctx
, input
);
714 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
716 isl_basic_set_free(bset1
);
717 isl_basic_set_free(bset2
);
723 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
725 const char *str1
, *str2
;
726 isl_set
*set1
, *set2
;
727 int orig_convex
= ctx
->opt
->convex
;
728 ctx
->opt
->convex
= convex
;
730 test_convex_hull_case(ctx
, "convex0");
731 test_convex_hull_case(ctx
, "convex1");
732 test_convex_hull_case(ctx
, "convex2");
733 test_convex_hull_case(ctx
, "convex3");
734 test_convex_hull_case(ctx
, "convex4");
735 test_convex_hull_case(ctx
, "convex5");
736 test_convex_hull_case(ctx
, "convex6");
737 test_convex_hull_case(ctx
, "convex7");
738 test_convex_hull_case(ctx
, "convex8");
739 test_convex_hull_case(ctx
, "convex9");
740 test_convex_hull_case(ctx
, "convex10");
741 test_convex_hull_case(ctx
, "convex11");
742 test_convex_hull_case(ctx
, "convex12");
743 test_convex_hull_case(ctx
, "convex13");
744 test_convex_hull_case(ctx
, "convex14");
745 test_convex_hull_case(ctx
, "convex15");
747 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
748 "(i0 = 1 and i1 = 0 and i2 = 1) or "
749 "(i0 = 0 and i1 = 0 and i2 = 0) }";
750 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
751 set1
= isl_set_read_from_str(ctx
, str1
);
752 set2
= isl_set_read_from_str(ctx
, str2
);
753 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
754 assert(isl_set_is_equal(set1
, set2
));
758 ctx
->opt
->convex
= orig_convex
;
761 void test_convex_hull(struct isl_ctx
*ctx
)
763 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
764 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
767 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
771 struct isl_basic_set
*bset1
, *bset2
;
773 filename
= get_filename(ctx
, name
, "polylib");
775 input
= fopen(filename
, "r");
778 bset1
= isl_basic_set_read_from_file(ctx
, input
);
779 bset2
= isl_basic_set_read_from_file(ctx
, input
);
781 bset1
= isl_basic_set_gist(bset1
, bset2
);
783 bset2
= isl_basic_set_read_from_file(ctx
, input
);
785 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
787 isl_basic_set_free(bset1
);
788 isl_basic_set_free(bset2
);
794 void test_gist(struct isl_ctx
*ctx
)
797 isl_basic_set
*bset1
, *bset2
;
799 test_gist_case(ctx
, "gist1");
801 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
802 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
803 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
804 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
805 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
806 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
807 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
808 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
809 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
810 bset1
= isl_basic_set_read_from_str(ctx
, str
);
811 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
812 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
813 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
814 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
815 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
816 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
817 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
818 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
819 bset2
= isl_basic_set_read_from_str(ctx
, str
);
820 bset1
= isl_basic_set_gist(bset1
, bset2
);
821 assert(bset1
&& bset1
->n_div
== 0);
822 isl_basic_set_free(bset1
);
825 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
831 set
= isl_set_read_from_str(ctx
, str
);
832 set
= isl_set_coalesce(set
);
833 set2
= isl_set_read_from_str(ctx
, str
);
834 equal
= isl_set_is_equal(set
, set2
);
835 one
= set
&& set
->n
== 1;
842 isl_die(ctx
, isl_error_unknown
,
843 "coalesced set not equal to input", return -1);
844 if (check_one
&& !one
)
845 isl_die(ctx
, isl_error_unknown
,
846 "coalesced set should not be a union", return -1);
851 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
856 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
857 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
859 if (test_coalesce_set(ctx
,
860 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
861 "-x - y + 1 >= 0 and -3 <= z <= 3;"
862 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
863 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
864 "-10 <= y <= 0}", 1) < 0)
866 if (test_coalesce_set(ctx
,
867 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
869 if (test_coalesce_set(ctx
,
870 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
878 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
883 int test_coalesce(struct isl_ctx
*ctx
)
886 struct isl_set
*set
, *set2
;
887 struct isl_map
*map
, *map2
;
889 set
= isl_set_read_from_str(ctx
,
890 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
891 "y >= x & x >= 2 & 5 >= y }");
892 set
= isl_set_coalesce(set
);
893 assert(set
&& set
->n
== 1);
896 set
= isl_set_read_from_str(ctx
,
897 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
898 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}");
899 set
= isl_set_coalesce(set
);
900 assert(set
&& set
->n
== 1);
903 set
= isl_set_read_from_str(ctx
,
904 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
905 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}");
906 set
= isl_set_coalesce(set
);
907 assert(set
&& set
->n
== 2);
910 set
= isl_set_read_from_str(ctx
,
911 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
912 "y >= 0 & x >= 6 & x <= 10 & y <= x}");
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 & x <= 5 & y <= x or "
919 "y >= 0 & x >= 7 & x <= 10 & y <= x}");
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 + 1 <= x}");
927 set
= isl_set_coalesce(set
);
928 assert(set
&& set
->n
== 2);
931 set
= isl_set_read_from_str(ctx
,
932 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
933 "y >= 0 & x = 6 & y <= 6}");
934 set
= isl_set_coalesce(set
);
935 assert(set
&& set
->n
== 1);
938 set
= isl_set_read_from_str(ctx
,
939 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
940 "y >= 0 & x = 7 & y <= 6}");
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 <= 5}");
948 set
= isl_set_coalesce(set
);
949 assert(set
&& set
->n
== 1);
950 set2
= isl_set_read_from_str(ctx
,
951 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
952 "y >= 0 & x = 6 & y <= 5}");
953 assert(isl_set_is_equal(set
, set2
));
957 set
= isl_set_read_from_str(ctx
,
958 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
959 "y >= 0 & x = 6 & y <= 7}");
960 set
= isl_set_coalesce(set
);
961 assert(set
&& set
->n
== 2);
964 set
= isl_set_read_from_str(ctx
,
965 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
966 set
= isl_set_coalesce(set
);
967 assert(set
&& set
->n
== 1);
968 set2
= isl_set_read_from_str(ctx
,
969 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
970 assert(isl_set_is_equal(set
, set2
));
974 set
= isl_set_read_from_str(ctx
,
975 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
976 set
= isl_set_coalesce(set
);
977 set2
= isl_set_read_from_str(ctx
,
978 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
979 assert(isl_set_is_equal(set
, set2
));
983 set
= isl_set_read_from_str(ctx
,
984 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
985 "2 <= i and i <= n }");
986 set
= isl_set_coalesce(set
);
987 assert(set
&& set
->n
== 1);
988 set2
= isl_set_read_from_str(ctx
,
989 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
990 "2 <= i and i <= n }");
991 assert(isl_set_is_equal(set
, set2
));
995 map
= isl_map_read_from_str(ctx
,
996 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
997 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
998 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
999 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1000 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1001 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1002 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1003 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1004 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1005 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1006 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1007 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1008 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1009 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1010 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1011 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1012 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1013 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
1014 map
= isl_map_coalesce(map
);
1015 map2
= isl_map_read_from_str(ctx
,
1016 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1017 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1018 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1019 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1020 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1021 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1022 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1023 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1024 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1025 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1026 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1027 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1028 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1029 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1030 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1031 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1032 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1033 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
1034 assert(isl_map_is_equal(map
, map2
));
1038 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1039 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1040 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1041 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
1042 map
= isl_map_read_from_str(ctx
, str
);
1043 map
= isl_map_coalesce(map
);
1044 map2
= isl_map_read_from_str(ctx
, str
);
1045 assert(isl_map_is_equal(map
, map2
));
1049 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
1050 "[o0, o1, o2, o3, o4, o5, o6] : "
1051 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1052 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1053 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1054 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1055 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1056 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1057 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1058 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1059 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1060 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1061 "o6 >= i3 + i6 - o3 and M >= 0 and "
1062 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1063 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
1064 map
= isl_map_read_from_str(ctx
, str
);
1065 map
= isl_map_coalesce(map
);
1066 map2
= isl_map_read_from_str(ctx
, str
);
1067 assert(isl_map_is_equal(map
, map2
));
1071 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1072 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1073 "(o0 = 0 and M >= 2 and N >= 3) or "
1074 "(M = 0 and o0 = 0 and N >= 3) }";
1075 map
= isl_map_read_from_str(ctx
, str
);
1076 map
= isl_map_coalesce(map
);
1077 map2
= isl_map_read_from_str(ctx
, str
);
1078 assert(isl_map_is_equal(map
, map2
));
1082 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1083 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1084 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1085 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
1086 map
= isl_map_read_from_str(ctx
, str
);
1087 map
= isl_map_coalesce(map
);
1088 map2
= isl_map_read_from_str(ctx
, str
);
1089 assert(isl_map_is_equal(map
, map2
));
1093 test_coalesce_set(ctx
,
1094 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
1095 "(i1 = M and M >= 1) }", 0);
1096 test_coalesce_set(ctx
,
1097 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
1098 test_coalesce_set(ctx
,
1099 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1100 "(y = 3 and x = 1) }", 1);
1101 test_coalesce_set(ctx
,
1102 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1103 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1104 "i1 <= M and i3 <= M and i4 <= M) or "
1105 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1106 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1107 "i4 <= -1 + M) }", 1);
1108 test_coalesce_set(ctx
,
1109 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1110 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
1111 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1113 if (test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0) < 0)
1115 if (test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1) < 0)
1117 if (test_coalesce_set(ctx
, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1) < 0)
1119 if (test_coalesce_set(ctx
, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0) < 0)
1121 if (test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1) < 0)
1123 if (test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0) < 0)
1125 if (test_coalesce_set(ctx
, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1127 if (test_coalesce_set(ctx
, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
1129 if (test_coalesce_set(ctx
, "{ [a, b] : exists e : 2e = a and "
1130 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }", 0) < 0)
1132 if (test_coalesce_set(ctx
,
1133 "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1134 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1135 "j >= 1 and j' <= i + j - i' and i >= 1; "
1136 "[1, 1, 1, 1] }", 0) < 0)
1138 if (test_coalesce_set(ctx
, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1139 "[i,j] : exists a : j = 3a }", 1) < 0)
1144 void test_closure(struct isl_ctx
*ctx
)
1148 isl_map
*up
, *right
;
1149 isl_map
*map
, *map2
;
1152 /* COCOA example 1 */
1153 map
= isl_map_read_from_str(ctx
,
1154 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1155 "1 <= i and i < n and 1 <= j and j < n or "
1156 "i2 = i + 1 and j2 = j - 1 and "
1157 "1 <= i and i < n and 2 <= j and j <= n }");
1158 map
= isl_map_power(map
, &exact
);
1162 /* COCOA example 1 */
1163 map
= isl_map_read_from_str(ctx
,
1164 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1165 "1 <= i and i < n and 1 <= j and j < n or "
1166 "i2 = i + 1 and j2 = j - 1 and "
1167 "1 <= i and i < n and 2 <= j and j <= n }");
1168 map
= isl_map_transitive_closure(map
, &exact
);
1170 map2
= isl_map_read_from_str(ctx
,
1171 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1172 "1 <= i and i < n and 1 <= j and j <= n and "
1173 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1174 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1175 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1176 assert(isl_map_is_equal(map
, map2
));
1180 map
= isl_map_read_from_str(ctx
,
1181 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1182 " 0 <= y and y <= n }");
1183 map
= isl_map_transitive_closure(map
, &exact
);
1184 map2
= isl_map_read_from_str(ctx
,
1185 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1186 " 0 <= y and y <= n }");
1187 assert(isl_map_is_equal(map
, map2
));
1191 /* COCOA example 2 */
1192 map
= isl_map_read_from_str(ctx
,
1193 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1194 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1195 "i2 = i + 2 and j2 = j - 2 and "
1196 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1197 map
= isl_map_transitive_closure(map
, &exact
);
1199 map2
= isl_map_read_from_str(ctx
,
1200 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1201 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1202 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1203 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1204 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1205 assert(isl_map_is_equal(map
, map2
));
1209 /* COCOA Fig.2 left */
1210 map
= isl_map_read_from_str(ctx
,
1211 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1212 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1214 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1215 "j <= 2 i - 3 and j <= n - 2 or "
1216 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1217 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1218 map
= isl_map_transitive_closure(map
, &exact
);
1222 /* COCOA Fig.2 right */
1223 map
= isl_map_read_from_str(ctx
,
1224 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1225 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1227 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1228 "j <= 2 i - 4 and j <= n - 3 or "
1229 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1230 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1231 map
= isl_map_power(map
, &exact
);
1235 /* COCOA Fig.2 right */
1236 map
= isl_map_read_from_str(ctx
,
1237 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1238 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1240 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1241 "j <= 2 i - 4 and j <= n - 3 or "
1242 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1243 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1244 map
= isl_map_transitive_closure(map
, &exact
);
1246 map2
= isl_map_read_from_str(ctx
,
1247 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1248 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1249 "j <= n and 3 + i + 2 j <= 3 n and "
1250 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1251 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1252 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1253 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1254 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1255 assert(isl_map_is_equal(map
, map2
));
1259 /* COCOA Fig.1 right */
1260 dom
= isl_set_read_from_str(ctx
,
1261 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1262 "2 x - 3 y + 3 >= 0 }");
1263 right
= isl_map_read_from_str(ctx
,
1264 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1265 up
= isl_map_read_from_str(ctx
,
1266 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1267 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1268 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1269 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1270 up
= isl_map_intersect_range(up
, dom
);
1271 map
= isl_map_union(up
, right
);
1272 map
= isl_map_transitive_closure(map
, &exact
);
1274 map2
= isl_map_read_from_str(ctx
,
1275 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1276 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1277 assert(isl_map_is_equal(map
, map2
));
1281 /* COCOA Theorem 1 counter example */
1282 map
= isl_map_read_from_str(ctx
,
1283 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1284 "i2 = 1 and j2 = j or "
1285 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1286 map
= isl_map_transitive_closure(map
, &exact
);
1290 map
= isl_map_read_from_str(ctx
,
1291 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1292 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1293 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1294 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1295 map
= isl_map_transitive_closure(map
, &exact
);
1299 /* Kelly et al 1996, fig 12 */
1300 map
= isl_map_read_from_str(ctx
,
1301 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1302 "1 <= i,j,j+1 <= n or "
1303 "j = n and j2 = 1 and i2 = i + 1 and "
1304 "1 <= i,i+1 <= n }");
1305 map
= isl_map_transitive_closure(map
, &exact
);
1307 map2
= isl_map_read_from_str(ctx
,
1308 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1309 "1 <= i <= n and i = i2 or "
1310 "1 <= i < i2 <= n and 1 <= j <= n and "
1312 assert(isl_map_is_equal(map
, map2
));
1316 /* Omega's closure4 */
1317 map
= isl_map_read_from_str(ctx
,
1318 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1319 "1 <= x,y <= 10 or "
1320 "x2 = x + 1 and y2 = y and "
1321 "1 <= x <= 20 && 5 <= y <= 15 }");
1322 map
= isl_map_transitive_closure(map
, &exact
);
1326 map
= isl_map_read_from_str(ctx
,
1327 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1328 map
= isl_map_transitive_closure(map
, &exact
);
1330 map2
= isl_map_read_from_str(ctx
,
1331 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1332 assert(isl_map_is_equal(map
, map2
));
1336 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1337 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1338 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1339 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1340 map
= isl_map_read_from_str(ctx
, str
);
1341 map
= isl_map_transitive_closure(map
, &exact
);
1343 map2
= isl_map_read_from_str(ctx
, str
);
1344 assert(isl_map_is_equal(map
, map2
));
1348 str
= "{[0] -> [1]; [2] -> [3]}";
1349 map
= isl_map_read_from_str(ctx
, str
);
1350 map
= isl_map_transitive_closure(map
, &exact
);
1352 map2
= isl_map_read_from_str(ctx
, str
);
1353 assert(isl_map_is_equal(map
, map2
));
1357 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1358 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1359 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1360 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1361 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1362 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1363 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1364 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1365 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1366 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1367 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1368 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1369 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1370 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1371 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1372 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1373 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1374 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1375 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1376 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1377 map
= isl_map_read_from_str(ctx
, str
);
1378 map
= isl_map_transitive_closure(map
, NULL
);
1383 void test_lex(struct isl_ctx
*ctx
)
1388 dim
= isl_space_set_alloc(ctx
, 0, 0);
1389 map
= isl_map_lex_le(dim
);
1390 assert(!isl_map_is_empty(map
));
1394 void test_lexmin(struct isl_ctx
*ctx
)
1397 isl_basic_map
*bmap
;
1398 isl_map
*map
, *map2
;
1401 isl_pw_multi_aff
*pma
;
1403 str
= "[p0, p1] -> { [] -> [] : "
1404 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1405 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1406 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1407 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1408 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1409 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1410 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1411 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1412 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1413 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1414 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1415 map
= isl_map_read_from_str(ctx
, str
);
1416 map
= isl_map_lexmin(map
);
1419 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1420 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1421 set
= isl_set_read_from_str(ctx
, str
);
1422 set
= isl_set_lexmax(set
);
1423 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1424 set2
= isl_set_read_from_str(ctx
, str
);
1425 set
= isl_set_intersect(set
, set2
);
1426 assert(!isl_set_is_empty(set
));
1429 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1430 map
= isl_map_read_from_str(ctx
, str
);
1431 map
= isl_map_lexmin(map
);
1432 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1433 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1434 map2
= isl_map_read_from_str(ctx
, str
);
1435 assert(isl_map_is_equal(map
, map2
));
1439 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1440 map
= isl_map_read_from_str(ctx
, str
);
1441 map2
= isl_map_copy(map
);
1442 map
= isl_map_lexmin(map
);
1443 assert(isl_map_is_equal(map
, map2
));
1447 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1448 map
= isl_map_read_from_str(ctx
, str
);
1449 map
= isl_map_lexmin(map
);
1450 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1451 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1452 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1453 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1454 map2
= isl_map_read_from_str(ctx
, str
);
1455 assert(isl_map_is_equal(map
, map2
));
1459 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1460 " 8i' <= i and 8i' >= -7 + i }";
1461 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1462 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1463 map2
= isl_map_from_pw_multi_aff(pma
);
1464 map
= isl_map_from_basic_map(bmap
);
1465 assert(isl_map_is_equal(map
, map2
));
1469 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1470 map
= isl_map_read_from_str(ctx
, str
);
1471 map
= isl_map_lexmin(map
);
1472 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1473 map2
= isl_map_read_from_str(ctx
, str
);
1474 assert(isl_map_is_equal(map
, map2
));
1484 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1485 void *dep_user
, void *user
)
1487 struct must_may
*mm
= (struct must_may
*)user
;
1490 mm
->must
= isl_map_union(mm
->must
, dep
);
1492 mm
->may
= isl_map_union(mm
->may
, dep
);
1497 static int common_space(void *first
, void *second
)
1499 int depth
= *(int *)first
;
1503 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1511 map2
= isl_map_read_from_str(map
->ctx
, str
);
1512 equal
= isl_map_is_equal(map
, map2
);
1518 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1522 equal
= map_is_equal(map
, str
);
1526 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1527 "result not as expected", return -1);
1531 void test_dep(struct isl_ctx
*ctx
)
1536 isl_access_info
*ai
;
1543 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1544 map
= isl_map_read_from_str(ctx
, str
);
1545 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1547 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1548 map
= isl_map_read_from_str(ctx
, str
);
1549 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1551 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1552 map
= isl_map_read_from_str(ctx
, str
);
1553 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1555 flow
= isl_access_info_compute_flow(ai
);
1556 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1557 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1558 mm
.may
= isl_map_empty(dim
);
1560 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1562 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1563 " [1,10,0] -> [2,5,0] }";
1564 assert(map_is_equal(mm
.must
, str
));
1565 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1566 assert(map_is_equal(mm
.may
, str
));
1568 isl_map_free(mm
.must
);
1569 isl_map_free(mm
.may
);
1570 isl_flow_free(flow
);
1573 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1574 map
= isl_map_read_from_str(ctx
, str
);
1575 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1577 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1578 map
= isl_map_read_from_str(ctx
, str
);
1579 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1581 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1582 map
= isl_map_read_from_str(ctx
, str
);
1583 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1585 flow
= isl_access_info_compute_flow(ai
);
1586 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1587 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1588 mm
.may
= isl_map_empty(dim
);
1590 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1592 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1593 assert(map_is_equal(mm
.must
, str
));
1594 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1595 assert(map_is_equal(mm
.may
, str
));
1597 isl_map_free(mm
.must
);
1598 isl_map_free(mm
.may
);
1599 isl_flow_free(flow
);
1602 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1603 map
= isl_map_read_from_str(ctx
, str
);
1604 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1606 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1607 map
= isl_map_read_from_str(ctx
, str
);
1608 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1610 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1611 map
= isl_map_read_from_str(ctx
, str
);
1612 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1614 flow
= isl_access_info_compute_flow(ai
);
1615 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1616 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1617 mm
.may
= isl_map_empty(dim
);
1619 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1621 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1622 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1623 assert(map_is_equal(mm
.may
, str
));
1624 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1625 assert(map_is_equal(mm
.must
, str
));
1627 isl_map_free(mm
.must
);
1628 isl_map_free(mm
.may
);
1629 isl_flow_free(flow
);
1632 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1633 map
= isl_map_read_from_str(ctx
, str
);
1634 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1636 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1637 map
= isl_map_read_from_str(ctx
, str
);
1638 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1640 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1641 map
= isl_map_read_from_str(ctx
, str
);
1642 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1644 flow
= isl_access_info_compute_flow(ai
);
1645 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1646 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1647 mm
.may
= isl_map_empty(dim
);
1649 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1651 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1652 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1653 assert(map_is_equal(mm
.may
, str
));
1654 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1655 assert(map_is_equal(mm
.must
, str
));
1657 isl_map_free(mm
.must
);
1658 isl_map_free(mm
.may
);
1659 isl_flow_free(flow
);
1662 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1663 map
= isl_map_read_from_str(ctx
, str
);
1664 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1666 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1667 map
= isl_map_read_from_str(ctx
, str
);
1668 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1670 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1671 map
= isl_map_read_from_str(ctx
, str
);
1672 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1674 flow
= isl_access_info_compute_flow(ai
);
1675 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1676 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1677 mm
.may
= isl_map_empty(dim
);
1679 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1681 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1682 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1683 assert(map_is_equal(mm
.may
, str
));
1684 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1685 assert(map_is_equal(mm
.must
, str
));
1687 isl_map_free(mm
.must
);
1688 isl_map_free(mm
.may
);
1689 isl_flow_free(flow
);
1694 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1695 map
= isl_map_read_from_str(ctx
, str
);
1696 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1698 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1699 map
= isl_map_read_from_str(ctx
, str
);
1700 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1702 flow
= isl_access_info_compute_flow(ai
);
1703 dim
= isl_space_alloc(ctx
, 0, 5, 5);
1704 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1705 mm
.may
= isl_map_empty(dim
);
1707 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1709 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1710 assert(map_is_equal(mm
.must
, str
));
1711 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1712 assert(map_is_equal(mm
.may
, str
));
1714 isl_map_free(mm
.must
);
1715 isl_map_free(mm
.may
);
1716 isl_flow_free(flow
);
1719 int test_sv(isl_ctx
*ctx
)
1723 isl_union_map
*umap
;
1726 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1727 map
= isl_map_read_from_str(ctx
, str
);
1728 sv
= isl_map_is_single_valued(map
);
1733 isl_die(ctx
, isl_error_internal
,
1734 "map not detected as single valued", return -1);
1736 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1737 map
= isl_map_read_from_str(ctx
, str
);
1738 sv
= isl_map_is_single_valued(map
);
1743 isl_die(ctx
, isl_error_internal
,
1744 "map detected as single valued", return -1);
1746 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1747 umap
= isl_union_map_read_from_str(ctx
, str
);
1748 sv
= isl_union_map_is_single_valued(umap
);
1749 isl_union_map_free(umap
);
1753 isl_die(ctx
, isl_error_internal
,
1754 "map not detected as single valued", return -1);
1756 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1757 umap
= isl_union_map_read_from_str(ctx
, str
);
1758 sv
= isl_union_map_is_single_valued(umap
);
1759 isl_union_map_free(umap
);
1763 isl_die(ctx
, isl_error_internal
,
1764 "map detected as single valued", return -1);
1769 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1773 map
= isl_map_read_from_str(ctx
, str
);
1775 assert(isl_map_is_bijective(map
));
1777 assert(!isl_map_is_bijective(map
));
1781 void test_bijective(struct isl_ctx
*ctx
)
1783 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1784 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1785 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1786 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1787 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1788 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1789 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1790 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1791 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1792 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1793 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1794 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1795 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1798 void test_pwqp(struct isl_ctx
*ctx
)
1802 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1804 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1805 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1807 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1810 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1811 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1813 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1815 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1817 isl_pw_qpolynomial_free(pwqp1
);
1819 str
= "{ [i] -> i }";
1820 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1821 str
= "{ [k] : exists a : k = 2a }";
1822 set
= isl_set_read_from_str(ctx
, str
);
1823 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1824 str
= "{ [i] -> i }";
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 + [ (i + [i/3])/2 ] }";
1834 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1836 set
= isl_set_read_from_str(ctx
, str
);
1837 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1838 str
= "{ [i] -> 16 }";
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)/2]) }";
1848 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1849 str
= "{ [k] : exists a : k = 2a+1 }";
1850 set
= isl_set_read_from_str(ctx
, str
);
1851 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1852 str
= "{ [i] -> -1/2 + 1/2 * i }";
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] + [i/2])/5]) }";
1862 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1863 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
1864 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1866 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1868 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1870 isl_pw_qpolynomial_free(pwqp1
);
1872 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
1873 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1874 str
= "{ [x] -> x }";
1875 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1877 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1879 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1881 isl_pw_qpolynomial_free(pwqp1
);
1883 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1884 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1885 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1886 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
1887 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1888 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1889 isl_pw_qpolynomial_free(pwqp1
);
1892 void test_split_periods(isl_ctx
*ctx
)
1895 isl_pw_qpolynomial
*pwqp
;
1897 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1898 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1899 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1900 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1902 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1905 isl_pw_qpolynomial_free(pwqp
);
1908 void test_union(isl_ctx
*ctx
)
1911 isl_union_set
*uset1
, *uset2
;
1912 isl_union_map
*umap1
, *umap2
;
1914 str
= "{ [i] : 0 <= i <= 1 }";
1915 uset1
= isl_union_set_read_from_str(ctx
, str
);
1916 str
= "{ [1] -> [0] }";
1917 umap1
= isl_union_map_read_from_str(ctx
, str
);
1919 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
1920 assert(isl_union_map_is_equal(umap1
, umap2
));
1922 isl_union_map_free(umap1
);
1923 isl_union_map_free(umap2
);
1925 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1926 umap1
= isl_union_map_read_from_str(ctx
, str
);
1927 str
= "{ A[i]; B[i] }";
1928 uset1
= isl_union_set_read_from_str(ctx
, str
);
1930 uset2
= isl_union_map_domain(umap1
);
1932 assert(isl_union_set_is_equal(uset1
, uset2
));
1934 isl_union_set_free(uset1
);
1935 isl_union_set_free(uset2
);
1938 void test_bound(isl_ctx
*ctx
)
1941 isl_pw_qpolynomial
*pwqp
;
1942 isl_pw_qpolynomial_fold
*pwf
;
1944 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
1945 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1946 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1947 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
1948 isl_pw_qpolynomial_fold_free(pwf
);
1950 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1951 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1952 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1953 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
1954 isl_pw_qpolynomial_fold_free(pwf
);
1957 void test_lift(isl_ctx
*ctx
)
1960 isl_basic_map
*bmap
;
1961 isl_basic_set
*bset
;
1963 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
1964 bset
= isl_basic_set_read_from_str(ctx
, str
);
1965 bset
= isl_basic_set_lift(bset
);
1966 bmap
= isl_basic_map_from_range(bset
);
1967 bset
= isl_basic_map_domain(bmap
);
1968 isl_basic_set_free(bset
);
1971 void test_subset(isl_ctx
*ctx
)
1974 isl_set
*set1
, *set2
;
1976 str
= "{ [112, 0] }";
1977 set1
= isl_set_read_from_str(ctx
, str
);
1978 str
= "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1979 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1980 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1981 set2
= isl_set_read_from_str(ctx
, str
);
1982 assert(isl_set_is_subset(set1
, set2
));
1987 void test_factorize(isl_ctx
*ctx
)
1990 isl_basic_set
*bset
;
1993 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1994 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1995 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1996 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1997 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1998 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1999 "3i5 >= -2i0 - i2 + 3i4 }";
2000 bset
= isl_basic_set_read_from_str(ctx
, str
);
2001 f
= isl_basic_set_factorizer(bset
);
2003 isl_basic_set_free(bset
);
2004 isl_factorizer_free(f
);
2006 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2007 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2008 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2009 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2010 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2011 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2012 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2013 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2014 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2015 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2016 bset
= isl_basic_set_read_from_str(ctx
, str
);
2017 f
= isl_basic_set_factorizer(bset
);
2019 isl_basic_set_free(bset
);
2020 isl_factorizer_free(f
);
2023 static int check_injective(__isl_take isl_map
*map
, void *user
)
2025 int *injective
= user
;
2027 *injective
= isl_map_is_injective(map
);
2030 if (*injective
< 0 || !*injective
)
2036 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2037 const char *r
, const char *s
, int tilable
, int parallel
)
2041 isl_union_map
*W
, *R
, *S
;
2042 isl_union_map
*empty
;
2043 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2044 isl_union_map
*validity
, *proximity
;
2045 isl_union_map
*schedule
;
2046 isl_union_map
*test
;
2047 isl_union_set
*delta
;
2048 isl_union_set
*domain
;
2052 isl_schedule
*sched
;
2053 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2055 D
= isl_union_set_read_from_str(ctx
, d
);
2056 W
= isl_union_map_read_from_str(ctx
, w
);
2057 R
= isl_union_map_read_from_str(ctx
, r
);
2058 S
= isl_union_map_read_from_str(ctx
, s
);
2060 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2061 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2063 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2064 isl_union_map_compute_flow(isl_union_map_copy(R
),
2065 isl_union_map_copy(W
), empty
,
2066 isl_union_map_copy(S
),
2067 &dep_raw
, NULL
, NULL
, NULL
);
2068 isl_union_map_compute_flow(isl_union_map_copy(W
),
2069 isl_union_map_copy(W
),
2070 isl_union_map_copy(R
),
2071 isl_union_map_copy(S
),
2072 &dep_waw
, &dep_war
, NULL
, NULL
);
2074 dep
= isl_union_map_union(dep_waw
, dep_war
);
2075 dep
= isl_union_map_union(dep
, dep_raw
);
2076 validity
= isl_union_map_copy(dep
);
2077 proximity
= isl_union_map_copy(dep
);
2079 sched
= isl_union_set_compute_schedule(isl_union_set_copy(D
),
2080 validity
, proximity
);
2081 schedule
= isl_schedule_get_map(sched
);
2082 isl_schedule_free(sched
);
2083 isl_union_map_free(W
);
2084 isl_union_map_free(R
);
2085 isl_union_map_free(S
);
2088 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2090 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2091 is_complete
= isl_union_set_is_subset(D
, domain
);
2092 isl_union_set_free(D
);
2093 isl_union_set_free(domain
);
2095 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2096 test
= isl_union_map_apply_range(test
, dep
);
2097 test
= isl_union_map_apply_range(test
, schedule
);
2099 delta
= isl_union_map_deltas(test
);
2100 if (isl_union_set_n_set(delta
) == 0) {
2104 isl_union_set_free(delta
);
2106 delta_set
= isl_set_from_union_set(delta
);
2108 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2109 for (i
= 0; i
< tilable
; ++i
)
2110 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2111 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2112 isl_set_free(slice
);
2114 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2115 for (i
= 0; i
< parallel
; ++i
)
2116 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2117 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2118 isl_set_free(slice
);
2120 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2121 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2122 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2124 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2125 delta_set
= isl_set_lexmin(delta_set
);
2127 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2129 isl_set_free(origin
);
2130 isl_set_free(delta_set
);
2133 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2134 is_injection
< 0 || is_complete
< 0)
2137 isl_die(ctx
, isl_error_unknown
,
2138 "generated schedule incomplete", return -1);
2140 isl_die(ctx
, isl_error_unknown
,
2141 "generated schedule not injective on each statement",
2144 isl_die(ctx
, isl_error_unknown
,
2145 "negative dependences in generated schedule",
2148 isl_die(ctx
, isl_error_unknown
,
2149 "generated schedule not as tilable as expected",
2152 isl_die(ctx
, isl_error_unknown
,
2153 "generated schedule not as parallel as expected",
2159 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2160 const char *validity
, const char *proximity
, const char *expected_sched
)
2164 isl_union_map
*prox
;
2165 isl_union_map
*sched1
, *sched2
;
2166 isl_schedule
*schedule
;
2169 dom
= isl_union_set_read_from_str(ctx
, domain
);
2170 dep
= isl_union_map_read_from_str(ctx
, validity
);
2171 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2172 schedule
= isl_union_set_compute_schedule(dom
, dep
, prox
);
2173 sched1
= isl_schedule_get_map(schedule
);
2174 isl_schedule_free(schedule
);
2176 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2178 equal
= isl_union_map_is_equal(sched1
, sched2
);
2179 isl_union_map_free(sched1
);
2180 isl_union_map_free(sched2
);
2185 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2191 int test_schedule(isl_ctx
*ctx
)
2193 const char *D
, *W
, *R
, *V
, *P
, *S
;
2196 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2197 W
= "{ S1[t,i] -> a[t,i] }";
2198 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2199 "S1[t,i] -> a[t-1,i+1] }";
2200 S
= "{ S1[t,i] -> [t,i] }";
2201 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2204 /* Fig. 5 of CC2008 */
2205 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2207 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2208 "j >= 2 and j <= -1 + N }";
2209 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2210 "j >= 2 and j <= -1 + N; "
2211 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2212 "j >= 2 and j <= -1 + N }";
2213 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2214 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2217 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2218 W
= "{ S1[i] -> a[i] }";
2219 R
= "{ S2[i] -> a[i+1] }";
2220 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2221 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2224 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2225 W
= "{ S1[i] -> a[i] }";
2226 R
= "{ S2[i] -> a[9-i] }";
2227 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2228 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2231 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2232 W
= "{ S1[i] -> a[i] }";
2233 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2234 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2235 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2238 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2239 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2240 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2241 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2242 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2245 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2246 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2247 R
= "{ S2[i,j] -> a[i-1,j] }";
2248 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2249 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2252 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2253 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2254 R
= "{ S2[i,j] -> a[i,j-1] }";
2255 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2256 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2259 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2260 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2261 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2262 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2263 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2264 "S_0[] -> [0, 0, 0] }";
2265 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2267 ctx
->opt
->schedule_parametric
= 0;
2268 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2270 ctx
->opt
->schedule_parametric
= 1;
2272 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2273 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2274 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2275 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2276 "S4[i] -> a[i,N] }";
2277 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2278 "S4[i] -> [4,i,0] }";
2279 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2282 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2283 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2285 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2287 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2289 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2290 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2293 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2294 " S_2[t] : t >= 0 and t <= -1 + N; "
2295 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2297 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2298 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2299 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2300 "i >= 0 and i <= -1 + N }";
2301 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2302 "i >= 0 and i <= -1 + N; "
2303 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2304 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2305 " S_0[t] -> [0, t, 0] }";
2307 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2309 ctx
->opt
->schedule_parametric
= 0;
2310 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2312 ctx
->opt
->schedule_parametric
= 1;
2314 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2315 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2316 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
2319 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2320 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2321 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2322 "j >= 0 and j <= -1 + N; "
2323 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2324 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2325 "j >= 0 and j <= -1 + N; "
2326 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2327 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2328 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2331 D
= "{ S_0[i] : i >= 0 }";
2332 W
= "{ S_0[i] -> a[i] : i >= 0 }";
2333 R
= "{ S_0[i] -> a[0] : i >= 0 }";
2334 S
= "{ S_0[i] -> [0, i, 0] }";
2335 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2338 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2339 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2340 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2341 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2342 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2345 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2346 "k <= -1 + n and k >= 0 }";
2347 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2348 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2349 "k <= -1 + n and k >= 0; "
2350 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2351 "k <= -1 + n and k >= 0; "
2352 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2353 "k <= -1 + n and k >= 0 }";
2354 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
2355 ctx
->opt
->schedule_outer_zero_distance
= 1;
2356 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2358 ctx
->opt
->schedule_outer_zero_distance
= 0;
2360 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
2361 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2362 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2363 "Stmt_for_body24[i0, i1, 1, 0]:"
2364 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2365 "Stmt_for_body7[i0, i1, i2]:"
2366 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2369 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
2370 "Stmt_for_body24[1, i1, i2, i3]:"
2371 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2373 "Stmt_for_body24[0, i1, i2, i3] -> "
2374 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2375 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2377 "Stmt_for_body24[0, i1, i2, i3] ->"
2378 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2379 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2380 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2381 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2382 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2383 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2384 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2385 "i1 <= 6 and i1 >= 0;"
2386 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2387 "Stmt_for_body7[i0, i1, i2] -> "
2388 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2389 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2390 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2391 "Stmt_for_body7[i0, i1, i2] -> "
2392 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2393 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2394 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2396 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2397 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2398 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2400 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2403 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2404 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2405 "j >= 1 and j <= 7;"
2406 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2407 "j >= 1 and j <= 8 }";
2409 S
= "{ S_0[i, j] -> [i + j, j] }";
2410 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2411 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2413 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2415 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2416 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2417 "j >= 0 and j <= -1 + i }";
2418 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2419 "i <= -1 + N and j >= 0;"
2420 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2423 S
= "{ S_0[i, j] -> [i, j] }";
2424 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2425 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2427 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2429 /* Test both algorithms on a case with only proximity dependences. */
2430 D
= "{ S[i,j] : 0 <= i <= 10 }";
2432 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2433 S
= "{ S[i, j] -> [j, i] }";
2434 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2435 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2437 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2438 return test_special_schedule(ctx
, D
, V
, P
, S
);
2441 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
2443 isl_union_map
*umap
;
2446 umap
= isl_union_map_read_from_str(ctx
, str
);
2447 test
= isl_union_map_plain_is_injective(umap
);
2448 isl_union_map_free(umap
);
2451 if (test
== injective
)
2454 isl_die(ctx
, isl_error_unknown
,
2455 "map not detected as injective", return -1);
2457 isl_die(ctx
, isl_error_unknown
,
2458 "map detected as injective", return -1);
2461 int test_injective(isl_ctx
*ctx
)
2465 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2467 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
2469 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
2471 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
2473 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2475 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2477 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2479 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2482 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2483 if (test_plain_injective(ctx
, str
, 1))
2485 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2486 if (test_plain_injective(ctx
, str
, 0))
2492 int test_aff(isl_ctx
*ctx
)
2497 isl_local_space
*ls
;
2501 dim
= isl_space_set_alloc(ctx
, 0, 1);
2502 ls
= isl_local_space_from_space(dim
);
2503 aff
= isl_aff_zero_on_domain(ls
);
2505 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2506 aff
= isl_aff_scale_down_ui(aff
, 3);
2507 aff
= isl_aff_floor(aff
);
2508 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2509 aff
= isl_aff_scale_down_ui(aff
, 2);
2510 aff
= isl_aff_floor(aff
);
2511 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2514 set
= isl_set_read_from_str(ctx
, str
);
2515 aff
= isl_aff_gist(aff
, set
);
2517 aff
= isl_aff_add_constant_si(aff
, -16);
2518 zero
= isl_aff_plain_is_zero(aff
);
2524 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2529 int test_dim_max(isl_ctx
*ctx
)
2533 isl_set
*set1
, *set2
;
2538 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
2539 set
= isl_set_read_from_str(ctx
, str
);
2540 pwaff
= isl_set_dim_max(set
, 0);
2541 set1
= isl_set_from_pw_aff(pwaff
);
2542 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2543 set2
= isl_set_read_from_str(ctx
, str
);
2544 equal
= isl_set_is_equal(set1
, set2
);
2550 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2552 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2553 set
= isl_set_read_from_str(ctx
, str
);
2554 pwaff
= isl_set_dim_max(set
, 0);
2555 set1
= isl_set_from_pw_aff(pwaff
);
2556 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2557 set2
= isl_set_read_from_str(ctx
, str
);
2558 equal
= isl_set_is_equal(set1
, set2
);
2564 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2566 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2567 set
= isl_set_read_from_str(ctx
, str
);
2568 pwaff
= isl_set_dim_max(set
, 0);
2569 set1
= isl_set_from_pw_aff(pwaff
);
2570 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2571 set2
= isl_set_read_from_str(ctx
, str
);
2572 equal
= isl_set_is_equal(set1
, set2
);
2578 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2580 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2581 "0 <= i < N and 0 <= j < M }";
2582 map
= isl_map_read_from_str(ctx
, str
);
2583 set
= isl_map_range(map
);
2585 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
2586 set1
= isl_set_from_pw_aff(pwaff
);
2587 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
2588 set2
= isl_set_read_from_str(ctx
, str
);
2589 equal
= isl_set_is_equal(set1
, set2
);
2593 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
2594 set1
= isl_set_from_pw_aff(pwaff
);
2595 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
2596 set2
= isl_set_read_from_str(ctx
, str
);
2597 if (equal
>= 0 && equal
)
2598 equal
= isl_set_is_equal(set1
, set2
);
2607 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2612 int test_product(isl_ctx
*ctx
)
2616 isl_union_set
*uset1
, *uset2
;
2620 set
= isl_set_read_from_str(ctx
, str
);
2621 set
= isl_set_product(set
, isl_set_copy(set
));
2622 ok
= isl_set_is_wrapping(set
);
2627 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2630 uset1
= isl_union_set_read_from_str(ctx
, str
);
2631 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
2632 str
= "{ [[] -> []] }";
2633 uset2
= isl_union_set_read_from_str(ctx
, str
);
2634 ok
= isl_union_set_is_equal(uset1
, uset2
);
2635 isl_union_set_free(uset1
);
2636 isl_union_set_free(uset2
);
2640 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2645 int test_equal(isl_ctx
*ctx
)
2648 isl_set
*set
, *set2
;
2652 set
= isl_set_read_from_str(ctx
, str
);
2654 set2
= isl_set_read_from_str(ctx
, str
);
2655 equal
= isl_set_is_equal(set
, set2
);
2661 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2666 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
2667 enum isl_dim_type type
, unsigned pos
, int fixed
)
2671 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
2678 isl_die(ctx
, isl_error_unknown
,
2679 "map not detected as fixed", return -1);
2681 isl_die(ctx
, isl_error_unknown
,
2682 "map detected as fixed", return -1);
2685 int test_fixed(isl_ctx
*ctx
)
2690 str
= "{ [i] -> [i] }";
2691 map
= isl_map_read_from_str(ctx
, str
);
2692 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
2694 str
= "{ [i] -> [1] }";
2695 map
= isl_map_read_from_str(ctx
, str
);
2696 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2698 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
2699 map
= isl_map_read_from_str(ctx
, str
);
2700 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2702 map
= isl_map_read_from_str(ctx
, str
);
2703 map
= isl_map_neg(map
);
2704 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2710 int test_vertices(isl_ctx
*ctx
)
2713 isl_basic_set
*bset
;
2714 isl_vertices
*vertices
;
2716 str
= "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
2717 bset
= isl_basic_set_read_from_str(ctx
, str
);
2718 vertices
= isl_basic_set_compute_vertices(bset
);
2719 isl_basic_set_free(bset
);
2720 isl_vertices_free(vertices
);
2724 str
= "{ A[t, i] : t = 14 and i = 1 }";
2725 bset
= isl_basic_set_read_from_str(ctx
, str
);
2726 vertices
= isl_basic_set_compute_vertices(bset
);
2727 isl_basic_set_free(bset
);
2728 isl_vertices_free(vertices
);
2735 int test_union_pw(isl_ctx
*ctx
)
2739 isl_union_set
*uset
;
2740 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
2742 str
= "{ [x] -> x^2 }";
2743 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
2744 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
2745 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
2746 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
2747 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
2748 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
2749 isl_union_pw_qpolynomial_free(upwqp1
);
2750 isl_union_pw_qpolynomial_free(upwqp2
);
2754 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2759 int test_output(isl_ctx
*ctx
)
2767 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
2768 pa
= isl_pw_aff_read_from_str(ctx
, str
);
2770 p
= isl_printer_to_str(ctx
);
2771 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
2772 p
= isl_printer_print_pw_aff(p
, pa
);
2773 s
= isl_printer_get_str(p
);
2774 isl_printer_free(p
);
2775 isl_pw_aff_free(pa
);
2776 equal
= !strcmp(s
, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
2781 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2786 int test_sample(isl_ctx
*ctx
)
2789 isl_basic_set
*bset1
, *bset2
;
2792 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
2793 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
2794 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
2795 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
2796 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
2797 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
2798 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
2799 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
2800 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
2801 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
2802 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
2803 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
2804 "d - 1073741821e and "
2805 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
2806 "3j >= 1 - a + b + 2e and "
2807 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
2808 "3i <= 4 - a + 4b - e and "
2809 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
2810 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
2811 "c <= -1 + a and 3i >= -2 - a + 3e and "
2812 "1073741822e <= 1073741823 - a + 1073741822b + c and "
2813 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
2814 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
2815 "1073741823e >= 1 + 1073741823b - d and "
2816 "3i >= 1073741823b + c - 1073741823e - f and "
2817 "3i >= 1 + 2b + e + 3g }";
2818 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2819 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
2820 empty
= isl_basic_set_is_empty(bset2
);
2821 subset
= isl_basic_set_is_subset(bset2
, bset1
);
2822 isl_basic_set_free(bset1
);
2823 isl_basic_set_free(bset2
);
2825 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
2827 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
2832 int test_fixed_power(isl_ctx
*ctx
)
2840 str
= "{ [i] -> [i + 1] }";
2841 map
= isl_map_read_from_str(ctx
, str
);
2842 isl_int_set_si(exp
, 23);
2843 map
= isl_map_fixed_power(map
, exp
);
2844 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
2853 int test_slice(isl_ctx
*ctx
)
2859 str
= "{ [i] -> [j] }";
2860 map
= isl_map_read_from_str(ctx
, str
);
2861 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
2862 equal
= map_check_equal(map
, "{ [i] -> [i] }");
2867 str
= "{ [i] -> [j] }";
2868 map
= isl_map_read_from_str(ctx
, str
);
2869 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
2870 equal
= map_check_equal(map
, "{ [i] -> [j] }");
2875 str
= "{ [i] -> [j] }";
2876 map
= isl_map_read_from_str(ctx
, str
);
2877 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
2878 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
2883 str
= "{ [i] -> [j] }";
2884 map
= isl_map_read_from_str(ctx
, str
);
2885 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
2886 equal
= map_check_equal(map
, "{ [0] -> [j] }");
2896 struct isl_ctx
*ctx
;
2898 srcdir
= getenv("srcdir");
2901 ctx
= isl_ctx_alloc();
2902 if (test_slice(ctx
) < 0)
2904 if (test_fixed_power(ctx
) < 0)
2906 if (test_sample(ctx
) < 0)
2908 if (test_output(ctx
) < 0)
2910 if (test_vertices(ctx
) < 0)
2912 if (test_fixed(ctx
) < 0)
2914 if (test_equal(ctx
) < 0)
2916 if (test_product(ctx
) < 0)
2918 if (test_dim_max(ctx
) < 0)
2920 if (test_aff(ctx
) < 0)
2922 if (test_injective(ctx
) < 0)
2924 if (test_schedule(ctx
) < 0)
2926 if (test_union_pw(ctx
) < 0)
2928 test_factorize(ctx
);
2933 test_split_periods(ctx
);
2934 if (test_parse(ctx
) < 0)
2938 if (test_sv(ctx
) < 0)
2940 test_bijective(ctx
);
2944 test_construction(ctx
);
2947 test_application(ctx
);
2948 if (test_affine_hull(ctx
) < 0)
2950 test_convex_hull(ctx
);
2952 if (test_coalesce(ctx
) < 0)