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 void test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
58 map
= isl_map_read_from_str(ctx
, str
);
59 map2
= isl_map_read_from_str(ctx
, str2
);
60 assert(map
&& map2
&& isl_map_is_equal(map
, map2
));
65 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
67 isl_pw_qpolynomial
*pwqp
;
69 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
71 isl_pw_qpolynomial_free(pwqp
);
74 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
78 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
80 isl_pw_aff_free(pwaff
);
83 void test_parse(struct isl_ctx
*ctx
)
86 const char *str
, *str2
;
88 str
= "{ [i] -> [-i] }";
89 map
= isl_map_read_from_str(ctx
, str
);
93 str
= "{ A[i] -> L[([i/3])] }";
94 map
= isl_map_read_from_str(ctx
, str
);
98 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
99 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
100 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
102 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
103 str2
= "{ [x, y] : 2y >= 6 - x }";
104 test_parse_map_equal(ctx
, str
, str2
);
106 test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
107 "{ [x,y] : x <= y, 2*y + 3 }");
108 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
109 test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }", str
);
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
);
113 str
= "{ [new, old] -> [o0, o1] : "
114 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
115 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
116 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
117 map2
= isl_map_read_from_str(ctx
, str
);
118 assert(isl_map_is_equal(map
, map2
));
122 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
123 map
= isl_map_read_from_str(ctx
, str
);
124 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
125 map2
= isl_map_read_from_str(ctx
, str
);
126 assert(isl_map_is_equal(map
, map2
));
130 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
131 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
132 test_parse_map_equal(ctx
, str
, str2
);
134 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
135 str2
= "{ [i,j] -> [min(i,j)] }";
136 test_parse_map_equal(ctx
, str
, str2
);
138 str
= "{ [i,j] : i != j }";
139 str2
= "{ [i,j] : i < j or i > j }";
140 test_parse_map_equal(ctx
, str
, str2
);
142 str
= "{ [i,j] : (i+1)*2 >= j }";
143 str2
= "{ [i, j] : j <= 2 + 2i }";
144 test_parse_map_equal(ctx
, str
, str2
);
146 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
147 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
148 test_parse_map_equal(ctx
, str
, str2
);
150 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
151 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
152 test_parse_map_equal(ctx
, str
, str2
);
154 str
= "{ [x] : x >= 0 }";
155 str2
= "{ [x] : x-0 >= 0 }";
156 test_parse_map_equal(ctx
, str
, str2
);
158 str
= "{ [i] : ((i > 10)) }";
159 str2
= "{ [i] : i >= 11 }";
160 test_parse_map_equal(ctx
, str
, str2
);
162 str
= "{ [i] -> [0] }";
163 str2
= "{ [i] -> [0 * i] }";
164 test_parse_map_equal(ctx
, str
, str2
);
166 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
167 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
168 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
169 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
172 void test_read(struct isl_ctx
*ctx
)
176 struct isl_basic_set
*bset1
, *bset2
;
177 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
179 filename
= get_filename(ctx
, "set", "omega");
181 input
= fopen(filename
, "r");
184 bset1
= isl_basic_set_read_from_file(ctx
, input
);
185 bset2
= isl_basic_set_read_from_str(ctx
, str
);
187 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
189 isl_basic_set_free(bset1
);
190 isl_basic_set_free(bset2
);
196 void test_bounded(struct isl_ctx
*ctx
)
201 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
202 bounded
= isl_set_is_bounded(set
);
206 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
207 bounded
= isl_set_is_bounded(set
);
211 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
212 bounded
= isl_set_is_bounded(set
);
217 /* Construct the basic set { [i] : 5 <= i <= N } */
218 void test_construction(struct isl_ctx
*ctx
)
223 struct isl_basic_set
*bset
;
224 struct isl_constraint
*c
;
228 dim
= isl_space_set_alloc(ctx
, 1, 1);
229 bset
= isl_basic_set_universe(isl_space_copy(dim
));
230 ls
= isl_local_space_from_space(dim
);
232 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
233 isl_int_set_si(v
, -1);
234 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
235 isl_int_set_si(v
, 1);
236 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
237 bset
= isl_basic_set_add_constraint(bset
, c
);
239 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
240 isl_int_set_si(v
, 1);
241 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
242 isl_int_set_si(v
, -5);
243 isl_constraint_set_constant(c
, v
);
244 bset
= isl_basic_set_add_constraint(bset
, c
);
246 isl_local_space_free(ls
);
247 isl_basic_set_free(bset
);
252 void test_dim(struct isl_ctx
*ctx
)
255 isl_map
*map1
, *map2
;
257 map1
= isl_map_read_from_str(ctx
,
258 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
259 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
260 map2
= isl_map_read_from_str(ctx
,
261 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
262 assert(isl_map_is_equal(map1
, map2
));
265 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
266 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
267 assert(isl_map_is_equal(map1
, map2
));
272 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
273 map1
= isl_map_read_from_str(ctx
, str
);
274 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
275 map2
= isl_map_read_from_str(ctx
, str
);
276 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
277 assert(isl_map_is_equal(map1
, map2
));
283 void test_div(struct isl_ctx
*ctx
)
288 struct isl_basic_set
*bset
;
289 struct isl_constraint
*c
;
294 dim
= isl_space_set_alloc(ctx
, 0, 3);
295 bset
= isl_basic_set_universe(isl_space_copy(dim
));
296 ls
= isl_local_space_from_space(dim
);
298 c
= isl_equality_alloc(isl_local_space_copy(ls
));
299 isl_int_set_si(v
, -1);
300 isl_constraint_set_constant(c
, v
);
301 isl_int_set_si(v
, 1);
302 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
303 isl_int_set_si(v
, 3);
304 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
305 bset
= isl_basic_set_add_constraint(bset
, c
);
307 c
= isl_equality_alloc(isl_local_space_copy(ls
));
308 isl_int_set_si(v
, 1);
309 isl_constraint_set_constant(c
, v
);
310 isl_int_set_si(v
, -1);
311 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
312 isl_int_set_si(v
, 3);
313 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
314 bset
= isl_basic_set_add_constraint(bset
, c
);
316 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
318 assert(bset
&& bset
->n_div
== 1);
319 isl_local_space_free(ls
);
320 isl_basic_set_free(bset
);
323 dim
= isl_space_set_alloc(ctx
, 0, 3);
324 bset
= isl_basic_set_universe(isl_space_copy(dim
));
325 ls
= isl_local_space_from_space(dim
);
327 c
= isl_equality_alloc(isl_local_space_copy(ls
));
328 isl_int_set_si(v
, 1);
329 isl_constraint_set_constant(c
, v
);
330 isl_int_set_si(v
, -1);
331 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
332 isl_int_set_si(v
, 3);
333 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
334 bset
= isl_basic_set_add_constraint(bset
, c
);
336 c
= isl_equality_alloc(isl_local_space_copy(ls
));
337 isl_int_set_si(v
, -1);
338 isl_constraint_set_constant(c
, v
);
339 isl_int_set_si(v
, 1);
340 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
341 isl_int_set_si(v
, 3);
342 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
343 bset
= isl_basic_set_add_constraint(bset
, c
);
345 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
347 assert(bset
&& bset
->n_div
== 1);
348 isl_local_space_free(ls
);
349 isl_basic_set_free(bset
);
352 dim
= isl_space_set_alloc(ctx
, 0, 3);
353 bset
= isl_basic_set_universe(isl_space_copy(dim
));
354 ls
= isl_local_space_from_space(dim
);
356 c
= isl_equality_alloc(isl_local_space_copy(ls
));
357 isl_int_set_si(v
, 1);
358 isl_constraint_set_constant(c
, v
);
359 isl_int_set_si(v
, -1);
360 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
361 isl_int_set_si(v
, 3);
362 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
363 bset
= isl_basic_set_add_constraint(bset
, c
);
365 c
= isl_equality_alloc(isl_local_space_copy(ls
));
366 isl_int_set_si(v
, -3);
367 isl_constraint_set_constant(c
, v
);
368 isl_int_set_si(v
, 1);
369 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
370 isl_int_set_si(v
, 4);
371 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
372 bset
= isl_basic_set_add_constraint(bset
, c
);
374 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
376 assert(bset
&& bset
->n_div
== 1);
377 isl_local_space_free(ls
);
378 isl_basic_set_free(bset
);
381 dim
= isl_space_set_alloc(ctx
, 0, 3);
382 bset
= isl_basic_set_universe(isl_space_copy(dim
));
383 ls
= isl_local_space_from_space(dim
);
385 c
= isl_equality_alloc(isl_local_space_copy(ls
));
386 isl_int_set_si(v
, 2);
387 isl_constraint_set_constant(c
, v
);
388 isl_int_set_si(v
, -1);
389 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
390 isl_int_set_si(v
, 3);
391 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
392 bset
= isl_basic_set_add_constraint(bset
, c
);
394 c
= isl_equality_alloc(isl_local_space_copy(ls
));
395 isl_int_set_si(v
, -1);
396 isl_constraint_set_constant(c
, v
);
397 isl_int_set_si(v
, 1);
398 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
399 isl_int_set_si(v
, 6);
400 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
401 bset
= isl_basic_set_add_constraint(bset
, c
);
403 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
405 assert(isl_basic_set_is_empty(bset
));
406 isl_local_space_free(ls
);
407 isl_basic_set_free(bset
);
410 dim
= isl_space_set_alloc(ctx
, 0, 3);
411 bset
= isl_basic_set_universe(isl_space_copy(dim
));
412 ls
= isl_local_space_from_space(dim
);
414 c
= isl_equality_alloc(isl_local_space_copy(ls
));
415 isl_int_set_si(v
, -1);
416 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
417 isl_int_set_si(v
, 3);
418 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
419 bset
= isl_basic_set_add_constraint(bset
, c
);
421 c
= isl_equality_alloc(isl_local_space_copy(ls
));
422 isl_int_set_si(v
, 1);
423 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
424 isl_int_set_si(v
, -3);
425 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
426 bset
= isl_basic_set_add_constraint(bset
, c
);
428 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
430 assert(bset
&& bset
->n_div
== 0);
431 isl_basic_set_free(bset
);
432 isl_local_space_free(ls
);
435 dim
= isl_space_set_alloc(ctx
, 0, 3);
436 bset
= isl_basic_set_universe(isl_space_copy(dim
));
437 ls
= isl_local_space_from_space(dim
);
439 c
= isl_equality_alloc(isl_local_space_copy(ls
));
440 isl_int_set_si(v
, -1);
441 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
442 isl_int_set_si(v
, 6);
443 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
444 bset
= isl_basic_set_add_constraint(bset
, c
);
446 c
= isl_equality_alloc(isl_local_space_copy(ls
));
447 isl_int_set_si(v
, 1);
448 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
449 isl_int_set_si(v
, -3);
450 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
451 bset
= isl_basic_set_add_constraint(bset
, c
);
453 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
455 assert(bset
&& bset
->n_div
== 1);
456 isl_basic_set_free(bset
);
457 isl_local_space_free(ls
);
460 /* This test is a bit tricky. We set up an equality
462 * Normalization of divs creates _two_ divs
465 * Afterwards e0 is removed again because it has coefficient -1
466 * and we end up with the original equality and div again.
467 * Perhaps we can avoid the introduction of this temporary div.
469 dim
= isl_space_set_alloc(ctx
, 0, 4);
470 bset
= isl_basic_set_universe(isl_space_copy(dim
));
471 ls
= isl_local_space_from_space(dim
);
473 c
= isl_equality_alloc(isl_local_space_copy(ls
));
474 isl_int_set_si(v
, -1);
475 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
476 isl_int_set_si(v
, -3);
477 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
478 isl_int_set_si(v
, -3);
479 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
480 isl_int_set_si(v
, 6);
481 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
482 bset
= isl_basic_set_add_constraint(bset
, c
);
484 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
486 /* Test disabled for now */
488 assert(bset && bset->n_div == 1);
490 isl_local_space_free(ls
);
491 isl_basic_set_free(bset
);
494 dim
= isl_space_set_alloc(ctx
, 0, 5);
495 bset
= isl_basic_set_universe(isl_space_copy(dim
));
496 ls
= isl_local_space_from_space(dim
);
498 c
= isl_equality_alloc(isl_local_space_copy(ls
));
499 isl_int_set_si(v
, -1);
500 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
501 isl_int_set_si(v
, -3);
502 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
503 isl_int_set_si(v
, -3);
504 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
505 isl_int_set_si(v
, 6);
506 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
507 bset
= isl_basic_set_add_constraint(bset
, c
);
509 c
= isl_equality_alloc(isl_local_space_copy(ls
));
510 isl_int_set_si(v
, -1);
511 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
512 isl_int_set_si(v
, 1);
513 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
514 isl_int_set_si(v
, 1);
515 isl_constraint_set_constant(c
, v
);
516 bset
= isl_basic_set_add_constraint(bset
, c
);
518 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
520 /* Test disabled for now */
522 assert(bset && bset->n_div == 1);
524 isl_local_space_free(ls
);
525 isl_basic_set_free(bset
);
528 dim
= isl_space_set_alloc(ctx
, 0, 4);
529 bset
= isl_basic_set_universe(isl_space_copy(dim
));
530 ls
= isl_local_space_from_space(dim
);
532 c
= isl_equality_alloc(isl_local_space_copy(ls
));
533 isl_int_set_si(v
, 1);
534 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
535 isl_int_set_si(v
, -1);
536 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
537 isl_int_set_si(v
, -2);
538 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
539 bset
= isl_basic_set_add_constraint(bset
, c
);
541 c
= isl_equality_alloc(isl_local_space_copy(ls
));
542 isl_int_set_si(v
, -1);
543 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
544 isl_int_set_si(v
, 3);
545 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
546 isl_int_set_si(v
, 2);
547 isl_constraint_set_constant(c
, v
);
548 bset
= isl_basic_set_add_constraint(bset
, c
);
550 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
552 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
554 assert(!isl_basic_set_is_empty(bset
));
556 isl_local_space_free(ls
);
557 isl_basic_set_free(bset
);
560 dim
= isl_space_set_alloc(ctx
, 0, 3);
561 bset
= isl_basic_set_universe(isl_space_copy(dim
));
562 ls
= isl_local_space_from_space(dim
);
564 c
= isl_equality_alloc(isl_local_space_copy(ls
));
565 isl_int_set_si(v
, 1);
566 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
567 isl_int_set_si(v
, -2);
568 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
569 bset
= isl_basic_set_add_constraint(bset
, c
);
571 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
573 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
575 isl_local_space_free(ls
);
576 isl_basic_set_free(bset
);
581 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
585 struct isl_basic_set
*bset1
, *bset2
;
586 struct isl_basic_map
*bmap
;
588 filename
= get_filename(ctx
, name
, "omega");
590 input
= fopen(filename
, "r");
593 bset1
= isl_basic_set_read_from_file(ctx
, input
);
594 bmap
= isl_basic_map_read_from_file(ctx
, input
);
596 bset1
= isl_basic_set_apply(bset1
, bmap
);
598 bset2
= isl_basic_set_read_from_file(ctx
, input
);
600 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
602 isl_basic_set_free(bset1
);
603 isl_basic_set_free(bset2
);
609 void test_application(struct isl_ctx
*ctx
)
611 test_application_case(ctx
, "application");
612 test_application_case(ctx
, "application2");
615 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
619 struct isl_basic_set
*bset1
, *bset2
;
621 filename
= get_filename(ctx
, name
, "polylib");
623 input
= fopen(filename
, "r");
626 bset1
= isl_basic_set_read_from_file(ctx
, input
);
627 bset2
= isl_basic_set_read_from_file(ctx
, input
);
629 bset1
= isl_basic_set_affine_hull(bset1
);
631 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
633 isl_basic_set_free(bset1
);
634 isl_basic_set_free(bset2
);
640 int test_affine_hull(struct isl_ctx
*ctx
)
647 test_affine_hull_case(ctx
, "affine2");
648 test_affine_hull_case(ctx
, "affine");
649 test_affine_hull_case(ctx
, "affine3");
651 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
652 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
653 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
654 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
655 set
= isl_set_read_from_str(ctx
, str
);
656 bset
= isl_set_affine_hull(set
);
657 n
= isl_basic_set_dim(bset
, isl_dim_div
);
658 isl_basic_set_free(bset
);
660 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
666 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
670 struct isl_basic_set
*bset1
, *bset2
;
673 filename
= get_filename(ctx
, name
, "polylib");
675 input
= fopen(filename
, "r");
678 bset1
= isl_basic_set_read_from_file(ctx
, input
);
679 bset2
= isl_basic_set_read_from_file(ctx
, input
);
681 set
= isl_basic_set_union(bset1
, bset2
);
682 bset1
= isl_set_convex_hull(set
);
684 bset2
= isl_basic_set_read_from_file(ctx
, input
);
686 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
688 isl_basic_set_free(bset1
);
689 isl_basic_set_free(bset2
);
695 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
697 const char *str1
, *str2
;
698 isl_set
*set1
, *set2
;
699 int orig_convex
= ctx
->opt
->convex
;
700 ctx
->opt
->convex
= convex
;
702 test_convex_hull_case(ctx
, "convex0");
703 test_convex_hull_case(ctx
, "convex1");
704 test_convex_hull_case(ctx
, "convex2");
705 test_convex_hull_case(ctx
, "convex3");
706 test_convex_hull_case(ctx
, "convex4");
707 test_convex_hull_case(ctx
, "convex5");
708 test_convex_hull_case(ctx
, "convex6");
709 test_convex_hull_case(ctx
, "convex7");
710 test_convex_hull_case(ctx
, "convex8");
711 test_convex_hull_case(ctx
, "convex9");
712 test_convex_hull_case(ctx
, "convex10");
713 test_convex_hull_case(ctx
, "convex11");
714 test_convex_hull_case(ctx
, "convex12");
715 test_convex_hull_case(ctx
, "convex13");
716 test_convex_hull_case(ctx
, "convex14");
717 test_convex_hull_case(ctx
, "convex15");
719 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
720 "(i0 = 1 and i1 = 0 and i2 = 1) or "
721 "(i0 = 0 and i1 = 0 and i2 = 0) }";
722 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
723 set1
= isl_set_read_from_str(ctx
, str1
);
724 set2
= isl_set_read_from_str(ctx
, str2
);
725 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
726 assert(isl_set_is_equal(set1
, set2
));
730 ctx
->opt
->convex
= orig_convex
;
733 void test_convex_hull(struct isl_ctx
*ctx
)
735 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
736 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
739 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
743 struct isl_basic_set
*bset1
, *bset2
;
745 filename
= get_filename(ctx
, name
, "polylib");
747 input
= fopen(filename
, "r");
750 bset1
= isl_basic_set_read_from_file(ctx
, input
);
751 bset2
= isl_basic_set_read_from_file(ctx
, input
);
753 bset1
= isl_basic_set_gist(bset1
, bset2
);
755 bset2
= isl_basic_set_read_from_file(ctx
, input
);
757 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
759 isl_basic_set_free(bset1
);
760 isl_basic_set_free(bset2
);
766 void test_gist(struct isl_ctx
*ctx
)
769 isl_basic_set
*bset1
, *bset2
;
771 test_gist_case(ctx
, "gist1");
773 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
774 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
775 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
776 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
777 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
778 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
779 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
780 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
781 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
782 bset1
= isl_basic_set_read_from_str(ctx
, str
);
783 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
784 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
785 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
786 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
787 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
788 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
789 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
790 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
791 bset2
= isl_basic_set_read_from_str(ctx
, str
);
792 bset1
= isl_basic_set_gist(bset1
, bset2
);
793 assert(bset1
&& bset1
->n_div
== 0);
794 isl_basic_set_free(bset1
);
797 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
801 set
= isl_set_read_from_str(ctx
, str
);
802 set
= isl_set_coalesce(set
);
803 set2
= isl_set_read_from_str(ctx
, str
);
804 assert(isl_set_is_equal(set
, set2
));
806 assert(set
&& set
->n
== 1);
811 void test_coalesce(struct isl_ctx
*ctx
)
814 struct isl_set
*set
, *set2
;
815 struct isl_map
*map
, *map2
;
817 set
= isl_set_read_from_str(ctx
,
818 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
819 "y >= x & x >= 2 & 5 >= y }");
820 set
= isl_set_coalesce(set
);
821 assert(set
&& set
->n
== 1);
824 set
= isl_set_read_from_str(ctx
,
825 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
826 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}");
827 set
= isl_set_coalesce(set
);
828 assert(set
&& set
->n
== 1);
831 set
= isl_set_read_from_str(ctx
,
832 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
833 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}");
834 set
= isl_set_coalesce(set
);
835 assert(set
&& set
->n
== 2);
838 set
= isl_set_read_from_str(ctx
,
839 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
840 "y >= 0 & x >= 6 & x <= 10 & y <= x}");
841 set
= isl_set_coalesce(set
);
842 assert(set
&& set
->n
== 1);
845 set
= isl_set_read_from_str(ctx
,
846 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
847 "y >= 0 & x >= 7 & x <= 10 & y <= x}");
848 set
= isl_set_coalesce(set
);
849 assert(set
&& set
->n
== 2);
852 set
= isl_set_read_from_str(ctx
,
853 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
854 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}");
855 set
= isl_set_coalesce(set
);
856 assert(set
&& set
->n
== 2);
859 set
= isl_set_read_from_str(ctx
,
860 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
861 "y >= 0 & x = 6 & y <= 6}");
862 set
= isl_set_coalesce(set
);
863 assert(set
&& set
->n
== 1);
866 set
= isl_set_read_from_str(ctx
,
867 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
868 "y >= 0 & x = 7 & y <= 6}");
869 set
= isl_set_coalesce(set
);
870 assert(set
&& set
->n
== 2);
873 set
= isl_set_read_from_str(ctx
,
874 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
875 "y >= 0 & x = 6 & y <= 5}");
876 set
= isl_set_coalesce(set
);
877 assert(set
&& set
->n
== 1);
878 set2
= isl_set_read_from_str(ctx
,
879 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
880 "y >= 0 & x = 6 & y <= 5}");
881 assert(isl_set_is_equal(set
, set2
));
885 set
= isl_set_read_from_str(ctx
,
886 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
887 "y >= 0 & x = 6 & y <= 7}");
888 set
= isl_set_coalesce(set
);
889 assert(set
&& set
->n
== 2);
892 set
= isl_set_read_from_str(ctx
,
893 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
894 set
= isl_set_coalesce(set
);
895 assert(set
&& set
->n
== 1);
896 set2
= isl_set_read_from_str(ctx
,
897 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }");
898 assert(isl_set_is_equal(set
, set2
));
902 set
= isl_set_read_from_str(ctx
,
903 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
904 set
= isl_set_coalesce(set
);
905 set2
= isl_set_read_from_str(ctx
,
906 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}");
907 assert(isl_set_is_equal(set
, set2
));
911 set
= isl_set_read_from_str(ctx
,
912 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
913 "2 <= i and i <= n }");
914 set
= isl_set_coalesce(set
);
915 assert(set
&& set
->n
== 1);
916 set2
= isl_set_read_from_str(ctx
,
917 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
918 "2 <= i and i <= n }");
919 assert(isl_set_is_equal(set
, set2
));
923 map
= isl_map_read_from_str(ctx
,
924 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
925 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
926 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
927 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
928 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
929 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
930 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
931 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
932 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
933 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
934 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
935 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
936 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
937 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
938 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
939 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
940 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
941 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
942 map
= isl_map_coalesce(map
);
943 map2
= isl_map_read_from_str(ctx
,
944 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
945 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
946 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
947 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
948 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
949 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
950 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
951 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
952 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
953 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
954 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
955 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
956 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
957 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
958 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
959 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
960 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
961 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }");
962 assert(isl_map_is_equal(map
, map2
));
966 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
967 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
968 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
969 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
970 map
= isl_map_read_from_str(ctx
, str
);
971 map
= isl_map_coalesce(map
);
972 map2
= isl_map_read_from_str(ctx
, str
);
973 assert(isl_map_is_equal(map
, map2
));
977 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
978 "[o0, o1, o2, o3, o4, o5, o6] : "
979 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
980 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
981 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
982 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
983 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
984 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
985 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
986 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
987 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
988 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
989 "o6 >= i3 + i6 - o3 and M >= 0 and "
990 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
991 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
992 map
= isl_map_read_from_str(ctx
, str
);
993 map
= isl_map_coalesce(map
);
994 map2
= isl_map_read_from_str(ctx
, str
);
995 assert(isl_map_is_equal(map
, map2
));
999 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1000 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1001 "(o0 = 0 and M >= 2 and N >= 3) or "
1002 "(M = 0 and o0 = 0 and N >= 3) }";
1003 map
= isl_map_read_from_str(ctx
, str
);
1004 map
= isl_map_coalesce(map
);
1005 map2
= isl_map_read_from_str(ctx
, str
);
1006 assert(isl_map_is_equal(map
, map2
));
1010 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1011 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1012 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1013 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
1014 map
= isl_map_read_from_str(ctx
, str
);
1015 map
= isl_map_coalesce(map
);
1016 map2
= isl_map_read_from_str(ctx
, str
);
1017 assert(isl_map_is_equal(map
, map2
));
1021 test_coalesce_set(ctx
,
1022 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
1023 "(i1 = M and M >= 1) }", 0);
1024 test_coalesce_set(ctx
,
1025 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
1026 test_coalesce_set(ctx
,
1027 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1028 "(y = 3 and x = 1) }", 1);
1029 test_coalesce_set(ctx
,
1030 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1031 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1032 "i1 <= M and i3 <= M and i4 <= M) or "
1033 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1034 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1035 "i4 <= -1 + M) }", 1);
1036 test_coalesce_set(ctx
,
1037 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1038 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
1039 test_coalesce_set(ctx
,
1040 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1041 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1042 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1043 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
1044 test_coalesce_set(ctx
,
1045 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
1046 test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
1047 test_coalesce_set(ctx
,
1048 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
1049 test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
1050 test_coalesce_set(ctx
, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
1051 test_coalesce_set(ctx
, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
1052 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
1053 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
1054 test_coalesce_set(ctx
, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
1055 test_coalesce_set(ctx
, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
1058 void test_closure(struct isl_ctx
*ctx
)
1062 isl_map
*up
, *right
;
1063 isl_map
*map
, *map2
;
1066 /* COCOA example 1 */
1067 map
= isl_map_read_from_str(ctx
,
1068 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1069 "1 <= i and i < n and 1 <= j and j < n or "
1070 "i2 = i + 1 and j2 = j - 1 and "
1071 "1 <= i and i < n and 2 <= j and j <= n }");
1072 map
= isl_map_power(map
, &exact
);
1076 /* COCOA example 1 */
1077 map
= isl_map_read_from_str(ctx
,
1078 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1079 "1 <= i and i < n and 1 <= j and j < n or "
1080 "i2 = i + 1 and j2 = j - 1 and "
1081 "1 <= i and i < n and 2 <= j and j <= n }");
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,k : "
1086 "1 <= i and i < n and 1 <= j and j <= n and "
1087 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1088 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1089 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1090 assert(isl_map_is_equal(map
, map2
));
1094 map
= isl_map_read_from_str(ctx
,
1095 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1096 " 0 <= y and y <= n }");
1097 map
= isl_map_transitive_closure(map
, &exact
);
1098 map2
= isl_map_read_from_str(ctx
,
1099 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1100 " 0 <= y and y <= n }");
1101 assert(isl_map_is_equal(map
, map2
));
1105 /* COCOA example 2 */
1106 map
= isl_map_read_from_str(ctx
,
1107 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1108 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1109 "i2 = i + 2 and j2 = j - 2 and "
1110 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1111 map
= isl_map_transitive_closure(map
, &exact
);
1113 map2
= isl_map_read_from_str(ctx
,
1114 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1115 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1116 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1117 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1118 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1119 assert(isl_map_is_equal(map
, map2
));
1123 /* COCOA Fig.2 left */
1124 map
= isl_map_read_from_str(ctx
,
1125 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1126 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1128 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1129 "j <= 2 i - 3 and j <= n - 2 or "
1130 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1131 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1132 map
= isl_map_transitive_closure(map
, &exact
);
1136 /* COCOA Fig.2 right */
1137 map
= isl_map_read_from_str(ctx
,
1138 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1139 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1141 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1142 "j <= 2 i - 4 and j <= n - 3 or "
1143 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1144 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1145 map
= isl_map_power(map
, &exact
);
1149 /* COCOA Fig.2 right */
1150 map
= isl_map_read_from_str(ctx
,
1151 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1152 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1154 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1155 "j <= 2 i - 4 and j <= n - 3 or "
1156 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1157 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1158 map
= isl_map_transitive_closure(map
, &exact
);
1160 map2
= isl_map_read_from_str(ctx
,
1161 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1162 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1163 "j <= n and 3 + i + 2 j <= 3 n and "
1164 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1165 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1166 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1167 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1168 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1169 assert(isl_map_is_equal(map
, map2
));
1173 /* COCOA Fig.1 right */
1174 dom
= isl_set_read_from_str(ctx
,
1175 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1176 "2 x - 3 y + 3 >= 0 }");
1177 right
= isl_map_read_from_str(ctx
,
1178 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1179 up
= isl_map_read_from_str(ctx
,
1180 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1181 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1182 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1183 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1184 up
= isl_map_intersect_range(up
, dom
);
1185 map
= isl_map_union(up
, right
);
1186 map
= isl_map_transitive_closure(map
, &exact
);
1188 map2
= isl_map_read_from_str(ctx
,
1189 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1190 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1191 assert(isl_map_is_equal(map
, map2
));
1195 /* COCOA Theorem 1 counter example */
1196 map
= isl_map_read_from_str(ctx
,
1197 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1198 "i2 = 1 and j2 = j or "
1199 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1200 map
= isl_map_transitive_closure(map
, &exact
);
1204 map
= isl_map_read_from_str(ctx
,
1205 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1206 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1207 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1208 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1209 map
= isl_map_transitive_closure(map
, &exact
);
1213 /* Kelly et al 1996, fig 12 */
1214 map
= isl_map_read_from_str(ctx
,
1215 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1216 "1 <= i,j,j+1 <= n or "
1217 "j = n and j2 = 1 and i2 = i + 1 and "
1218 "1 <= i,i+1 <= n }");
1219 map
= isl_map_transitive_closure(map
, &exact
);
1221 map2
= isl_map_read_from_str(ctx
,
1222 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1223 "1 <= i <= n and i = i2 or "
1224 "1 <= i < i2 <= n and 1 <= j <= n and "
1226 assert(isl_map_is_equal(map
, map2
));
1230 /* Omega's closure4 */
1231 map
= isl_map_read_from_str(ctx
,
1232 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1233 "1 <= x,y <= 10 or "
1234 "x2 = x + 1 and y2 = y and "
1235 "1 <= x <= 20 && 5 <= y <= 15 }");
1236 map
= isl_map_transitive_closure(map
, &exact
);
1240 map
= isl_map_read_from_str(ctx
,
1241 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1242 map
= isl_map_transitive_closure(map
, &exact
);
1244 map2
= isl_map_read_from_str(ctx
,
1245 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1246 assert(isl_map_is_equal(map
, map2
));
1250 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1251 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1252 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1253 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1254 map
= isl_map_read_from_str(ctx
, str
);
1255 map
= isl_map_transitive_closure(map
, &exact
);
1257 map2
= isl_map_read_from_str(ctx
, str
);
1258 assert(isl_map_is_equal(map
, map2
));
1262 str
= "{[0] -> [1]; [2] -> [3]}";
1263 map
= isl_map_read_from_str(ctx
, str
);
1264 map
= isl_map_transitive_closure(map
, &exact
);
1266 map2
= isl_map_read_from_str(ctx
, str
);
1267 assert(isl_map_is_equal(map
, map2
));
1271 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1272 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1273 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1274 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1275 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1276 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1277 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1278 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1279 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1280 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1281 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1282 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1283 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1284 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1285 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1286 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1287 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1288 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1289 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1290 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1291 map
= isl_map_read_from_str(ctx
, str
);
1292 map
= isl_map_transitive_closure(map
, NULL
);
1297 void test_lex(struct isl_ctx
*ctx
)
1302 dim
= isl_space_set_alloc(ctx
, 0, 0);
1303 map
= isl_map_lex_le(dim
);
1304 assert(!isl_map_is_empty(map
));
1308 void test_lexmin(struct isl_ctx
*ctx
)
1311 isl_basic_map
*bmap
;
1312 isl_map
*map
, *map2
;
1315 isl_pw_multi_aff
*pma
;
1317 str
= "[p0, p1] -> { [] -> [] : "
1318 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1319 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1320 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1321 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1322 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1323 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1324 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1325 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1326 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1327 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1328 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1329 map
= isl_map_read_from_str(ctx
, str
);
1330 map
= isl_map_lexmin(map
);
1333 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1334 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1335 set
= isl_set_read_from_str(ctx
, str
);
1336 set
= isl_set_lexmax(set
);
1337 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1338 set2
= isl_set_read_from_str(ctx
, str
);
1339 set
= isl_set_intersect(set
, set2
);
1340 assert(!isl_set_is_empty(set
));
1343 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1344 map
= isl_map_read_from_str(ctx
, str
);
1345 map
= isl_map_lexmin(map
);
1346 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1347 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1348 map2
= isl_map_read_from_str(ctx
, str
);
1349 assert(isl_map_is_equal(map
, map2
));
1353 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1354 map
= isl_map_read_from_str(ctx
, str
);
1355 map2
= isl_map_copy(map
);
1356 map
= isl_map_lexmin(map
);
1357 assert(isl_map_is_equal(map
, map2
));
1361 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1362 map
= isl_map_read_from_str(ctx
, str
);
1363 map
= isl_map_lexmin(map
);
1364 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1365 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1366 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1367 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1368 map2
= isl_map_read_from_str(ctx
, str
);
1369 assert(isl_map_is_equal(map
, map2
));
1373 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1374 " 8i' <= i and 8i' >= -7 + i }";
1375 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1376 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1377 map2
= isl_map_from_pw_multi_aff(pma
);
1378 map
= isl_map_from_basic_map(bmap
);
1379 assert(isl_map_is_equal(map
, map2
));
1383 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1384 map
= isl_map_read_from_str(ctx
, str
);
1385 map
= isl_map_lexmin(map
);
1386 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1387 map2
= isl_map_read_from_str(ctx
, str
);
1388 assert(isl_map_is_equal(map
, map2
));
1398 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1399 void *dep_user
, void *user
)
1401 struct must_may
*mm
= (struct must_may
*)user
;
1404 mm
->must
= isl_map_union(mm
->must
, dep
);
1406 mm
->may
= isl_map_union(mm
->may
, dep
);
1411 static int common_space(void *first
, void *second
)
1413 int depth
= *(int *)first
;
1417 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1425 map2
= isl_map_read_from_str(map
->ctx
, str
);
1426 equal
= isl_map_is_equal(map
, map2
);
1432 void test_dep(struct isl_ctx
*ctx
)
1437 isl_access_info
*ai
;
1444 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1445 map
= isl_map_read_from_str(ctx
, str
);
1446 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1448 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1449 map
= isl_map_read_from_str(ctx
, str
);
1450 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1452 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1453 map
= isl_map_read_from_str(ctx
, str
);
1454 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1456 flow
= isl_access_info_compute_flow(ai
);
1457 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1458 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1459 mm
.may
= isl_map_empty(dim
);
1461 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1463 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1464 " [1,10,0] -> [2,5,0] }";
1465 assert(map_is_equal(mm
.must
, str
));
1466 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1467 assert(map_is_equal(mm
.may
, str
));
1469 isl_map_free(mm
.must
);
1470 isl_map_free(mm
.may
);
1471 isl_flow_free(flow
);
1474 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1475 map
= isl_map_read_from_str(ctx
, str
);
1476 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1478 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1479 map
= isl_map_read_from_str(ctx
, str
);
1480 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1482 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1483 map
= isl_map_read_from_str(ctx
, str
);
1484 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1486 flow
= isl_access_info_compute_flow(ai
);
1487 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1488 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1489 mm
.may
= isl_map_empty(dim
);
1491 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1493 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1494 assert(map_is_equal(mm
.must
, str
));
1495 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1496 assert(map_is_equal(mm
.may
, str
));
1498 isl_map_free(mm
.must
);
1499 isl_map_free(mm
.may
);
1500 isl_flow_free(flow
);
1503 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1504 map
= isl_map_read_from_str(ctx
, str
);
1505 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1507 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1508 map
= isl_map_read_from_str(ctx
, str
);
1509 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1511 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1512 map
= isl_map_read_from_str(ctx
, str
);
1513 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1515 flow
= isl_access_info_compute_flow(ai
);
1516 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1517 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1518 mm
.may
= isl_map_empty(dim
);
1520 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1522 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1523 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1524 assert(map_is_equal(mm
.may
, str
));
1525 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1526 assert(map_is_equal(mm
.must
, str
));
1528 isl_map_free(mm
.must
);
1529 isl_map_free(mm
.may
);
1530 isl_flow_free(flow
);
1533 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1534 map
= isl_map_read_from_str(ctx
, str
);
1535 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1537 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1538 map
= isl_map_read_from_str(ctx
, str
);
1539 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1541 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1542 map
= isl_map_read_from_str(ctx
, str
);
1543 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1545 flow
= isl_access_info_compute_flow(ai
);
1546 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1547 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1548 mm
.may
= isl_map_empty(dim
);
1550 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1552 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1553 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1554 assert(map_is_equal(mm
.may
, str
));
1555 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1556 assert(map_is_equal(mm
.must
, str
));
1558 isl_map_free(mm
.must
);
1559 isl_map_free(mm
.may
);
1560 isl_flow_free(flow
);
1563 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1564 map
= isl_map_read_from_str(ctx
, str
);
1565 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1567 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1568 map
= isl_map_read_from_str(ctx
, str
);
1569 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1571 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1572 map
= isl_map_read_from_str(ctx
, str
);
1573 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1575 flow
= isl_access_info_compute_flow(ai
);
1576 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1577 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1578 mm
.may
= isl_map_empty(dim
);
1580 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1582 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1583 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1584 assert(map_is_equal(mm
.may
, str
));
1585 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1586 assert(map_is_equal(mm
.must
, str
));
1588 isl_map_free(mm
.must
);
1589 isl_map_free(mm
.may
);
1590 isl_flow_free(flow
);
1595 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1596 map
= isl_map_read_from_str(ctx
, str
);
1597 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1599 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1600 map
= isl_map_read_from_str(ctx
, str
);
1601 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1603 flow
= isl_access_info_compute_flow(ai
);
1604 dim
= isl_space_alloc(ctx
, 0, 5, 5);
1605 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1606 mm
.may
= isl_map_empty(dim
);
1608 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1610 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1611 assert(map_is_equal(mm
.must
, str
));
1612 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1613 assert(map_is_equal(mm
.may
, str
));
1615 isl_map_free(mm
.must
);
1616 isl_map_free(mm
.may
);
1617 isl_flow_free(flow
);
1620 int test_sv(isl_ctx
*ctx
)
1624 isl_union_map
*umap
;
1627 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1628 map
= isl_map_read_from_str(ctx
, str
);
1629 sv
= isl_map_is_single_valued(map
);
1634 isl_die(ctx
, isl_error_internal
,
1635 "map not detected as single valued", return -1);
1637 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1638 map
= isl_map_read_from_str(ctx
, str
);
1639 sv
= isl_map_is_single_valued(map
);
1644 isl_die(ctx
, isl_error_internal
,
1645 "map detected as single valued", return -1);
1647 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1648 umap
= isl_union_map_read_from_str(ctx
, str
);
1649 sv
= isl_union_map_is_single_valued(umap
);
1650 isl_union_map_free(umap
);
1654 isl_die(ctx
, isl_error_internal
,
1655 "map not detected as single valued", return -1);
1657 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
1658 umap
= isl_union_map_read_from_str(ctx
, str
);
1659 sv
= isl_union_map_is_single_valued(umap
);
1660 isl_union_map_free(umap
);
1664 isl_die(ctx
, isl_error_internal
,
1665 "map detected as single valued", return -1);
1670 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1674 map
= isl_map_read_from_str(ctx
, str
);
1676 assert(isl_map_is_bijective(map
));
1678 assert(!isl_map_is_bijective(map
));
1682 void test_bijective(struct isl_ctx
*ctx
)
1684 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1685 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1686 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1687 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1688 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1689 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1690 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1691 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1692 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1693 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1694 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1695 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1696 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1699 void test_pwqp(struct isl_ctx
*ctx
)
1703 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1705 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1706 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1708 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1711 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1712 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1714 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1716 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1718 isl_pw_qpolynomial_free(pwqp1
);
1720 str
= "{ [i] -> i }";
1721 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1722 str
= "{ [k] : exists a : k = 2a }";
1723 set
= isl_set_read_from_str(ctx
, str
);
1724 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1725 str
= "{ [i] -> i }";
1726 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1728 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1730 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1732 isl_pw_qpolynomial_free(pwqp1
);
1734 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
1735 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1737 set
= isl_set_read_from_str(ctx
, str
);
1738 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1739 str
= "{ [i] -> 16 }";
1740 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1742 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1744 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1746 isl_pw_qpolynomial_free(pwqp1
);
1748 str
= "{ [i] -> ([(i)/2]) }";
1749 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1750 str
= "{ [k] : exists a : k = 2a+1 }";
1751 set
= isl_set_read_from_str(ctx
, str
);
1752 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1753 str
= "{ [i] -> -1/2 + 1/2 * i }";
1754 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1756 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1758 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1760 isl_pw_qpolynomial_free(pwqp1
);
1762 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
1763 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1764 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
1765 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1767 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1769 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1771 isl_pw_qpolynomial_free(pwqp1
);
1773 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
1774 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1775 str
= "{ [x] -> x }";
1776 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1778 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1780 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1782 isl_pw_qpolynomial_free(pwqp1
);
1784 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
1785 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1786 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1787 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
1788 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1789 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1790 isl_pw_qpolynomial_free(pwqp1
);
1793 void test_split_periods(isl_ctx
*ctx
)
1796 isl_pw_qpolynomial
*pwqp
;
1798 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1799 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1800 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1801 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1803 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1806 isl_pw_qpolynomial_free(pwqp
);
1809 void test_union(isl_ctx
*ctx
)
1812 isl_union_set
*uset1
, *uset2
;
1813 isl_union_map
*umap1
, *umap2
;
1815 str
= "{ [i] : 0 <= i <= 1 }";
1816 uset1
= isl_union_set_read_from_str(ctx
, str
);
1817 str
= "{ [1] -> [0] }";
1818 umap1
= isl_union_map_read_from_str(ctx
, str
);
1820 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
1821 assert(isl_union_map_is_equal(umap1
, umap2
));
1823 isl_union_map_free(umap1
);
1824 isl_union_map_free(umap2
);
1826 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1827 umap1
= isl_union_map_read_from_str(ctx
, str
);
1828 str
= "{ A[i]; B[i] }";
1829 uset1
= isl_union_set_read_from_str(ctx
, str
);
1831 uset2
= isl_union_map_domain(umap1
);
1833 assert(isl_union_set_is_equal(uset1
, uset2
));
1835 isl_union_set_free(uset1
);
1836 isl_union_set_free(uset2
);
1839 void test_bound(isl_ctx
*ctx
)
1842 isl_pw_qpolynomial
*pwqp
;
1843 isl_pw_qpolynomial_fold
*pwf
;
1845 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
1846 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1847 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1848 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
1849 isl_pw_qpolynomial_fold_free(pwf
);
1851 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1852 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1853 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1854 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
1855 isl_pw_qpolynomial_fold_free(pwf
);
1858 void test_lift(isl_ctx
*ctx
)
1861 isl_basic_map
*bmap
;
1862 isl_basic_set
*bset
;
1864 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
1865 bset
= isl_basic_set_read_from_str(ctx
, str
);
1866 bset
= isl_basic_set_lift(bset
);
1867 bmap
= isl_basic_map_from_range(bset
);
1868 bset
= isl_basic_map_domain(bmap
);
1869 isl_basic_set_free(bset
);
1872 void test_subset(isl_ctx
*ctx
)
1875 isl_set
*set1
, *set2
;
1877 str
= "{ [112, 0] }";
1878 set1
= isl_set_read_from_str(ctx
, str
);
1879 str
= "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1880 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1881 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1882 set2
= isl_set_read_from_str(ctx
, str
);
1883 assert(isl_set_is_subset(set1
, set2
));
1888 void test_factorize(isl_ctx
*ctx
)
1891 isl_basic_set
*bset
;
1894 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1895 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1896 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1897 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1898 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1899 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1900 "3i5 >= -2i0 - i2 + 3i4 }";
1901 bset
= isl_basic_set_read_from_str(ctx
, str
);
1902 f
= isl_basic_set_factorizer(bset
);
1904 isl_basic_set_free(bset
);
1905 isl_factorizer_free(f
);
1907 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1908 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1909 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1910 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1911 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1912 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1913 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1914 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1915 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1916 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1917 bset
= isl_basic_set_read_from_str(ctx
, str
);
1918 f
= isl_basic_set_factorizer(bset
);
1920 isl_basic_set_free(bset
);
1921 isl_factorizer_free(f
);
1924 static int check_injective(__isl_take isl_map
*map
, void *user
)
1926 int *injective
= user
;
1928 *injective
= isl_map_is_injective(map
);
1931 if (*injective
< 0 || !*injective
)
1937 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
1938 const char *r
, const char *s
, int tilable
, int parallel
)
1942 isl_union_map
*W
, *R
, *S
;
1943 isl_union_map
*empty
;
1944 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
1945 isl_union_map
*validity
, *proximity
;
1946 isl_union_map
*schedule
;
1947 isl_union_map
*test
;
1948 isl_union_set
*delta
;
1949 isl_union_set
*domain
;
1953 isl_schedule
*sched
;
1954 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
1956 D
= isl_union_set_read_from_str(ctx
, d
);
1957 W
= isl_union_map_read_from_str(ctx
, w
);
1958 R
= isl_union_map_read_from_str(ctx
, r
);
1959 S
= isl_union_map_read_from_str(ctx
, s
);
1961 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
1962 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
1964 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
1965 isl_union_map_compute_flow(isl_union_map_copy(R
),
1966 isl_union_map_copy(W
), empty
,
1967 isl_union_map_copy(S
),
1968 &dep_raw
, NULL
, NULL
, NULL
);
1969 isl_union_map_compute_flow(isl_union_map_copy(W
),
1970 isl_union_map_copy(W
),
1971 isl_union_map_copy(R
),
1972 isl_union_map_copy(S
),
1973 &dep_waw
, &dep_war
, NULL
, NULL
);
1975 dep
= isl_union_map_union(dep_waw
, dep_war
);
1976 dep
= isl_union_map_union(dep
, dep_raw
);
1977 validity
= isl_union_map_copy(dep
);
1978 proximity
= isl_union_map_copy(dep
);
1980 sched
= isl_union_set_compute_schedule(isl_union_set_copy(D
),
1981 validity
, proximity
);
1982 schedule
= isl_schedule_get_map(sched
);
1983 isl_schedule_free(sched
);
1984 isl_union_map_free(W
);
1985 isl_union_map_free(R
);
1986 isl_union_map_free(S
);
1989 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
1991 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
1992 is_complete
= isl_union_set_is_subset(D
, domain
);
1993 isl_union_set_free(D
);
1994 isl_union_set_free(domain
);
1996 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
1997 test
= isl_union_map_apply_range(test
, dep
);
1998 test
= isl_union_map_apply_range(test
, schedule
);
2000 delta
= isl_union_map_deltas(test
);
2001 if (isl_union_set_n_set(delta
) == 0) {
2005 isl_union_set_free(delta
);
2007 delta_set
= isl_set_from_union_set(delta
);
2009 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2010 for (i
= 0; i
< tilable
; ++i
)
2011 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2012 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2013 isl_set_free(slice
);
2015 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2016 for (i
= 0; i
< parallel
; ++i
)
2017 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2018 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2019 isl_set_free(slice
);
2021 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2022 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2023 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2025 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2026 delta_set
= isl_set_lexmin(delta_set
);
2028 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2030 isl_set_free(origin
);
2031 isl_set_free(delta_set
);
2034 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2035 is_injection
< 0 || is_complete
< 0)
2038 isl_die(ctx
, isl_error_unknown
,
2039 "generated schedule incomplete", return -1);
2041 isl_die(ctx
, isl_error_unknown
,
2042 "generated schedule not injective on each statement",
2045 isl_die(ctx
, isl_error_unknown
,
2046 "negative dependences in generated schedule",
2049 isl_die(ctx
, isl_error_unknown
,
2050 "generated schedule not as tilable as expected",
2053 isl_die(ctx
, isl_error_unknown
,
2054 "generated schedule not as parallel as expected",
2060 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2061 const char *validity
, const char *proximity
, const char *expected_sched
)
2065 isl_union_map
*prox
;
2066 isl_union_map
*sched1
, *sched2
;
2067 isl_schedule
*schedule
;
2070 dom
= isl_union_set_read_from_str(ctx
, domain
);
2071 dep
= isl_union_map_read_from_str(ctx
, validity
);
2072 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2073 schedule
= isl_union_set_compute_schedule(dom
, dep
, prox
);
2074 sched1
= isl_schedule_get_map(schedule
);
2075 isl_schedule_free(schedule
);
2077 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2079 equal
= isl_union_map_is_equal(sched1
, sched2
);
2080 isl_union_map_free(sched1
);
2081 isl_union_map_free(sched2
);
2086 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2092 int test_schedule(isl_ctx
*ctx
)
2094 const char *D
, *W
, *R
, *V
, *P
, *S
;
2097 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2098 W
= "{ S1[t,i] -> a[t,i] }";
2099 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2100 "S1[t,i] -> a[t-1,i+1] }";
2101 S
= "{ S1[t,i] -> [t,i] }";
2102 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2105 /* Fig. 5 of CC2008 */
2106 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2108 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2109 "j >= 2 and j <= -1 + N }";
2110 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2111 "j >= 2 and j <= -1 + N; "
2112 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2113 "j >= 2 and j <= -1 + N }";
2114 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2115 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2118 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2119 W
= "{ S1[i] -> a[i] }";
2120 R
= "{ S2[i] -> a[i+1] }";
2121 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2122 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2125 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2126 W
= "{ S1[i] -> a[i] }";
2127 R
= "{ S2[i] -> a[9-i] }";
2128 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2129 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2132 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2133 W
= "{ S1[i] -> a[i] }";
2134 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2135 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2136 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2139 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2140 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2141 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2142 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2143 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2146 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2147 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2148 R
= "{ S2[i,j] -> a[i-1,j] }";
2149 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2150 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2153 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2154 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2155 R
= "{ S2[i,j] -> a[i,j-1] }";
2156 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2157 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2160 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2161 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2162 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2163 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2164 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2165 "S_0[] -> [0, 0, 0] }";
2166 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2168 ctx
->opt
->schedule_parametric
= 0;
2169 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2171 ctx
->opt
->schedule_parametric
= 1;
2173 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2174 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2175 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2176 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2177 "S4[i] -> a[i,N] }";
2178 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2179 "S4[i] -> [4,i,0] }";
2180 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2183 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2184 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2186 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2188 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2190 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2191 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2194 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2195 " S_2[t] : t >= 0 and t <= -1 + N; "
2196 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2198 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2199 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2200 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2201 "i >= 0 and i <= -1 + N }";
2202 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2203 "i >= 0 and i <= -1 + N; "
2204 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2205 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2206 " S_0[t] -> [0, t, 0] }";
2208 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2210 ctx
->opt
->schedule_parametric
= 0;
2211 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2213 ctx
->opt
->schedule_parametric
= 1;
2215 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2216 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2217 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
2220 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2221 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2222 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2223 "j >= 0 and j <= -1 + N; "
2224 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2225 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2226 "j >= 0 and j <= -1 + N; "
2227 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2228 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2229 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2232 D
= "{ S_0[i] : i >= 0 }";
2233 W
= "{ S_0[i] -> a[i] : i >= 0 }";
2234 R
= "{ S_0[i] -> a[0] : i >= 0 }";
2235 S
= "{ S_0[i] -> [0, i, 0] }";
2236 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2239 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2240 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2241 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2242 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2243 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2246 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2247 "k <= -1 + n and k >= 0 }";
2248 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2249 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2250 "k <= -1 + n and k >= 0; "
2251 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2252 "k <= -1 + n and k >= 0; "
2253 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2254 "k <= -1 + n and k >= 0 }";
2255 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
2256 ctx
->opt
->schedule_outer_zero_distance
= 1;
2257 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2259 ctx
->opt
->schedule_outer_zero_distance
= 0;
2261 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
2262 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2263 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2264 "Stmt_for_body24[i0, i1, 1, 0]:"
2265 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2266 "Stmt_for_body7[i0, i1, i2]:"
2267 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2270 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
2271 "Stmt_for_body24[1, i1, i2, i3]:"
2272 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2274 "Stmt_for_body24[0, i1, i2, i3] -> "
2275 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2276 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2278 "Stmt_for_body24[0, i1, i2, i3] ->"
2279 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2280 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2281 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2282 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2283 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2284 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2285 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2286 "i1 <= 6 and i1 >= 0;"
2287 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2288 "Stmt_for_body7[i0, i1, i2] -> "
2289 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2290 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2291 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2292 "Stmt_for_body7[i0, i1, i2] -> "
2293 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2294 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2295 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2297 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2298 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2299 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2301 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2304 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2305 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2306 "j >= 1 and j <= 7;"
2307 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2308 "j >= 1 and j <= 8 }";
2310 S
= "{ S_0[i, j] -> [i + j, j] }";
2311 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2312 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2314 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2316 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2317 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2318 "j >= 0 and j <= -1 + i }";
2319 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2320 "i <= -1 + N and j >= 0;"
2321 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2324 S
= "{ S_0[i, j] -> [i, j] }";
2325 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2326 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2328 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2330 /* Test both algorithms on a case with only proximity dependences. */
2331 D
= "{ S[i,j] : 0 <= i <= 10 }";
2333 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2334 S
= "{ S[i, j] -> [j, i] }";
2335 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2336 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2338 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2339 return test_special_schedule(ctx
, D
, V
, P
, S
);
2342 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
2344 isl_union_map
*umap
;
2347 umap
= isl_union_map_read_from_str(ctx
, str
);
2348 test
= isl_union_map_plain_is_injective(umap
);
2349 isl_union_map_free(umap
);
2352 if (test
== injective
)
2355 isl_die(ctx
, isl_error_unknown
,
2356 "map not detected as injective", return -1);
2358 isl_die(ctx
, isl_error_unknown
,
2359 "map detected as injective", return -1);
2362 int test_injective(isl_ctx
*ctx
)
2366 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2368 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
2370 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
2372 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
2374 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2376 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2378 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2380 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2383 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2384 if (test_plain_injective(ctx
, str
, 1))
2386 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2387 if (test_plain_injective(ctx
, str
, 0))
2393 int test_aff(isl_ctx
*ctx
)
2398 isl_local_space
*ls
;
2402 dim
= isl_space_set_alloc(ctx
, 0, 1);
2403 ls
= isl_local_space_from_space(dim
);
2404 aff
= isl_aff_zero_on_domain(ls
);
2406 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2407 aff
= isl_aff_scale_down_ui(aff
, 3);
2408 aff
= isl_aff_floor(aff
);
2409 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2410 aff
= isl_aff_scale_down_ui(aff
, 2);
2411 aff
= isl_aff_floor(aff
);
2412 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2415 set
= isl_set_read_from_str(ctx
, str
);
2416 aff
= isl_aff_gist(aff
, set
);
2418 aff
= isl_aff_add_constant_si(aff
, -16);
2419 zero
= isl_aff_plain_is_zero(aff
);
2425 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2430 int test_dim_max(isl_ctx
*ctx
)
2434 isl_set
*set1
, *set2
;
2439 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
2440 set
= isl_set_read_from_str(ctx
, str
);
2441 pwaff
= isl_set_dim_max(set
, 0);
2442 set1
= isl_set_from_pw_aff(pwaff
);
2443 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
2444 set2
= isl_set_read_from_str(ctx
, str
);
2445 equal
= isl_set_is_equal(set1
, set2
);
2451 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2453 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
2454 set
= isl_set_read_from_str(ctx
, str
);
2455 pwaff
= isl_set_dim_max(set
, 0);
2456 set1
= isl_set_from_pw_aff(pwaff
);
2457 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2458 set2
= isl_set_read_from_str(ctx
, str
);
2459 equal
= isl_set_is_equal(set1
, set2
);
2465 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2467 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
2468 set
= isl_set_read_from_str(ctx
, str
);
2469 pwaff
= isl_set_dim_max(set
, 0);
2470 set1
= isl_set_from_pw_aff(pwaff
);
2471 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
2472 set2
= isl_set_read_from_str(ctx
, str
);
2473 equal
= isl_set_is_equal(set1
, set2
);
2479 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2481 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
2482 "0 <= i < N and 0 <= j < M }";
2483 map
= isl_map_read_from_str(ctx
, str
);
2484 set
= isl_map_range(map
);
2486 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
2487 set1
= isl_set_from_pw_aff(pwaff
);
2488 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
2489 set2
= isl_set_read_from_str(ctx
, str
);
2490 equal
= isl_set_is_equal(set1
, set2
);
2494 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
2495 set1
= isl_set_from_pw_aff(pwaff
);
2496 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
2497 set2
= isl_set_read_from_str(ctx
, str
);
2498 if (equal
>= 0 && equal
)
2499 equal
= isl_set_is_equal(set1
, set2
);
2508 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2513 int test_product(isl_ctx
*ctx
)
2517 isl_union_set
*uset1
, *uset2
;
2521 set
= isl_set_read_from_str(ctx
, str
);
2522 set
= isl_set_product(set
, isl_set_copy(set
));
2523 ok
= isl_set_is_wrapping(set
);
2528 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2531 uset1
= isl_union_set_read_from_str(ctx
, str
);
2532 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
2533 str
= "{ [[] -> []] }";
2534 uset2
= isl_union_set_read_from_str(ctx
, str
);
2535 ok
= isl_union_set_is_equal(uset1
, uset2
);
2536 isl_union_set_free(uset1
);
2537 isl_union_set_free(uset2
);
2541 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2546 int test_equal(isl_ctx
*ctx
)
2549 isl_set
*set
, *set2
;
2553 set
= isl_set_read_from_str(ctx
, str
);
2555 set2
= isl_set_read_from_str(ctx
, str
);
2556 equal
= isl_set_is_equal(set
, set2
);
2562 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2567 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
2568 enum isl_dim_type type
, unsigned pos
, int fixed
)
2572 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
2579 isl_die(ctx
, isl_error_unknown
,
2580 "map not detected as fixed", return -1);
2582 isl_die(ctx
, isl_error_unknown
,
2583 "map detected as fixed", return -1);
2586 int test_fixed(isl_ctx
*ctx
)
2591 str
= "{ [i] -> [i] }";
2592 map
= isl_map_read_from_str(ctx
, str
);
2593 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
2595 str
= "{ [i] -> [1] }";
2596 map
= isl_map_read_from_str(ctx
, str
);
2597 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2599 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
2600 map
= isl_map_read_from_str(ctx
, str
);
2601 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2603 map
= isl_map_read_from_str(ctx
, str
);
2604 map
= isl_map_neg(map
);
2605 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
2611 int test_vertices(isl_ctx
*ctx
)
2614 isl_basic_set
*bset
;
2615 isl_vertices
*vertices
;
2617 str
= "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
2618 bset
= isl_basic_set_read_from_str(ctx
, str
);
2619 vertices
= isl_basic_set_compute_vertices(bset
);
2620 isl_basic_set_free(bset
);
2621 isl_vertices_free(vertices
);
2625 str
= "{ A[t, i] : t = 14 and i = 1 }";
2626 bset
= isl_basic_set_read_from_str(ctx
, str
);
2627 vertices
= isl_basic_set_compute_vertices(bset
);
2628 isl_basic_set_free(bset
);
2629 isl_vertices_free(vertices
);
2636 int test_union_pw(isl_ctx
*ctx
)
2640 isl_union_set
*uset
;
2641 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
2643 str
= "{ [x] -> x^2 }";
2644 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
2645 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
2646 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
2647 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
2648 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
2649 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
2650 isl_union_pw_qpolynomial_free(upwqp1
);
2651 isl_union_pw_qpolynomial_free(upwqp2
);
2655 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2660 int test_output(isl_ctx
*ctx
)
2668 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
2669 pa
= isl_pw_aff_read_from_str(ctx
, str
);
2671 p
= isl_printer_to_str(ctx
);
2672 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
2673 p
= isl_printer_print_pw_aff(p
, pa
);
2674 s
= isl_printer_get_str(p
);
2675 isl_printer_free(p
);
2676 isl_pw_aff_free(pa
);
2677 equal
= !strcmp(s
, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
2682 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2689 struct isl_ctx
*ctx
;
2691 srcdir
= getenv("srcdir");
2694 ctx
= isl_ctx_alloc();
2695 if (test_output(ctx
) < 0)
2697 if (test_vertices(ctx
) < 0)
2699 if (test_fixed(ctx
) < 0)
2701 if (test_equal(ctx
) < 0)
2703 if (test_product(ctx
) < 0)
2705 if (test_dim_max(ctx
) < 0)
2707 if (test_aff(ctx
) < 0)
2709 if (test_injective(ctx
) < 0)
2711 if (test_schedule(ctx
) < 0)
2713 if (test_union_pw(ctx
) < 0)
2715 test_factorize(ctx
);
2720 test_split_periods(ctx
);
2724 if (test_sv(ctx
) < 0)
2726 test_bijective(ctx
);
2730 test_construction(ctx
);
2733 test_application(ctx
);
2734 if (test_affine_hull(ctx
) < 0)
2736 test_convex_hull(ctx
);