File: | build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/polly/lib/External/isl/isl_test.c |
Warning: | line 7955, column 12 The left operand of '<' is a garbage value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright 2008-2009 Katholieke Universiteit Leuven |
3 | * Copyright 2010 INRIA Saclay |
4 | * Copyright 2012-2013 Ecole Normale Superieure |
5 | * Copyright 2014 INRIA Rocquencourt |
6 | * |
7 | * Use of this software is governed by the MIT license |
8 | * |
9 | * Written by Sven Verdoolaege, K.U.Leuven, Departement |
10 | * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium |
11 | * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite, |
12 | * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France |
13 | * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France |
14 | * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt, |
15 | * B.P. 105 - 78153 Le Chesnay, France |
16 | */ |
17 | |
18 | #include <assert.h> |
19 | #include <stdio.h> |
20 | #include <limits.h> |
21 | #include <isl_ctx_private.h> |
22 | #include <isl_map_private.h> |
23 | #include <isl_aff_private.h> |
24 | #include <isl_space_private.h> |
25 | #include <isl/id.h> |
26 | #include <isl/set.h> |
27 | #include <isl/flow.h> |
28 | #include <isl_constraint_private.h> |
29 | #include <isl/polynomial.h> |
30 | #include <isl/union_set.h> |
31 | #include <isl/union_map.h> |
32 | #include <isl_factorization.h> |
33 | #include <isl/schedule.h> |
34 | #include <isl/schedule_node.h> |
35 | #include <isl_options_private.h> |
36 | #include <isl_vertices_private.h> |
37 | #include <isl/ast_build.h> |
38 | #include <isl/val.h> |
39 | #include <isl/ilp.h> |
40 | #include <isl_ast_build_expr.h> |
41 | #include <isl/options.h> |
42 | |
43 | #include "isl_srcdir.c" |
44 | |
45 | #define ARRAY_SIZE(array)(sizeof(array)/sizeof(*array)) (sizeof(array)/sizeof(*array)) |
46 | |
47 | static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) { |
48 | char *filename; |
49 | int length; |
50 | char *pattern = "%s/test_inputs/%s.%s"; |
51 | |
52 | length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name) |
53 | + strlen(suffix) + 1; |
54 | filename = isl_alloc_array(ctx, char, length)((char *)isl_malloc_or_die(ctx, (length)*sizeof(char))); |
55 | |
56 | if (!filename) |
57 | return NULL((void*)0); |
58 | |
59 | sprintf(filename, pattern, srcdir, name, suffix)__builtin___sprintf_chk (filename, 2 - 1, __builtin_object_size (filename, 2 > 1), pattern, srcdir, name, suffix); |
60 | |
61 | return filename; |
62 | } |
63 | |
64 | void test_parse_map(isl_ctx *ctx, const char *str) |
65 | { |
66 | isl_map *map; |
67 | |
68 | map = isl_map_read_from_str(ctx, str); |
69 | assert(map)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else __assert_fail ("map", "polly/lib/External/isl/isl_test.c", 69 , __extension__ __PRETTY_FUNCTION__); })); |
70 | isl_map_free(map); |
71 | } |
72 | |
73 | int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2) |
74 | { |
75 | isl_map *map, *map2; |
76 | int equal; |
77 | |
78 | map = isl_map_read_from_str(ctx, str); |
79 | map2 = isl_map_read_from_str(ctx, str2); |
80 | equal = isl_map_is_equal(map, map2); |
81 | isl_map_free(map); |
82 | isl_map_free(map2); |
83 | |
84 | if (equal < 0) |
85 | return -1; |
86 | if (!equal) |
87 | isl_die(ctx, isl_error_unknown, "maps not equal",do { isl_handle_error(ctx, isl_error_unknown, "maps not equal" , "polly/lib/External/isl/isl_test.c", 88); return -1; } while (0) |
88 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "maps not equal" , "polly/lib/External/isl/isl_test.c", 88); return -1; } while (0); |
89 | |
90 | return 0; |
91 | } |
92 | |
93 | void test_parse_pwqp(isl_ctx *ctx, const char *str) |
94 | { |
95 | isl_pw_qpolynomial *pwqp; |
96 | |
97 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
98 | assert(pwqp)((void) sizeof ((pwqp) ? 1 : 0), __extension__ ({ if (pwqp) ; else __assert_fail ("pwqp", "polly/lib/External/isl/isl_test.c" , 98, __extension__ __PRETTY_FUNCTION__); })); |
99 | isl_pw_qpolynomial_free(pwqp); |
100 | } |
101 | |
102 | static void test_parse_pwaff(isl_ctx *ctx, const char *str) |
103 | { |
104 | isl_pw_aff *pwaff; |
105 | |
106 | pwaff = isl_pw_aff_read_from_str(ctx, str); |
107 | assert(pwaff)((void) sizeof ((pwaff) ? 1 : 0), __extension__ ({ if (pwaff) ; else __assert_fail ("pwaff", "polly/lib/External/isl/isl_test.c" , 107, __extension__ __PRETTY_FUNCTION__); })); |
108 | isl_pw_aff_free(pwaff); |
109 | } |
110 | |
111 | /* Check that we can read an isl_multi_val from "str" without errors. |
112 | */ |
113 | static int test_parse_multi_val(isl_ctx *ctx, const char *str) |
114 | { |
115 | isl_multi_val *mv; |
116 | |
117 | mv = isl_multi_val_read_from_str(ctx, str); |
118 | isl_multi_val_free(mv); |
119 | |
120 | return mv ? 0 : -1; |
121 | } |
122 | |
123 | /* String descriptions of multi piecewise affine expressions |
124 | * that are used for testing printing and parsing. |
125 | */ |
126 | static const char *reparse_multi_pw_aff_tests[] = { |
127 | "{ A[x, y] -> [] : x + y >= 0 }", |
128 | "{ A[x, y] -> B[] : x + y >= 0 }", |
129 | "{ A[x, y] -> [x] : x + y >= 0 }", |
130 | "[N] -> { A[x, y] -> [x] : x + y <= N }", |
131 | "{ A[x, y] -> [x, y] : x + y >= 0 }", |
132 | "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }", |
133 | "[N] -> { [] : N >= 0 }", |
134 | "[N] -> { [] : N >= 0 }", |
135 | "[N] -> { [N] : N >= 0 }", |
136 | "[N] -> { [N, N + 1] : N >= 0 }", |
137 | "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }", |
138 | "{ [a] -> [b = a] }", |
139 | "{ [a] -> [b = a] : a >= 0 }", |
140 | }; |
141 | |
142 | #undef BASEunion_pw_aff |
143 | #define BASEunion_pw_aff multi_pw_aff |
144 | |
145 | #include "check_reparse_templ.c" |
146 | #include "check_reparse_test_templ.c" |
147 | |
148 | /* String descriptions that cannot be parsed |
149 | * as multi piecewise affine expressions. |
150 | */ |
151 | static const char *parse_multi_pw_aff_fail_tests[] = { |
152 | "{ [a] -> [b] : b = a }", |
153 | "{ [a] -> [b = a] : b >= 0 }", |
154 | }; |
155 | |
156 | #include "check_parse_fail_test_templ.c" |
157 | |
158 | /* String descriptions of piecewise multi affine expressions |
159 | * that are used for testing printing and parsing. |
160 | */ |
161 | static const char *reparse_pw_multi_aff_tests[] = { |
162 | "{ [x] -> [x] }", |
163 | "{ [x] -> [x % 4] }", |
164 | "{ [x] -> [x % 4] : x mod 3 = 1 }", |
165 | "{ [x, x] -> [x % 4] }", |
166 | "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }", |
167 | "{ [x, x mod 2] -> [x % 4] }", |
168 | }; |
169 | |
170 | #undef BASEunion_pw_aff |
171 | #define BASEunion_pw_aff pw_multi_aff |
172 | |
173 | #include "check_reparse_templ.c" |
174 | #include "check_reparse_test_templ.c" |
175 | |
176 | /* Test parsing of piecewise multi affine expressions by printing |
177 | * the expressions and checking that parsing the output results |
178 | * in the same expression. |
179 | * Do this for an expression converted from a map with an output |
180 | * dimension name that is equal to an automatically generated name, and |
181 | * a set of expressions parsed from strings. |
182 | */ |
183 | static isl_stat test_parse_pma(isl_ctx *ctx) |
184 | { |
185 | isl_map *map; |
186 | isl_pw_multi_aff *pma; |
187 | |
188 | map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }"); |
189 | pma = isl_pw_multi_aff_from_map(map); |
190 | if (check_reparse_pw_multi_aff(ctx, pma) < 0) |
191 | return isl_stat_error; |
192 | |
193 | if (check_reparse_pw_multi_aff_tests(ctx) < 0) |
194 | return isl_stat_error; |
195 | |
196 | return isl_stat_ok; |
197 | } |
198 | |
199 | /* String descriptions that cannot be parsed |
200 | * as union piecewise multi affine expressions. |
201 | */ |
202 | static const char *parse_union_pw_multi_aff_fail_tests[] = { |
203 | "{ [a] -> [b] : b = a }", |
204 | "{ [a] -> [b = a] : b >= 0 }", |
205 | }; |
206 | |
207 | #undef BASEunion_pw_aff |
208 | #define BASEunion_pw_aff union_pw_multi_aff |
209 | |
210 | #include "check_parse_fail_test_templ.c" |
211 | |
212 | /* Test parsing of union piecewise multi affine expressions. |
213 | * |
214 | * In particular, check some cases where parsing is supposed to fail. |
215 | */ |
216 | static isl_stat test_parse_upma(isl_ctx *ctx) |
217 | { |
218 | if (check_parse_union_pw_multi_aff_fail_tests(ctx) < 0) |
219 | return isl_stat_error; |
220 | |
221 | return isl_stat_ok; |
222 | } |
223 | |
224 | /* Test parsing of multi piecewise affine expressions by printing |
225 | * the expressions and checking that parsing the output results |
226 | * in the same expression. |
227 | * Do this for a couple of manually constructed expressions, |
228 | * an expression converted from a map with an output dimension name |
229 | * that is equal to an automatically generated name, and |
230 | * a set of expressions parsed from strings. |
231 | * |
232 | * Additionally, check some cases where parsing is supposed to fail. |
233 | */ |
234 | static int test_parse_mpa(isl_ctx *ctx) |
235 | { |
236 | isl_space *space; |
237 | isl_setisl_map *dom; |
238 | isl_map *map; |
239 | isl_pw_multi_aff *pma; |
240 | isl_multi_pw_aff *mpa; |
241 | isl_stat r; |
242 | |
243 | space = isl_space_set_alloc(ctx, 0, 0); |
244 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
245 | mpa = isl_multi_pw_aff_zero(space); |
246 | r = check_reparse_multi_pw_aff(ctx, mpa); |
247 | if (r < 0) |
248 | return -1; |
249 | |
250 | space = isl_space_set_alloc(ctx, 1, 0); |
251 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
252 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
253 | dom = isl_set_universe(isl_space_params(isl_space_copy(space))); |
254 | dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5); |
255 | mpa = isl_multi_pw_aff_zero(space); |
256 | mpa = isl_multi_pw_aff_intersect_domain(mpa, dom); |
257 | r = check_reparse_multi_pw_aff(ctx, mpa); |
258 | if (r < 0) |
259 | return -1; |
260 | |
261 | map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }"); |
262 | pma = isl_pw_multi_aff_from_map(map); |
263 | mpa = isl_multi_pw_aff_from_pw_multi_aff(pma); |
264 | if (check_reparse_multi_pw_aff(ctx, mpa) < 0) |
265 | return -1; |
266 | |
267 | if (check_reparse_multi_pw_aff_tests(ctx) < 0) |
268 | return -1; |
269 | if (check_parse_multi_pw_aff_fail_tests(ctx) < 0) |
270 | return -1; |
271 | |
272 | return 0; |
273 | } |
274 | |
275 | /* String descriptions of multi union piecewise affine expressions |
276 | * that are used for testing printing and parsing. |
277 | */ |
278 | static const char *reparse_multi_union_pw_aff_tests[] = { |
279 | "[]", |
280 | "A[]", |
281 | "A[B[] -> C[]]", |
282 | "(A[] : { S[x] : x > 0; T[y] : y >= 0 })", |
283 | "(A[] : { })", |
284 | "[N] -> (A[] : { })", |
285 | "[N] -> (A[] : { : N >= 0 })", |
286 | "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })", |
287 | "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })", |
288 | "A[{ S[x] -> [x + 1]; T[x] -> [x] }]", |
289 | "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : " |
290 | "{ S[x] : x > 0; T[y] : y >= 0 })", |
291 | }; |
292 | |
293 | #undef BASEunion_pw_aff |
294 | #define BASEunion_pw_aff multi_union_pw_aff |
295 | |
296 | #include "check_reparse_templ.c" |
297 | #include "check_reparse_test_templ.c" |
298 | |
299 | /* Test parsing of multi union piecewise affine expressions by printing |
300 | * the expressions and checking that parsing the output results |
301 | * in the same expression. |
302 | * Do this for a couple of manually constructed expressions and |
303 | * a set of expressions parsed from strings. |
304 | */ |
305 | static int test_parse_mupa(isl_ctx *ctx) |
306 | { |
307 | isl_space *space; |
308 | isl_multi_union_pw_aff *mupa; |
309 | isl_setisl_map *dom; |
310 | isl_union_set *uset; |
311 | isl_stat r; |
312 | |
313 | space = isl_space_set_alloc(ctx, 0, 0); |
314 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
315 | mupa = isl_multi_union_pw_aff_zero(space); |
316 | r = check_reparse_multi_union_pw_aff(ctx, mupa); |
317 | if (r < 0) |
318 | return -1; |
319 | |
320 | space = isl_space_set_alloc(ctx, 1, 0); |
321 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
322 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
323 | dom = isl_set_universe(space); |
324 | dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5); |
325 | uset = isl_union_set_from_set(dom); |
326 | space = isl_space_set_alloc(ctx, 1, 0); |
327 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
328 | space = isl_space_set_tuple_name(space, isl_dim_set, "B"); |
329 | mupa = isl_multi_union_pw_aff_zero(space); |
330 | mupa = isl_multi_union_pw_aff_intersect_domain(mupa, uset); |
331 | r = check_reparse_multi_union_pw_aff(ctx, mupa); |
332 | if (r < 0) |
333 | return -1; |
334 | |
335 | if (check_reparse_multi_union_pw_aff_tests(ctx) < 0) |
336 | return -1; |
337 | |
338 | return 0; |
339 | } |
340 | |
341 | /* Test parsing of multi expressions. |
342 | */ |
343 | static int test_parse_multi(isl_ctx *ctx) |
344 | { |
345 | if (test_parse_mpa(ctx) < 0) |
346 | return -1; |
347 | if (test_parse_mupa(ctx) < 0) |
348 | return -1; |
349 | |
350 | return 0; |
351 | } |
352 | |
353 | /* Pairs of binary relation representations that should represent |
354 | * the same binary relations. |
355 | */ |
356 | struct { |
357 | const char *map1; |
358 | const char *map2; |
359 | } parse_map_equal_tests[] = { |
360 | { "{ [x,y] : [([x/2]+y)/3] >= 1 }", |
361 | "{ [x, y] : 2y >= 6 - x }" }, |
362 | { "{ [x,y] : x <= min(y, 2*y+3) }", |
363 | "{ [x,y] : x <= y, 2*y + 3 }" }, |
364 | { "{ [x,y] : x >= min(y, 2*y+3) }", |
365 | "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" }, |
366 | { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }", |
367 | "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" }, |
368 | { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }", |
369 | "{ [i,j] -> [min(i,j)] }" }, |
370 | { "{ [i,j] : i != j }", |
371 | "{ [i,j] : i < j or i > j }" }, |
372 | { "{ [i,j] : (i+1)*2 >= j }", |
373 | "{ [i, j] : j <= 2 + 2i }" }, |
374 | { "{ [i] -> [i > 0 ? 4 : 5] }", |
375 | "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" }, |
376 | { "[N=2,M] -> { [i=[(M+N)/4]] }", |
377 | "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" }, |
378 | { "{ [x] : x >= 0 }", |
379 | "{ [x] : x-0 >= 0 }" }, |
380 | { "{ [i] : ((i > 10)) }", |
381 | "{ [i] : i >= 11 }" }, |
382 | { "{ [i] -> [0] }", |
383 | "{ [i] -> [0 * i] }" }, |
384 | { "{ [a] -> [b] : (not false) }", |
385 | "{ [a] -> [b] : true }" }, |
386 | { "{ [i] : i/2 <= 5 }", |
387 | "{ [i] : i <= 10 }" }, |
388 | { "{Sym=[n] [i] : i <= n }", |
389 | "[n] -> { [i] : i <= n }" }, |
390 | { "{ [*] }", |
391 | "{ [a] }" }, |
392 | { "{ [i] : 2*floor(i/2) = i }", |
393 | "{ [i] : exists a : i = 2 a }" }, |
394 | { "{ [a] -> [b] : a = 5 implies b = 5 }", |
395 | "{ [a] -> [b] : a != 5 or b = 5 }" }, |
396 | { "{ [a] -> [a - 1 : a > 0] }", |
397 | "{ [a] -> [a - 1] : a > 0 }" }, |
398 | { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }", |
399 | "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" }, |
400 | { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }", |
401 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
402 | { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }", |
403 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
404 | { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }", |
405 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
406 | { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }", |
407 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
408 | { "{ [a,b] -> [i,j] : a,b << i,j }", |
409 | "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" }, |
410 | { "{ [a,b] -> [i,j] : a,b <<= i,j }", |
411 | "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" }, |
412 | { "{ [a,b] -> [i,j] : a,b >> i,j }", |
413 | "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" }, |
414 | { "{ [a,b] -> [i,j] : a,b >>= i,j }", |
415 | "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" }, |
416 | { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and " |
417 | "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and " |
418 | "8c < n - 32a and i < n and c >= 0 and " |
419 | "c <= 3 and c >= -4a) }", |
420 | "{ [n] -> [i] : 0 <= i < n }" }, |
421 | { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and " |
422 | "2b <= x - 8a and 2b >= -1 + x - 8a) }", |
423 | "{ [x] -> [] : 0 <= x <= 15 }" }, |
424 | { "{ [x] -> [x] : }", |
425 | "{ [x] -> [x] }" }, |
426 | { "{ [x=4:5] -> [x + 1] }", |
427 | "{ [x] -> [x + 1] : 4 <= x <= 5 }" }, |
428 | { "{ [x=4:5] -> [x + 1 : x + 1] }", |
429 | "{ [x=4:5] -> [x + 1] }" }, |
430 | { "{ [x] -> [x - 1 : x + 1] }", |
431 | "{ [x] -> [y] : x - 1 <= y <= x + 1 }" }, |
432 | { "{ [x=4:] -> [x + 1] }", |
433 | "{ [x] -> [x + 1] : 4 <= x }" }, |
434 | { "{ [x=:5] -> [x + 1] }", |
435 | "{ [x] -> [x + 1] : x <= 5 }" }, |
436 | { "{ [x=:] -> [x + 1] }", |
437 | "{ [x] -> [x + 1] }" }, |
438 | { "{ [:] -> [:] }", |
439 | "{ [x] -> [y] }" }, |
440 | { "{ [x, x//4] }", |
441 | "{ [x, floor(x/4)] }" }, |
442 | { "{ [10//4] }", |
443 | "{ [2] }" }, |
444 | }; |
445 | |
446 | int test_parse(struct isl_ctx *ctx) |
447 | { |
448 | int i; |
449 | isl_map *map, *map2; |
450 | const char *str, *str2; |
451 | |
452 | if (test_parse_multi_val(ctx, "{ A[B[2] -> C[5, 7]] }") < 0) |
453 | return -1; |
454 | if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0) |
455 | return -1; |
456 | if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0) |
457 | return -1; |
458 | if (test_parse_multi(ctx) < 0) |
459 | return -1; |
460 | if (test_parse_pma(ctx) < 0) |
461 | return -1; |
462 | if (test_parse_upma(ctx) < 0) |
463 | return -1; |
464 | |
465 | str = "{ [i] -> [-i] }"; |
466 | map = isl_map_read_from_str(ctx, str); |
467 | assert(map)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else __assert_fail ("map", "polly/lib/External/isl/isl_test.c", 467 , __extension__ __PRETTY_FUNCTION__); })); |
468 | isl_map_free(map); |
469 | |
470 | str = "{ A[i] -> L[([i/3])] }"; |
471 | map = isl_map_read_from_str(ctx, str); |
472 | assert(map)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else __assert_fail ("map", "polly/lib/External/isl/isl_test.c", 472 , __extension__ __PRETTY_FUNCTION__); })); |
473 | isl_map_free(map); |
474 | |
475 | test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}"); |
476 | test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : " |
477 | "p1 = 1 && (y1 <= y2 || y2 = 0) }"); |
478 | |
479 | for (i = 0; i < ARRAY_SIZE(parse_map_equal_tests)(sizeof(parse_map_equal_tests)/sizeof(*parse_map_equal_tests) ); ++i) { |
480 | str = parse_map_equal_tests[i].map1; |
481 | str2 = parse_map_equal_tests[i].map2; |
482 | if (test_parse_map_equal(ctx, str, str2) < 0) |
483 | return -1; |
484 | } |
485 | |
486 | str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}"; |
487 | map = isl_map_read_from_str(ctx, str); |
488 | str = "{ [new, old] -> [o0, o1] : " |
489 | "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: " |
490 | "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and " |
491 | "o0 <= 1 and o1 >= 0 and o1 <= 1) }"; |
492 | map2 = isl_map_read_from_str(ctx, str); |
493 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 493, __extension__ __PRETTY_FUNCTION__ ); })); |
494 | isl_map_free(map); |
495 | isl_map_free(map2); |
496 | |
497 | str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}"; |
498 | map = isl_map_read_from_str(ctx, str); |
499 | str = "{[new,old] -> [(new+1)%2,(old+1)%2]}"; |
500 | map2 = isl_map_read_from_str(ctx, str); |
501 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 501, __extension__ __PRETTY_FUNCTION__ ); })); |
502 | isl_map_free(map); |
503 | isl_map_free(map2); |
504 | |
505 | test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }"); |
506 | test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }"); |
507 | test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }"); |
508 | test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }"); |
509 | test_parse_pwaff(ctx, "{ [] -> [(100)] }"); |
510 | |
511 | return 0; |
512 | } |
513 | |
514 | static int test_read(isl_ctx *ctx) |
515 | { |
516 | char *filename; |
517 | FILE *input; |
518 | isl_basic_setisl_basic_map *bset1, *bset2; |
519 | const char *str = "{[y]: Exists ( alpha : 2alpha = y)}"; |
520 | int equal; |
521 | |
522 | filename = get_filename(ctx, "set", "omega"); |
523 | assert(filename)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename ) ; else __assert_fail ("filename", "polly/lib/External/isl/isl_test.c" , 523, __extension__ __PRETTY_FUNCTION__); })); |
524 | input = fopen(filename, "r"); |
525 | assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input) ; else __assert_fail ("input", "polly/lib/External/isl/isl_test.c" , 525, __extension__ __PRETTY_FUNCTION__); })); |
526 | |
527 | bset1 = isl_basic_set_read_from_file(ctx, input); |
528 | bset2 = isl_basic_set_read_from_str(ctx, str); |
529 | |
530 | equal = isl_basic_set_is_equal(bset1, bset2); |
531 | |
532 | isl_basic_set_free(bset1); |
533 | isl_basic_set_free(bset2); |
534 | free(filename); |
535 | |
536 | fclose(input); |
537 | |
538 | if (equal < 0) |
539 | return -1; |
540 | if (!equal) |
541 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "read sets not equal" , "polly/lib/External/isl/isl_test.c", 542); return -1; } while (0) |
542 | "read sets not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "read sets not equal" , "polly/lib/External/isl/isl_test.c", 542); return -1; } while (0); |
543 | |
544 | return 0; |
545 | } |
546 | |
547 | static int test_bounded(isl_ctx *ctx) |
548 | { |
549 | isl_setisl_map *set; |
550 | isl_bool bounded; |
551 | |
552 | set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }"); |
553 | bounded = isl_set_is_bounded(set); |
554 | isl_set_free(set); |
555 | |
556 | if (bounded < 0) |
557 | return -1; |
558 | if (!bounded) |
559 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set not considered bounded" , "polly/lib/External/isl/isl_test.c", 560); return -1; } while (0) |
560 | "set not considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set not considered bounded" , "polly/lib/External/isl/isl_test.c", 560); return -1; } while (0); |
561 | |
562 | set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }"); |
563 | bounded = isl_set_is_bounded(set); |
564 | assert(!bounded)((void) sizeof ((!bounded) ? 1 : 0), __extension__ ({ if (!bounded ) ; else __assert_fail ("!bounded", "polly/lib/External/isl/isl_test.c" , 564, __extension__ __PRETTY_FUNCTION__); })); |
565 | isl_set_free(set); |
566 | |
567 | if (bounded < 0) |
568 | return -1; |
569 | if (bounded) |
570 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "polly/lib/External/isl/isl_test.c", 571); return -1; } while (0) |
571 | "set considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "polly/lib/External/isl/isl_test.c", 571); return -1; } while (0); |
572 | |
573 | set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }"); |
574 | bounded = isl_set_is_bounded(set); |
575 | isl_set_free(set); |
576 | |
577 | if (bounded < 0) |
578 | return -1; |
579 | if (bounded) |
580 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "polly/lib/External/isl/isl_test.c", 581); return -1; } while (0) |
581 | "set considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "polly/lib/External/isl/isl_test.c", 581); return -1; } while (0); |
582 | |
583 | return 0; |
584 | } |
585 | |
586 | /* Construct the basic set { [i] : 5 <= i <= N } */ |
587 | static int test_construction_1(isl_ctx *ctx) |
588 | { |
589 | isl_space *space; |
590 | isl_local_space *ls; |
591 | isl_basic_setisl_basic_map *bset; |
592 | isl_constraint *c; |
593 | |
594 | space = isl_space_set_alloc(ctx, 1, 1); |
595 | bset = isl_basic_set_universe(isl_space_copy(space)); |
596 | ls = isl_local_space_from_space(space); |
597 | |
598 | c = isl_constraint_alloc_inequality(isl_local_space_copy(ls)); |
599 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
600 | c = isl_constraint_set_coefficient_si(c, isl_dim_param, 0, 1); |
601 | bset = isl_basic_set_add_constraint(bset, c); |
602 | |
603 | c = isl_constraint_alloc_inequality(isl_local_space_copy(ls)); |
604 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
605 | c = isl_constraint_set_constant_si(c, -5); |
606 | bset = isl_basic_set_add_constraint(bset, c); |
607 | |
608 | isl_local_space_free(ls); |
609 | isl_basic_set_free(bset); |
610 | |
611 | return 0; |
612 | } |
613 | |
614 | /* Construct the basic set { [x] : -100 <= x <= 100 } |
615 | * using isl_basic_set_{lower,upper}_bound_val and |
616 | * check that it is equal the same basic set parsed from a string. |
617 | */ |
618 | static int test_construction_2(isl_ctx *ctx) |
619 | { |
620 | isl_bool equal; |
621 | isl_val *v; |
622 | isl_space *space; |
623 | isl_basic_setisl_basic_map *bset1, *bset2; |
624 | |
625 | v = isl_val_int_from_si(ctx, 100); |
626 | space = isl_space_set_alloc(ctx, 0, 1); |
627 | bset1 = isl_basic_set_universe(space); |
628 | bset1 = isl_basic_set_upper_bound_val(bset1, isl_dim_set, 0, |
629 | isl_val_copy(v)); |
630 | bset1 = isl_basic_set_lower_bound_val(bset1, isl_dim_set, 0, |
631 | isl_val_neg(v)); |
632 | bset2 = isl_basic_set_read_from_str(ctx, "{ [x] : -100 <= x <= 100 }"); |
633 | equal = isl_basic_set_is_equal(bset1, bset2); |
634 | isl_basic_set_free(bset1); |
635 | isl_basic_set_free(bset2); |
636 | |
637 | if (equal < 0) |
638 | return -1; |
639 | if (!equal) |
640 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed construction" , "polly/lib/External/isl/isl_test.c", 641); return -1; } while (0) |
641 | "failed construction", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed construction" , "polly/lib/External/isl/isl_test.c", 641); return -1; } while (0); |
642 | |
643 | return 0; |
644 | } |
645 | |
646 | /* Basic tests for constructing basic sets. |
647 | */ |
648 | static int test_construction(isl_ctx *ctx) |
649 | { |
650 | if (test_construction_1(ctx) < 0) |
651 | return -1; |
652 | if (test_construction_2(ctx) < 0) |
653 | return -1; |
654 | return 0; |
655 | } |
656 | |
657 | static int test_dim(isl_ctx *ctx) |
658 | { |
659 | const char *str; |
660 | isl_map *map1, *map2; |
661 | int equal; |
662 | |
663 | map1 = isl_map_read_from_str(ctx, |
664 | "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }"); |
665 | map1 = isl_map_add_dims(map1, isl_dim_in, 1); |
666 | map2 = isl_map_read_from_str(ctx, |
667 | "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }"); |
668 | equal = isl_map_is_equal(map1, map2); |
669 | isl_map_free(map2); |
670 | |
671 | map1 = isl_map_project_out(map1, isl_dim_in, 0, 1); |
672 | map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }"); |
673 | if (equal >= 0 && equal) |
674 | equal = isl_map_is_equal(map1, map2); |
675 | |
676 | isl_map_free(map1); |
677 | isl_map_free(map2); |
678 | |
679 | if (equal < 0) |
680 | return -1; |
681 | if (!equal) |
682 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 683); return -1; } while (0) |
683 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 683); return -1; } while (0); |
684 | |
685 | str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }"; |
686 | map1 = isl_map_read_from_str(ctx, str); |
687 | str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }"; |
688 | map2 = isl_map_read_from_str(ctx, str); |
689 | map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1); |
690 | equal = isl_map_is_equal(map1, map2); |
691 | isl_map_free(map1); |
692 | isl_map_free(map2); |
693 | |
694 | if (equal < 0) |
695 | return -1; |
696 | if (!equal) |
697 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 698); return -1; } while (0) |
698 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 698); return -1; } while (0); |
699 | |
700 | return 0; |
701 | } |
702 | |
703 | #undef BASEunion_pw_aff |
704 | #define BASEunion_pw_aff multi_val |
705 | #include "isl_test_plain_equal_templ.c" |
706 | |
707 | #undef BASEunion_pw_aff |
708 | #define BASEunion_pw_aff multi_aff |
709 | #include "isl_test_plain_equal_templ.c" |
710 | |
711 | /* Check that "val" is equal to the value described by "str". |
712 | * If "str" is "NaN", then check for a NaN value explicitly. |
713 | */ |
714 | static isl_stat val_check_equal(__isl_keep isl_val *val, const char *str) |
715 | { |
716 | isl_bool ok, is_nan; |
717 | isl_ctx *ctx; |
718 | isl_val *res; |
719 | |
720 | if (!val) |
721 | return isl_stat_error; |
722 | |
723 | ctx = isl_val_get_ctx(val); |
724 | res = isl_val_read_from_str(ctx, str); |
725 | is_nan = isl_val_is_nan(res); |
726 | if (is_nan < 0) |
727 | ok = isl_bool_error; |
728 | else if (is_nan) |
729 | ok = isl_val_is_nan(val); |
730 | else |
731 | ok = isl_val_eq(val, res); |
732 | isl_val_free(res); |
733 | if (ok < 0) |
734 | return isl_stat_error; |
735 | if (!ok) |
736 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 737); return isl_stat_error ; } while (0) |
737 | "unexpected result", return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 737); return isl_stat_error ; } while (0); |
738 | return isl_stat_ok; |
739 | } |
740 | |
741 | struct { |
742 | __isl_give isl_val *(*op)(__isl_take isl_val *v); |
743 | const char *arg; |
744 | const char *res; |
745 | } val_un_tests[] = { |
746 | { &isl_val_neg, "0", "0" }, |
747 | { &isl_val_abs, "0", "0" }, |
748 | { &isl_val_pow2, "0", "1" }, |
749 | { &isl_val_floor, "0", "0" }, |
750 | { &isl_val_ceil, "0", "0" }, |
751 | { &isl_val_neg, "1", "-1" }, |
752 | { &isl_val_neg, "-1", "1" }, |
753 | { &isl_val_neg, "1/2", "-1/2" }, |
754 | { &isl_val_neg, "-1/2", "1/2" }, |
755 | { &isl_val_neg, "infty", "-infty" }, |
756 | { &isl_val_neg, "-infty", "infty" }, |
757 | { &isl_val_neg, "NaN", "NaN" }, |
758 | { &isl_val_abs, "1", "1" }, |
759 | { &isl_val_abs, "-1", "1" }, |
760 | { &isl_val_abs, "1/2", "1/2" }, |
761 | { &isl_val_abs, "-1/2", "1/2" }, |
762 | { &isl_val_abs, "infty", "infty" }, |
763 | { &isl_val_abs, "-infty", "infty" }, |
764 | { &isl_val_abs, "NaN", "NaN" }, |
765 | { &isl_val_floor, "1", "1" }, |
766 | { &isl_val_floor, "-1", "-1" }, |
767 | { &isl_val_floor, "1/2", "0" }, |
768 | { &isl_val_floor, "-1/2", "-1" }, |
769 | { &isl_val_floor, "infty", "infty" }, |
770 | { &isl_val_floor, "-infty", "-infty" }, |
771 | { &isl_val_floor, "NaN", "NaN" }, |
772 | { &isl_val_ceil, "1", "1" }, |
773 | { &isl_val_ceil, "-1", "-1" }, |
774 | { &isl_val_ceil, "1/2", "1" }, |
775 | { &isl_val_ceil, "-1/2", "0" }, |
776 | { &isl_val_ceil, "infty", "infty" }, |
777 | { &isl_val_ceil, "-infty", "-infty" }, |
778 | { &isl_val_ceil, "NaN", "NaN" }, |
779 | { &isl_val_pow2, "-3", "1/8" }, |
780 | { &isl_val_pow2, "-1", "1/2" }, |
781 | { &isl_val_pow2, "1", "2" }, |
782 | { &isl_val_pow2, "2", "4" }, |
783 | { &isl_val_pow2, "3", "8" }, |
784 | { &isl_val_inv, "1", "1" }, |
785 | { &isl_val_inv, "2", "1/2" }, |
786 | { &isl_val_inv, "1/2", "2" }, |
787 | { &isl_val_inv, "-2", "-1/2" }, |
788 | { &isl_val_inv, "-1/2", "-2" }, |
789 | { &isl_val_inv, "0", "NaN" }, |
790 | { &isl_val_inv, "NaN", "NaN" }, |
791 | { &isl_val_inv, "infty", "0" }, |
792 | { &isl_val_inv, "-infty", "0" }, |
793 | }; |
794 | |
795 | /* Perform some basic tests of unary operations on isl_val objects. |
796 | */ |
797 | static int test_un_val(isl_ctx *ctx) |
798 | { |
799 | int i; |
800 | isl_val *v; |
801 | __isl_give isl_val *(*fn)(__isl_take isl_val *v); |
802 | |
803 | for (i = 0; i < ARRAY_SIZE(val_un_tests)(sizeof(val_un_tests)/sizeof(*val_un_tests)); ++i) { |
804 | isl_stat r; |
805 | |
806 | v = isl_val_read_from_str(ctx, val_un_tests[i].arg); |
807 | fn = val_un_tests[i].op; |
808 | v = fn(v); |
809 | r = val_check_equal(v, val_un_tests[i].res); |
810 | isl_val_free(v); |
811 | if (r < 0) |
812 | return -1; |
813 | } |
814 | |
815 | return 0; |
816 | } |
817 | |
818 | struct { |
819 | __isl_give isl_val *(*fn)(__isl_take isl_val *v1, |
820 | __isl_take isl_val *v2); |
821 | } val_bin_op[] = { |
822 | ['+'] = { &isl_val_add }, |
823 | ['-'] = { &isl_val_sub }, |
824 | ['*'] = { &isl_val_mul }, |
825 | ['/'] = { &isl_val_div }, |
826 | ['g'] = { &isl_val_gcd }, |
827 | ['m'] = { &isl_val_min }, |
828 | ['M'] = { &isl_val_max }, |
829 | }; |
830 | |
831 | struct { |
832 | const char *arg1; |
833 | unsigned char op; |
834 | const char *arg2; |
835 | const char *res; |
836 | } val_bin_tests[] = { |
837 | { "0", '+', "0", "0" }, |
838 | { "1", '+', "0", "1" }, |
839 | { "1", '+', "1", "2" }, |
840 | { "1", '-', "1", "0" }, |
841 | { "1", '*', "1", "1" }, |
842 | { "1", '/', "1", "1" }, |
843 | { "2", '*', "3", "6" }, |
844 | { "2", '*', "1/2", "1" }, |
845 | { "2", '*', "1/3", "2/3" }, |
846 | { "2/3", '*', "3/5", "2/5" }, |
847 | { "2/3", '*', "7/5", "14/15" }, |
848 | { "2", '/', "1/2", "4" }, |
849 | { "-2", '/', "-1/2", "4" }, |
850 | { "-2", '/', "1/2", "-4" }, |
851 | { "2", '/', "-1/2", "-4" }, |
852 | { "2", '/', "2", "1" }, |
853 | { "2", '/', "3", "2/3" }, |
854 | { "2/3", '/', "5/3", "2/5" }, |
855 | { "2/3", '/', "5/7", "14/15" }, |
856 | { "0", '/', "0", "NaN" }, |
857 | { "42", '/', "0", "NaN" }, |
858 | { "-42", '/', "0", "NaN" }, |
859 | { "infty", '/', "0", "NaN" }, |
860 | { "-infty", '/', "0", "NaN" }, |
861 | { "NaN", '/', "0", "NaN" }, |
862 | { "0", '/', "NaN", "NaN" }, |
863 | { "42", '/', "NaN", "NaN" }, |
864 | { "-42", '/', "NaN", "NaN" }, |
865 | { "infty", '/', "NaN", "NaN" }, |
866 | { "-infty", '/', "NaN", "NaN" }, |
867 | { "NaN", '/', "NaN", "NaN" }, |
868 | { "0", '/', "infty", "0" }, |
869 | { "42", '/', "infty", "0" }, |
870 | { "-42", '/', "infty", "0" }, |
871 | { "infty", '/', "infty", "NaN" }, |
872 | { "-infty", '/', "infty", "NaN" }, |
873 | { "NaN", '/', "infty", "NaN" }, |
874 | { "0", '/', "-infty", "0" }, |
875 | { "42", '/', "-infty", "0" }, |
876 | { "-42", '/', "-infty", "0" }, |
877 | { "infty", '/', "-infty", "NaN" }, |
878 | { "-infty", '/', "-infty", "NaN" }, |
879 | { "NaN", '/', "-infty", "NaN" }, |
880 | { "1", '-', "1/3", "2/3" }, |
881 | { "1/3", '+', "1/2", "5/6" }, |
882 | { "1/2", '+', "1/2", "1" }, |
883 | { "3/4", '-', "1/4", "1/2" }, |
884 | { "1/2", '-', "1/3", "1/6" }, |
885 | { "infty", '+', "42", "infty" }, |
886 | { "infty", '+', "infty", "infty" }, |
887 | { "42", '+', "infty", "infty" }, |
888 | { "infty", '-', "infty", "NaN" }, |
889 | { "infty", '*', "infty", "infty" }, |
890 | { "infty", '*', "-infty", "-infty" }, |
891 | { "-infty", '*', "infty", "-infty" }, |
892 | { "-infty", '*', "-infty", "infty" }, |
893 | { "0", '*', "infty", "NaN" }, |
894 | { "1", '*', "infty", "infty" }, |
895 | { "infty", '*', "0", "NaN" }, |
896 | { "infty", '*', "42", "infty" }, |
897 | { "42", '-', "infty", "-infty" }, |
898 | { "infty", '+', "-infty", "NaN" }, |
899 | { "4", 'g', "6", "2" }, |
900 | { "5", 'g', "6", "1" }, |
901 | { "42", 'm', "3", "3" }, |
902 | { "42", 'M', "3", "42" }, |
903 | { "3", 'm', "42", "3" }, |
904 | { "3", 'M', "42", "42" }, |
905 | { "42", 'm', "infty", "42" }, |
906 | { "42", 'M', "infty", "infty" }, |
907 | { "42", 'm', "-infty", "-infty" }, |
908 | { "42", 'M', "-infty", "42" }, |
909 | { "42", 'm', "NaN", "NaN" }, |
910 | { "42", 'M', "NaN", "NaN" }, |
911 | { "infty", 'm', "-infty", "-infty" }, |
912 | { "infty", 'M', "-infty", "infty" }, |
913 | }; |
914 | |
915 | /* Perform some basic tests of binary operations on isl_val objects. |
916 | */ |
917 | static int test_bin_val(isl_ctx *ctx) |
918 | { |
919 | int i; |
920 | isl_val *v1, *v2, *res; |
921 | __isl_give isl_val *(*fn)(__isl_take isl_val *v1, |
922 | __isl_take isl_val *v2); |
923 | int ok; |
924 | |
925 | for (i = 0; i < ARRAY_SIZE(val_bin_tests)(sizeof(val_bin_tests)/sizeof(*val_bin_tests)); ++i) { |
926 | v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1); |
927 | v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2); |
928 | res = isl_val_read_from_str(ctx, val_bin_tests[i].res); |
929 | fn = val_bin_op[val_bin_tests[i].op].fn; |
930 | v1 = fn(v1, v2); |
931 | if (isl_val_is_nan(res)) |
932 | ok = isl_val_is_nan(v1); |
933 | else |
934 | ok = isl_val_eq(v1, res); |
935 | isl_val_free(v1); |
936 | isl_val_free(res); |
937 | if (ok < 0) |
938 | return -1; |
939 | if (!ok) |
940 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 941); return -1; } while (0) |
941 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 941); return -1; } while (0); |
942 | } |
943 | |
944 | return 0; |
945 | } |
946 | |
947 | /* Perform some basic tests on isl_val objects. |
948 | */ |
949 | static int test_val(isl_ctx *ctx) |
950 | { |
951 | if (test_un_val(ctx) < 0) |
952 | return -1; |
953 | if (test_bin_val(ctx) < 0) |
954 | return -1; |
955 | return 0; |
956 | } |
957 | |
958 | /* Sets described using existentially quantified variables that |
959 | * can also be described without. |
960 | */ |
961 | static const char *elimination_tests[] = { |
962 | "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }", |
963 | "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }", |
964 | "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }", |
965 | }; |
966 | |
967 | /* Check that redundant existentially quantified variables are |
968 | * getting removed. |
969 | */ |
970 | static int test_elimination(isl_ctx *ctx) |
971 | { |
972 | int i; |
973 | isl_size n; |
974 | isl_basic_setisl_basic_map *bset; |
975 | |
976 | for (i = 0; i < ARRAY_SIZE(elimination_tests)(sizeof(elimination_tests)/sizeof(*elimination_tests)); ++i) { |
977 | bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]); |
978 | n = isl_basic_set_dim(bset, isl_dim_div); |
979 | isl_basic_set_free(bset); |
980 | if (n < 0) |
981 | return -1; |
982 | if (n != 0) |
983 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting no existentials" , "polly/lib/External/isl/isl_test.c", 984); return -1; } while (0) |
984 | "expecting no existentials", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting no existentials" , "polly/lib/External/isl/isl_test.c", 984); return -1; } while (0); |
985 | } |
986 | |
987 | return 0; |
988 | } |
989 | |
990 | static int test_div(isl_ctx *ctx) |
991 | { |
992 | const char *str; |
993 | int empty; |
994 | isl_space *space; |
995 | isl_setisl_map *set; |
996 | isl_local_space *ls; |
997 | struct isl_basic_setisl_basic_map *bset; |
998 | struct isl_constraint *c; |
999 | |
1000 | /* test 1 */ |
1001 | space = isl_space_set_alloc(ctx, 0, 3); |
1002 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1003 | ls = isl_local_space_from_space(space); |
1004 | |
1005 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1006 | c = isl_constraint_set_constant_si(c, -1); |
1007 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1008 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
1009 | bset = isl_basic_set_add_constraint(bset, c); |
1010 | |
1011 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1012 | c = isl_constraint_set_constant_si(c, 1); |
1013 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1014 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3); |
1015 | bset = isl_basic_set_add_constraint(bset, c); |
1016 | |
1017 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
1018 | |
1019 | assert(bset && bset->n_div == 1)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0 ), __extension__ ({ if (bset && bset->n_div == 1) ; else __assert_fail ("bset && bset->n_div == 1", "polly/lib/External/isl/isl_test.c" , 1019, __extension__ __PRETTY_FUNCTION__); })); |
1020 | isl_local_space_free(ls); |
1021 | isl_basic_set_free(bset); |
1022 | |
1023 | /* test 2 */ |
1024 | space = isl_space_set_alloc(ctx, 0, 3); |
1025 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1026 | ls = isl_local_space_from_space(space); |
1027 | |
1028 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1029 | c = isl_constraint_set_constant_si(c, 1); |
1030 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1031 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
1032 | bset = isl_basic_set_add_constraint(bset, c); |
1033 | |
1034 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1035 | c = isl_constraint_set_constant_si(c, -1); |
1036 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1037 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3); |
1038 | bset = isl_basic_set_add_constraint(bset, c); |
1039 | |
1040 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
1041 | |
1042 | assert(bset && bset->n_div == 1)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0 ), __extension__ ({ if (bset && bset->n_div == 1) ; else __assert_fail ("bset && bset->n_div == 1", "polly/lib/External/isl/isl_test.c" , 1042, __extension__ __PRETTY_FUNCTION__); })); |
1043 | isl_local_space_free(ls); |
1044 | isl_basic_set_free(bset); |
1045 | |
1046 | /* test 3 */ |
1047 | space = isl_space_set_alloc(ctx, 0, 3); |
1048 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1049 | ls = isl_local_space_from_space(space); |
1050 | |
1051 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1052 | c = isl_constraint_set_constant_si(c, 1); |
1053 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1054 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
1055 | bset = isl_basic_set_add_constraint(bset, c); |
1056 | |
1057 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1058 | c = isl_constraint_set_constant_si(c, -3); |
1059 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1060 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 4); |
1061 | bset = isl_basic_set_add_constraint(bset, c); |
1062 | |
1063 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
1064 | |
1065 | assert(bset && bset->n_div == 1)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0 ), __extension__ ({ if (bset && bset->n_div == 1) ; else __assert_fail ("bset && bset->n_div == 1", "polly/lib/External/isl/isl_test.c" , 1065, __extension__ __PRETTY_FUNCTION__); })); |
1066 | isl_local_space_free(ls); |
1067 | isl_basic_set_free(bset); |
1068 | |
1069 | /* test 4 */ |
1070 | space = isl_space_set_alloc(ctx, 0, 3); |
1071 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1072 | ls = isl_local_space_from_space(space); |
1073 | |
1074 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1075 | c = isl_constraint_set_constant_si(c, 2); |
1076 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1077 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
1078 | bset = isl_basic_set_add_constraint(bset, c); |
1079 | |
1080 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1081 | c = isl_constraint_set_constant_si(c, -1); |
1082 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1083 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6); |
1084 | bset = isl_basic_set_add_constraint(bset, c); |
1085 | |
1086 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
1087 | |
1088 | assert(isl_basic_set_is_empty(bset))((void) sizeof ((isl_basic_set_is_empty(bset)) ? 1 : 0), __extension__ ({ if (isl_basic_set_is_empty(bset)) ; else __assert_fail ("isl_basic_set_is_empty(bset)" , "polly/lib/External/isl/isl_test.c", 1088, __extension__ __PRETTY_FUNCTION__ ); })); |
1089 | isl_local_space_free(ls); |
1090 | isl_basic_set_free(bset); |
1091 | |
1092 | /* test 5 */ |
1093 | space = isl_space_set_alloc(ctx, 0, 3); |
1094 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1095 | ls = isl_local_space_from_space(space); |
1096 | |
1097 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1098 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1099 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3); |
1100 | bset = isl_basic_set_add_constraint(bset, c); |
1101 | |
1102 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1103 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1104 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1105 | bset = isl_basic_set_add_constraint(bset, c); |
1106 | |
1107 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
1108 | |
1109 | assert(bset && bset->n_div == 0)((void) sizeof ((bset && bset->n_div == 0) ? 1 : 0 ), __extension__ ({ if (bset && bset->n_div == 0) ; else __assert_fail ("bset && bset->n_div == 0", "polly/lib/External/isl/isl_test.c" , 1109, __extension__ __PRETTY_FUNCTION__); })); |
1110 | isl_basic_set_free(bset); |
1111 | isl_local_space_free(ls); |
1112 | |
1113 | /* test 6 */ |
1114 | space = isl_space_set_alloc(ctx, 0, 3); |
1115 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1116 | ls = isl_local_space_from_space(space); |
1117 | |
1118 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1119 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1120 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6); |
1121 | bset = isl_basic_set_add_constraint(bset, c); |
1122 | |
1123 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1124 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1125 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1126 | bset = isl_basic_set_add_constraint(bset, c); |
1127 | |
1128 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
1129 | |
1130 | assert(bset && bset->n_div == 1)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0 ), __extension__ ({ if (bset && bset->n_div == 1) ; else __assert_fail ("bset && bset->n_div == 1", "polly/lib/External/isl/isl_test.c" , 1130, __extension__ __PRETTY_FUNCTION__); })); |
1131 | isl_basic_set_free(bset); |
1132 | isl_local_space_free(ls); |
1133 | |
1134 | /* test 7 */ |
1135 | /* This test is a bit tricky. We set up an equality |
1136 | * a + 3b + 3c = 6 e0 |
1137 | * Normalization of divs creates _two_ divs |
1138 | * a = 3 e0 |
1139 | * c - b - e0 = 2 e1 |
1140 | * Afterwards e0 is removed again because it has coefficient -1 |
1141 | * and we end up with the original equality and div again. |
1142 | * Perhaps we can avoid the introduction of this temporary div. |
1143 | */ |
1144 | space = isl_space_set_alloc(ctx, 0, 4); |
1145 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1146 | ls = isl_local_space_from_space(space); |
1147 | |
1148 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1149 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1150 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1151 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -3); |
1152 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 6); |
1153 | bset = isl_basic_set_add_constraint(bset, c); |
1154 | |
1155 | bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1); |
1156 | |
1157 | /* Test disabled for now */ |
1158 | /* |
1159 | assert(bset && bset->n_div == 1); |
1160 | */ |
1161 | isl_local_space_free(ls); |
1162 | isl_basic_set_free(bset); |
1163 | |
1164 | /* test 8 */ |
1165 | space = isl_space_set_alloc(ctx, 0, 5); |
1166 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1167 | ls = isl_local_space_from_space(space); |
1168 | |
1169 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1170 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1171 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1172 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, -3); |
1173 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 4, 6); |
1174 | bset = isl_basic_set_add_constraint(bset, c); |
1175 | |
1176 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1177 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1178 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 1); |
1179 | c = isl_constraint_set_constant_si(c, 1); |
1180 | bset = isl_basic_set_add_constraint(bset, c); |
1181 | |
1182 | bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1); |
1183 | |
1184 | /* Test disabled for now */ |
1185 | /* |
1186 | assert(bset && bset->n_div == 1); |
1187 | */ |
1188 | isl_local_space_free(ls); |
1189 | isl_basic_set_free(bset); |
1190 | |
1191 | /* test 9 */ |
1192 | space = isl_space_set_alloc(ctx, 0, 4); |
1193 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1194 | ls = isl_local_space_from_space(space); |
1195 | |
1196 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1197 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1198 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -1); |
1199 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2); |
1200 | bset = isl_basic_set_add_constraint(bset, c); |
1201 | |
1202 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1203 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1204 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 3); |
1205 | c = isl_constraint_set_constant_si(c, 2); |
1206 | bset = isl_basic_set_add_constraint(bset, c); |
1207 | |
1208 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2); |
1209 | |
1210 | bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2); |
1211 | |
1212 | assert(!isl_basic_set_is_empty(bset))((void) sizeof ((!isl_basic_set_is_empty(bset)) ? 1 : 0), __extension__ ({ if (!isl_basic_set_is_empty(bset)) ; else __assert_fail ( "!isl_basic_set_is_empty(bset)", "polly/lib/External/isl/isl_test.c" , 1212, __extension__ __PRETTY_FUNCTION__); })); |
1213 | |
1214 | isl_local_space_free(ls); |
1215 | isl_basic_set_free(bset); |
1216 | |
1217 | /* test 10 */ |
1218 | space = isl_space_set_alloc(ctx, 0, 3); |
1219 | bset = isl_basic_set_universe(isl_space_copy(space)); |
1220 | ls = isl_local_space_from_space(space); |
1221 | |
1222 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1223 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1224 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2); |
1225 | bset = isl_basic_set_add_constraint(bset, c); |
1226 | |
1227 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
1228 | |
1229 | bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2); |
1230 | |
1231 | isl_local_space_free(ls); |
1232 | isl_basic_set_free(bset); |
1233 | |
1234 | str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and " |
1235 | "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }"; |
1236 | set = isl_set_read_from_str(ctx, str); |
1237 | set = isl_set_compute_divs(set); |
1238 | isl_set_free(set); |
1239 | if (!set) |
1240 | return -1; |
1241 | |
1242 | if (test_elimination(ctx) < 0) |
1243 | return -1; |
1244 | |
1245 | str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }"; |
1246 | set = isl_set_read_from_str(ctx, str); |
1247 | set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2); |
1248 | set = isl_set_fix_si(set, isl_dim_set, 2, -3); |
1249 | empty = isl_set_is_empty(set); |
1250 | isl_set_free(set); |
1251 | if (empty < 0) |
1252 | return -1; |
1253 | if (!empty) |
1254 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as accurate as expected" , "polly/lib/External/isl/isl_test.c", 1255); return -1; } while (0) |
1255 | "result not as accurate as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as accurate as expected" , "polly/lib/External/isl/isl_test.c", 1255); return -1; } while (0); |
1256 | |
1257 | return 0; |
1258 | } |
1259 | |
1260 | void test_application_case(struct isl_ctx *ctx, const char *name) |
1261 | { |
1262 | char *filename; |
1263 | FILE *input; |
1264 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1265 | struct isl_basic_map *bmap; |
1266 | |
1267 | filename = get_filename(ctx, name, "omega"); |
1268 | assert(filename)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename ) ; else __assert_fail ("filename", "polly/lib/External/isl/isl_test.c" , 1268, __extension__ __PRETTY_FUNCTION__); })); |
1269 | input = fopen(filename, "r"); |
1270 | assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input) ; else __assert_fail ("input", "polly/lib/External/isl/isl_test.c" , 1270, __extension__ __PRETTY_FUNCTION__); })); |
1271 | |
1272 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1273 | bmap = isl_basic_map_read_from_file(ctx, input); |
1274 | |
1275 | bset1 = isl_basic_set_apply(bset1, bmap); |
1276 | |
1277 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1278 | |
1279 | assert(isl_basic_set_is_equal(bset1, bset2) == 1)((void) sizeof ((isl_basic_set_is_equal(bset1, bset2) == 1) ? 1 : 0), __extension__ ({ if (isl_basic_set_is_equal(bset1, bset2 ) == 1) ; else __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1" , "polly/lib/External/isl/isl_test.c", 1279, __extension__ __PRETTY_FUNCTION__ ); })); |
1280 | |
1281 | isl_basic_set_free(bset1); |
1282 | isl_basic_set_free(bset2); |
1283 | free(filename); |
1284 | |
1285 | fclose(input); |
1286 | } |
1287 | |
1288 | static int test_application(isl_ctx *ctx) |
1289 | { |
1290 | test_application_case(ctx, "application"); |
1291 | test_application_case(ctx, "application2"); |
1292 | |
1293 | return 0; |
1294 | } |
1295 | |
1296 | void test_affine_hull_case(struct isl_ctx *ctx, const char *name) |
1297 | { |
1298 | char *filename; |
1299 | FILE *input; |
1300 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1301 | |
1302 | filename = get_filename(ctx, name, "polylib"); |
1303 | assert(filename)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename ) ; else __assert_fail ("filename", "polly/lib/External/isl/isl_test.c" , 1303, __extension__ __PRETTY_FUNCTION__); })); |
1304 | input = fopen(filename, "r"); |
1305 | assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input) ; else __assert_fail ("input", "polly/lib/External/isl/isl_test.c" , 1305, __extension__ __PRETTY_FUNCTION__); })); |
1306 | |
1307 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1308 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1309 | |
1310 | bset1 = isl_basic_set_affine_hull(bset1); |
1311 | |
1312 | assert(isl_basic_set_is_equal(bset1, bset2) == 1)((void) sizeof ((isl_basic_set_is_equal(bset1, bset2) == 1) ? 1 : 0), __extension__ ({ if (isl_basic_set_is_equal(bset1, bset2 ) == 1) ; else __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1" , "polly/lib/External/isl/isl_test.c", 1312, __extension__ __PRETTY_FUNCTION__ ); })); |
1313 | |
1314 | isl_basic_set_free(bset1); |
1315 | isl_basic_set_free(bset2); |
1316 | free(filename); |
1317 | |
1318 | fclose(input); |
1319 | } |
1320 | |
1321 | /* Pairs of sets and the corresponding expected results of |
1322 | * isl_basic_set_recession_cone. |
1323 | */ |
1324 | struct { |
1325 | const char *set; |
1326 | const char *cone; |
1327 | } recession_cone_tests[] = { |
1328 | { "{ [i] : 0 <= i <= 10 }", "{ [0] }" }, |
1329 | { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" }, |
1330 | { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" }, |
1331 | { "{ [i] : false }", "{ [i] : false }" }, |
1332 | }; |
1333 | |
1334 | /* Perform some basic isl_basic_set_recession_cone tests. |
1335 | */ |
1336 | static int test_recession_cone(struct isl_ctx *ctx) |
1337 | { |
1338 | int i; |
1339 | |
1340 | for (i = 0; i < ARRAY_SIZE(recession_cone_tests)(sizeof(recession_cone_tests)/sizeof(*recession_cone_tests)); ++i) { |
1341 | const char *str; |
1342 | isl_basic_setisl_basic_map *bset; |
1343 | isl_basic_setisl_basic_map *cone, *expected; |
1344 | isl_bool equal; |
1345 | |
1346 | str = recession_cone_tests[i].set; |
1347 | bset = isl_basic_set_read_from_str(ctx, str); |
1348 | str = recession_cone_tests[i].cone; |
1349 | expected = isl_basic_set_read_from_str(ctx, str); |
1350 | cone = isl_basic_set_recession_cone(bset); |
1351 | equal = isl_basic_set_is_equal(cone, expected); |
1352 | isl_basic_set_free(cone); |
1353 | isl_basic_set_free(expected); |
1354 | if (equal < 0) |
1355 | return -1; |
1356 | if (!equal) |
1357 | isl_die(ctx, isl_error_unknown, "unexpected cone",do { isl_handle_error(ctx, isl_error_unknown, "unexpected cone" , "polly/lib/External/isl/isl_test.c", 1358); return -1; } while (0) |
1358 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected cone" , "polly/lib/External/isl/isl_test.c", 1358); return -1; } while (0); |
1359 | } |
1360 | |
1361 | return 0; |
1362 | } |
1363 | |
1364 | int test_affine_hull(struct isl_ctx *ctx) |
1365 | { |
1366 | const char *str; |
1367 | isl_setisl_map *set; |
1368 | isl_basic_setisl_basic_map *bset, *bset2; |
1369 | isl_size n; |
1370 | isl_bool subset; |
1371 | |
1372 | test_affine_hull_case(ctx, "affine2"); |
1373 | test_affine_hull_case(ctx, "affine"); |
1374 | test_affine_hull_case(ctx, "affine3"); |
1375 | |
1376 | str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and " |
1377 | "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and " |
1378 | "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and " |
1379 | "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }"; |
1380 | set = isl_set_read_from_str(ctx, str); |
1381 | bset = isl_set_affine_hull(set); |
1382 | n = isl_basic_set_dim(bset, isl_dim_div); |
1383 | isl_basic_set_free(bset); |
1384 | if (n < 0) |
1385 | return -1; |
1386 | if (n != 0) |
1387 | isl_die(ctx, isl_error_unknown, "not expecting any divs",do { isl_handle_error(ctx, isl_error_unknown, "not expecting any divs" , "polly/lib/External/isl/isl_test.c", 1388); return -1; } while (0) |
1388 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "not expecting any divs" , "polly/lib/External/isl/isl_test.c", 1388); return -1; } while (0); |
1389 | |
1390 | /* Check that isl_map_affine_hull is not confused by |
1391 | * the reordering of divs in isl_map_align_divs. |
1392 | */ |
1393 | str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: " |
1394 | "32e0 = b and 32e1 = c); " |
1395 | "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }"; |
1396 | set = isl_set_read_from_str(ctx, str); |
1397 | bset = isl_set_affine_hull(set); |
1398 | isl_basic_set_free(bset); |
1399 | if (!bset) |
1400 | return -1; |
1401 | |
1402 | str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and " |
1403 | "32e2 = 31 + 31e0 }"; |
1404 | set = isl_set_read_from_str(ctx, str); |
1405 | bset = isl_set_affine_hull(set); |
1406 | str = "{ [a] : exists e : a = 32 e }"; |
1407 | bset2 = isl_basic_set_read_from_str(ctx, str); |
1408 | subset = isl_basic_set_is_subset(bset, bset2); |
1409 | isl_basic_set_free(bset); |
1410 | isl_basic_set_free(bset2); |
1411 | if (subset < 0) |
1412 | return -1; |
1413 | if (!subset) |
1414 | isl_die(ctx, isl_error_unknown, "not as accurate as expected",do { isl_handle_error(ctx, isl_error_unknown, "not as accurate as expected" , "polly/lib/External/isl/isl_test.c", 1415); return -1; } while (0) |
1415 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "not as accurate as expected" , "polly/lib/External/isl/isl_test.c", 1415); return -1; } while (0); |
1416 | |
1417 | return 0; |
1418 | } |
1419 | |
1420 | /* Test a special case of isl_set_plain_unshifted_simple_hull |
1421 | * where older versions of isl would include a redundant constraint |
1422 | * in the result. |
1423 | * Check that the result does not have any constraints. |
1424 | */ |
1425 | static isl_stat test_plain_unshifted_simple_hull_special(isl_ctx *ctx) |
1426 | { |
1427 | const char *str; |
1428 | isl_bool is_universe; |
1429 | isl_setisl_map *set; |
1430 | isl_basic_setisl_basic_map *bset; |
1431 | |
1432 | str = "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }"; |
1433 | set = isl_set_read_from_str(ctx, str); |
1434 | bset = isl_set_plain_unshifted_simple_hull(set); |
1435 | is_universe = isl_basic_set_plain_is_universe(bset); |
1436 | isl_basic_set_free(bset); |
1437 | |
1438 | if (is_universe < 0) |
1439 | return isl_stat_error; |
1440 | if (!is_universe) |
1441 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "hull should not have any constraints" , "polly/lib/External/isl/isl_test.c", 1443); return isl_stat_error ; } while (0) |
1442 | "hull should not have any constraints",do { isl_handle_error(ctx, isl_error_unknown, "hull should not have any constraints" , "polly/lib/External/isl/isl_test.c", 1443); return isl_stat_error ; } while (0) |
1443 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "hull should not have any constraints" , "polly/lib/External/isl/isl_test.c", 1443); return isl_stat_error ; } while (0); |
1444 | |
1445 | return isl_stat_ok; |
1446 | } |
1447 | |
1448 | /* Inputs for simple hull tests, consisting of |
1449 | * the specific simple hull function, the input set and the expected result. |
1450 | */ |
1451 | struct { |
1452 | __isl_give isl_basic_setisl_basic_map *(*fn)(__isl_take isl_setisl_map *set); |
1453 | const char *set; |
1454 | const char *hull; |
1455 | } simple_hull_tests[] = { |
1456 | { &isl_set_plain_unshifted_simple_hull, |
1457 | "{ [i,j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }", |
1458 | "{ [i,j] : i >= 1 }" }, |
1459 | { &isl_set_plain_unshifted_simple_hull, |
1460 | "{ [n,i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or " |
1461 | "(j mod 4 = 2 and k mod 6 = n) }", |
1462 | "{ [n,i,j,k] : j mod 4 = 2 }" }, |
1463 | { &isl_set_unshifted_simple_hull, |
1464 | "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }", |
1465 | "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" }, |
1466 | { &isl_set_simple_hull, |
1467 | "{ [a, b] : b <= 0 and " |
1468 | "2*floor((-2*floor((b)/2))/5) >= a - floor((b)/2); " |
1469 | "[a, b] : a mod 2 = 0 }", |
1470 | "{ [a, b] }" }, |
1471 | }; |
1472 | |
1473 | /* Basic tests for various simple hull functions. |
1474 | */ |
1475 | static int test_various_simple_hull(isl_ctx *ctx) |
1476 | { |
1477 | int i; |
1478 | isl_setisl_map *set; |
1479 | isl_basic_setisl_basic_map *hull, *expected; |
1480 | isl_bool equal; |
1481 | |
1482 | for (i = 0; i < ARRAY_SIZE(simple_hull_tests)(sizeof(simple_hull_tests)/sizeof(*simple_hull_tests)); ++i) { |
1483 | const char *str; |
1484 | str = simple_hull_tests[i].set; |
1485 | set = isl_set_read_from_str(ctx, str); |
1486 | str = simple_hull_tests[i].hull; |
1487 | expected = isl_basic_set_read_from_str(ctx, str); |
1488 | hull = simple_hull_tests[i].fn(set); |
1489 | equal = isl_basic_set_is_equal(hull, expected); |
1490 | isl_basic_set_free(hull); |
1491 | isl_basic_set_free(expected); |
1492 | if (equal < 0) |
1493 | return -1; |
1494 | if (!equal) |
1495 | isl_die(ctx, isl_error_unknown, "unexpected hull",do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "polly/lib/External/isl/isl_test.c", 1496); return -1; } while (0) |
1496 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "polly/lib/External/isl/isl_test.c", 1496); return -1; } while (0); |
1497 | } |
1498 | |
1499 | return 0; |
1500 | } |
1501 | |
1502 | static int test_simple_hull(struct isl_ctx *ctx) |
1503 | { |
1504 | const char *str; |
1505 | isl_setisl_map *set; |
1506 | isl_basic_setisl_basic_map *bset; |
1507 | isl_bool is_empty; |
1508 | |
1509 | str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;" |
1510 | "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }"; |
1511 | set = isl_set_read_from_str(ctx, str); |
1512 | bset = isl_set_simple_hull(set); |
1513 | is_empty = isl_basic_set_is_empty(bset); |
1514 | isl_basic_set_free(bset); |
1515 | |
1516 | if (is_empty == isl_bool_error) |
1517 | return -1; |
1518 | |
1519 | if (is_empty == isl_bool_false) |
1520 | isl_die(ctx, isl_error_unknown, "Empty set should be detected",do { isl_handle_error(ctx, isl_error_unknown, "Empty set should be detected" , "polly/lib/External/isl/isl_test.c", 1521); return -1; } while (0) |
1521 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "Empty set should be detected" , "polly/lib/External/isl/isl_test.c", 1521); return -1; } while (0); |
1522 | |
1523 | if (test_plain_unshifted_simple_hull_special(ctx) < 0) |
1524 | return -1; |
1525 | if (test_various_simple_hull(ctx) < 0) |
1526 | return -1; |
1527 | |
1528 | return 0; |
1529 | } |
1530 | |
1531 | /* Inputs for isl_set_get_simple_fixed_box_hull tests. |
1532 | * "set" is the input set. |
1533 | * "offset" is the expected box offset. |
1534 | * "size" is the expected box size. |
1535 | */ |
1536 | static struct { |
1537 | const char *set; |
1538 | const char *offset; |
1539 | const char *size; |
1540 | } box_hull_tests[] = { |
1541 | { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" }, |
1542 | { "[N] -> { S[x, y] : N <= x, y < N + 10 }", |
1543 | "[N] -> { S[N, N] }", "{ S[10, 10] }" }, |
1544 | { "{ S[x, y] : 0 <= x + y, x - y < 10 }", |
1545 | "{ S[0, -4] }", "{ S[10, 9] }" }, |
1546 | { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and " |
1547 | "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }", |
1548 | "{ [3] }", "{ [8] }" }, |
1549 | { "[N] -> { [w = 0:17] : exists (e0: w < 2N and " |
1550 | "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }", |
1551 | "[N] -> { [N] }", "{ [9] }" }, |
1552 | }; |
1553 | |
1554 | /* Perform basic isl_set_get_simple_fixed_box_hull tests. |
1555 | */ |
1556 | static int test_box_hull(struct isl_ctx *ctx) |
1557 | { |
1558 | int i; |
1559 | |
1560 | for (i = 0; i < ARRAY_SIZE(box_hull_tests)(sizeof(box_hull_tests)/sizeof(*box_hull_tests)); ++i) { |
1561 | const char *str; |
1562 | isl_stat r; |
1563 | isl_setisl_map *set; |
1564 | isl_multi_aff *offset; |
1565 | isl_multi_val *size; |
1566 | isl_fixed_box *box; |
1567 | |
1568 | set = isl_set_read_from_str(ctx, box_hull_tests[i].set); |
1569 | box = isl_set_get_simple_fixed_box_hull(set); |
1570 | offset = isl_fixed_box_get_offset(box); |
1571 | size = isl_fixed_box_get_size(box); |
1572 | str = box_hull_tests[i].offset; |
1573 | r = multi_aff_check_plain_equal(offset, str); |
1574 | str = box_hull_tests[i].size; |
1575 | if (r >= 0) |
1576 | r = multi_val_check_plain_equal(size, str); |
1577 | isl_multi_aff_free(offset); |
1578 | isl_multi_val_free(size); |
1579 | isl_fixed_box_free(box); |
1580 | isl_set_free(set); |
1581 | if (r < 0) |
1582 | return -1; |
1583 | } |
1584 | |
1585 | return 0; |
1586 | } |
1587 | |
1588 | void test_convex_hull_case(struct isl_ctx *ctx, const char *name) |
1589 | { |
1590 | char *filename; |
1591 | FILE *input; |
1592 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1593 | struct isl_setisl_map *set; |
1594 | |
1595 | filename = get_filename(ctx, name, "polylib"); |
1596 | assert(filename)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename ) ; else __assert_fail ("filename", "polly/lib/External/isl/isl_test.c" , 1596, __extension__ __PRETTY_FUNCTION__); })); |
1597 | input = fopen(filename, "r"); |
1598 | assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input) ; else __assert_fail ("input", "polly/lib/External/isl/isl_test.c" , 1598, __extension__ __PRETTY_FUNCTION__); })); |
1599 | |
1600 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1601 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1602 | |
1603 | set = isl_basic_set_union(bset1, bset2); |
1604 | bset1 = isl_set_convex_hull(set); |
1605 | |
1606 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1607 | |
1608 | assert(isl_basic_set_is_equal(bset1, bset2) == 1)((void) sizeof ((isl_basic_set_is_equal(bset1, bset2) == 1) ? 1 : 0), __extension__ ({ if (isl_basic_set_is_equal(bset1, bset2 ) == 1) ; else __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1" , "polly/lib/External/isl/isl_test.c", 1608, __extension__ __PRETTY_FUNCTION__ ); })); |
1609 | |
1610 | isl_basic_set_free(bset1); |
1611 | isl_basic_set_free(bset2); |
1612 | free(filename); |
1613 | |
1614 | fclose(input); |
1615 | } |
1616 | |
1617 | struct { |
1618 | const char *set; |
1619 | const char *hull; |
1620 | } convex_hull_tests[] = { |
1621 | { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or " |
1622 | "(i0 = 1 and i1 = 0 and i2 = 1) or " |
1623 | "(i0 = 0 and i1 = 0 and i2 = 0) }", |
1624 | "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" }, |
1625 | { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; " |
1626 | "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and " |
1627 | "i2 <= 5 and i2 >= 4; " |
1628 | "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }", |
1629 | "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and " |
1630 | "i2 <= 5 + i0 and i2 >= i0 }" }, |
1631 | { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }", |
1632 | "{ [x, y] : 1 = 0 }" }, |
1633 | { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; " |
1634 | "[x, y, 0] : x >= 0 and y < 0 }", |
1635 | "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" }, |
1636 | { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and " |
1637 | "c <= a; " |
1638 | "[0, 2, 0]; [3, 1, 0] }", |
1639 | "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and " |
1640 | "5c <= 6 - a - 3b }" }, |
1641 | }; |
1642 | |
1643 | static int test_convex_hull_algo(isl_ctx *ctx, int convex) |
1644 | { |
1645 | int i; |
1646 | int orig_convex = ctx->opt->convex; |
1647 | ctx->opt->convex = convex; |
1648 | |
1649 | test_convex_hull_case(ctx, "convex0"); |
1650 | test_convex_hull_case(ctx, "convex1"); |
1651 | test_convex_hull_case(ctx, "convex2"); |
1652 | test_convex_hull_case(ctx, "convex3"); |
1653 | test_convex_hull_case(ctx, "convex4"); |
1654 | test_convex_hull_case(ctx, "convex5"); |
1655 | test_convex_hull_case(ctx, "convex6"); |
1656 | test_convex_hull_case(ctx, "convex7"); |
1657 | test_convex_hull_case(ctx, "convex8"); |
1658 | test_convex_hull_case(ctx, "convex9"); |
1659 | test_convex_hull_case(ctx, "convex10"); |
1660 | test_convex_hull_case(ctx, "convex11"); |
1661 | test_convex_hull_case(ctx, "convex12"); |
1662 | test_convex_hull_case(ctx, "convex13"); |
1663 | test_convex_hull_case(ctx, "convex14"); |
1664 | test_convex_hull_case(ctx, "convex15"); |
1665 | |
1666 | for (i = 0; i < ARRAY_SIZE(convex_hull_tests)(sizeof(convex_hull_tests)/sizeof(*convex_hull_tests)); ++i) { |
1667 | isl_setisl_map *set1, *set2; |
1668 | int equal; |
1669 | |
1670 | set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set); |
1671 | set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull); |
1672 | set1 = isl_set_from_basic_set(isl_set_convex_hull(set1)); |
1673 | equal = isl_set_is_equal(set1, set2); |
1674 | isl_set_free(set1); |
1675 | isl_set_free(set2); |
1676 | |
1677 | if (equal < 0) |
1678 | return -1; |
1679 | if (!equal) |
1680 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected convex hull" , "polly/lib/External/isl/isl_test.c", 1681); return -1; } while (0) |
1681 | "unexpected convex hull", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected convex hull" , "polly/lib/External/isl/isl_test.c", 1681); return -1; } while (0); |
1682 | } |
1683 | |
1684 | ctx->opt->convex = orig_convex; |
1685 | |
1686 | return 0; |
1687 | } |
1688 | |
1689 | static int test_convex_hull(isl_ctx *ctx) |
1690 | { |
1691 | if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM1) < 0) |
1692 | return -1; |
1693 | if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP0) < 0) |
1694 | return -1; |
1695 | return 0; |
1696 | } |
1697 | |
1698 | /* Check that computing the gist of "map" with respect to "context" |
1699 | * does not make any copy of "map" get marked empty. |
1700 | * Earlier versions of isl would end up doing that. |
1701 | */ |
1702 | static isl_stat test_gist_empty_pair(isl_ctx *ctx, const char *map, |
1703 | const char *context) |
1704 | { |
1705 | isl_map *m1, *m2, *m3; |
1706 | isl_bool empty_before, empty_after; |
1707 | |
1708 | m1 = isl_map_read_from_str(ctx, map); |
1709 | m2 = isl_map_read_from_str(ctx, context); |
1710 | m3 = isl_map_copy(m1); |
1711 | empty_before = isl_map_is_empty(m3); |
1712 | m1 = isl_map_gist(m1, m2); |
1713 | empty_after = isl_map_is_empty(m3); |
1714 | isl_map_free(m1); |
1715 | isl_map_free(m3); |
1716 | |
1717 | if (empty_before < 0 || empty_after < 0) |
1718 | return isl_stat_error; |
1719 | if (empty_before) |
1720 | isl_die(ctx, isl_error_unknown, "map should not be empty",do { isl_handle_error(ctx, isl_error_unknown, "map should not be empty" , "polly/lib/External/isl/isl_test.c", 1721); return isl_stat_error ; } while (0) |
1721 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "map should not be empty" , "polly/lib/External/isl/isl_test.c", 1721); return isl_stat_error ; } while (0); |
1722 | if (empty_after) |
1723 | isl_die(ctx, isl_error_unknown, "map should still not be empty",do { isl_handle_error(ctx, isl_error_unknown, "map should still not be empty" , "polly/lib/External/isl/isl_test.c", 1724); return isl_stat_error ; } while (0) |
1724 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "map should still not be empty" , "polly/lib/External/isl/isl_test.c", 1724); return isl_stat_error ; } while (0); |
1725 | |
1726 | return isl_stat_ok; |
1727 | } |
1728 | |
1729 | /* Check that computing a gist does not make any copy of the input |
1730 | * get marked empty. |
1731 | * Earlier versions of isl would end up doing that on some pairs of inputs. |
1732 | */ |
1733 | static isl_stat test_gist_empty(isl_ctx *ctx) |
1734 | { |
1735 | const char *map, *context; |
1736 | |
1737 | map = "{ [] -> [a, b, c] : 2b = 1 + a }"; |
1738 | context = "{ [] -> [a, b, c] : 2c = 2 + a }"; |
1739 | if (test_gist_empty_pair(ctx, map, context) < 0) |
1740 | return isl_stat_error; |
1741 | map = "{ [] -> [0, 0] }"; |
1742 | context = "{ [] -> [a, b] : a > b }"; |
1743 | if (test_gist_empty_pair(ctx, map, context) < 0) |
1744 | return isl_stat_error; |
1745 | |
1746 | return isl_stat_ok; |
1747 | } |
1748 | |
1749 | /* Inputs to isl_map_plain_gist_basic_map, along with the expected output. |
1750 | */ |
1751 | struct { |
1752 | const char *map; |
1753 | const char *context; |
1754 | const char *gist; |
1755 | } plain_gist_tests[] = { |
1756 | { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }", |
1757 | "{ [i] -> [j] : i >= 1 }", |
1758 | "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" }, |
1759 | { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or " |
1760 | "(j mod 4 = 2 and k mod 6 = n) }", |
1761 | "{ [n] -> [i,j,k] : j mod 4 = 2 }", |
1762 | "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" }, |
1763 | { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }", |
1764 | "{ [i] -> [j] : i > j }", |
1765 | "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" }, |
1766 | }; |
1767 | |
1768 | /* Basic tests for isl_map_plain_gist_basic_map. |
1769 | */ |
1770 | static int test_plain_gist(isl_ctx *ctx) |
1771 | { |
1772 | int i; |
1773 | |
1774 | for (i = 0; i < ARRAY_SIZE(plain_gist_tests)(sizeof(plain_gist_tests)/sizeof(*plain_gist_tests)); ++i) { |
1775 | const char *str; |
1776 | int equal; |
1777 | isl_map *map, *gist; |
1778 | isl_basic_map *context; |
1779 | |
1780 | map = isl_map_read_from_str(ctx, plain_gist_tests[i].map); |
1781 | str = plain_gist_tests[i].context; |
1782 | context = isl_basic_map_read_from_str(ctx, str); |
1783 | map = isl_map_plain_gist_basic_map(map, context); |
1784 | gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist); |
1785 | equal = isl_map_is_equal(map, gist); |
1786 | isl_map_free(map); |
1787 | isl_map_free(gist); |
1788 | if (equal < 0) |
1789 | return -1; |
1790 | if (!equal) |
1791 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "polly/lib/External/isl/isl_test.c", 1792); return -1; } while (0) |
1792 | "incorrect gist result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "polly/lib/External/isl/isl_test.c", 1792); return -1; } while (0); |
1793 | } |
1794 | |
1795 | return 0; |
1796 | } |
1797 | |
1798 | /* Inputs for isl_basic_set_gist tests that are expected to fail. |
1799 | */ |
1800 | struct { |
1801 | const char *set; |
1802 | const char *context; |
1803 | } gist_fail_tests[] = { |
1804 | { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and " |
1805 | "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }", |
1806 | "{ [i] : i >= 0 }" }, |
1807 | }; |
1808 | |
1809 | /* Check that isl_basic_set_gist fails (gracefully) when expected. |
1810 | * In particular, the user should be able to recover from the failure. |
1811 | */ |
1812 | static isl_stat test_gist_fail(struct isl_ctx *ctx) |
1813 | { |
1814 | int i, n; |
1815 | int on_error; |
1816 | |
1817 | on_error = isl_options_get_on_error(ctx); |
1818 | isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE1); |
1819 | n = ARRAY_SIZE(gist_fail_tests)(sizeof(gist_fail_tests)/sizeof(*gist_fail_tests)); |
1820 | for (i = 0; i < n; ++i) { |
1821 | const char *str; |
1822 | isl_basic_setisl_basic_map *bset, *context; |
1823 | |
1824 | bset = isl_basic_set_read_from_str(ctx, gist_fail_tests[i].set); |
1825 | str = gist_fail_tests[i].context; |
1826 | context = isl_basic_set_read_from_str(ctx, str); |
1827 | bset = isl_basic_set_gist(bset, context); |
1828 | isl_basic_set_free(bset); |
1829 | if (bset) |
1830 | break; |
1831 | } |
1832 | isl_options_set_on_error(ctx, on_error); |
1833 | if (i < n) |
1834 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "polly/lib/External/isl/isl_test.c", 1836); return isl_stat_error ; } while (0) |
1835 | "operation not expected to succeed",do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "polly/lib/External/isl/isl_test.c", 1836); return isl_stat_error ; } while (0) |
1836 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "polly/lib/External/isl/isl_test.c", 1836); return isl_stat_error ; } while (0); |
1837 | |
1838 | return isl_stat_ok; |
1839 | } |
1840 | |
1841 | struct { |
1842 | const char *set; |
1843 | const char *context; |
1844 | const char *gist; |
1845 | } gist_tests[] = { |
1846 | { "{ [1, -1, 3] }", |
1847 | "{ [1, b, 2 - b] : -1 <= b <= 2 }", |
1848 | "{ [a, -1, c] }" }, |
1849 | { "{ [a, b, c] : a <= 15 and a >= 1 }", |
1850 | "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and " |
1851 | "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }", |
1852 | "{ [a, b, c] : a <= 15 }" }, |
1853 | { "{ : }", "{ : 1 = 0 }", "{ : }" }, |
1854 | { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" }, |
1855 | { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }", |
1856 | "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" }, |
1857 | { "{ [m, n, a, b] : a <= 2147 + n }", |
1858 | "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and " |
1859 | "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or " |
1860 | "(n >= 1 and a >= 0 and b <= 2148 - n - a and " |
1861 | "b >= 0) }", |
1862 | "{ [m, n, ku, kl] }" }, |
1863 | { "{ [a, a, b] : a >= 10 }", |
1864 | "{ [a, b, c] : c >= a and c <= b and c >= 2 }", |
1865 | "{ [a, a, b] : a >= 10 }" }, |
1866 | { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }", |
1867 | "{ [0, j] : j >= 0 }" }, |
1868 | /* Check that no constraints on i6 are introduced in the gist */ |
1869 | { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): " |
1870 | "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and " |
1871 | "5e0 <= 381 - t1 and i4 <= 1) }", |
1872 | "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): " |
1873 | "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }", |
1874 | "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): " |
1875 | "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and " |
1876 | "20e0 >= 1511 - 4t1 - 5i4) }" }, |
1877 | /* Check that no constraints on i6 are introduced in the gist */ |
1878 | { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), " |
1879 | "e1 = floor((1530 - 4t1 - 5i4)/20), " |
1880 | "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), " |
1881 | "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and " |
1882 | "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and " |
1883 | "2e0 <= 1 + i4 and 2e0 >= i4 and " |
1884 | "20e1 <= 1530 - 4t1 - 5i4 and " |
1885 | "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and " |
1886 | "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }", |
1887 | "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), " |
1888 | "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and " |
1889 | "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and " |
1890 | "10e0 <= -91 + 5i4 + 4i6 and " |
1891 | "10e0 >= -105 + 5i4 + 4i6) }", |
1892 | "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), " |
1893 | "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and " |
1894 | "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" }, |
1895 | { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }", |
1896 | "{ [a, b, q, p] : b >= 1 + a }", |
1897 | "{ [a, b, q, p] : false }" }, |
1898 | { "[n] -> { [x] : x = n && x mod 32 = 0 }", |
1899 | "[n] -> { [x] : x mod 32 = 0 }", |
1900 | "[n] -> { [x = n] }" }, |
1901 | { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }", |
1902 | "{ [x] : x mod 2 = 0 }" }, |
1903 | { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }", |
1904 | "{ [x] : x mod 128 = 0 }" }, |
1905 | { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }", |
1906 | "{ [x] : x mod 3200 = 0 }" }, |
1907 | { "{ [a, b, c] : a mod 2 = 0 and a = c }", |
1908 | "{ [a, b, c] : b mod 2 = 0 and b = c }", |
1909 | "{ [a, b, c = a] }" }, |
1910 | { "{ [a, b, c] : a mod 6 = 0 and a = c }", |
1911 | "{ [a, b, c] : b mod 2 = 0 and b = c }", |
1912 | "{ [a, b, c = a] : a mod 3 = 0 }" }, |
1913 | { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }", |
1914 | "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }", |
1915 | "{ [x] }" }, |
1916 | { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }", |
1917 | "{ [x,y] : 1 <= y <= 3 }", |
1918 | "{ [x,y] }" }, |
1919 | }; |
1920 | |
1921 | /* Check that isl_set_gist behaves as expected. |
1922 | * |
1923 | * For the test cases in gist_tests, besides checking that the result |
1924 | * is as expected, also check that applying the gist operation does |
1925 | * not modify the input set (an earlier version of isl would do that) and |
1926 | * that the test case is consistent, i.e., that the gist has the same |
1927 | * intersection with the context as the input set. |
1928 | */ |
1929 | static int test_gist(struct isl_ctx *ctx) |
1930 | { |
1931 | int i; |
1932 | const char *str; |
1933 | isl_basic_setisl_basic_map *bset1, *bset2; |
1934 | isl_map *map1, *map2; |
1935 | isl_bool equal; |
1936 | isl_size n_div; |
1937 | |
1938 | for (i = 0; i < ARRAY_SIZE(gist_tests)(sizeof(gist_tests)/sizeof(*gist_tests)); ++i) { |
1939 | isl_bool equal_input, equal_intersection; |
1940 | isl_setisl_map *set1, *set2, *copy, *context; |
1941 | |
1942 | set1 = isl_set_read_from_str(ctx, gist_tests[i].set); |
1943 | context = isl_set_read_from_str(ctx, gist_tests[i].context); |
1944 | copy = isl_set_copy(set1); |
1945 | set1 = isl_set_gist(set1, isl_set_copy(context)); |
1946 | set2 = isl_set_read_from_str(ctx, gist_tests[i].gist); |
1947 | equal = isl_set_is_equal(set1, set2); |
1948 | isl_set_free(set1); |
1949 | set1 = isl_set_read_from_str(ctx, gist_tests[i].set); |
1950 | equal_input = isl_set_is_equal(set1, copy); |
1951 | isl_set_free(copy); |
1952 | set1 = isl_set_intersect(set1, isl_set_copy(context)); |
1953 | set2 = isl_set_intersect(set2, context); |
1954 | equal_intersection = isl_set_is_equal(set1, set2); |
1955 | isl_set_free(set2); |
1956 | isl_set_free(set1); |
1957 | if (equal < 0 || equal_input < 0 || equal_intersection < 0) |
1958 | return -1; |
1959 | if (!equal) |
1960 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "polly/lib/External/isl/isl_test.c", 1961); return -1; } while (0) |
1961 | "incorrect gist result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "polly/lib/External/isl/isl_test.c", 1961); return -1; } while (0); |
1962 | if (!equal_input) |
1963 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "gist modified input" , "polly/lib/External/isl/isl_test.c", 1964); return -1; } while (0) |
1964 | "gist modified input", return -1)do { isl_handle_error(ctx, isl_error_unknown, "gist modified input" , "polly/lib/External/isl/isl_test.c", 1964); return -1; } while (0); |
1965 | if (!equal_input) |
1966 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case" , "polly/lib/External/isl/isl_test.c", 1967); return -1; } while (0) |
1967 | "inconsistent gist test case", return -1)do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case" , "polly/lib/External/isl/isl_test.c", 1967); return -1; } while (0); |
1968 | } |
1969 | |
1970 | if (test_gist_fail(ctx) < 0) |
1971 | return -1; |
1972 | |
1973 | str = "[p0, p2, p3, p5, p6, p10] -> { [] : " |
1974 | "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], " |
1975 | "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], " |
1976 | "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and " |
1977 | "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and " |
1978 | "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and " |
1979 | "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and " |
1980 | "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and " |
1981 | "p10 <= 15 and p10 <= -1 + p0 - p6) }"; |
1982 | bset1 = isl_basic_set_read_from_str(ctx, str); |
1983 | str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], " |
1984 | "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], " |
1985 | "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and " |
1986 | "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and " |
1987 | "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and " |
1988 | "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and " |
1989 | "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and " |
1990 | "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }"; |
1991 | bset2 = isl_basic_set_read_from_str(ctx, str); |
1992 | bset1 = isl_basic_set_gist(bset1, bset2); |
1993 | assert(bset1 && bset1->n_div == 0)((void) sizeof ((bset1 && bset1->n_div == 0) ? 1 : 0), __extension__ ({ if (bset1 && bset1->n_div == 0) ; else __assert_fail ("bset1 && bset1->n_div == 0" , "polly/lib/External/isl/isl_test.c", 1993, __extension__ __PRETTY_FUNCTION__ ); })); |
1994 | isl_basic_set_free(bset1); |
1995 | |
1996 | /* Check that the integer divisions of the second disjunct |
1997 | * do not spread to the first disjunct. |
1998 | */ |
1999 | str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: " |
2000 | "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or " |
2001 | "(exists (e0 = [(-1 + t1)/16], " |
2002 | "e1 = [(-16 + t1 - 16e0)/4294967296]: " |
2003 | "4294967296e1 = -16 + t1 - o0 - 16e0 and " |
2004 | "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and " |
2005 | "o0 <= 4294967295 and t1 <= -1)) }"; |
2006 | map1 = isl_map_read_from_str(ctx, str); |
2007 | str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }"; |
2008 | map2 = isl_map_read_from_str(ctx, str); |
2009 | map1 = isl_map_gist(map1, map2); |
2010 | if (!map1) |
2011 | return -1; |
2012 | if (map1->n != 1) |
2013 | isl_die(ctx, isl_error_unknown, "expecting single disjunct",do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct" , "polly/lib/External/isl/isl_test.c", 2014); isl_map_free(map1 ); return -1; } while (0) |
2014 | isl_map_free(map1); return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct" , "polly/lib/External/isl/isl_test.c", 2014); isl_map_free(map1 ); return -1; } while (0); |
2015 | n_div = isl_basic_map_dim(map1->p[0], isl_dim_div); |
2016 | isl_map_free(map1); |
2017 | if (n_div < 0) |
2018 | return -1; |
2019 | if (n_div != 1) |
2020 | isl_die(ctx, isl_error_unknown, "expecting single div",do { isl_handle_error(ctx, isl_error_unknown, "expecting single div" , "polly/lib/External/isl/isl_test.c", 2021); return -1; } while (0) |
2021 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single div" , "polly/lib/External/isl/isl_test.c", 2021); return -1; } while (0); |
2022 | |
2023 | if (test_gist_empty(ctx) < 0) |
2024 | return -1; |
2025 | if (test_plain_gist(ctx) < 0) |
2026 | return -1; |
2027 | |
2028 | return 0; |
2029 | } |
2030 | |
2031 | int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one) |
2032 | { |
2033 | isl_setisl_map *set, *set2; |
2034 | int equal; |
2035 | int one; |
2036 | |
2037 | set = isl_set_read_from_str(ctx, str); |
2038 | set = isl_set_coalesce(set); |
2039 | set2 = isl_set_read_from_str(ctx, str); |
2040 | equal = isl_set_is_equal(set, set2); |
2041 | one = set && set->n == 1; |
2042 | isl_set_free(set); |
2043 | isl_set_free(set2); |
2044 | |
2045 | if (equal < 0) |
2046 | return -1; |
2047 | if (!equal) |
2048 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "coalesced set not equal to input" , "polly/lib/External/isl/isl_test.c", 2049); return -1; } while (0) |
2049 | "coalesced set not equal to input", return -1)do { isl_handle_error(ctx, isl_error_unknown, "coalesced set not equal to input" , "polly/lib/External/isl/isl_test.c", 2049); return -1; } while (0); |
2050 | if (check_one && !one) |
2051 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "coalesced set should not be a union" , "polly/lib/External/isl/isl_test.c", 2052); return -1; } while (0) |
2052 | "coalesced set should not be a union", return -1)do { isl_handle_error(ctx, isl_error_unknown, "coalesced set should not be a union" , "polly/lib/External/isl/isl_test.c", 2052); return -1; } while (0); |
2053 | |
2054 | return 0; |
2055 | } |
2056 | |
2057 | /* Inputs for coalescing tests with unbounded wrapping. |
2058 | * "str" is a string representation of the input set. |
2059 | * "single_disjunct" is set if we expect the result to consist of |
2060 | * a single disjunct. |
2061 | */ |
2062 | struct { |
2063 | int single_disjunct; |
2064 | const char *str; |
2065 | } coalesce_unbounded_tests[] = { |
2066 | { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and " |
2067 | "-x - y + 1 >= 0 and -3 <= z <= 3;" |
2068 | "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and " |
2069 | "x-z + 20 >= 0 and x+z + 20 >= 0 and " |
2070 | "-10 <= y <= 0}" }, |
2071 | { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" }, |
2072 | { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" }, |
2073 | { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" }, |
2074 | { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" }, |
2075 | { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; " |
2076 | "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" }, |
2077 | { 1, "{ [0:1, 0:1]; [0, 2:3] }" }, |
2078 | { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" }, |
2079 | { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" }, |
2080 | { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" }, |
2081 | { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" }, |
2082 | { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" }, |
2083 | { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" }, |
2084 | }; |
2085 | |
2086 | /* Test the functionality of isl_set_coalesce with the bounded wrapping |
2087 | * option turned off. |
2088 | */ |
2089 | int test_coalesce_unbounded_wrapping(isl_ctx *ctx) |
2090 | { |
2091 | int i; |
2092 | int r = 0; |
2093 | int bounded; |
2094 | |
2095 | bounded = isl_options_get_coalesce_bounded_wrapping(ctx); |
2096 | isl_options_set_coalesce_bounded_wrapping(ctx, 0); |
2097 | |
2098 | for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests)(sizeof(coalesce_unbounded_tests)/sizeof(*coalesce_unbounded_tests )); ++i) { |
2099 | const char *str = coalesce_unbounded_tests[i].str; |
2100 | int check_one = coalesce_unbounded_tests[i].single_disjunct; |
2101 | if (test_coalesce_set(ctx, str, check_one) >= 0) |
2102 | continue; |
2103 | r = -1; |
2104 | break; |
2105 | } |
2106 | |
2107 | isl_options_set_coalesce_bounded_wrapping(ctx, bounded); |
2108 | |
2109 | return r; |
2110 | } |
2111 | |
2112 | /* Inputs for coalescing tests. |
2113 | * "str" is a string representation of the input set. |
2114 | * "single_disjunct" is set if we expect the result to consist of |
2115 | * a single disjunct. |
2116 | */ |
2117 | struct { |
2118 | int single_disjunct; |
2119 | const char *str; |
2120 | } coalesce_tests[] = { |
2121 | { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or " |
2122 | "y >= x & x >= 2 & 5 >= y }" }, |
2123 | { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or " |
2124 | "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" }, |
2125 | { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or " |
2126 | "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" }, |
2127 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
2128 | "y >= 0 & x >= 6 & x <= 10 & y <= x}" }, |
2129 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
2130 | "y >= 0 & x >= 7 & x <= 10 & y <= x}" }, |
2131 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
2132 | "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" }, |
2133 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" }, |
2134 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" }, |
2135 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" }, |
2136 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" }, |
2137 | { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" }, |
2138 | { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" }, |
2139 | { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" }, |
2140 | { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], " |
2141 | "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], " |
2142 | "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and " |
2143 | "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and " |
2144 | "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and " |
2145 | "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and " |
2146 | "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and " |
2147 | "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);" |
2148 | "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], " |
2149 | "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], " |
2150 | "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and " |
2151 | "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and " |
2152 | "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and " |
2153 | "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and " |
2154 | "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and " |
2155 | "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and " |
2156 | "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and " |
2157 | "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" }, |
2158 | { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and " |
2159 | "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or " |
2160 | "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and " |
2161 | "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" }, |
2162 | { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> " |
2163 | "[o0, o1, o2, o3, o4, o5, o6]] : " |
2164 | "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and " |
2165 | "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and " |
2166 | "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and " |
2167 | "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 " |
2168 | "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and " |
2169 | "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 " |
2170 | "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and " |
2171 | "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 " |
2172 | "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or " |
2173 | "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and " |
2174 | "o6 >= i3 + i6 - o3 and M >= 0 and " |
2175 | "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and " |
2176 | "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" }, |
2177 | { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or " |
2178 | "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or " |
2179 | "(o0 = 0 and M >= 2 and N >= 3) or " |
2180 | "(M = 0 and o0 = 0 and N >= 3) }" }, |
2181 | { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and " |
2182 | "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or " |
2183 | "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and " |
2184 | "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" }, |
2185 | { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" }, |
2186 | { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" }, |
2187 | { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or " |
2188 | "(y = 3 and x = 1) }" }, |
2189 | { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and " |
2190 | "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and " |
2191 | "i1 <= M and i3 <= M and i4 <= M) or " |
2192 | "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and " |
2193 | "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and " |
2194 | "i4 <= -1 + M) }" }, |
2195 | { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or " |
2196 | "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" }, |
2197 | { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" }, |
2198 | { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" }, |
2199 | { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" }, |
2200 | { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" }, |
2201 | { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" }, |
2202 | { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" }, |
2203 | { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" }, |
2204 | { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" }, |
2205 | { 0, "{ [a, b] : exists e : 2e = a and " |
2206 | "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" }, |
2207 | { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and " |
2208 | "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and " |
2209 | "j >= 1 and j' <= i + j - i' and i >= 1; " |
2210 | "[1, 1, 1, 1] }" }, |
2211 | { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; " |
2212 | "[i,j] : exists a : j = 3a }" }, |
2213 | { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and " |
2214 | "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and " |
2215 | "a >= 3) or " |
2216 | "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and " |
2217 | "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" }, |
2218 | { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and " |
2219 | "c <= 6 + 8a and a >= 3; " |
2220 | "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and " |
2221 | "c <= 7 + 8a and a >= 3 and a <= 4 }" }, |
2222 | { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; " |
2223 | "[x,0] : 3 <= x <= 4 }" }, |
2224 | { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; " |
2225 | "[x,0] : 4 <= x <= 5 }" }, |
2226 | { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; " |
2227 | "[x,0] : 3 <= x <= 5 }" }, |
2228 | { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; " |
2229 | "[x,0] : 3 <= x <= 4 }" }, |
2230 | { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and " |
2231 | "i1 <= 0; " |
2232 | "[i0, 0] : i0 >= 123 and i0 <= 124 }" }, |
2233 | { 1, "{ [0,0]; [1,1] }" }, |
2234 | { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" }, |
2235 | { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and " |
2236 | "ii <= k;" |
2237 | "[k, 0, k] : k <= 6 and k >= 1 }" }, |
2238 | { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;" |
2239 | "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" }, |
2240 | { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" }, |
2241 | { 1, "[n] -> { [1] : n >= 0;" |
2242 | "[x] : exists (e0 = floor((x)/2): x >= 2 and " |
2243 | "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" }, |
2244 | { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): " |
2245 | "3e1 = y and x >= 2 and 2e0 >= -1 + x and " |
2246 | "2e0 <= x and 2e0 <= n);" |
2247 | "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and " |
2248 | "n >= 0) }" }, |
2249 | { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): " |
2250 | "128e0 >= -134 + 127t1 and t1 >= 2 and " |
2251 | "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or " |
2252 | "t1 = 1 }" }, |
2253 | { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and " |
2254 | "3e0 >= -1 + 2i and i <= 9 and i >= 1);" |
2255 | "[0, 0] }" }, |
2256 | { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and " |
2257 | "t1 >= 13 and t1 <= 16);" |
2258 | "[t1] : t1 <= 15 and t1 >= 12 }" }, |
2259 | { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" }, |
2260 | { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" }, |
2261 | { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" }, |
2262 | { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" }, |
2263 | { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;" |
2264 | "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and " |
2265 | "i <= 4j + 2 }" }, |
2266 | { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or " |
2267 | "(exists (e0 : 3e0 = -2 + c0)) }" }, |
2268 | { 0, "[n, b0, t0] -> " |
2269 | "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : " |
2270 | "(exists (e0 = floor((-32b0 + i4)/1048576), " |
2271 | "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and " |
2272 | "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and " |
2273 | "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and " |
2274 | "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and " |
2275 | "i8 >= -157 + i0 - 4i4 and i8 >= 0 and " |
2276 | "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or " |
2277 | "(exists (e0 = floor((-32b0 + i4)/1048576), " |
2278 | "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and " |
2279 | "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and " |
2280 | "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and " |
2281 | "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and " |
2282 | "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and " |
2283 | "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));" |
2284 | "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : " |
2285 | "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and " |
2286 | "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and " |
2287 | "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and " |
2288 | "i8 >= -40 + i0 and i8 <= -10 + i0)) }" }, |
2289 | { 0, "{ [i0, i1, i2] : " |
2290 | "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): " |
2291 | "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and " |
2292 | "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and " |
2293 | "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and " |
2294 | "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and " |
2295 | "32e0 <= 31 + i0)) or " |
2296 | "i0 >= 0 }" }, |
2297 | { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" }, |
2298 | { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and " |
2299 | "2*floor((c)/2) = c and 0 <= a <= 192;" |
2300 | "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }" |
2301 | }, |
2302 | { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or " |
2303 | "(0 <= a <= b <= n) }" }, |
2304 | { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and " |
2305 | "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" }, |
2306 | { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" }, |
2307 | { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and " |
2308 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
2309 | "(exists (e0 = floor((-16 + 2c)/9): a = 4 and " |
2310 | "b = 3 and 9e0 <= -19 + 2c)) }" }, |
2311 | { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and " |
2312 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
2313 | "(a = 4 and b = 3 and " |
2314 | "9*floor((-16 + 2c)/9) <= -19 + 2c) }" }, |
2315 | { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or " |
2316 | "(b = -1 + a and 0 < a <= 3 and " |
2317 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
2318 | "(exists (e0 = floor((-16 + 2c)/9): a = 4 and " |
2319 | "b = 3 and 9e0 <= -19 + 2c)) }" }, |
2320 | { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;" |
2321 | "[1, 0] }" }, |
2322 | { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;" |
2323 | "[0, 1] }" }, |
2324 | { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" }, |
2325 | { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" }, |
2326 | { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; " |
2327 | "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; " |
2328 | "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; " |
2329 | "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" }, |
2330 | { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; " |
2331 | "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; " |
2332 | "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" }, |
2333 | { 1, "{ [a] : a <= 8 and " |
2334 | "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" }, |
2335 | { 1, "{ [x, y] : 2y = -x and x <= 0 or " |
2336 | "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" }, |
2337 | { 0, "{ [x, y] : 2y = -x and x <= 0 or " |
2338 | "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" }, |
2339 | { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or " |
2340 | "(a < 0 and 3*floor((a)/3) < a) }" }, |
2341 | { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or " |
2342 | "(a < -1 and 3*floor((a)/3) < a) }" }, |
2343 | { 1, "{ [a, b] : a <= 1024 and b >= 0 and " |
2344 | "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and " |
2345 | "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))" |
2346 | "or (2 <= a <= 15 and b < a)) }" }, |
2347 | { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and " |
2348 | "32*floor((a)/32) < a) or a <= 15) }" }, |
2349 | { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and " |
2350 | "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;" |
2351 | "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and " |
2352 | "10 - a <= c <= 5 and 5 <= d <= 73 - c }" }, |
2353 | { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and " |
2354 | "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; " |
2355 | "S_0[n] : n <= m <= 2 + n }" }, |
2356 | { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and " |
2357 | "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and " |
2358 | "2e0 <= a + b); " |
2359 | "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and " |
2360 | "2e0 >= -1 - a + b and 2e0 <= -a + b and " |
2361 | "2e0 < -a + 2b) }" }, |
2362 | { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; " |
2363 | "[i, 0, i] : 0 <= i <= 7 }" }, |
2364 | { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" }, |
2365 | { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" }, |
2366 | { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" }, |
2367 | { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" }, |
2368 | { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" }, |
2369 | { 0, "{ [a, c] : (2 + a) mod 4 = 0 or " |
2370 | "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or " |
2371 | "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and " |
2372 | "a > 0 and a <= 5) }" }, |
2373 | { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" }, |
2374 | { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and " |
2375 | "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; " |
2376 | "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" }, |
2377 | { 0, "{ [0:1, 0:1]; [0, 2:3] }" }, |
2378 | { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or " |
2379 | "((a) mod 2 = 0 and 0 < a <= 15)) }" }, |
2380 | }; |
2381 | |
2382 | /* A specialized coalescing test case that would result |
2383 | * in a segmentation fault or a failed assertion in earlier versions of isl. |
2384 | */ |
2385 | static int test_coalesce_special(struct isl_ctx *ctx) |
2386 | { |
2387 | const char *str; |
2388 | isl_map *map1, *map2; |
2389 | |
2390 | str = "[y] -> { [S_L220_OUT[] -> T7[]] -> " |
2391 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : " |
2392 | "(y = 201 and o1 <= 239 and o1 >= 212) or " |
2393 | "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and " |
2394 | "o1 <= 239 and o1 >= 212)) or " |
2395 | "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and " |
2396 | "o1 <= 241 and o1 >= 240));" |
2397 | "[S_L220_OUT[] -> T7[]] -> " |
2398 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : " |
2399 | "(y = 2 and o1 <= 241 and o1 >= 212) or " |
2400 | "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and " |
2401 | "y >= 5 and o1 <= 241 and o1 >= 212)) }"; |
2402 | map1 = isl_map_read_from_str(ctx, str); |
2403 | map1 = isl_map_align_divs_internal(map1); |
2404 | map1 = isl_map_coalesce(map1); |
2405 | str = "[y] -> { [S_L220_OUT[] -> T7[]] -> " |
2406 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : " |
2407 | "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and " |
2408 | "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and " |
2409 | "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }"; |
2410 | map2 = isl_map_read_from_str(ctx, str); |
2411 | map2 = isl_map_union(map2, map1); |
2412 | map2 = isl_map_align_divs_internal(map2); |
2413 | map2 = isl_map_coalesce(map2); |
2414 | isl_map_free(map2); |
2415 | if (!map2) |
2416 | return -1; |
2417 | |
2418 | return 0; |
2419 | } |
2420 | |
2421 | /* Check that the union of the basic sets described by "str1" and "str2" |
2422 | * can be coalesced. |
2423 | * The explicit call to isl_basic_set_union prevents the implicit |
2424 | * equality constraints in the basic maps from being detected prior |
2425 | * to the call to isl_set_coalesce, at least at the point |
2426 | * where this function was introduced. |
2427 | */ |
2428 | static isl_stat test_coalesce_union(isl_ctx *ctx, const char *str1, |
2429 | const char *str2) |
2430 | { |
2431 | isl_basic_setisl_basic_map *bset1, *bset2; |
2432 | isl_setisl_map *set; |
2433 | |
2434 | bset1 = isl_basic_set_read_from_str(ctx, str1); |
2435 | bset2 = isl_basic_set_read_from_str(ctx, str2); |
2436 | set = isl_basic_set_union(bset1, bset2); |
2437 | set = isl_set_coalesce(set); |
2438 | isl_set_free(set); |
2439 | |
2440 | return isl_stat_non_null(set); |
2441 | } |
2442 | |
2443 | /* A specialized coalescing test case that would result in an assertion |
2444 | * in an earlier version of isl. Use test_coalesce_union with |
2445 | * an explicit call to isl_basic_set_union to prevent the implicit |
2446 | * equality constraints in the first basic map from being detected prior |
2447 | * to the call to isl_set_coalesce, at least at the point |
2448 | * where this test case was introduced. |
2449 | */ |
2450 | static isl_stat test_coalesce_special2(struct isl_ctx *ctx) |
2451 | { |
2452 | const char *str1; |
2453 | const char *str2; |
2454 | |
2455 | str1 = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }"; |
2456 | str2 = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }"; |
2457 | return test_coalesce_union(ctx, str1, str2); |
2458 | } |
2459 | |
2460 | /* Check that calling isl_set_coalesce does not leave other sets |
2461 | * that may share some information with the input to isl_set_coalesce |
2462 | * in an inconsistent state. |
2463 | * In particular, older versions of isl would modify all copies |
2464 | * of the basic sets in the isl_set_coalesce input in a way |
2465 | * that could leave them in an inconsistent state. |
2466 | * The result of printing any other set containing one of these |
2467 | * basic sets would then result in an invalid set description. |
2468 | */ |
2469 | static int test_coalesce_special3(isl_ctx *ctx) |
2470 | { |
2471 | const char *str; |
2472 | char *s; |
2473 | isl_setisl_map *set1, *set2; |
2474 | isl_printer *p; |
2475 | |
2476 | set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }"); |
2477 | str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }"; |
2478 | set2 = isl_set_read_from_str(ctx, str); |
2479 | set1 = isl_set_union(set1, isl_set_copy(set2)); |
2480 | set1 = isl_set_coalesce(set1); |
2481 | isl_set_free(set1); |
2482 | |
2483 | p = isl_printer_to_str(ctx); |
2484 | p = isl_printer_print_set(p, set2); |
2485 | isl_set_free(set2); |
2486 | s = isl_printer_get_str(p); |
2487 | isl_printer_free(p); |
2488 | set1 = isl_set_read_from_str(ctx, s); |
2489 | free(s); |
2490 | isl_set_free(set1); |
2491 | |
2492 | if (!set1) |
2493 | return -1; |
2494 | |
2495 | return 0; |
2496 | } |
2497 | |
2498 | /* Check that calling isl_set_coalesce on the intersection of |
2499 | * the sets described by "s1" and "s2" does not leave other sets |
2500 | * that may share some information with the input to isl_set_coalesce |
2501 | * in an inconsistent state. |
2502 | * In particular, when isl_set_coalesce detects equality constraints, |
2503 | * it does not immediately perform Gaussian elimination on them, |
2504 | * but then it needs to ensure that it is performed at some point. |
2505 | * The input set has implicit equality constraints in the first disjunct. |
2506 | * It is constructed as an intersection, because otherwise |
2507 | * those equality constraints would already be detected during parsing. |
2508 | */ |
2509 | static isl_stat test_coalesce_intersection(isl_ctx *ctx, |
2510 | const char *s1, const char *s2) |
2511 | { |
2512 | isl_setisl_map *set1, *set2; |
2513 | |
2514 | set1 = isl_set_read_from_str(ctx, s1); |
2515 | set2 = isl_set_read_from_str(ctx, s2); |
2516 | set1 = isl_set_intersect(set1, set2); |
2517 | isl_set_free(isl_set_coalesce(isl_set_copy(set1))); |
2518 | set1 = isl_set_coalesce(set1); |
2519 | isl_set_free(set1); |
2520 | |
2521 | if (!set1) |
2522 | return isl_stat_error; |
2523 | |
2524 | return isl_stat_ok; |
2525 | } |
2526 | |
2527 | /* Check that calling isl_set_coalesce does not leave other sets |
2528 | * that may share some information with the input to isl_set_coalesce |
2529 | * in an inconsistent state, for the case where one disjunct |
2530 | * is a subset of the other. |
2531 | */ |
2532 | static isl_stat test_coalesce_special4(isl_ctx *ctx) |
2533 | { |
2534 | const char *s1, *s2; |
2535 | |
2536 | s1 = "{ [a, b] : b <= 0 or a <= 1 }"; |
2537 | s2 = "{ [a, b] : -1 <= -a < b }"; |
2538 | return test_coalesce_intersection(ctx, s1, s2); |
2539 | } |
2540 | |
2541 | /* Check that calling isl_set_coalesce does not leave other sets |
2542 | * that may share some information with the input to isl_set_coalesce |
2543 | * in an inconsistent state, for the case where two disjuncts |
2544 | * can be fused. |
2545 | */ |
2546 | static isl_stat test_coalesce_special5(isl_ctx *ctx) |
2547 | { |
2548 | const char *s1, *s2; |
2549 | |
2550 | s1 = "{ [a, b, c] : b <= 0 }"; |
2551 | s2 = "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }"; |
2552 | return test_coalesce_intersection(ctx, s1, s2); |
2553 | } |
2554 | |
2555 | /* Check that calling isl_set_coalesce does not leave other sets |
2556 | * that may share some information with the input to isl_set_coalesce |
2557 | * in an inconsistent state, for the case where two disjuncts |
2558 | * can be fused and where both disjuncts have implicit equality constraints. |
2559 | */ |
2560 | static isl_stat test_coalesce_special6(isl_ctx *ctx) |
2561 | { |
2562 | const char *s1, *s2; |
2563 | |
2564 | s1 = "{ [a, b, c] : c <= 0 }"; |
2565 | s2 = "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }"; |
2566 | return test_coalesce_intersection(ctx, s1, s2); |
2567 | } |
2568 | |
2569 | /* A specialized coalescing test case that would result in an assertion failure |
2570 | * in an earlier version of isl. Use test_coalesce_union with |
2571 | * an explicit call to isl_basic_set_union to prevent the implicit |
2572 | * equality constraints in the basic maps from being detected prior |
2573 | * to the call to isl_set_coalesce, at least at the point |
2574 | * where this test case was introduced. |
2575 | */ |
2576 | static isl_stat test_coalesce_special7(isl_ctx *ctx) |
2577 | { |
2578 | const char *str1; |
2579 | const char *str2; |
2580 | |
2581 | str1 = "{ [a, b, c=0:17] : a <= 7 and 2b <= 11 - a and " |
2582 | "c <= -7 + 2a and 2c >= - 3 + 3a - 2b }"; |
2583 | str2 = "{ [a, b, c] : c > -15a and c >= -7 + 2a and c < 0 and " |
2584 | "3c <= -5 + 5a - 3b and 2b >= 11 - a }"; |
2585 | return test_coalesce_union(ctx, str1, str2); |
2586 | } |
2587 | |
2588 | /* Test the functionality of isl_set_coalesce. |
2589 | * That is, check that the output is always equal to the input |
2590 | * and in some cases that the result consists of a single disjunct. |
2591 | */ |
2592 | static int test_coalesce(struct isl_ctx *ctx) |
2593 | { |
2594 | int i; |
2595 | |
2596 | for (i = 0; i < ARRAY_SIZE(coalesce_tests)(sizeof(coalesce_tests)/sizeof(*coalesce_tests)); ++i) { |
2597 | const char *str = coalesce_tests[i].str; |
2598 | int check_one = coalesce_tests[i].single_disjunct; |
2599 | if (test_coalesce_set(ctx, str, check_one) < 0) |
2600 | return -1; |
2601 | } |
2602 | |
2603 | if (test_coalesce_unbounded_wrapping(ctx) < 0) |
2604 | return -1; |
2605 | if (test_coalesce_special(ctx) < 0) |
2606 | return -1; |
2607 | if (test_coalesce_special2(ctx) < 0) |
2608 | return -1; |
2609 | if (test_coalesce_special3(ctx) < 0) |
2610 | return -1; |
2611 | if (test_coalesce_special4(ctx) < 0) |
2612 | return -1; |
2613 | if (test_coalesce_special5(ctx) < 0) |
2614 | return -1; |
2615 | if (test_coalesce_special6(ctx) < 0) |
2616 | return -1; |
2617 | if (test_coalesce_special7(ctx) < 0) |
2618 | return -1; |
2619 | |
2620 | |
2621 | return 0; |
2622 | } |
2623 | |
2624 | /* Construct a representation of the graph on the right of Figure 1 |
2625 | * in "Computing the Transitive Closure of a Union of |
2626 | * Affine Integer Tuple Relations". |
2627 | */ |
2628 | static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx) |
2629 | { |
2630 | isl_setisl_map *dom; |
2631 | isl_map *up, *right; |
2632 | |
2633 | dom = isl_set_read_from_str(ctx, |
2634 | "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and " |
2635 | "2 x - 3 y + 3 >= 0 }"); |
2636 | right = isl_map_read_from_str(ctx, |
2637 | "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }"); |
2638 | up = isl_map_read_from_str(ctx, |
2639 | "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }"); |
2640 | right = isl_map_intersect_domain(right, isl_set_copy(dom)); |
2641 | right = isl_map_intersect_range(right, isl_set_copy(dom)); |
2642 | up = isl_map_intersect_domain(up, isl_set_copy(dom)); |
2643 | up = isl_map_intersect_range(up, dom); |
2644 | return isl_map_union(up, right); |
2645 | } |
2646 | |
2647 | /* Construct a representation of the power of the graph |
2648 | * on the right of Figure 1 in "Computing the Transitive Closure of |
2649 | * a Union of Affine Integer Tuple Relations". |
2650 | */ |
2651 | static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx) |
2652 | { |
2653 | return isl_map_read_from_str(ctx, |
2654 | "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; " |
2655 | " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; " |
2656 | " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }"); |
2657 | } |
2658 | |
2659 | /* Construct a representation of the transitive closure of the graph |
2660 | * on the right of Figure 1 in "Computing the Transitive Closure of |
2661 | * a Union of Affine Integer Tuple Relations". |
2662 | */ |
2663 | static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx) |
2664 | { |
2665 | return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx))); |
2666 | } |
2667 | |
2668 | static int test_closure(isl_ctx *ctx) |
2669 | { |
2670 | const char *str; |
2671 | isl_map *map, *map2; |
2672 | isl_bool exact, equal; |
2673 | |
2674 | /* COCOA example 1 */ |
2675 | map = isl_map_read_from_str(ctx, |
2676 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and " |
2677 | "1 <= i and i < n and 1 <= j and j < n or " |
2678 | "i2 = i + 1 and j2 = j - 1 and " |
2679 | "1 <= i and i < n and 2 <= j and j <= n }"); |
2680 | map = isl_map_power(map, &exact); |
2681 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2681, __extension__ __PRETTY_FUNCTION__); })); |
2682 | isl_map_free(map); |
2683 | |
2684 | /* COCOA example 1 */ |
2685 | map = isl_map_read_from_str(ctx, |
2686 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and " |
2687 | "1 <= i and i < n and 1 <= j and j < n or " |
2688 | "i2 = i + 1 and j2 = j - 1 and " |
2689 | "1 <= i and i < n and 2 <= j and j <= n }"); |
2690 | map = isl_map_transitive_closure(map, &exact); |
2691 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2691, __extension__ __PRETTY_FUNCTION__); })); |
2692 | map2 = isl_map_read_from_str(ctx, |
2693 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : " |
2694 | "1 <= i and i < n and 1 <= j and j <= n and " |
2695 | "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and " |
2696 | "i2 = i + k1 + k2 and j2 = j + k1 - k2 and " |
2697 | "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}"); |
2698 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2698, __extension__ __PRETTY_FUNCTION__ ); })); |
2699 | isl_map_free(map2); |
2700 | isl_map_free(map); |
2701 | |
2702 | map = isl_map_read_from_str(ctx, |
2703 | "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and " |
2704 | " 0 <= y and y <= n }"); |
2705 | map = isl_map_transitive_closure(map, &exact); |
2706 | map2 = isl_map_read_from_str(ctx, |
2707 | "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and " |
2708 | " 0 <= y and y <= n }"); |
2709 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2709, __extension__ __PRETTY_FUNCTION__ ); })); |
2710 | isl_map_free(map2); |
2711 | isl_map_free(map); |
2712 | |
2713 | /* COCOA example 2 */ |
2714 | map = isl_map_read_from_str(ctx, |
2715 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and " |
2716 | "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or " |
2717 | "i2 = i + 2 and j2 = j - 2 and " |
2718 | "1 <= i and i < n - 1 and 3 <= j and j <= n }"); |
2719 | map = isl_map_transitive_closure(map, &exact); |
2720 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2720, __extension__ __PRETTY_FUNCTION__); })); |
2721 | map2 = isl_map_read_from_str(ctx, |
2722 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : " |
2723 | "1 <= i and i < n - 1 and 1 <= j and j <= n and " |
2724 | "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and " |
2725 | "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and " |
2726 | "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }"); |
2727 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2727, __extension__ __PRETTY_FUNCTION__ ); })); |
2728 | isl_map_free(map); |
2729 | isl_map_free(map2); |
2730 | |
2731 | /* COCOA Fig.2 left */ |
2732 | map = isl_map_read_from_str(ctx, |
2733 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and " |
2734 | "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and " |
2735 | "j <= n or " |
2736 | "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and " |
2737 | "j <= 2 i - 3 and j <= n - 2 or " |
2738 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2739 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2740 | map = isl_map_transitive_closure(map, &exact); |
2741 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2741, __extension__ __PRETTY_FUNCTION__); })); |
2742 | isl_map_free(map); |
2743 | |
2744 | /* COCOA Fig.2 right */ |
2745 | map = isl_map_read_from_str(ctx, |
2746 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and " |
2747 | "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and " |
2748 | "j <= n or " |
2749 | "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and " |
2750 | "j <= 2 i - 4 and j <= n - 3 or " |
2751 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2752 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2753 | map = isl_map_power(map, &exact); |
2754 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2754, __extension__ __PRETTY_FUNCTION__); })); |
2755 | isl_map_free(map); |
2756 | |
2757 | /* COCOA Fig.2 right */ |
2758 | map = isl_map_read_from_str(ctx, |
2759 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and " |
2760 | "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and " |
2761 | "j <= n or " |
2762 | "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and " |
2763 | "j <= 2 i - 4 and j <= n - 3 or " |
2764 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2765 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2766 | map = isl_map_transitive_closure(map, &exact); |
2767 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2767, __extension__ __PRETTY_FUNCTION__); })); |
2768 | map2 = isl_map_read_from_str(ctx, |
2769 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : " |
2770 | "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and " |
2771 | "j <= n and 3 + i + 2 j <= 3 n and " |
2772 | "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and " |
2773 | "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and " |
2774 | "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and " |
2775 | "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and " |
2776 | "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }"); |
2777 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2777, __extension__ __PRETTY_FUNCTION__ ); })); |
2778 | isl_map_free(map2); |
2779 | isl_map_free(map); |
2780 | |
2781 | map = cocoa_fig_1_right_graph(ctx); |
2782 | map = isl_map_transitive_closure(map, &exact); |
2783 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2783, __extension__ __PRETTY_FUNCTION__); })); |
2784 | map2 = cocoa_fig_1_right_tc(ctx); |
2785 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2785, __extension__ __PRETTY_FUNCTION__ ); })); |
2786 | isl_map_free(map2); |
2787 | isl_map_free(map); |
2788 | |
2789 | map = cocoa_fig_1_right_graph(ctx); |
2790 | map = isl_map_power(map, &exact); |
2791 | map2 = cocoa_fig_1_right_power(ctx); |
2792 | equal = isl_map_is_equal(map, map2); |
2793 | isl_map_free(map2); |
2794 | isl_map_free(map); |
2795 | if (equal < 0) |
2796 | return -1; |
2797 | if (!exact) |
2798 | isl_die(ctx, isl_error_unknown, "power not exact", return -1)do { isl_handle_error(ctx, isl_error_unknown, "power not exact" , "polly/lib/External/isl/isl_test.c", 2798); return -1; } while (0); |
2799 | if (!equal) |
2800 | isl_die(ctx, isl_error_unknown, "unexpected power", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected power" , "polly/lib/External/isl/isl_test.c", 2800); return -1; } while (0); |
2801 | |
2802 | /* COCOA Theorem 1 counter example */ |
2803 | map = isl_map_read_from_str(ctx, |
2804 | "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and " |
2805 | "i2 = 1 and j2 = j or " |
2806 | "i = 0 and j = 0 and i2 = 0 and j2 = 1 }"); |
2807 | map = isl_map_transitive_closure(map, &exact); |
2808 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2808, __extension__ __PRETTY_FUNCTION__); })); |
2809 | isl_map_free(map); |
2810 | |
2811 | map = isl_map_read_from_str(ctx, |
2812 | "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and " |
2813 | "1 <= i,i2 <= n and 1 <= j,j2 <= m or " |
2814 | "i2 = i + 1 and 3 <= j2 - j <= 4 and " |
2815 | "1 <= i,i2 <= n and 1 <= j,j2 <= m }"); |
2816 | map = isl_map_transitive_closure(map, &exact); |
2817 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2817, __extension__ __PRETTY_FUNCTION__); })); |
2818 | isl_map_free(map); |
2819 | |
2820 | /* Kelly et al 1996, fig 12 */ |
2821 | map = isl_map_read_from_str(ctx, |
2822 | "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and " |
2823 | "1 <= i,j,j+1 <= n or " |
2824 | "j = n and j2 = 1 and i2 = i + 1 and " |
2825 | "1 <= i,i+1 <= n }"); |
2826 | map = isl_map_transitive_closure(map, &exact); |
2827 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2827, __extension__ __PRETTY_FUNCTION__); })); |
2828 | map2 = isl_map_read_from_str(ctx, |
2829 | "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and " |
2830 | "1 <= i <= n and i = i2 or " |
2831 | "1 <= i < i2 <= n and 1 <= j <= n and " |
2832 | "1 <= j2 <= n }"); |
2833 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2833, __extension__ __PRETTY_FUNCTION__ ); })); |
2834 | isl_map_free(map2); |
2835 | isl_map_free(map); |
2836 | |
2837 | /* Omega's closure4 */ |
2838 | map = isl_map_read_from_str(ctx, |
2839 | "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and " |
2840 | "1 <= x,y <= 10 or " |
2841 | "x2 = x + 1 and y2 = y and " |
2842 | "1 <= x <= 20 && 5 <= y <= 15 }"); |
2843 | map = isl_map_transitive_closure(map, &exact); |
2844 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2844, __extension__ __PRETTY_FUNCTION__); })); |
2845 | isl_map_free(map); |
2846 | |
2847 | map = isl_map_read_from_str(ctx, |
2848 | "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }"); |
2849 | map = isl_map_transitive_closure(map, &exact); |
2850 | assert(!exact)((void) sizeof ((!exact) ? 1 : 0), __extension__ ({ if (!exact ) ; else __assert_fail ("!exact", "polly/lib/External/isl/isl_test.c" , 2850, __extension__ __PRETTY_FUNCTION__); })); |
2851 | map2 = isl_map_read_from_str(ctx, |
2852 | "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }"); |
2853 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2853, __extension__ __PRETTY_FUNCTION__ ); })); |
2854 | isl_map_free(map); |
2855 | isl_map_free(map2); |
2856 | |
2857 | str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : " |
2858 | "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and " |
2859 | "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and " |
2860 | "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }"; |
2861 | map = isl_map_read_from_str(ctx, str); |
2862 | map = isl_map_transitive_closure(map, &exact); |
2863 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2863, __extension__ __PRETTY_FUNCTION__); })); |
2864 | map2 = isl_map_read_from_str(ctx, str); |
2865 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2865, __extension__ __PRETTY_FUNCTION__ ); })); |
2866 | isl_map_free(map); |
2867 | isl_map_free(map2); |
2868 | |
2869 | str = "{[0] -> [1]; [2] -> [3]}"; |
2870 | map = isl_map_read_from_str(ctx, str); |
2871 | map = isl_map_transitive_closure(map, &exact); |
2872 | assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact) ; else __assert_fail ("exact", "polly/lib/External/isl/isl_test.c" , 2872, __extension__ __PRETTY_FUNCTION__); })); |
2873 | map2 = isl_map_read_from_str(ctx, str); |
2874 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 2874, __extension__ __PRETTY_FUNCTION__ ); })); |
2875 | isl_map_free(map); |
2876 | isl_map_free(map2); |
2877 | |
2878 | str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> " |
2879 | "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : " |
2880 | "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and " |
2881 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2882 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2883 | "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> " |
2884 | "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : " |
2885 | "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and " |
2886 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2887 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2888 | "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> " |
2889 | "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : " |
2890 | "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and " |
2891 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2892 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2893 | "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> " |
2894 | "[[i0, i1, 1, 0, i0] -> [i5, 1]] : " |
2895 | "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and " |
2896 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2897 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }"; |
2898 | map = isl_map_read_from_str(ctx, str); |
2899 | map = isl_map_transitive_closure(map, NULL((void*)0)); |
2900 | assert(map)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else __assert_fail ("map", "polly/lib/External/isl/isl_test.c", 2900 , __extension__ __PRETTY_FUNCTION__); })); |
2901 | isl_map_free(map); |
2902 | |
2903 | return 0; |
2904 | } |
2905 | |
2906 | /* Check that the actual result of a boolean operation is equal |
2907 | * to the expected result. |
2908 | */ |
2909 | static isl_stat check_bool(isl_ctx *ctx, isl_bool actual, isl_bool expected) |
2910 | { |
2911 | if (actual != expected) |
2912 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect boolean operation" , "polly/lib/External/isl/isl_test.c", 2913); return isl_stat_error ; } while (0) |
2913 | "incorrect boolean operation", return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "incorrect boolean operation" , "polly/lib/External/isl/isl_test.c", 2913); return isl_stat_error ; } while (0); |
2914 | return isl_stat_ok; |
2915 | } |
2916 | |
2917 | /* Test operations on isl_bool values. |
2918 | * |
2919 | * This tests: |
2920 | * |
2921 | * isl_bool_not |
2922 | * isl_bool_ok |
2923 | */ |
2924 | static int test_isl_bool(isl_ctx *ctx) |
2925 | { |
2926 | if (check_bool(ctx, isl_bool_not(isl_bool_true), isl_bool_false) < 0) |
2927 | return -1; |
2928 | if (check_bool(ctx, isl_bool_not(isl_bool_false), isl_bool_true) < 0) |
2929 | return -1; |
2930 | if (check_bool(ctx, isl_bool_not(isl_bool_error), isl_bool_error) < 0) |
2931 | return -1; |
2932 | if (check_bool(ctx, isl_bool_ok(0), isl_bool_false) < 0) |
2933 | return -1; |
2934 | if (check_bool(ctx, isl_bool_ok(1), isl_bool_true) < 0) |
2935 | return -1; |
2936 | if (check_bool(ctx, isl_bool_ok(-1), isl_bool_true) < 0) |
2937 | return -1; |
2938 | if (check_bool(ctx, isl_bool_ok(2), isl_bool_true) < 0) |
2939 | return -1; |
2940 | if (check_bool(ctx, isl_bool_ok(-2), isl_bool_true) < 0) |
2941 | return -1; |
2942 | |
2943 | return 0; |
2944 | } |
2945 | |
2946 | static int test_lex(struct isl_ctx *ctx) |
2947 | { |
2948 | isl_space *space; |
2949 | isl_map *map; |
2950 | int empty; |
2951 | |
2952 | space = isl_space_set_alloc(ctx, 0, 0); |
2953 | map = isl_map_lex_le(space); |
2954 | empty = isl_map_is_empty(map); |
2955 | isl_map_free(map); |
2956 | |
2957 | if (empty < 0) |
2958 | return -1; |
2959 | if (empty) |
2960 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result" , "polly/lib/External/isl/isl_test.c", 2961); return -1; } while (0) |
2961 | "expecting non-empty result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result" , "polly/lib/External/isl/isl_test.c", 2961); return -1; } while (0); |
2962 | |
2963 | return 0; |
2964 | } |
2965 | |
2966 | /* Inputs for isl_map_lexmin tests. |
2967 | * "map" is the input and "lexmin" is the expected result. |
2968 | */ |
2969 | struct { |
2970 | const char *map; |
2971 | const char *lexmin; |
2972 | } lexmin_tests [] = { |
2973 | { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }", |
2974 | "{ [x] -> [5] : 6 <= x <= 8; " |
2975 | "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" }, |
2976 | { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }", |
2977 | "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" }, |
2978 | { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }", |
2979 | "{ [x] -> [y] : (4y = x and x >= 0) or " |
2980 | "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and " |
2981 | "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or " |
2982 | "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" }, |
2983 | { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }", |
2984 | "{ T[a] -> S[b, c] : 2b = a and 2c = a }" }, |
2985 | /* Check that empty pieces are properly combined. */ |
2986 | { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and " |
2987 | "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and " |
2988 | "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }", |
2989 | "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and " |
2990 | "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and " |
2991 | "x >= 4 }" }, |
2992 | { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and " |
2993 | "a <= 255 and c <= 255 and d <= 255 - j and " |
2994 | "255 - j <= 7d <= 7 - i and 240d <= 239 + a and " |
2995 | "247d <= 247 + k - j and 247d <= 247 + k - b and " |
2996 | "247d <= 247 + i and 248 - b <= 248d <= c and " |
2997 | "254d >= i - a + b and 254d >= -a + b and " |
2998 | "255d >= -i + a - b and 1792d >= -63736 + 257b }", |
2999 | "{ [i, k, j] -> " |
3000 | "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : " |
3001 | "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and " |
3002 | "247j >= 62738 - i and 509j <= 129795 + i and " |
3003 | "742j >= 188724 - i; " |
3004 | "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" }, |
3005 | { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and " |
3006 | "16*floor((8 + b)/16) <= 7 + b; " |
3007 | "[a] -> [1] }", |
3008 | "{ [a] -> [b = 1] : a >= 510 or a <= 0; " |
3009 | "[a] -> [b = 0] : 0 < a <= 509 }" }, |
3010 | { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" }, |
3011 | { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" }, |
3012 | { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" }, |
3013 | }; |
3014 | |
3015 | static int test_lexmin(struct isl_ctx *ctx) |
3016 | { |
3017 | int i; |
3018 | int equal; |
3019 | const char *str; |
3020 | isl_basic_map *bmap; |
3021 | isl_map *map, *map2; |
3022 | isl_setisl_map *set; |
3023 | isl_setisl_map *set2; |
3024 | isl_pw_multi_aff *pma; |
3025 | |
3026 | str = "[p0, p1] -> { [] -> [] : " |
3027 | "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], " |
3028 | "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: " |
3029 | "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and " |
3030 | "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and " |
3031 | "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and " |
3032 | "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and " |
3033 | "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and " |
3034 | "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and " |
3035 | "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and " |
3036 | "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and " |
3037 | "e2 <= e1 and e3 >= 1 and e4 <= e2) }"; |
3038 | map = isl_map_read_from_str(ctx, str); |
3039 | map = isl_map_lexmin(map); |
3040 | isl_map_free(map); |
3041 | if (!map) |
3042 | return -1; |
3043 | |
3044 | str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and " |
3045 | "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }"; |
3046 | set = isl_set_read_from_str(ctx, str); |
3047 | set = isl_set_lexmax(set); |
3048 | str = "[C] -> { [obj,a,b,c] : C = 8 }"; |
3049 | set2 = isl_set_read_from_str(ctx, str); |
3050 | set = isl_set_intersect(set, set2); |
3051 | assert(!isl_set_is_empty(set))((void) sizeof ((!isl_set_is_empty(set)) ? 1 : 0), __extension__ ({ if (!isl_set_is_empty(set)) ; else __assert_fail ("!isl_set_is_empty(set)" , "polly/lib/External/isl/isl_test.c", 3051, __extension__ __PRETTY_FUNCTION__ ); })); |
3052 | isl_set_free(set); |
3053 | |
3054 | for (i = 0; i < ARRAY_SIZE(lexmin_tests)(sizeof(lexmin_tests)/sizeof(*lexmin_tests)); ++i) { |
3055 | map = isl_map_read_from_str(ctx, lexmin_tests[i].map); |
3056 | map = isl_map_lexmin(map); |
3057 | map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin); |
3058 | equal = isl_map_is_equal(map, map2); |
3059 | isl_map_free(map); |
3060 | isl_map_free(map2); |
3061 | |
3062 | if (equal < 0) |
3063 | return -1; |
3064 | if (!equal) |
3065 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 3066); return -1; } while (0) |
3066 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 3066); return -1; } while (0); |
3067 | } |
3068 | |
3069 | str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and " |
3070 | " 8i' <= i and 8i' >= -7 + i }"; |
3071 | bmap = isl_basic_map_read_from_str(ctx, str); |
3072 | pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap)); |
3073 | map2 = isl_map_from_pw_multi_aff(pma); |
3074 | map = isl_map_from_basic_map(bmap); |
3075 | assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__ ({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)" , "polly/lib/External/isl/isl_test.c", 3075, __extension__ __PRETTY_FUNCTION__ ); })); |
3076 | isl_map_free(map); |
3077 | isl_map_free(map2); |
3078 | |
3079 | str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and " |
3080 | " 8i' <= i and 8i' >= -7 + i }"; |
3081 | set = isl_set_read_from_str(ctx, str); |
3082 | pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set)); |
3083 | set2 = isl_set_from_pw_multi_aff(pma); |
3084 | equal = isl_set_is_equal(set, set2); |
3085 | isl_set_free(set); |
3086 | isl_set_free(set2); |
3087 | if (equal < 0) |
3088 | return -1; |
3089 | if (!equal) |
3090 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "polly/lib/External/isl/isl_test.c" , 3092); return -1; } while (0) |
3091 | "unexpected difference between set and "do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "polly/lib/External/isl/isl_test.c" , 3092); return -1; } while (0) |
3092 | "piecewise affine expression", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "polly/lib/External/isl/isl_test.c" , 3092); return -1; } while (0); |
3093 | |
3094 | return 0; |
3095 | } |
3096 | |
3097 | /* Inputs for isl_pw_multi_aff_max_multi_val tests. |
3098 | * "pma" is the input. |
3099 | * "res" is the expected result. |
3100 | */ |
3101 | static struct { |
3102 | const char *pma; |
3103 | const char *res; |
3104 | } opt_pw_tests[] = { |
3105 | { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" }, |
3106 | { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : " |
3107 | "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" }, |
3108 | { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }", |
3109 | "{ A[10, 0, 20] }" }, |
3110 | { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" }, |
3111 | }; |
3112 | |
3113 | /* Perform basic isl_pw_multi_aff_max_multi_val tests. |
3114 | */ |
3115 | static isl_stat test_pw_max(struct isl_ctx *ctx) |
3116 | { |
3117 | int i; |
3118 | isl_pw_multi_aff *pma; |
3119 | isl_multi_val *mv; |
3120 | isl_stat r; |
3121 | |
3122 | for (i = 0; i < ARRAY_SIZE(opt_pw_tests)(sizeof(opt_pw_tests)/sizeof(*opt_pw_tests)); ++i) { |
3123 | pma = isl_pw_multi_aff_read_from_str(ctx, opt_pw_tests[i].pma); |
3124 | mv = isl_pw_multi_aff_max_multi_val(pma); |
3125 | r = multi_val_check_plain_equal(mv, opt_pw_tests[i].res); |
3126 | isl_multi_val_free(mv); |
3127 | |
3128 | if (r < 0) |
3129 | return isl_stat_error; |
3130 | } |
3131 | |
3132 | return isl_stat_ok; |
3133 | } |
3134 | |
3135 | /* A specialized isl_set_min_val test case that would return the wrong result |
3136 | * in earlier versions of isl. |
3137 | * The explicit call to isl_basic_set_union prevents the second basic set |
3138 | * from being determined to be empty prior to the call to isl_set_min_val, |
3139 | * at least at the point where this test case was introduced. |
3140 | */ |
3141 | static int test_min_special(isl_ctx *ctx) |
3142 | { |
3143 | const char *str; |
3144 | isl_basic_setisl_basic_map *bset1, *bset2; |
3145 | isl_setisl_map *set; |
3146 | isl_aff *obj; |
3147 | isl_val *res; |
3148 | int ok; |
3149 | |
3150 | str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }"; |
3151 | bset1 = isl_basic_set_read_from_str(ctx, str); |
3152 | str = "{ [a, b] : 1 <= a, b and a + b <= 1 }"; |
3153 | bset2 = isl_basic_set_read_from_str(ctx, str); |
3154 | set = isl_basic_set_union(bset1, bset2); |
3155 | obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }"); |
3156 | |
3157 | res = isl_set_min_val(set, obj); |
3158 | ok = isl_val_cmp_si(res, 5) == 0; |
3159 | |
3160 | isl_aff_free(obj); |
3161 | isl_set_free(set); |
3162 | isl_val_free(res); |
3163 | |
3164 | if (!res) |
3165 | return -1; |
3166 | if (!ok) |
3167 | isl_die(ctx, isl_error_unknown, "unexpected minimum",do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum" , "polly/lib/External/isl/isl_test.c", 3168); return -1; } while (0) |
3168 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum" , "polly/lib/External/isl/isl_test.c", 3168); return -1; } while (0); |
3169 | |
3170 | return 0; |
3171 | } |
3172 | |
3173 | /* A specialized isl_set_min_val test case that would return an error |
3174 | * in earlier versions of isl. |
3175 | */ |
3176 | static int test_min_special2(isl_ctx *ctx) |
3177 | { |
3178 | const char *str; |
3179 | isl_basic_setisl_basic_map *bset; |
3180 | isl_aff *obj; |
3181 | isl_val *res; |
3182 | |
3183 | str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }"; |
3184 | bset = isl_basic_set_read_from_str(ctx, str); |
3185 | |
3186 | obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }"); |
3187 | |
3188 | res = isl_basic_set_max_val(bset, obj); |
3189 | |
3190 | isl_basic_set_free(bset); |
3191 | isl_aff_free(obj); |
3192 | isl_val_free(res); |
3193 | |
3194 | if (!res) |
3195 | return -1; |
3196 | |
3197 | return 0; |
3198 | } |
3199 | |
3200 | /* Check that the result of isl_set_min_multi_pw_aff |
3201 | * on the union of the sets with string descriptions "s1" and "s2" |
3202 | * consists of a single expression (on a single cell). |
3203 | */ |
3204 | static isl_stat check_single_expr_min(isl_ctx *ctx, const char *s1, |
3205 | const char *s2) |
3206 | { |
3207 | isl_size n; |
3208 | isl_setisl_map *set1, *set2; |
3209 | isl_multi_pw_aff *mpa; |
3210 | isl_pw_multi_aff *pma; |
3211 | |
3212 | set1 = isl_set_read_from_str(ctx, s1); |
3213 | set2 = isl_set_read_from_str(ctx, s2); |
3214 | set1 = isl_set_union(set1, set2); |
3215 | mpa = isl_set_min_multi_pw_aff(set1); |
3216 | pma = isl_pw_multi_aff_from_multi_pw_aff(mpa); |
3217 | n = isl_pw_multi_aff_n_piece(pma); |
3218 | isl_pw_multi_aff_free(pma); |
3219 | |
3220 | if (n < 0) |
3221 | return isl_stat_error; |
3222 | if (n != 1) |
3223 | isl_die(ctx, isl_error_unknown, "expecting single expression",do { isl_handle_error(ctx, isl_error_unknown, "expecting single expression" , "polly/lib/External/isl/isl_test.c", 3224); return isl_stat_error ; } while (0) |
3224 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "expecting single expression" , "polly/lib/External/isl/isl_test.c", 3224); return isl_stat_error ; } while (0); |
3225 | return isl_stat_ok; |
3226 | } |
3227 | |
3228 | /* A specialized isl_set_min_multi_pw_aff test that checks |
3229 | * that the minimum of 2N and 3N for N >= 0 is represented |
3230 | * by a single expression, without splitting off the special case N = 0. |
3231 | * Do this for both orderings. |
3232 | */ |
3233 | static int test_min_mpa(isl_ctx *ctx) |
3234 | { |
3235 | const char *s1, *s2; |
3236 | |
3237 | s1 = "[N=0:] -> { [1, 3N:] }"; |
3238 | s2 = "[N=0:] -> { [10, 2N:] }"; |
3239 | if (check_single_expr_min(ctx, s1, s2) < 0) |
3240 | return -1; |
3241 | if (check_single_expr_min(ctx, s2, s1) < 0) |
3242 | return -1; |
3243 | |
3244 | return 0; |
3245 | } |
3246 | |
3247 | struct { |
3248 | const char *set; |
3249 | const char *obj; |
3250 | __isl_give isl_val *(*fn)(__isl_keep isl_setisl_map *set, |
3251 | __isl_keep isl_aff *obj); |
3252 | const char *res; |
3253 | } opt_tests[] = { |
3254 | { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" }, |
3255 | { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" }, |
3256 | { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}", |
3257 | "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }", |
3258 | &isl_set_max_val, "30" }, |
3259 | |
3260 | }; |
3261 | |
3262 | /* Perform basic isl_set_min_val and isl_set_max_val tests. |
3263 | * In particular, check the results on non-convex inputs. |
3264 | */ |
3265 | static int test_min(struct isl_ctx *ctx) |
3266 | { |
3267 | int i; |
3268 | isl_setisl_map *set; |
3269 | isl_aff *obj; |
3270 | isl_val *val, *res; |
3271 | isl_bool ok; |
3272 | |
3273 | for (i = 0; i < ARRAY_SIZE(opt_tests)(sizeof(opt_tests)/sizeof(*opt_tests)); ++i) { |
3274 | set = isl_set_read_from_str(ctx, opt_tests[i].set); |
3275 | obj = isl_aff_read_from_str(ctx, opt_tests[i].obj); |
3276 | res = isl_val_read_from_str(ctx, opt_tests[i].res); |
3277 | val = opt_tests[i].fn(set, obj); |
3278 | ok = isl_val_eq(res, val); |
3279 | isl_val_free(res); |
3280 | isl_val_free(val); |
3281 | isl_aff_free(obj); |
3282 | isl_set_free(set); |
3283 | |
3284 | if (ok < 0) |
3285 | return -1; |
3286 | if (!ok) |
3287 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum" , "polly/lib/External/isl/isl_test.c", 3288); return -1; } while (0) |
3288 | "unexpected optimum", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum" , "polly/lib/External/isl/isl_test.c", 3288); return -1; } while (0); |
3289 | } |
3290 | |
3291 | if (test_pw_max(ctx) < 0) |
3292 | return -1; |
3293 | if (test_min_special(ctx) < 0) |
3294 | return -1; |
3295 | if (test_min_special2(ctx) < 0) |
3296 | return -1; |
3297 | |
3298 | return 0; |
3299 | } |
3300 | |
3301 | struct must_may { |
3302 | isl_map *must; |
3303 | isl_map *may; |
3304 | }; |
3305 | |
3306 | static isl_stat collect_must_may(__isl_take isl_map *dep, int must, |
3307 | void *dep_user, void *user) |
3308 | { |
3309 | struct must_may *mm = (struct must_may *)user; |
3310 | |
3311 | if (must) |
3312 | mm->must = isl_map_union(mm->must, dep); |
3313 | else |
3314 | mm->may = isl_map_union(mm->may, dep); |
3315 | |
3316 | return isl_stat_ok; |
3317 | } |
3318 | |
3319 | static int common_space(void *first, void *second) |
3320 | { |
3321 | int depth = *(int *)first; |
3322 | return 2 * depth; |
3323 | } |
3324 | |
3325 | static int map_is_equal(__isl_keep isl_map *map, const char *str) |
3326 | { |
3327 | isl_map *map2; |
3328 | int equal; |
3329 | |
3330 | if (!map) |
3331 | return -1; |
3332 | |
3333 | map2 = isl_map_read_from_str(map->ctx, str); |
3334 | equal = isl_map_is_equal(map, map2); |
3335 | isl_map_free(map2); |
3336 | |
3337 | return equal; |
3338 | } |
3339 | |
3340 | static int map_check_equal(__isl_keep isl_map *map, const char *str) |
3341 | { |
3342 | int equal; |
3343 | |
3344 | equal = map_is_equal(map, str); |
3345 | if (equal < 0) |
3346 | return -1; |
3347 | if (!equal) |
3348 | isl_die(isl_map_get_ctx(map), isl_error_unknown,do { isl_handle_error(isl_map_get_ctx(map), isl_error_unknown , "result not as expected", "polly/lib/External/isl/isl_test.c" , 3349); return -1; } while (0) |
3349 | "result not as expected", return -1)do { isl_handle_error(isl_map_get_ctx(map), isl_error_unknown , "result not as expected", "polly/lib/External/isl/isl_test.c" , 3349); return -1; } while (0); |
3350 | return 0; |
3351 | } |
3352 | |
3353 | /* Is "set" equal to the set described by "str"? |
3354 | */ |
3355 | static isl_bool set_is_equal(__isl_keep isl_setisl_map *set, const char *str) |
3356 | { |
3357 | isl_setisl_map *set2; |
3358 | isl_bool equal; |
3359 | |
3360 | if (!set) |
3361 | return isl_bool_error; |
3362 | |
3363 | set2 = isl_set_read_from_str(isl_set_get_ctx(set), str); |
3364 | equal = isl_set_is_equal(set, set2); |
3365 | isl_set_free(set2); |
3366 | |
3367 | return equal; |
3368 | } |
3369 | |
3370 | /* Check that "set" is equal to the set described by "str". |
3371 | */ |
3372 | static isl_stat set_check_equal(__isl_keep isl_setisl_map *set, const char *str) |
3373 | { |
3374 | isl_bool equal; |
3375 | |
3376 | equal = set_is_equal(set, str); |
3377 | if (equal < 0) |
3378 | return isl_stat_error; |
3379 | if (!equal) |
3380 | isl_die(isl_set_get_ctx(set), isl_error_unknown,do { isl_handle_error(isl_set_get_ctx(set), isl_error_unknown , "result not as expected", "polly/lib/External/isl/isl_test.c" , 3381); return isl_stat_error; } while (0) |
3381 | "result not as expected", return isl_stat_error)do { isl_handle_error(isl_set_get_ctx(set), isl_error_unknown , "result not as expected", "polly/lib/External/isl/isl_test.c" , 3381); return isl_stat_error; } while (0); |
3382 | return isl_stat_ok; |
3383 | } |
3384 | |
3385 | /* Is "uset" equal to the union set described by "str"? |
3386 | */ |
3387 | static isl_bool uset_is_equal(__isl_keep isl_union_set *uset, const char *str) |
3388 | { |
3389 | isl_union_set *uset2; |
3390 | isl_bool equal; |
3391 | |
3392 | if (!uset) |
3393 | return isl_bool_error; |
3394 | |
3395 | uset2 = isl_union_set_read_from_str(isl_union_set_get_ctx(uset), str); |
3396 | equal = isl_union_set_is_equal(uset, uset2); |
3397 | isl_union_set_free(uset2); |
3398 | |
3399 | return equal; |
3400 | } |
3401 | |
3402 | /* Check that "uset" is equal to the union set described by "str". |
3403 | */ |
3404 | static isl_stat uset_check_equal(__isl_keep isl_union_set *uset, |
3405 | const char *str) |
3406 | { |
3407 | isl_bool equal; |
3408 | |
3409 | equal = uset_is_equal(uset, str); |
3410 | if (equal < 0) |
3411 | return isl_stat_error; |
3412 | if (!equal) |
3413 | isl_die(isl_union_set_get_ctx(uset), isl_error_unknown,do { isl_handle_error(isl_union_set_get_ctx(uset), isl_error_unknown , "result not as expected", "polly/lib/External/isl/isl_test.c" , 3414); return isl_stat_error; } while (0) |
3414 | "result not as expected", return isl_stat_error)do { isl_handle_error(isl_union_set_get_ctx(uset), isl_error_unknown , "result not as expected", "polly/lib/External/isl/isl_test.c" , 3414); return isl_stat_error; } while (0); |
3415 | return isl_stat_ok; |
3416 | } |
3417 | |
3418 | static int test_dep(struct isl_ctx *ctx) |
3419 | { |
3420 | const char *str; |
3421 | isl_space *space; |
3422 | isl_map *map; |
3423 | isl_access_info *ai; |
3424 | isl_flow *flow; |
3425 | int depth; |
3426 | struct must_may mm; |
3427 | |
3428 | depth = 3; |
3429 | |
3430 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
3431 | map = isl_map_read_from_str(ctx, str); |
3432 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
3433 | |
3434 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
3435 | map = isl_map_read_from_str(ctx, str); |
3436 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
3437 | |
3438 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
3439 | map = isl_map_read_from_str(ctx, str); |
3440 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
3441 | |
3442 | flow = isl_access_info_compute_flow(ai); |
3443 | space = isl_space_alloc(ctx, 0, 3, 3); |
3444 | mm.must = isl_map_empty(isl_space_copy(space)); |
3445 | mm.may = isl_map_empty(space); |
3446 | |
3447 | isl_flow_foreach(flow, collect_must_may, &mm); |
3448 | |
3449 | str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); " |
3450 | " [1,10,0] -> [2,5,0] }"; |
3451 | assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)" , "polly/lib/External/isl/isl_test.c", 3451, __extension__ __PRETTY_FUNCTION__ ); })); |
3452 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
3453 | assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)" , "polly/lib/External/isl/isl_test.c", 3453, __extension__ __PRETTY_FUNCTION__ ); })); |
3454 | |
3455 | isl_map_free(mm.must); |
3456 | isl_map_free(mm.may); |
3457 | isl_flow_free(flow); |
3458 | |
3459 | |
3460 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
3461 | map = isl_map_read_from_str(ctx, str); |
3462 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
3463 | |
3464 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
3465 | map = isl_map_read_from_str(ctx, str); |
3466 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
3467 | |
3468 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
3469 | map = isl_map_read_from_str(ctx, str); |
3470 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3471 | |
3472 | flow = isl_access_info_compute_flow(ai); |
3473 | space = isl_space_alloc(ctx, 0, 3, 3); |
3474 | mm.must = isl_map_empty(isl_space_copy(space)); |
3475 | mm.may = isl_map_empty(space); |
3476 | |
3477 | isl_flow_foreach(flow, collect_must_may, &mm); |
3478 | |
3479 | str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }"; |
3480 | assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)" , "polly/lib/External/isl/isl_test.c", 3480, __extension__ __PRETTY_FUNCTION__ ); })); |
3481 | str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }"; |
3482 | assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)" , "polly/lib/External/isl/isl_test.c", 3482, __extension__ __PRETTY_FUNCTION__ ); })); |
3483 | |
3484 | isl_map_free(mm.must); |
3485 | isl_map_free(mm.may); |
3486 | isl_flow_free(flow); |
3487 | |
3488 | |
3489 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
3490 | map = isl_map_read_from_str(ctx, str); |
3491 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
3492 | |
3493 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
3494 | map = isl_map_read_from_str(ctx, str); |
3495 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3496 | |
3497 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
3498 | map = isl_map_read_from_str(ctx, str); |
3499 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3500 | |
3501 | flow = isl_access_info_compute_flow(ai); |
3502 | space = isl_space_alloc(ctx, 0, 3, 3); |
3503 | mm.must = isl_map_empty(isl_space_copy(space)); |
3504 | mm.may = isl_map_empty(space); |
3505 | |
3506 | isl_flow_foreach(flow, collect_must_may, &mm); |
3507 | |
3508 | str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; " |
3509 | " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }"; |
3510 | assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)" , "polly/lib/External/isl/isl_test.c", 3510, __extension__ __PRETTY_FUNCTION__ ); })); |
3511 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
3512 | assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)" , "polly/lib/External/isl/isl_test.c", 3512, __extension__ __PRETTY_FUNCTION__ ); })); |
3513 | |
3514 | isl_map_free(mm.must); |
3515 | isl_map_free(mm.may); |
3516 | isl_flow_free(flow); |
3517 | |
3518 | |
3519 | str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }"; |
3520 | map = isl_map_read_from_str(ctx, str); |
3521 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
3522 | |
3523 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
3524 | map = isl_map_read_from_str(ctx, str); |
3525 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3526 | |
3527 | str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }"; |
3528 | map = isl_map_read_from_str(ctx, str); |
3529 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3530 | |
3531 | flow = isl_access_info_compute_flow(ai); |
3532 | space = isl_space_alloc(ctx, 0, 3, 3); |
3533 | mm.must = isl_map_empty(isl_space_copy(space)); |
3534 | mm.may = isl_map_empty(space); |
3535 | |
3536 | isl_flow_foreach(flow, collect_must_may, &mm); |
3537 | |
3538 | str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; " |
3539 | " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }"; |
3540 | assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)" , "polly/lib/External/isl/isl_test.c", 3540, __extension__ __PRETTY_FUNCTION__ ); })); |
3541 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
3542 | assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)" , "polly/lib/External/isl/isl_test.c", 3542, __extension__ __PRETTY_FUNCTION__ ); })); |
3543 | |
3544 | isl_map_free(mm.must); |
3545 | isl_map_free(mm.may); |
3546 | isl_flow_free(flow); |
3547 | |
3548 | |
3549 | str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }"; |
3550 | map = isl_map_read_from_str(ctx, str); |
3551 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
3552 | |
3553 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
3554 | map = isl_map_read_from_str(ctx, str); |
3555 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3556 | |
3557 | str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }"; |
3558 | map = isl_map_read_from_str(ctx, str); |
3559 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3560 | |
3561 | flow = isl_access_info_compute_flow(ai); |
3562 | space = isl_space_alloc(ctx, 0, 3, 3); |
3563 | mm.must = isl_map_empty(isl_space_copy(space)); |
3564 | mm.may = isl_map_empty(space); |
3565 | |
3566 | isl_flow_foreach(flow, collect_must_may, &mm); |
3567 | |
3568 | str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; " |
3569 | " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }"; |
3570 | assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)" , "polly/lib/External/isl/isl_test.c", 3570, __extension__ __PRETTY_FUNCTION__ ); })); |
3571 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
3572 | assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)" , "polly/lib/External/isl/isl_test.c", 3572, __extension__ __PRETTY_FUNCTION__ ); })); |
3573 | |
3574 | isl_map_free(mm.must); |
3575 | isl_map_free(mm.may); |
3576 | isl_flow_free(flow); |
3577 | |
3578 | |
3579 | depth = 5; |
3580 | |
3581 | str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }"; |
3582 | map = isl_map_read_from_str(ctx, str); |
3583 | ai = isl_access_info_alloc(map, &depth, &common_space, 1); |
3584 | |
3585 | str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }"; |
3586 | map = isl_map_read_from_str(ctx, str); |
3587 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
3588 | |
3589 | flow = isl_access_info_compute_flow(ai); |
3590 | space = isl_space_alloc(ctx, 0, 5, 5); |
3591 | mm.must = isl_map_empty(isl_space_copy(space)); |
3592 | mm.may = isl_map_empty(space); |
3593 | |
3594 | isl_flow_foreach(flow, collect_must_may, &mm); |
3595 | |
3596 | str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }"; |
3597 | assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)" , "polly/lib/External/isl/isl_test.c", 3597, __extension__ __PRETTY_FUNCTION__ ); })); |
3598 | str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }"; |
3599 | assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__ ({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)" , "polly/lib/External/isl/isl_test.c", 3599, __extension__ __PRETTY_FUNCTION__ ); })); |
3600 | |
3601 | isl_map_free(mm.must); |
3602 | isl_map_free(mm.may); |
3603 | isl_flow_free(flow); |
3604 | |
3605 | return 0; |
3606 | } |
3607 | |
3608 | /* Check that the dependence analysis proceeds without errors. |
3609 | * Earlier versions of isl would break down during the analysis |
3610 | * due to the use of the wrong spaces. |
3611 | */ |
3612 | static int test_flow(isl_ctx *ctx) |
3613 | { |
3614 | const char *str; |
3615 | isl_union_map *access, *schedule; |
3616 | isl_union_map *must_dep, *may_dep; |
3617 | int r; |
3618 | |
3619 | str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }"; |
3620 | access = isl_union_map_read_from_str(ctx, str); |
3621 | str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; " |
3622 | "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; " |
3623 | "S2[] -> [1,0,0,0]; " |
3624 | "S3[] -> [-1,0,0,0] }"; |
3625 | schedule = isl_union_map_read_from_str(ctx, str); |
3626 | r = isl_union_map_compute_flow(access, isl_union_map_copy(access), |
3627 | isl_union_map_copy(access), schedule, |
3628 | &must_dep, &may_dep, NULL((void*)0), NULL((void*)0)); |
3629 | isl_union_map_free(may_dep); |
3630 | isl_union_map_free(must_dep); |
3631 | |
3632 | return r; |
3633 | } |
3634 | |
3635 | struct { |
3636 | const char *map; |
3637 | int sv; |
3638 | } sv_tests[] = { |
3639 | { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 }, |
3640 | { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 }, |
3641 | { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 }, |
3642 | { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 }, |
3643 | { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 }, |
3644 | { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 }, |
3645 | { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 }, |
3646 | { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 }, |
3647 | { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 }, |
3648 | }; |
3649 | |
3650 | int test_sv(isl_ctx *ctx) |
3651 | { |
3652 | isl_union_map *umap; |
3653 | int i; |
3654 | int sv; |
3655 | |
3656 | for (i = 0; i < ARRAY_SIZE(sv_tests)(sizeof(sv_tests)/sizeof(*sv_tests)); ++i) { |
3657 | umap = isl_union_map_read_from_str(ctx, sv_tests[i].map); |
3658 | sv = isl_union_map_is_single_valued(umap); |
3659 | isl_union_map_free(umap); |
3660 | if (sv < 0) |
3661 | return -1; |
3662 | if (sv_tests[i].sv && !sv) |
3663 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as single valued" , "polly/lib/External/isl/isl_test.c", 3664); return -1; } while (0) |
3664 | "map not detected as single valued", return -1)do { isl_handle_error(ctx, isl_error_internal, "map not detected as single valued" , "polly/lib/External/isl/isl_test.c", 3664); return -1; } while (0); |
3665 | if (!sv_tests[i].sv && sv) |
3666 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued" , "polly/lib/External/isl/isl_test.c", 3667); return -1; } while (0) |
3667 | "map detected as single valued", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued" , "polly/lib/External/isl/isl_test.c", 3667); return -1; } while (0); |
3668 | } |
3669 | |
3670 | return 0; |
3671 | } |
3672 | |
3673 | struct { |
3674 | const char *str; |
3675 | int bijective; |
3676 | } bijective_tests[] = { |
3677 | { "[N,M]->{[i,j] -> [i]}", 0 }, |
3678 | { "[N,M]->{[i,j] -> [i] : j=i}", 1 }, |
3679 | { "[N,M]->{[i,j] -> [i] : j=0}", 1 }, |
3680 | { "[N,M]->{[i,j] -> [i] : j=N}", 1 }, |
3681 | { "[N,M]->{[i,j] -> [j,i]}", 1 }, |
3682 | { "[N,M]->{[i,j] -> [i+j]}", 0 }, |
3683 | { "[N,M]->{[i,j] -> []}", 0 }, |
3684 | { "[N,M]->{[i,j] -> [i,j,N]}", 1 }, |
3685 | { "[N,M]->{[i,j] -> [2i]}", 0 }, |
3686 | { "[N,M]->{[i,j] -> [i,i]}", 0 }, |
3687 | { "[N,M]->{[i,j] -> [2i,i]}", 0 }, |
3688 | { "[N,M]->{[i,j] -> [2i,j]}", 1 }, |
3689 | { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 }, |
3690 | }; |
3691 | |
3692 | static int test_bijective(struct isl_ctx *ctx) |
3693 | { |
3694 | isl_map *map; |
3695 | int i; |
3696 | int bijective; |
3697 | |
3698 | for (i = 0; i < ARRAY_SIZE(bijective_tests)(sizeof(bijective_tests)/sizeof(*bijective_tests)); ++i) { |
3699 | map = isl_map_read_from_str(ctx, bijective_tests[i].str); |
3700 | bijective = isl_map_is_bijective(map); |
3701 | isl_map_free(map); |
3702 | if (bijective < 0) |
3703 | return -1; |
3704 | if (bijective_tests[i].bijective && !bijective) |
3705 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective" , "polly/lib/External/isl/isl_test.c", 3706); return -1; } while (0) |
3706 | "map not detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective" , "polly/lib/External/isl/isl_test.c", 3706); return -1; } while (0); |
3707 | if (!bijective_tests[i].bijective && bijective) |
3708 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective" , "polly/lib/External/isl/isl_test.c", 3709); return -1; } while (0) |
3709 | "map detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective" , "polly/lib/External/isl/isl_test.c", 3709); return -1; } while (0); |
3710 | } |
3711 | |
3712 | return 0; |
3713 | } |
3714 | |
3715 | /* Inputs for isl_pw_qpolynomial_gist tests. |
3716 | * "pwqp" is the input, "set" is the context and "gist" is the expected result. |
3717 | */ |
3718 | struct { |
3719 | const char *pwqp; |
3720 | const char *set; |
3721 | const char *gist; |
3722 | } pwqp_gist_tests[] = { |
3723 | { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" }, |
3724 | { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" }, |
3725 | { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }", |
3726 | "{ [i] -> -1/2 + 1/2 * i }" }, |
3727 | { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" }, |
3728 | }; |
3729 | |
3730 | /* Perform some basic isl_pw_qpolynomial_gist tests. |
3731 | */ |
3732 | static isl_stat test_pwqp_gist(isl_ctx *ctx) |
3733 | { |
3734 | int i; |
3735 | const char *str; |
3736 | isl_setisl_map *set; |
3737 | isl_pw_qpolynomial *pwqp1, *pwqp2; |
3738 | isl_bool equal; |
3739 | |
3740 | for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests)(sizeof(pwqp_gist_tests)/sizeof(*pwqp_gist_tests)); ++i) { |
3741 | str = pwqp_gist_tests[i].pwqp; |
3742 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3743 | str = pwqp_gist_tests[i].set; |
3744 | set = isl_set_read_from_str(ctx, str); |
3745 | pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set); |
3746 | str = pwqp_gist_tests[i].gist; |
3747 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3748 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3749 | equal = isl_pw_qpolynomial_is_zero(pwqp1); |
3750 | isl_pw_qpolynomial_free(pwqp1); |
3751 | |
3752 | if (equal < 0) |
3753 | return isl_stat_error; |
3754 | if (!equal) |
3755 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 3756); return isl_stat_error ; } while (0) |
3756 | "unexpected result", return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 3756); return isl_stat_error ; } while (0); |
3757 | } |
3758 | |
3759 | return isl_stat_ok; |
3760 | } |
3761 | |
3762 | /* Perform a basic isl_pw_qpolynomial_max test. |
3763 | */ |
3764 | static isl_stat test_pwqp_max(isl_ctx *ctx) |
3765 | { |
3766 | const char *str; |
3767 | isl_pw_qpolynomial *pwqp; |
3768 | isl_val *v; |
3769 | int ok; |
3770 | |
3771 | str = "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }"; |
3772 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3773 | v = isl_pw_qpolynomial_max(pwqp); |
3774 | ok = isl_val_cmp_si(v, -1) == 0; |
3775 | isl_val_free(v); |
3776 | |
3777 | if (!v) |
3778 | return isl_stat_error; |
3779 | if (!ok) |
3780 | isl_die(ctx, isl_error_unknown, "unexpected maximum",do { isl_handle_error(ctx, isl_error_unknown, "unexpected maximum" , "polly/lib/External/isl/isl_test.c", 3781); return isl_stat_error ; } while (0) |
3781 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "unexpected maximum" , "polly/lib/External/isl/isl_test.c", 3781); return isl_stat_error ; } while (0); |
3782 | |
3783 | return isl_stat_ok; |
3784 | } |
3785 | |
3786 | static int test_pwqp(struct isl_ctx *ctx) |
3787 | { |
3788 | const char *str; |
3789 | isl_setisl_map *set; |
3790 | isl_pw_qpolynomial *pwqp1, *pwqp2; |
3791 | int equal; |
3792 | |
3793 | str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }"; |
3794 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3795 | |
3796 | pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0, |
3797 | isl_dim_in, 1, 1); |
3798 | |
3799 | str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }"; |
3800 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3801 | |
3802 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3803 | |
3804 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0), __extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "polly/lib/External/isl/isl_test.c" , 3804, __extension__ __PRETTY_FUNCTION__); })); |
3805 | |
3806 | isl_pw_qpolynomial_free(pwqp1); |
3807 | |
3808 | if (test_pwqp_gist(ctx) < 0) |
3809 | return -1; |
3810 | |
3811 | str = "{ [i] -> ([([i/2] + [i/2])/5]) }"; |
3812 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3813 | str = "{ [i] -> ([(2 * [i/2])/5]) }"; |
3814 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3815 | |
3816 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3817 | |
3818 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0), __extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "polly/lib/External/isl/isl_test.c" , 3818, __extension__ __PRETTY_FUNCTION__); })); |
3819 | |
3820 | isl_pw_qpolynomial_free(pwqp1); |
3821 | |
3822 | str = "{ [x] -> ([x/2] + [(x+1)/2]) }"; |
3823 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3824 | str = "{ [x] -> x }"; |
3825 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3826 | |
3827 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3828 | |
3829 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0), __extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "polly/lib/External/isl/isl_test.c" , 3829, __extension__ __PRETTY_FUNCTION__); })); |
3830 | |
3831 | isl_pw_qpolynomial_free(pwqp1); |
3832 | |
3833 | str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }"; |
3834 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3835 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3836 | pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1); |
3837 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3838 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0), __extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "polly/lib/External/isl/isl_test.c" , 3838, __extension__ __PRETTY_FUNCTION__); })); |
3839 | isl_pw_qpolynomial_free(pwqp1); |
3840 | |
3841 | str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }"; |
3842 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3843 | str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }"; |
3844 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3845 | set = isl_set_read_from_str(ctx, "{ [a,b,a] }"); |
3846 | pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set); |
3847 | equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2); |
3848 | isl_pw_qpolynomial_free(pwqp1); |
3849 | isl_pw_qpolynomial_free(pwqp2); |
3850 | if (equal < 0) |
3851 | return -1; |
3852 | if (!equal) |
3853 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 3853); return -1; } while (0); |
3854 | |
3855 | str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }"; |
3856 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3857 | str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }"; |
3858 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3859 | pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1, |
3860 | isl_val_one(ctx)); |
3861 | equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2); |
3862 | isl_pw_qpolynomial_free(pwqp1); |
3863 | isl_pw_qpolynomial_free(pwqp2); |
3864 | if (equal < 0) |
3865 | return -1; |
3866 | if (!equal) |
3867 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 3867); return -1; } while (0); |
3868 | |
3869 | if (test_pwqp_max(ctx) < 0) |
3870 | return -1; |
3871 | |
3872 | return 0; |
3873 | } |
3874 | |
3875 | static int test_split_periods(isl_ctx *ctx) |
3876 | { |
3877 | const char *str; |
3878 | isl_pw_qpolynomial *pwqp; |
3879 | |
3880 | str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : " |
3881 | "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and " |
3882 | "U >= 0; [U,V] -> U^2 : U >= 100 }"; |
3883 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3884 | |
3885 | pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2); |
3886 | |
3887 | isl_pw_qpolynomial_free(pwqp); |
3888 | |
3889 | if (!pwqp) |
3890 | return -1; |
3891 | |
3892 | return 0; |
3893 | } |
3894 | |
3895 | static int test_union(isl_ctx *ctx) |
3896 | { |
3897 | const char *str; |
3898 | isl_union_set *uset1, *uset2; |
3899 | isl_union_map *umap1, *umap2; |
3900 | int equal; |
3901 | |
3902 | str = "{ [i] : 0 <= i <= 1 }"; |
3903 | uset1 = isl_union_set_read_from_str(ctx, str); |
3904 | str = "{ [1] -> [0] }"; |
3905 | umap1 = isl_union_map_read_from_str(ctx, str); |
3906 | |
3907 | umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1); |
3908 | equal = isl_union_map_is_equal(umap1, umap2); |
3909 | |
3910 | isl_union_map_free(umap1); |
3911 | isl_union_map_free(umap2); |
3912 | |
3913 | if (equal < 0) |
3914 | return -1; |
3915 | if (!equal) |
3916 | isl_die(ctx, isl_error_unknown, "union maps not equal",do { isl_handle_error(ctx, isl_error_unknown, "union maps not equal" , "polly/lib/External/isl/isl_test.c", 3917); return -1; } while (0) |
3917 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "union maps not equal" , "polly/lib/External/isl/isl_test.c", 3917); return -1; } while (0); |
3918 | |
3919 | str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }"; |
3920 | umap1 = isl_union_map_read_from_str(ctx, str); |
3921 | str = "{ A[i]; B[i] }"; |
3922 | uset1 = isl_union_set_read_from_str(ctx, str); |
3923 | |
3924 | uset2 = isl_union_map_domain(umap1); |
3925 | |
3926 | equal = isl_union_set_is_equal(uset1, uset2); |
3927 | |
3928 | isl_union_set_free(uset1); |
3929 | isl_union_set_free(uset2); |
3930 | |
3931 | if (equal < 0) |
3932 | return -1; |
3933 | if (!equal) |
3934 | isl_die(ctx, isl_error_unknown, "union sets not equal",do { isl_handle_error(ctx, isl_error_unknown, "union sets not equal" , "polly/lib/External/isl/isl_test.c", 3935); return -1; } while (0) |
3935 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "union sets not equal" , "polly/lib/External/isl/isl_test.c", 3935); return -1; } while (0); |
3936 | |
3937 | return 0; |
3938 | } |
3939 | |
3940 | /* Inputs for basic isl_pw_qpolynomial_bound tests. |
3941 | * "type" is the type of bound that should be computed. |
3942 | * "poly" is a string representation of the input. |
3943 | * "bound" is a string representation of the expected result. |
3944 | * "tight" is set if the result is expected to be tight. |
3945 | */ |
3946 | static struct { |
3947 | int tight; |
3948 | enum isl_fold type; |
3949 | const char *poly; |
3950 | const char *bound; |
3951 | } bound_tests[] = { |
3952 | /* Check that computing a bound of a non-zero polynomial |
3953 | * over an unbounded domain does not produce a rational value. |
3954 | * In particular, check that the upper bound is infinity. |
3955 | */ |
3956 | { 0, isl_fold_max, "{ [m, n] -> -m * n }", "{ max(infty) }" }, |
3957 | { 1, isl_fold_max, "{ [[a, b, c, d] -> [e]] -> 0 }", |
3958 | "{ [a, b, c, d] -> max(0) }" }, |
3959 | { 1, isl_fold_max, "{ [[x] -> [x]] -> 1 : exists a : x = 2 a }", |
3960 | "{ [x] -> max(1) : x mod 2 = 0 }" }, |
3961 | { 1, isl_fold_min, "{ [x=5:10] -> (x + 2)^2 }", "{ min(49) }" }, |
3962 | { 1, isl_fold_max, "{ [0:10] -> 1 }", "{ max(1) }" }, |
3963 | { 1, isl_fold_max, "{ [[m] -> [0:m]] -> m^2 }", |
3964 | "{ [m] -> max(m^2) : m >= 0 }" }, |
3965 | }; |
3966 | |
3967 | /* Check that the bound computation can handle differences |
3968 | * in domain dimension names of the input polynomial and its domain. |
3969 | */ |
3970 | static isl_stat test_bound_space(isl_ctx *ctx) |
3971 | { |
3972 | const char *str; |
3973 | isl_setisl_map *set; |
3974 | isl_pw_qpolynomial *pwqp; |
3975 | isl_pw_qpolynomial_fold *pwf; |
3976 | |
3977 | str = "{ [[c] -> [c]] }"; |
3978 | set = isl_set_read_from_str(ctx, str); |
3979 | str = "{ [[a] -> [b]] -> 1 }"; |
3980 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3981 | pwqp = isl_pw_qpolynomial_intersect_domain(pwqp, set); |
3982 | pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3983 | isl_pw_qpolynomial_fold_free(pwf); |
3984 | |
3985 | return isl_stat_non_null(pwf); |
3986 | } |
3987 | |
3988 | /* Perform basic isl_pw_qpolynomial_bound tests. |
3989 | */ |
3990 | static int test_bound(isl_ctx *ctx) |
3991 | { |
3992 | int i; |
3993 | |
3994 | if (test_bound_space(ctx) < 0) |
3995 | return -1; |
3996 | |
3997 | for (i = 0; i < ARRAY_SIZE(bound_tests)(sizeof(bound_tests)/sizeof(*bound_tests)); ++i) { |
3998 | const char *str; |
3999 | enum isl_fold type; |
4000 | isl_bool equal, tight; |
4001 | isl_pw_qpolynomial *pwqp; |
4002 | isl_pw_qpolynomial_fold *pwf1, *pwf2; |
4003 | |
4004 | str = bound_tests[i].poly; |
4005 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
4006 | type = bound_tests[i].type; |
4007 | pwf1 = isl_pw_qpolynomial_bound(pwqp, type, &tight); |
4008 | str = bound_tests[i].bound; |
4009 | pwf2 = isl_pw_qpolynomial_fold_read_from_str(ctx, str); |
4010 | equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf1, pwf2); |
4011 | isl_pw_qpolynomial_fold_free(pwf2); |
4012 | isl_pw_qpolynomial_fold_free(pwf1); |
4013 | if (equal < 0) |
4014 | return -1; |
4015 | if (!equal) |
4016 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect bound result" , "polly/lib/External/isl/isl_test.c", 4017); return -1; } while (0) |
4017 | "incorrect bound result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect bound result" , "polly/lib/External/isl/isl_test.c", 4017); return -1; } while (0); |
4018 | if (bound_tests[i].tight && !tight) |
4019 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "bound unexpectedly not tight" , "polly/lib/External/isl/isl_test.c", 4020); return -1; } while (0) |
4020 | "bound unexpectedly not tight", return -1)do { isl_handle_error(ctx, isl_error_unknown, "bound unexpectedly not tight" , "polly/lib/External/isl/isl_test.c", 4020); return -1; } while (0); |
4021 | } |
4022 | |
4023 | return 0; |
4024 | } |
4025 | |
4026 | /* isl_set is defined to isl_map internally, so the corresponding elements |
4027 | * are isl_basic_map objects. |
4028 | */ |
4029 | #undef EL_BASEmap |
4030 | #undef SET_BASEunion_map |
4031 | #define EL_BASEmap basic_map |
4032 | #define SET_BASEunion_map set |
4033 | #include "isl_test_list_templ.c" |
4034 | |
4035 | #undef EL_BASEmap |
4036 | #undef SET_BASEunion_map |
4037 | #define EL_BASEmap basic_set |
4038 | #define SET_BASEunion_map union_set |
4039 | #include "isl_test_list_templ.c" |
4040 | |
4041 | #undef EL_BASEmap |
4042 | #undef SET_BASEunion_map |
4043 | #define EL_BASEmap set |
4044 | #define SET_BASEunion_map union_set |
4045 | #include "isl_test_list_templ.c" |
4046 | |
4047 | #undef EL_BASEmap |
4048 | #undef SET_BASEunion_map |
4049 | #define EL_BASEmap basic_map |
4050 | #define SET_BASEunion_map map |
4051 | #include "isl_test_list_templ.c" |
4052 | |
4053 | #undef EL_BASEmap |
4054 | #undef SET_BASEunion_map |
4055 | #define EL_BASEmap map |
4056 | #define SET_BASEunion_map union_map |
4057 | #include "isl_test_list_templ.c" |
4058 | |
4059 | /* Check that the conversion from isl objects to lists works as expected. |
4060 | */ |
4061 | static int test_get_list(isl_ctx *ctx) |
4062 | { |
4063 | if (test_get_list_basic_map_from_set(ctx, "{ [0]; [2]; [3] }")) |
4064 | return -1; |
4065 | if (test_get_list_basic_set_from_union_set(ctx, "{ A[0]; B[2]; B[3] }")) |
4066 | return -1; |
4067 | if (test_get_list_set_from_union_set(ctx, "{ A[0]; A[2]; B[3] }")) |
4068 | return -1; |
4069 | if (test_get_list_basic_map_from_map(ctx, |
4070 | "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }")) |
4071 | return -1; |
4072 | if (test_get_list_map_from_union_map(ctx, |
4073 | "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }")) |
4074 | return -1; |
4075 | |
4076 | return 0; |
4077 | } |
4078 | |
4079 | static int test_lift(isl_ctx *ctx) |
4080 | { |
4081 | const char *str; |
4082 | isl_basic_map *bmap; |
4083 | isl_basic_setisl_basic_map *bset; |
4084 | |
4085 | str = "{ [i0] : exists e0 : i0 = 4e0 }"; |
4086 | bset = isl_basic_set_read_from_str(ctx, str); |
4087 | bset = isl_basic_set_lift(bset); |
4088 | bmap = isl_basic_map_from_range(bset); |
4089 | bset = isl_basic_map_domain(bmap); |
4090 | isl_basic_set_free(bset); |
4091 | |
4092 | return 0; |
4093 | } |
4094 | |
4095 | /* Check that isl_set_is_subset is not confused by identical |
4096 | * integer divisions. |
4097 | * The call to isl_set_normalize ensures that the equality constraints |
4098 | * a = b = 0 are discovered, turning e0 and e1 into identical |
4099 | * integer divisions. Any further simplification would remove |
4100 | * the duplicate integer divisions. |
4101 | */ |
4102 | static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx) |
4103 | { |
4104 | const char *str; |
4105 | isl_bool is_subset; |
4106 | isl_setisl_map *set1, *set2; |
4107 | |
4108 | str = "{ [a, b, c, d] : " |
4109 | "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), " |
4110 | "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), " |
4111 | "e3 = floor((-d + 4*floor((d)/4))/10): " |
4112 | "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and " |
4113 | "b >= 0 and a <= 0 and b <= a) }"; |
4114 | set1 = isl_set_read_from_str(ctx, str); |
4115 | set2 = isl_set_read_from_str(ctx, str); |
4116 | set2 = isl_set_normalize(set2); |
4117 | |
4118 | is_subset = isl_set_is_subset(set1, set2); |
4119 | |
4120 | isl_set_free(set1); |
4121 | isl_set_free(set2); |
4122 | |
4123 | if (is_subset < 0) |
4124 | return isl_stat_error; |
4125 | if (!is_subset) |
4126 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set is not considered to be a subset of itself" , "polly/lib/External/isl/isl_test.c", 4128); return isl_stat_error ; } while (0) |
4127 | "set is not considered to be a subset of itself",do { isl_handle_error(ctx, isl_error_unknown, "set is not considered to be a subset of itself" , "polly/lib/External/isl/isl_test.c", 4128); return isl_stat_error ; } while (0) |
4128 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "set is not considered to be a subset of itself" , "polly/lib/External/isl/isl_test.c", 4128); return isl_stat_error ; } while (0); |
4129 | |
4130 | return isl_stat_ok; |
4131 | } |
4132 | |
4133 | struct { |
4134 | const char *set1; |
4135 | const char *set2; |
4136 | int subset; |
4137 | } subset_tests[] = { |
4138 | { "{ [112, 0] }", |
4139 | "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: " |
4140 | "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and " |
4141 | "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 }, |
4142 | { "{ [65] }", |
4143 | "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], " |
4144 | "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], " |
4145 | "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: " |
4146 | "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and " |
4147 | "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and " |
4148 | "256e0 <= 255i and 256e0 >= -255 + 255i and " |
4149 | "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and " |
4150 | "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and " |
4151 | "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 }, |
4152 | { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 }, |
4153 | { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 }, |
4154 | { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 }, |
4155 | { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 }, |
4156 | { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and " |
4157 | "4e0 >= -1 + t and i >= 57 and i <= 62 and " |
4158 | "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and " |
4159 | "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and " |
4160 | "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }", |
4161 | "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and " |
4162 | "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and " |
4163 | "4e0 <= -57 + i0 + i1)) or " |
4164 | "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and " |
4165 | "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and " |
4166 | "4e0 >= -61 + i0 + i1)) or " |
4167 | "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 }, |
4168 | { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 }, |
4169 | }; |
4170 | |
4171 | static int test_subset(isl_ctx *ctx) |
4172 | { |
4173 | int i; |
4174 | isl_setisl_map *set1, *set2; |
4175 | int subset; |
4176 | |
4177 | if (test_subset_duplicate_integer_divisions(ctx) < 0) |
4178 | return -1; |
4179 | |
4180 | for (i = 0; i < ARRAY_SIZE(subset_tests)(sizeof(subset_tests)/sizeof(*subset_tests)); ++i) { |
4181 | set1 = isl_set_read_from_str(ctx, subset_tests[i].set1); |
4182 | set2 = isl_set_read_from_str(ctx, subset_tests[i].set2); |
4183 | subset = isl_set_is_subset(set1, set2); |
4184 | isl_set_free(set1); |
4185 | isl_set_free(set2); |
4186 | if (subset < 0) |
4187 | return -1; |
4188 | if (subset != subset_tests[i].subset) |
4189 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result" , "polly/lib/External/isl/isl_test.c", 4190); return -1; } while (0) |
4190 | "incorrect subset result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result" , "polly/lib/External/isl/isl_test.c", 4190); return -1; } while (0); |
4191 | } |
4192 | |
4193 | return 0; |
4194 | } |
4195 | |
4196 | /* Perform a set subtraction with a set that has a non-obviously empty disjunct. |
4197 | * Older versions of isl would fail on such cases. |
4198 | */ |
4199 | static isl_stat test_subtract_empty(isl_ctx *ctx) |
4200 | { |
4201 | const char *str; |
4202 | isl_setisl_map *s1, *s2; |
4203 | |
4204 | s1 = isl_set_read_from_str(ctx, "{ [0] }"); |
4205 | str = "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and " |
4206 | "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and " |
4207 | "33e2 >= -a + 33e0 + 1056e1 and " |
4208 | "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }"; |
4209 | s2 = isl_set_read_from_str(ctx, str); |
4210 | s1 = isl_set_subtract(s1, s2); |
4211 | isl_set_free(s1); |
4212 | |
4213 | return isl_stat_non_null(s1); |
4214 | } |
4215 | |
4216 | struct { |
4217 | const char *minuend; |
4218 | const char *subtrahend; |
4219 | const char *difference; |
4220 | } subtract_domain_tests[] = { |
4221 | { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" }, |
4222 | { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" }, |
4223 | { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" }, |
4224 | }; |
4225 | |
4226 | static int test_subtract(isl_ctx *ctx) |
4227 | { |
4228 | int i; |
4229 | isl_union_map *umap1, *umap2; |
4230 | isl_union_pw_multi_aff *upma1, *upma2; |
4231 | isl_union_set *uset; |
4232 | int equal; |
4233 | |
4234 | if (test_subtract_empty(ctx) < 0) |
4235 | return -1; |
4236 | |
4237 | for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests) ); ++i) { |
4238 | umap1 = isl_union_map_read_from_str(ctx, |
4239 | subtract_domain_tests[i].minuend); |
4240 | uset = isl_union_set_read_from_str(ctx, |
4241 | subtract_domain_tests[i].subtrahend); |
4242 | umap2 = isl_union_map_read_from_str(ctx, |
4243 | subtract_domain_tests[i].difference); |
4244 | umap1 = isl_union_map_subtract_domain(umap1, uset); |
4245 | equal = isl_union_map_is_equal(umap1, umap2); |
4246 | isl_union_map_free(umap1); |
4247 | isl_union_map_free(umap2); |
4248 | if (equal < 0) |
4249 | return -1; |
4250 | if (!equal) |
4251 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "polly/lib/External/isl/isl_test.c", 4252); return -1; } while (0) |
4252 | "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "polly/lib/External/isl/isl_test.c", 4252); return -1; } while (0); |
4253 | } |
4254 | |
4255 | for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests) ); ++i) { |
4256 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
4257 | subtract_domain_tests[i].minuend); |
4258 | uset = isl_union_set_read_from_str(ctx, |
4259 | subtract_domain_tests[i].subtrahend); |
4260 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
4261 | subtract_domain_tests[i].difference); |
4262 | upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset); |
4263 | equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2); |
4264 | isl_union_pw_multi_aff_free(upma1); |
4265 | isl_union_pw_multi_aff_free(upma2); |
4266 | if (equal < 0) |
4267 | return -1; |
4268 | if (!equal) |
4269 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "polly/lib/External/isl/isl_test.c", 4270); return -1; } while (0) |
4270 | "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "polly/lib/External/isl/isl_test.c", 4270); return -1; } while (0); |
4271 | } |
4272 | |
4273 | return 0; |
4274 | } |
4275 | |
4276 | /* Check that intersecting the empty basic set with another basic set |
4277 | * does not increase the number of constraints. In particular, |
4278 | * the empty basic set should maintain its canonical representation. |
4279 | */ |
4280 | static int test_intersect_1(isl_ctx *ctx) |
4281 | { |
4282 | isl_size n1, n2; |
4283 | isl_basic_setisl_basic_map *bset1, *bset2; |
4284 | |
4285 | bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }"); |
4286 | bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }"); |
4287 | n1 = isl_basic_set_n_constraint(bset1); |
4288 | bset1 = isl_basic_set_intersect(bset1, bset2); |
4289 | n2 = isl_basic_set_n_constraint(bset1); |
4290 | isl_basic_set_free(bset1); |
4291 | if (n1 < 0 || n2 < 0) |
4292 | return -1; |
4293 | if (n1 != n2) |
4294 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "polly/lib/External/isl/isl_test.c", 4296); return -1; } while (0) |
4295 | "number of constraints of empty set changed",do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "polly/lib/External/isl/isl_test.c", 4296); return -1; } while (0) |
4296 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "polly/lib/External/isl/isl_test.c", 4296); return -1; } while (0); |
4297 | |
4298 | return 0; |
4299 | } |
4300 | |
4301 | /* Check that intersecting a set with itself does not cause |
4302 | * an explosion in the number of disjuncts. |
4303 | */ |
4304 | static isl_stat test_intersect_2(isl_ctx *ctx) |
4305 | { |
4306 | int i; |
4307 | isl_setisl_map *set; |
4308 | |
4309 | set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }"); |
4310 | for (i = 0; i < 100; ++i) |
4311 | set = isl_set_intersect(set, isl_set_copy(set)); |
4312 | isl_set_free(set); |
4313 | if (!set) |
4314 | return isl_stat_error; |
4315 | return isl_stat_ok; |
4316 | } |
4317 | |
4318 | /* Perform some intersection tests. |
4319 | */ |
4320 | static int test_intersect(isl_ctx *ctx) |
4321 | { |
4322 | if (test_intersect_1(ctx) < 0) |
4323 | return -1; |
4324 | if (test_intersect_2(ctx) < 0) |
4325 | return -1; |
4326 | |
4327 | return 0; |
4328 | } |
4329 | |
4330 | int test_factorize(isl_ctx *ctx) |
4331 | { |
4332 | const char *str; |
4333 | isl_basic_setisl_basic_map *bset; |
4334 | isl_factorizer *f; |
4335 | |
4336 | str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and " |
4337 | "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and " |
4338 | "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and " |
4339 | "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and " |
4340 | "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and " |
4341 | "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and " |
4342 | "3i5 >= -2i0 - i2 + 3i4 }"; |
4343 | bset = isl_basic_set_read_from_str(ctx, str); |
4344 | f = isl_basic_set_factorizer(bset); |
4345 | isl_basic_set_free(bset); |
4346 | isl_factorizer_free(f); |
4347 | if (!f) |
4348 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "polly/lib/External/isl/isl_test.c", 4349); return -1; } while (0) |
4349 | "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "polly/lib/External/isl/isl_test.c", 4349); return -1; } while (0); |
4350 | |
4351 | str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : " |
4352 | "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and " |
4353 | "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and " |
4354 | "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and " |
4355 | "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and " |
4356 | "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and " |
4357 | "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and " |
4358 | "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and " |
4359 | "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and " |
4360 | "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }"; |
4361 | bset = isl_basic_set_read_from_str(ctx, str); |
4362 | f = isl_basic_set_factorizer(bset); |
4363 | isl_basic_set_free(bset); |
4364 | isl_factorizer_free(f); |
4365 | if (!f) |
4366 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "polly/lib/External/isl/isl_test.c", 4367); return -1; } while (0) |
4367 | "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "polly/lib/External/isl/isl_test.c", 4367); return -1; } while (0); |
4368 | |
4369 | return 0; |
4370 | } |
4371 | |
4372 | static isl_stat check_injective(__isl_take isl_map *map, void *user) |
4373 | { |
4374 | int *injective = user; |
4375 | |
4376 | *injective = isl_map_is_injective(map); |
4377 | isl_map_free(map); |
4378 | |
4379 | if (*injective < 0 || !*injective) |
4380 | return isl_stat_error; |
4381 | |
4382 | return isl_stat_ok; |
4383 | } |
4384 | |
4385 | int test_one_schedule(isl_ctx *ctx, const char *d, const char *w, |
4386 | const char *r, const char *s, int tilable, int parallel) |
4387 | { |
4388 | int i; |
4389 | isl_union_set *D; |
4390 | isl_union_map *W, *R, *S; |
4391 | isl_union_map *empty; |
4392 | isl_union_map *dep_raw, *dep_war, *dep_waw, *dep; |
4393 | isl_union_map *validity, *proximity, *coincidence; |
4394 | isl_union_map *schedule; |
4395 | isl_union_map *test; |
4396 | isl_union_set *delta; |
4397 | isl_union_set *domain; |
4398 | isl_setisl_map *delta_set; |
4399 | isl_setisl_map *slice; |
4400 | isl_setisl_map *origin; |
4401 | isl_schedule_constraints *sc; |
4402 | isl_schedule *sched; |
4403 | int is_nonneg, is_parallel, is_tilable, is_injection, is_complete; |
4404 | isl_size n; |
4405 | |
4406 | D = isl_union_set_read_from_str(ctx, d); |
4407 | W = isl_union_map_read_from_str(ctx, w); |
4408 | R = isl_union_map_read_from_str(ctx, r); |
4409 | S = isl_union_map_read_from_str(ctx, s); |
4410 | |
4411 | W = isl_union_map_intersect_domain(W, isl_union_set_copy(D)); |
4412 | R = isl_union_map_intersect_domain(R, isl_union_set_copy(D)); |
4413 | |
4414 | empty = isl_union_map_empty(isl_union_map_get_space(S)); |
4415 | isl_union_map_compute_flow(isl_union_map_copy(R), |
4416 | isl_union_map_copy(W), empty, |
4417 | isl_union_map_copy(S), |
4418 | &dep_raw, NULL((void*)0), NULL((void*)0), NULL((void*)0)); |
4419 | isl_union_map_compute_flow(isl_union_map_copy(W), |
4420 | isl_union_map_copy(W), |
4421 | isl_union_map_copy(R), |
4422 | isl_union_map_copy(S), |
4423 | &dep_waw, &dep_war, NULL((void*)0), NULL((void*)0)); |
4424 | |
4425 | dep = isl_union_map_union(dep_waw, dep_war); |
4426 | dep = isl_union_map_union(dep, dep_raw); |
4427 | validity = isl_union_map_copy(dep); |
4428 | coincidence = isl_union_map_copy(dep); |
4429 | proximity = isl_union_map_copy(dep); |
4430 | |
4431 | sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D)); |
4432 | sc = isl_schedule_constraints_set_validity(sc, validity); |
4433 | sc = isl_schedule_constraints_set_coincidence(sc, coincidence); |
4434 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
4435 | sched = isl_schedule_constraints_compute_schedule(sc); |
4436 | schedule = isl_schedule_get_map(sched); |
4437 | isl_schedule_free(sched); |
4438 | isl_union_map_free(W); |
4439 | isl_union_map_free(R); |
4440 | isl_union_map_free(S); |
4441 | |
4442 | is_injection = 1; |
4443 | isl_union_map_foreach_map(schedule, &check_injective, &is_injection); |
4444 | |
4445 | domain = isl_union_map_domain(isl_union_map_copy(schedule)); |
4446 | is_complete = isl_union_set_is_subset(D, domain); |
4447 | isl_union_set_free(D); |
4448 | isl_union_set_free(domain); |
4449 | |
4450 | test = isl_union_map_reverse(isl_union_map_copy(schedule)); |
4451 | test = isl_union_map_apply_range(test, dep); |
4452 | test = isl_union_map_apply_range(test, schedule); |
4453 | |
4454 | delta = isl_union_map_deltas(test); |
4455 | n = isl_union_set_n_set(delta); |
4456 | if (n < 0) { |
4457 | isl_union_set_free(delta); |
4458 | return -1; |
4459 | } |
4460 | if (n == 0) { |
4461 | is_tilable = 1; |
4462 | is_parallel = 1; |
4463 | is_nonneg = 1; |
4464 | isl_union_set_free(delta); |
4465 | } else { |
4466 | isl_size dim; |
4467 | |
4468 | delta_set = isl_set_from_union_set(delta); |
4469 | |
4470 | slice = isl_set_universe(isl_set_get_space(delta_set)); |
4471 | for (i = 0; i < tilable; ++i) |
4472 | slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0); |
4473 | is_tilable = isl_set_is_subset(delta_set, slice); |
4474 | isl_set_free(slice); |
4475 | |
4476 | slice = isl_set_universe(isl_set_get_space(delta_set)); |
4477 | for (i = 0; i < parallel; ++i) |
4478 | slice = isl_set_fix_si(slice, isl_dim_set, i, 0); |
4479 | is_parallel = isl_set_is_subset(delta_set, slice); |
4480 | isl_set_free(slice); |
4481 | |
4482 | origin = isl_set_universe(isl_set_get_space(delta_set)); |
4483 | dim = isl_set_dim(origin, isl_dim_set); |
4484 | if (dim < 0) |
4485 | origin = isl_set_free(origin); |
4486 | for (i = 0; i < dim; ++i) |
4487 | origin = isl_set_fix_si(origin, isl_dim_set, i, 0); |
4488 | |
4489 | delta_set = isl_set_union(delta_set, isl_set_copy(origin)); |
4490 | delta_set = isl_set_lexmin(delta_set); |
4491 | |
4492 | is_nonneg = isl_set_is_equal(delta_set, origin); |
4493 | |
4494 | isl_set_free(origin); |
4495 | isl_set_free(delta_set); |
4496 | } |
4497 | |
4498 | if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 || |
4499 | is_injection < 0 || is_complete < 0) |
4500 | return -1; |
4501 | if (!is_complete) |
4502 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete" , "polly/lib/External/isl/isl_test.c", 4503); return -1; } while (0) |
4503 | "generated schedule incomplete", return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete" , "polly/lib/External/isl/isl_test.c", 4503); return -1; } while (0); |
4504 | if (!is_injection) |
4505 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "polly/lib/External/isl/isl_test.c", 4507); return -1; } while (0) |
4506 | "generated schedule not injective on each statement",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "polly/lib/External/isl/isl_test.c", 4507); return -1; } while (0) |
4507 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "polly/lib/External/isl/isl_test.c", 4507); return -1; } while (0); |
4508 | if (!is_nonneg) |
4509 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "polly/lib/External/isl/isl_test.c", 4511); return -1; } while (0) |
4510 | "negative dependences in generated schedule",do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "polly/lib/External/isl/isl_test.c", 4511); return -1; } while (0) |
4511 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "polly/lib/External/isl/isl_test.c", 4511); return -1; } while (0); |
4512 | if (!is_tilable) |
4513 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "polly/lib/External/isl/isl_test.c", 4515); return -1; } while (0) |
4514 | "generated schedule not as tilable as expected",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "polly/lib/External/isl/isl_test.c", 4515); return -1; } while (0) |
4515 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "polly/lib/External/isl/isl_test.c", 4515); return -1; } while (0); |
4516 | if (!is_parallel) |
4517 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "polly/lib/External/isl/isl_test.c", 4519); return -1; } while (0) |
4518 | "generated schedule not as parallel as expected",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "polly/lib/External/isl/isl_test.c", 4519); return -1; } while (0) |
4519 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "polly/lib/External/isl/isl_test.c", 4519); return -1; } while (0); |
4520 | |
4521 | return 0; |
4522 | } |
4523 | |
4524 | /* Compute a schedule for the given instance set, validity constraints, |
4525 | * proximity constraints and context and return a corresponding union map |
4526 | * representation. |
4527 | */ |
4528 | static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx, |
4529 | const char *domain, const char *validity, const char *proximity, |
4530 | const char *context) |
4531 | { |
4532 | isl_setisl_map *con; |
4533 | isl_union_set *dom; |
4534 | isl_union_map *dep; |
4535 | isl_union_map *prox; |
4536 | isl_schedule_constraints *sc; |
4537 | isl_schedule *schedule; |
4538 | isl_union_map *sched; |
4539 | |
4540 | con = isl_set_read_from_str(ctx, context); |
4541 | dom = isl_union_set_read_from_str(ctx, domain); |
4542 | dep = isl_union_map_read_from_str(ctx, validity); |
4543 | prox = isl_union_map_read_from_str(ctx, proximity); |
4544 | sc = isl_schedule_constraints_on_domain(dom); |
4545 | sc = isl_schedule_constraints_set_context(sc, con); |
4546 | sc = isl_schedule_constraints_set_validity(sc, dep); |
4547 | sc = isl_schedule_constraints_set_proximity(sc, prox); |
4548 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4549 | sched = isl_schedule_get_map(schedule); |
4550 | isl_schedule_free(schedule); |
4551 | |
4552 | return sched; |
4553 | } |
4554 | |
4555 | /* Compute a schedule for the given instance set, validity constraints and |
4556 | * proximity constraints and return a corresponding union map representation. |
4557 | */ |
4558 | static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx, |
4559 | const char *domain, const char *validity, const char *proximity) |
4560 | { |
4561 | return compute_schedule_with_context(ctx, domain, validity, proximity, |
4562 | "{ : }"); |
4563 | } |
4564 | |
4565 | /* Check that a schedule can be constructed on the given domain |
4566 | * with the given validity and proximity constraints. |
4567 | */ |
4568 | static int test_has_schedule(isl_ctx *ctx, const char *domain, |
4569 | const char *validity, const char *proximity) |
4570 | { |
4571 | isl_union_map *sched; |
4572 | |
4573 | sched = compute_schedule(ctx, domain, validity, proximity); |
4574 | if (!sched) |
4575 | return -1; |
4576 | |
4577 | isl_union_map_free(sched); |
4578 | return 0; |
4579 | } |
4580 | |
4581 | int test_special_schedule(isl_ctx *ctx, const char *domain, |
4582 | const char *validity, const char *proximity, const char *expected_sched) |
4583 | { |
4584 | isl_union_map *sched1, *sched2; |
4585 | int equal; |
4586 | |
4587 | sched1 = compute_schedule(ctx, domain, validity, proximity); |
4588 | sched2 = isl_union_map_read_from_str(ctx, expected_sched); |
4589 | |
4590 | equal = isl_union_map_is_equal(sched1, sched2); |
4591 | isl_union_map_free(sched1); |
4592 | isl_union_map_free(sched2); |
4593 | |
4594 | if (equal < 0) |
4595 | return -1; |
4596 | if (!equal) |
4597 | isl_die(ctx, isl_error_unknown, "unexpected schedule",do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "polly/lib/External/isl/isl_test.c", 4598); return -1; } while (0) |
4598 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "polly/lib/External/isl/isl_test.c", 4598); return -1; } while (0); |
4599 | |
4600 | return 0; |
4601 | } |
4602 | |
4603 | /* Check that the schedule map is properly padded, i.e., that the range |
4604 | * lives in a single space. |
4605 | */ |
4606 | static int test_padded_schedule(isl_ctx *ctx) |
4607 | { |
4608 | const char *str; |
4609 | isl_union_set *D; |
4610 | isl_union_map *validity, *proximity; |
4611 | isl_schedule_constraints *sc; |
4612 | isl_schedule *sched; |
4613 | isl_union_map *umap; |
4614 | isl_union_set *range; |
4615 | isl_setisl_map *set; |
4616 | |
4617 | str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }"; |
4618 | D = isl_union_set_read_from_str(ctx, str); |
4619 | validity = isl_union_map_empty(isl_union_set_get_space(D)); |
4620 | proximity = isl_union_map_copy(validity); |
4621 | sc = isl_schedule_constraints_on_domain(D); |
4622 | sc = isl_schedule_constraints_set_validity(sc, validity); |
4623 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
4624 | sched = isl_schedule_constraints_compute_schedule(sc); |
4625 | umap = isl_schedule_get_map(sched); |
4626 | isl_schedule_free(sched); |
4627 | range = isl_union_map_range(umap); |
4628 | set = isl_set_from_union_set(range); |
4629 | isl_set_free(set); |
4630 | |
4631 | if (!set) |
4632 | return -1; |
4633 | |
4634 | return 0; |
4635 | } |
4636 | |
4637 | /* Check that conditional validity constraints are also taken into |
4638 | * account across bands. |
4639 | * In particular, try to make sure that live ranges D[1,0]->C[2,1] and |
4640 | * D[2,0]->C[3,0] are not local in the outer band of the generated schedule |
4641 | * and then check that the adjacent order constraint C[2,1]->D[2,0] |
4642 | * is enforced by the rest of the schedule. |
4643 | */ |
4644 | static int test_special_conditional_schedule_constraints(isl_ctx *ctx) |
4645 | { |
4646 | const char *str; |
4647 | isl_union_set *domain; |
4648 | isl_union_map *validity, *proximity, *condition; |
4649 | isl_union_map *sink, *source, *dep; |
4650 | isl_schedule_constraints *sc; |
4651 | isl_schedule *schedule; |
4652 | isl_union_access_info *access; |
4653 | isl_union_flow *flow; |
4654 | int empty; |
4655 | |
4656 | str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; " |
4657 | "A[k] : k >= 1 and k <= -1 + n; " |
4658 | "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; " |
4659 | "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }"; |
4660 | domain = isl_union_set_read_from_str(ctx, str); |
4661 | sc = isl_schedule_constraints_on_domain(domain); |
4662 | str = "[n] -> { D[k, i] -> C[1 + k, k - i] : " |
4663 | "k <= -2 + n and i >= 1 and i <= -1 + k; " |
4664 | "D[k, i] -> C[1 + k, i] : " |
4665 | "k <= -2 + n and i >= 1 and i <= -1 + k; " |
4666 | "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; " |
4667 | "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }"; |
4668 | validity = isl_union_map_read_from_str(ctx, str); |
4669 | sc = isl_schedule_constraints_set_validity(sc, validity); |
4670 | str = "[n] -> { C[k, i] -> D[k, i] : " |
4671 | "0 <= i <= -1 + k and k <= -1 + n }"; |
4672 | proximity = isl_union_map_read_from_str(ctx, str); |
4673 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
4674 | str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : " |
4675 | "i <= -1 + k and i >= 1 and k <= -2 + n; " |
4676 | "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : " |
4677 | "k <= -1 + n and i >= 0 and i <= -2 + k }"; |
4678 | condition = isl_union_map_read_from_str(ctx, str); |
4679 | str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : " |
4680 | "i >= 0 and i <= -1 + k and k <= -1 + n; " |
4681 | "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : " |
4682 | "i >= 0 and i <= -1 + k and k <= -1 + n and " |
4683 | "k' <= -1 + n and k' >= k - i and k' >= 1 + k; " |
4684 | "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : " |
4685 | "i >= 0 and i <= -1 + k and k <= -1 + n; " |
4686 | "[B[k, i] -> c[]] -> [A[k'] -> d[]] : " |
4687 | "k <= -1 + n and i >= 0 and i <= -1 + k and " |
4688 | "k' >= 1 and k' <= -1 + n and k' >= 1 + k }"; |
4689 | validity = isl_union_map_read_from_str(ctx, str); |
4690 | sc = isl_schedule_constraints_set_conditional_validity(sc, condition, |
4691 | validity); |
4692 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4693 | str = "{ D[2,0] -> [] }"; |
4694 | sink = isl_union_map_read_from_str(ctx, str); |
4695 | access = isl_union_access_info_from_sink(sink); |
4696 | str = "{ C[2,1] -> [] }"; |
4697 | source = isl_union_map_read_from_str(ctx, str); |
4698 | access = isl_union_access_info_set_must_source(access, source); |
4699 | access = isl_union_access_info_set_schedule(access, schedule); |
4700 | flow = isl_union_access_info_compute_flow(access); |
4701 | dep = isl_union_flow_get_must_dependence(flow); |
4702 | isl_union_flow_free(flow); |
4703 | empty = isl_union_map_is_empty(dep); |
4704 | isl_union_map_free(dep); |
4705 | |
4706 | if (empty < 0) |
4707 | return -1; |
4708 | if (empty) |
4709 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected" , "polly/lib/External/isl/isl_test.c", 4710); return -1; } while (0) |
4710 | "conditional validity not respected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected" , "polly/lib/External/isl/isl_test.c", 4710); return -1; } while (0); |
4711 | |
4712 | return 0; |
4713 | } |
4714 | |
4715 | /* Check that the test for violated conditional validity constraints |
4716 | * is not confused by domain compression. |
4717 | * In particular, earlier versions of isl would apply |
4718 | * a schedule on the compressed domains to the original domains, |
4719 | * resulting in a failure to detect that the default schedule |
4720 | * violates the conditional validity constraints. |
4721 | */ |
4722 | static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx) |
4723 | { |
4724 | const char *str; |
4725 | isl_bool empty; |
4726 | isl_union_set *domain; |
4727 | isl_union_map *validity, *condition; |
4728 | isl_schedule_constraints *sc; |
4729 | isl_schedule *schedule; |
4730 | isl_union_map *umap; |
4731 | isl_map *map, *ge; |
4732 | |
4733 | str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }"; |
4734 | domain = isl_union_set_read_from_str(ctx, str); |
4735 | sc = isl_schedule_constraints_on_domain(domain); |
4736 | str = "{ B[1, i] -> A[0, i + 1] }"; |
4737 | condition = isl_union_map_read_from_str(ctx, str); |
4738 | str = "{ A[0, i] -> B[1, i - 1] }"; |
4739 | validity = isl_union_map_read_from_str(ctx, str); |
4740 | sc = isl_schedule_constraints_set_conditional_validity(sc, condition, |
4741 | isl_union_map_copy(validity)); |
4742 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4743 | umap = isl_schedule_get_map(schedule); |
4744 | isl_schedule_free(schedule); |
4745 | validity = isl_union_map_apply_domain(validity, |
4746 | isl_union_map_copy(umap)); |
4747 | validity = isl_union_map_apply_range(validity, umap); |
4748 | map = isl_map_from_union_map(validity); |
4749 | ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map))); |
4750 | map = isl_map_intersect(map, ge); |
4751 | empty = isl_map_is_empty(map); |
4752 | isl_map_free(map); |
4753 | |
4754 | if (empty < 0) |
4755 | return -1; |
4756 | if (!empty) |
4757 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied" , "polly/lib/External/isl/isl_test.c", 4759); return -1; } while (0) |
4758 | "conditional validity constraints not satisfied",do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied" , "polly/lib/External/isl/isl_test.c", 4759); return -1; } while (0) |
4759 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied" , "polly/lib/External/isl/isl_test.c", 4759); return -1; } while (0); |
4760 | |
4761 | return 0; |
4762 | } |
4763 | |
4764 | /* Input for testing of schedule construction based on |
4765 | * conditional constraints. |
4766 | * |
4767 | * domain is the iteration domain |
4768 | * flow are the flow dependences, which determine the validity and |
4769 | * proximity constraints |
4770 | * condition are the conditions on the conditional validity constraints |
4771 | * conditional_validity are the conditional validity constraints |
4772 | * outer_band_n is the expected number of members in the outer band |
4773 | */ |
4774 | struct { |
4775 | const char *domain; |
4776 | const char *flow; |
4777 | const char *condition; |
4778 | const char *conditional_validity; |
4779 | int outer_band_n; |
4780 | } live_range_tests[] = { |
4781 | /* Contrived example that illustrates that we need to keep |
4782 | * track of tagged condition dependences and |
4783 | * tagged conditional validity dependences |
4784 | * in isl_sched_edge separately. |
4785 | * In particular, the conditional validity constraints on A |
4786 | * cannot be satisfied, |
4787 | * but they can be ignored because there are no corresponding |
4788 | * condition constraints. However, we do have an additional |
4789 | * conditional validity constraint that maps to the same |
4790 | * dependence relation |
4791 | * as the condition constraint on B. If we did not make a distinction |
4792 | * between tagged condition and tagged conditional validity |
4793 | * dependences, then we |
4794 | * could end up treating this shared dependence as an condition |
4795 | * constraint on A, forcing a localization of the conditions, |
4796 | * which is impossible. |
4797 | */ |
4798 | { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }", |
4799 | "{ S[i] -> S[i+1] : 0 <= i < 99 }", |
4800 | "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }", |
4801 | "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';" |
4802 | "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';" |
4803 | "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }", |
4804 | 1 |
4805 | }, |
4806 | /* TACO 2013 Fig. 7 */ |
4807 | { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }", |
4808 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
4809 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
4810 | "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;" |
4811 | "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : " |
4812 | "0 <= i < n and 0 <= j < n - 1 }", |
4813 | "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : " |
4814 | "0 <= i < n and 0 <= j < j' < n;" |
4815 | "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : " |
4816 | "0 <= i < i' < n and 0 <= j,j' < n;" |
4817 | "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : " |
4818 | "0 <= i,j,j' < n and j < j' }", |
4819 | 2 |
4820 | }, |
4821 | /* TACO 2013 Fig. 7, without tags */ |
4822 | { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }", |
4823 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
4824 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
4825 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
4826 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
4827 | "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;" |
4828 | "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;" |
4829 | "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }", |
4830 | 1 |
4831 | }, |
4832 | /* TACO 2013 Fig. 12 */ |
4833 | { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;" |
4834 | "S3[i,3] : 0 <= i <= 1 }", |
4835 | "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;" |
4836 | "S2[i,1] -> S2[i,2] : 0 <= i <= 1;" |
4837 | "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }", |
4838 | "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;" |
4839 | "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;" |
4840 | "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }", |
4841 | "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;" |
4842 | "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;" |
4843 | "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;" |
4844 | "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;" |
4845 | "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }", |
4846 | 1 |
4847 | } |
4848 | }; |
4849 | |
4850 | /* Test schedule construction based on conditional constraints. |
4851 | * In particular, check the number of members in the outer band node |
4852 | * as an indication of whether tiling is possible or not. |
4853 | */ |
4854 | static int test_conditional_schedule_constraints(isl_ctx *ctx) |
4855 | { |
4856 | int i; |
4857 | isl_union_set *domain; |
4858 | isl_union_map *condition; |
4859 | isl_union_map *flow; |
4860 | isl_union_map *validity; |
4861 | isl_schedule_constraints *sc; |
4862 | isl_schedule *schedule; |
4863 | isl_schedule_node *node; |
4864 | isl_size n_member; |
4865 | |
4866 | if (test_special_conditional_schedule_constraints(ctx) < 0) |
4867 | return -1; |
4868 | if (test_special_conditional_schedule_constraints_2(ctx) < 0) |
4869 | return -1; |
4870 | |
4871 | for (i = 0; i < ARRAY_SIZE(live_range_tests)(sizeof(live_range_tests)/sizeof(*live_range_tests)); ++i) { |
4872 | domain = isl_union_set_read_from_str(ctx, |
4873 | live_range_tests[i].domain); |
4874 | flow = isl_union_map_read_from_str(ctx, |
4875 | live_range_tests[i].flow); |
4876 | condition = isl_union_map_read_from_str(ctx, |
4877 | live_range_tests[i].condition); |
4878 | validity = isl_union_map_read_from_str(ctx, |
4879 | live_range_tests[i].conditional_validity); |
4880 | sc = isl_schedule_constraints_on_domain(domain); |
4881 | sc = isl_schedule_constraints_set_validity(sc, |
4882 | isl_union_map_copy(flow)); |
4883 | sc = isl_schedule_constraints_set_proximity(sc, flow); |
4884 | sc = isl_schedule_constraints_set_conditional_validity(sc, |
4885 | condition, validity); |
4886 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4887 | node = isl_schedule_get_root(schedule); |
4888 | while (node && |
4889 | isl_schedule_node_get_type(node) != isl_schedule_node_band) |
4890 | node = isl_schedule_node_first_child(node); |
4891 | n_member = isl_schedule_node_band_n_member(node); |
4892 | isl_schedule_node_free(node); |
4893 | isl_schedule_free(schedule); |
4894 | |
4895 | if (!schedule || n_member < 0) |
4896 | return -1; |
4897 | if (n_member != live_range_tests[i].outer_band_n) |
4898 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "polly/lib/External/isl/isl_test.c", 4900); return -1; } while (0) |
4899 | "unexpected number of members in outer band",do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "polly/lib/External/isl/isl_test.c", 4900); return -1; } while (0) |
4900 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "polly/lib/External/isl/isl_test.c", 4900); return -1; } while (0); |
4901 | } |
4902 | return 0; |
4903 | } |
4904 | |
4905 | /* Check that the schedule computed for the given instance set and |
4906 | * dependence relation strongly satisfies the dependences. |
4907 | * In particular, check that no instance is scheduled before |
4908 | * or together with an instance on which it depends. |
4909 | * Earlier versions of isl would produce a schedule that |
4910 | * only weakly satisfies the dependences. |
4911 | */ |
4912 | static int test_strongly_satisfying_schedule(isl_ctx *ctx) |
4913 | { |
4914 | const char *domain, *dep; |
4915 | isl_union_map *D, *schedule; |
4916 | isl_map *map, *ge; |
4917 | int empty; |
4918 | |
4919 | domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; " |
4920 | "A[i0] : 0 <= i0 <= 1 }"; |
4921 | dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; " |
4922 | "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }"; |
4923 | schedule = compute_schedule(ctx, domain, dep, dep); |
4924 | D = isl_union_map_read_from_str(ctx, dep); |
4925 | D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule)); |
4926 | D = isl_union_map_apply_range(D, schedule); |
4927 | map = isl_map_from_union_map(D); |
4928 | ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map))); |
4929 | map = isl_map_intersect(map, ge); |
4930 | empty = isl_map_is_empty(map); |
4931 | isl_map_free(map); |
4932 | |
4933 | if (empty < 0) |
4934 | return -1; |
4935 | if (!empty) |
4936 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied" , "polly/lib/External/isl/isl_test.c", 4937); return -1; } while (0) |
4937 | "dependences not strongly satisfied", return -1)do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied" , "polly/lib/External/isl/isl_test.c", 4937); return -1; } while (0); |
4938 | |
4939 | return 0; |
4940 | } |
4941 | |
4942 | /* Compute a schedule for input where the instance set constraints |
4943 | * conflict with the context constraints. |
4944 | * Earlier versions of isl did not properly handle this situation. |
4945 | */ |
4946 | static int test_conflicting_context_schedule(isl_ctx *ctx) |
4947 | { |
4948 | isl_union_map *schedule; |
4949 | const char *domain, *context; |
4950 | |
4951 | domain = "[n] -> { A[] : n >= 0 }"; |
4952 | context = "[n] -> { : n < 0 }"; |
4953 | schedule = compute_schedule_with_context(ctx, |
4954 | domain, "{}", "{}", context); |
4955 | isl_union_map_free(schedule); |
4956 | |
4957 | if (!schedule) |
4958 | return -1; |
4959 | |
4960 | return 0; |
4961 | } |
4962 | |
4963 | /* Check that a set of schedule constraints that only allow for |
4964 | * a coalescing schedule still produces a schedule even if the user |
4965 | * request a non-coalescing schedule. Earlier versions of isl |
4966 | * would not handle this case correctly. |
4967 | */ |
4968 | static int test_coalescing_schedule(isl_ctx *ctx) |
4969 | { |
4970 | const char *domain, *dep; |
4971 | isl_union_set *I; |
4972 | isl_union_map *D; |
4973 | isl_schedule_constraints *sc; |
4974 | isl_schedule *schedule; |
4975 | int treat_coalescing; |
4976 | |
4977 | domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }"; |
4978 | dep = "{ S[a, b] -> S[a + b, 1 - b] }"; |
4979 | I = isl_union_set_read_from_str(ctx, domain); |
4980 | D = isl_union_map_read_from_str(ctx, dep); |
4981 | sc = isl_schedule_constraints_on_domain(I); |
4982 | sc = isl_schedule_constraints_set_validity(sc, D); |
4983 | treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx); |
4984 | isl_options_set_schedule_treat_coalescing(ctx, 1); |
4985 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4986 | isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing); |
4987 | isl_schedule_free(schedule); |
4988 | if (!schedule) |
4989 | return -1; |
4990 | return 0; |
4991 | } |
4992 | |
4993 | /* Check that the scheduler does not perform any needless |
4994 | * compound skewing. Earlier versions of isl would compute |
4995 | * schedules in terms of transformed schedule coefficients and |
4996 | * would not accurately keep track of the sum of the original |
4997 | * schedule coefficients. It could then produce the schedule |
4998 | * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k] |
4999 | * for the input below instead of the schedule below. |
5000 | */ |
5001 | static int test_skewing_schedule(isl_ctx *ctx) |
5002 | { |
5003 | const char *D, *V, *P, *S; |
5004 | |
5005 | D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }"; |
5006 | V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and " |
5007 | "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and " |
5008 | "-1 <= a-i + b-j + c-k <= 1 }"; |
5009 | P = "{ }"; |
5010 | S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }"; |
5011 | |
5012 | return test_special_schedule(ctx, D, V, P, S); |
5013 | } |
5014 | |
5015 | int test_schedule(isl_ctx *ctx) |
5016 | { |
5017 | const char *D, *W, *R, *V, *P, *S; |
5018 | int max_coincidence; |
5019 | int treat_coalescing; |
5020 | |
5021 | /* Handle resulting schedule with zero bands. */ |
5022 | if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0) |
5023 | return -1; |
5024 | |
5025 | /* Jacobi */ |
5026 | D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }"; |
5027 | W = "{ S1[t,i] -> a[t,i] }"; |
5028 | R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; " |
5029 | "S1[t,i] -> a[t-1,i+1] }"; |
5030 | S = "{ S1[t,i] -> [t,i] }"; |
5031 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
5032 | return -1; |
5033 | |
5034 | /* Fig. 5 of CC2008 */ |
5035 | D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and " |
5036 | "j <= -1 + N }"; |
5037 | W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and " |
5038 | "j >= 2 and j <= -1 + N }"; |
5039 | R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and " |
5040 | "j >= 2 and j <= -1 + N; " |
5041 | "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and " |
5042 | "j >= 2 and j <= -1 + N }"; |
5043 | S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }"; |
5044 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
5045 | return -1; |
5046 | |
5047 | D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }"; |
5048 | W = "{ S1[i] -> a[i] }"; |
5049 | R = "{ S2[i] -> a[i+1] }"; |
5050 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
5051 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
5052 | return -1; |
5053 | |
5054 | D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }"; |
5055 | W = "{ S1[i] -> a[i] }"; |
5056 | R = "{ S2[i] -> a[9-i] }"; |
5057 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
5058 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
5059 | return -1; |
5060 | |
5061 | D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }"; |
5062 | W = "{ S1[i] -> a[i] }"; |
5063 | R = "[N] -> { S2[i] -> a[N-1-i] }"; |
5064 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
5065 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
5066 | return -1; |
5067 | |
5068 | D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }"; |
5069 | W = "{ S1[i] -> a[i]; S2[i] -> b[i] }"; |
5070 | R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }"; |
5071 | S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }"; |
5072 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5073 | return -1; |
5074 | |
5075 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }"; |
5076 | W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }"; |
5077 | R = "{ S2[i,j] -> a[i-1,j] }"; |
5078 | S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }"; |
5079 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
5080 | return -1; |
5081 | |
5082 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }"; |
5083 | W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }"; |
5084 | R = "{ S2[i,j] -> a[i,j-1] }"; |
5085 | S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }"; |
5086 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
5087 | return -1; |
5088 | |
5089 | D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }"; |
5090 | W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; " |
5091 | "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }"; |
5092 | R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }"; |
5093 | S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; " |
5094 | "S_0[] -> [0, 0, 0] }"; |
5095 | if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0) |
5096 | return -1; |
5097 | ctx->opt->schedule_parametric = 0; |
5098 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5099 | return -1; |
5100 | ctx->opt->schedule_parametric = 1; |
5101 | |
5102 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; " |
5103 | "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }"; |
5104 | W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }"; |
5105 | R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; " |
5106 | "S4[i] -> a[i,N] }"; |
5107 | S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; " |
5108 | "S4[i] -> [4,i,0] }"; |
5109 | max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx); |
5110 | isl_options_set_schedule_maximize_coincidence(ctx, 0); |
5111 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
5112 | return -1; |
5113 | isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence); |
5114 | |
5115 | D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }"; |
5116 | W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and " |
5117 | "j <= N }"; |
5118 | R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and " |
5119 | "j <= N; " |
5120 | "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and " |
5121 | "j <= N }"; |
5122 | S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }"; |
5123 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5124 | return -1; |
5125 | |
5126 | D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; " |
5127 | " S_2[t] : t >= 0 and t <= -1 + N; " |
5128 | " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and " |
5129 | "i <= -1 + N }"; |
5130 | W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; " |
5131 | " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; " |
5132 | " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and " |
5133 | "i >= 0 and i <= -1 + N }"; |
5134 | R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and " |
5135 | "i >= 0 and i <= -1 + N; " |
5136 | " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }"; |
5137 | S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; " |
5138 | " S_0[t] -> [0, t, 0] }"; |
5139 | |
5140 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
5141 | return -1; |
5142 | ctx->opt->schedule_parametric = 0; |
5143 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5144 | return -1; |
5145 | ctx->opt->schedule_parametric = 1; |
5146 | |
5147 | D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }"; |
5148 | S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }"; |
5149 | if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0) |
5150 | return -1; |
5151 | |
5152 | D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; " |
5153 | "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }"; |
5154 | W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and " |
5155 | "j >= 0 and j <= -1 + N; " |
5156 | "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }"; |
5157 | R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and " |
5158 | "j >= 0 and j <= -1 + N; " |
5159 | "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }"; |
5160 | S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }"; |
5161 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5162 | return -1; |
5163 | |
5164 | D = "{ S_0[i] : i >= 0 }"; |
5165 | W = "{ S_0[i] -> a[i] : i >= 0 }"; |
5166 | R = "{ S_0[i] -> a[0] : i >= 0 }"; |
5167 | S = "{ S_0[i] -> [0, i, 0] }"; |
5168 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5169 | return -1; |
5170 | |
5171 | D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }"; |
5172 | W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }"; |
5173 | R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }"; |
5174 | S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }"; |
5175 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5176 | return -1; |
5177 | |
5178 | D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and " |
5179 | "k <= -1 + n and k >= 0 }"; |
5180 | W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }"; |
5181 | R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " |
5182 | "k <= -1 + n and k >= 0; " |
5183 | "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and " |
5184 | "k <= -1 + n and k >= 0; " |
5185 | "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and " |
5186 | "k <= -1 + n and k >= 0 }"; |
5187 | S = "[n] -> { S_0[j, k] -> [2, j, k] }"; |
5188 | ctx->opt->schedule_outer_coincidence = 1; |
5189 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
5190 | return -1; |
5191 | ctx->opt->schedule_outer_coincidence = 0; |
5192 | |
5193 | D = "{Stmt_for_body24[i0, i1, i2, i3]:" |
5194 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and " |
5195 | "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;" |
5196 | "Stmt_for_body24[i0, i1, 1, 0]:" |
5197 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;" |
5198 | "Stmt_for_body7[i0, i1, i2]:" |
5199 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and " |
5200 | "i2 <= 7 }"; |
5201 | |
5202 | V = "{Stmt_for_body24[0, i1, i2, i3] -> " |
5203 | "Stmt_for_body24[1, i1, i2, i3]:" |
5204 | "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and " |
5205 | "i2 >= 1;" |
5206 | "Stmt_for_body24[0, i1, i2, i3] -> " |
5207 | "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:" |
5208 | "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and " |
5209 | "i3 >= 0;" |
5210 | "Stmt_for_body24[0, i1, i2, i3] ->" |
5211 | "Stmt_for_body7[1, i1, 1 + i1 + i3]:" |
5212 | "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;" |
5213 | "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:" |
5214 | "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or " |
5215 | "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or " |
5216 | "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);" |
5217 | "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:" |
5218 | "i1 <= 6 and i1 >= 0;" |
5219 | "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];" |
5220 | "Stmt_for_body7[i0, i1, i2] -> " |
5221 | "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:" |
5222 | "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and " |
5223 | "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;" |
5224 | "Stmt_for_body7[i0, i1, i2] -> " |
5225 | "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:" |
5226 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and " |
5227 | "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }"; |
5228 | P = V; |
5229 | |
5230 | treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx); |
5231 | isl_options_set_schedule_treat_coalescing(ctx, 0); |
5232 | if (test_has_schedule(ctx, D, V, P) < 0) |
5233 | return -1; |
5234 | isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing); |
5235 | |
5236 | D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }"; |
5237 | V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and " |
5238 | "j >= 1 and j <= 7;" |
5239 | "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and " |
5240 | "j >= 1 and j <= 8 }"; |
5241 | P = "{ }"; |
5242 | S = "{ S_0[i, j] -> [i + j, i] }"; |
5243 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
5244 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
5245 | return -1; |
5246 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
5247 | |
5248 | /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */ |
5249 | D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and " |
5250 | "j >= 0 and j <= -1 + i }"; |
5251 | V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and " |
5252 | "i <= -1 + N and j >= 0;" |
5253 | "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and " |
5254 | "i <= -2 + N }"; |
5255 | P = "{ }"; |
5256 | S = "{ S_0[i, j] -> [i, j] }"; |
5257 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
5258 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
5259 | return -1; |
5260 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
5261 | |
5262 | /* Test both algorithms on a case with only proximity dependences. */ |
5263 | D = "{ S[i,j] : 0 <= i <= 10 }"; |
5264 | V = "{ }"; |
5265 | P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }"; |
5266 | S = "{ S[i, j] -> [j, i] }"; |
5267 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
5268 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
5269 | return -1; |
5270 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
5271 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
5272 | return -1; |
5273 | |
5274 | D = "{ A[a]; B[] }"; |
5275 | V = "{}"; |
5276 | P = "{ A[a] -> B[] }"; |
5277 | if (test_has_schedule(ctx, D, V, P) < 0) |
5278 | return -1; |
5279 | |
5280 | if (test_padded_schedule(ctx) < 0) |
5281 | return -1; |
5282 | |
5283 | /* Check that check for progress is not confused by rational |
5284 | * solution. |
5285 | */ |
5286 | D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }"; |
5287 | V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and " |
5288 | "i0 <= -2 + N; " |
5289 | "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and " |
5290 | "i0 <= N and i1 >= 0 and i1 <= -1 + N }"; |
5291 | P = "{}"; |
5292 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
5293 | if (test_has_schedule(ctx, D, V, P) < 0) |
5294 | return -1; |
5295 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
5296 | |
5297 | /* Check that we allow schedule rows that are only non-trivial |
5298 | * on some full-dimensional domains. |
5299 | */ |
5300 | D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }"; |
5301 | V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];" |
5302 | "S1[j] -> S2[1] : 0 <= j <= 1 }"; |
5303 | P = "{}"; |
5304 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
5305 | if (test_has_schedule(ctx, D, V, P) < 0) |
5306 | return -1; |
5307 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
5308 | |
5309 | if (test_conditional_schedule_constraints(ctx) < 0) |
5310 | return -1; |
5311 | |
5312 | if (test_strongly_satisfying_schedule(ctx) < 0) |
5313 | return -1; |
5314 | |
5315 | if (test_conflicting_context_schedule(ctx) < 0) |
5316 | return -1; |
5317 | |
5318 | if (test_coalescing_schedule(ctx) < 0) |
5319 | return -1; |
5320 | if (test_skewing_schedule(ctx) < 0) |
5321 | return -1; |
5322 | |
5323 | return 0; |
5324 | } |
5325 | |
5326 | /* Perform scheduling tests using the whole component scheduler. |
5327 | */ |
5328 | static int test_schedule_whole(isl_ctx *ctx) |
5329 | { |
5330 | int whole; |
5331 | int r; |
5332 | |
5333 | whole = isl_options_get_schedule_whole_component(ctx); |
5334 | isl_options_set_schedule_whole_component(ctx, 1); |
5335 | r = test_schedule(ctx); |
5336 | isl_options_set_schedule_whole_component(ctx, whole); |
5337 | |
5338 | return r; |
5339 | } |
5340 | |
5341 | /* Perform scheduling tests using the incremental scheduler. |
5342 | */ |
5343 | static int test_schedule_incremental(isl_ctx *ctx) |
5344 | { |
5345 | int whole; |
5346 | int r; |
5347 | |
5348 | whole = isl_options_get_schedule_whole_component(ctx); |
5349 | isl_options_set_schedule_whole_component(ctx, 0); |
5350 | r = test_schedule(ctx); |
5351 | isl_options_set_schedule_whole_component(ctx, whole); |
5352 | |
5353 | return r; |
5354 | } |
5355 | |
5356 | int test_plain_injective(isl_ctx *ctx, const char *str, int injective) |
5357 | { |
5358 | isl_union_map *umap; |
5359 | int test; |
5360 | |
5361 | umap = isl_union_map_read_from_str(ctx, str); |
5362 | test = isl_union_map_plain_is_injective(umap); |
5363 | isl_union_map_free(umap); |
5364 | if (test < 0) |
5365 | return -1; |
5366 | if (test == injective) |
5367 | return 0; |
5368 | if (injective) |
5369 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective" , "polly/lib/External/isl/isl_test.c", 5370); return -1; } while (0) |
5370 | "map not detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective" , "polly/lib/External/isl/isl_test.c", 5370); return -1; } while (0); |
5371 | else |
5372 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective" , "polly/lib/External/isl/isl_test.c", 5373); return -1; } while (0) |
5373 | "map detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective" , "polly/lib/External/isl/isl_test.c", 5373); return -1; } while (0); |
5374 | } |
5375 | |
5376 | int test_injective(isl_ctx *ctx) |
5377 | { |
5378 | const char *str; |
5379 | |
5380 | if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0)) |
5381 | return -1; |
5382 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1)) |
5383 | return -1; |
5384 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1)) |
5385 | return -1; |
5386 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0)) |
5387 | return -1; |
5388 | if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1)) |
5389 | return -1; |
5390 | if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0)) |
5391 | return -1; |
5392 | if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1)) |
5393 | return -1; |
5394 | if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1)) |
5395 | return -1; |
5396 | |
5397 | str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}"; |
5398 | if (test_plain_injective(ctx, str, 1)) |
5399 | return -1; |
5400 | str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}"; |
5401 | if (test_plain_injective(ctx, str, 0)) |
5402 | return -1; |
5403 | |
5404 | return 0; |
5405 | } |
5406 | |
5407 | #undef BASEunion_pw_aff |
5408 | #define BASEunion_pw_aff aff |
5409 | #include "isl_test_plain_equal_templ.c" |
5410 | |
5411 | #undef BASEunion_pw_aff |
5412 | #define BASEunion_pw_aff pw_multi_aff |
5413 | #include "isl_test_plain_equal_templ.c" |
5414 | |
5415 | #undef BASEunion_pw_aff |
5416 | #define BASEunion_pw_aff union_pw_aff |
5417 | #include "isl_test_plain_equal_templ.c" |
5418 | |
5419 | /* Basic tests on isl_union_pw_aff. |
5420 | * |
5421 | * In particular, check that isl_union_pw_aff_aff_on_domain |
5422 | * aligns the parameters of the input objects and |
5423 | * that isl_union_pw_aff_param_on_domain_id properly |
5424 | * introduces the parameter. |
5425 | */ |
5426 | static int test_upa(isl_ctx *ctx) |
5427 | { |
5428 | const char *str; |
5429 | isl_id *id; |
5430 | isl_aff *aff; |
5431 | isl_union_set *domain; |
5432 | isl_union_pw_aff *upa; |
5433 | isl_stat ok; |
5434 | |
5435 | aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }"); |
5436 | str = "[M] -> { A[i] : 0 <= i < M; B[] }"; |
5437 | domain = isl_union_set_read_from_str(ctx, str); |
5438 | upa = isl_union_pw_aff_aff_on_domain(domain, aff); |
5439 | str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }"; |
5440 | ok = union_pw_aff_check_plain_equal(upa, str); |
5441 | isl_union_pw_aff_free(upa); |
5442 | if (ok < 0) |
5443 | return -1; |
5444 | |
5445 | id = isl_id_alloc(ctx, "N", NULL((void*)0)); |
5446 | str = "[M] -> { A[i] : 0 <= i < M; B[] }"; |
5447 | domain = isl_union_set_read_from_str(ctx, str); |
5448 | upa = isl_union_pw_aff_param_on_domain_id(domain, id); |
5449 | str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }"; |
5450 | ok = union_pw_aff_check_plain_equal(upa, str); |
5451 | isl_union_pw_aff_free(upa); |
5452 | if (ok < 0) |
5453 | return -1; |
5454 | |
5455 | return 0; |
5456 | } |
5457 | |
5458 | struct { |
5459 | __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1, |
5460 | __isl_take isl_aff *aff2); |
5461 | } aff_bin_op[] = { |
5462 | ['+'] = { &isl_aff_add }, |
5463 | ['-'] = { &isl_aff_sub }, |
5464 | ['*'] = { &isl_aff_mul }, |
5465 | ['/'] = { &isl_aff_div }, |
5466 | }; |
5467 | |
5468 | struct { |
5469 | const char *arg1; |
5470 | unsigned char op; |
5471 | const char *arg2; |
5472 | const char *res; |
5473 | } aff_bin_tests[] = { |
5474 | { "{ [i] -> [i] }", '+', "{ [i] -> [i] }", |
5475 | "{ [i] -> [2i] }" }, |
5476 | { "{ [i] -> [i] }", '-', "{ [i] -> [i] }", |
5477 | "{ [i] -> [0] }" }, |
5478 | { "{ [i] -> [i] }", '*', "{ [i] -> [2] }", |
5479 | "{ [i] -> [2i] }" }, |
5480 | { "{ [i] -> [2] }", '*', "{ [i] -> [i] }", |
5481 | "{ [i] -> [2i] }" }, |
5482 | { "{ [i] -> [i] }", '/', "{ [i] -> [2] }", |
5483 | "{ [i] -> [i/2] }" }, |
5484 | { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }", |
5485 | "{ [i] -> [i] }" }, |
5486 | { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }", |
5487 | "{ [i] -> [NaN] }" }, |
5488 | { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }", |
5489 | "{ [i] -> [NaN] }" }, |
5490 | { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }", |
5491 | "{ [i] -> [NaN] }" }, |
5492 | { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }", |
5493 | "{ [i] -> [NaN] }" }, |
5494 | { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }", |
5495 | "{ [i] -> [NaN] }" }, |
5496 | { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }", |
5497 | "{ [i] -> [NaN] }" }, |
5498 | { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }", |
5499 | "{ [i] -> [NaN] }" }, |
5500 | { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }", |
5501 | "{ [i] -> [NaN] }" }, |
5502 | { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }", |
5503 | "{ [i] -> [NaN] }" }, |
5504 | { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }", |
5505 | "{ [i] -> [NaN] }" }, |
5506 | { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }", |
5507 | "{ [i] -> [NaN] }" }, |
5508 | { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }", |
5509 | "{ [i] -> [NaN] }" }, |
5510 | { "{ [i] -> [i] }", '/', "{ [i] -> [0] }", |
5511 | "{ [i] -> [NaN] }" }, |
5512 | }; |
5513 | |
5514 | /* Perform some basic tests of binary operations on isl_aff objects. |
5515 | */ |
5516 | static int test_bin_aff(isl_ctx *ctx) |
5517 | { |
5518 | int i; |
5519 | isl_aff *aff1, *aff2, *res; |
5520 | __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1, |
5521 | __isl_take isl_aff *aff2); |
5522 | int ok; |
5523 | |
5524 | for (i = 0; i < ARRAY_SIZE(aff_bin_tests)(sizeof(aff_bin_tests)/sizeof(*aff_bin_tests)); ++i) { |
5525 | aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1); |
5526 | aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2); |
5527 | res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res); |
5528 | fn = aff_bin_op[aff_bin_tests[i].op].fn; |
5529 | aff1 = fn(aff1, aff2); |
5530 | if (isl_aff_is_nan(res)) |
5531 | ok = isl_aff_is_nan(aff1); |
5532 | else |
5533 | ok = isl_aff_plain_is_equal(aff1, res); |
5534 | isl_aff_free(aff1); |
5535 | isl_aff_free(res); |
5536 | if (ok < 0) |
5537 | return -1; |
5538 | if (!ok) |
5539 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5540); return -1; } while (0) |
5540 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5540); return -1; } while (0); |
5541 | } |
5542 | |
5543 | return 0; |
5544 | } |
5545 | |
5546 | struct { |
5547 | __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1, |
5548 | __isl_take isl_pw_aff *pa2); |
5549 | } pw_aff_bin_op[] = { |
5550 | ['m'] = { &isl_pw_aff_min }, |
5551 | ['M'] = { &isl_pw_aff_max }, |
5552 | }; |
5553 | |
5554 | /* Inputs for binary isl_pw_aff operation tests. |
5555 | * "arg1" and "arg2" are the two arguments, "op" identifies the operation |
5556 | * defined by pw_aff_bin_op, and "res" is the expected result. |
5557 | */ |
5558 | struct { |
5559 | const char *arg1; |
5560 | unsigned char op; |
5561 | const char *arg2; |
5562 | const char *res; |
5563 | } pw_aff_bin_tests[] = { |
5564 | { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }", |
5565 | "{ [i] -> [i] }" }, |
5566 | { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }", |
5567 | "{ [i] -> [i] }" }, |
5568 | { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }", |
5569 | "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" }, |
5570 | { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }", |
5571 | "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" }, |
5572 | { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }", |
5573 | "{ [i] -> [NaN] }" }, |
5574 | { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }", |
5575 | "{ [i] -> [NaN] }" }, |
5576 | }; |
5577 | |
5578 | /* Perform some basic tests of binary operations on isl_pw_aff objects. |
5579 | */ |
5580 | static int test_bin_pw_aff(isl_ctx *ctx) |
5581 | { |
5582 | int i; |
5583 | isl_bool ok; |
5584 | isl_pw_aff *pa1, *pa2, *res; |
5585 | |
5586 | for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests)(sizeof(pw_aff_bin_tests)/sizeof(*pw_aff_bin_tests)); ++i) { |
5587 | pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1); |
5588 | pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2); |
5589 | res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res); |
5590 | pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2); |
5591 | if (isl_pw_aff_involves_nan(res)) |
5592 | ok = isl_pw_aff_involves_nan(pa1); |
5593 | else |
5594 | ok = isl_pw_aff_plain_is_equal(pa1, res); |
5595 | isl_pw_aff_free(pa1); |
5596 | isl_pw_aff_free(res); |
5597 | if (ok < 0) |
5598 | return -1; |
5599 | if (!ok) |
5600 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5601); return -1; } while (0) |
5601 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5601); return -1; } while (0); |
5602 | } |
5603 | |
5604 | return 0; |
5605 | } |
5606 | |
5607 | /* Inputs for basic tests of test operations on |
5608 | * isl_union_pw_multi_aff objects. |
5609 | * "fn" is the function that is being tested. |
5610 | * "arg" is a string description of the input. |
5611 | * "res" is the expected result. |
5612 | */ |
5613 | static struct { |
5614 | isl_bool (*fn)(__isl_keep isl_union_pw_multi_aff *upma1); |
5615 | const char *arg; |
5616 | isl_bool res; |
5617 | } upma_test_tests[] = { |
5618 | { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [1] }", |
5619 | isl_bool_false }, |
5620 | { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [NaN]; B[0] -> [1] }", |
5621 | isl_bool_true }, |
5622 | { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [NaN] }", |
5623 | isl_bool_true }, |
5624 | { &isl_union_pw_multi_aff_involves_nan, |
5625 | "{ A[] -> [0]; B[0] -> [1, NaN, 5] }", |
5626 | isl_bool_true }, |
5627 | { &isl_union_pw_multi_aff_involves_locals, |
5628 | "{ A[] -> [0]; B[0] -> [1] }", |
5629 | isl_bool_false }, |
5630 | { &isl_union_pw_multi_aff_involves_locals, |
5631 | "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }", |
5632 | isl_bool_true }, |
5633 | { &isl_union_pw_multi_aff_involves_locals, |
5634 | "{ A[] -> [0]; B[x] -> [x // 2] }", |
5635 | isl_bool_true }, |
5636 | { &isl_union_pw_multi_aff_involves_locals, |
5637 | "{ A[i] -> [i // 2]; B[0] -> [1] }", |
5638 | isl_bool_true }, |
5639 | }; |
5640 | |
5641 | /* Perform some basic tests of test operations on |
5642 | * isl_union_pw_multi_aff objects. |
5643 | */ |
5644 | static isl_stat test_upma_test(isl_ctx *ctx) |
5645 | { |
5646 | int i; |
5647 | isl_union_pw_multi_aff *upma; |
5648 | isl_bool res; |
5649 | |
5650 | for (i = 0; i < ARRAY_SIZE(upma_test_tests)(sizeof(upma_test_tests)/sizeof(*upma_test_tests)); ++i) { |
5651 | const char *str; |
5652 | |
5653 | str = upma_test_tests[i].arg; |
5654 | upma = isl_union_pw_multi_aff_read_from_str(ctx, str); |
5655 | res = upma_test_tests[i].fn(upma); |
5656 | isl_union_pw_multi_aff_free(upma); |
5657 | if (res < 0) |
5658 | return isl_stat_error; |
5659 | if (res != upma_test_tests[i].res) |
5660 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5661); return isl_stat_error ; } while (0) |
5661 | "unexpected result", return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5661); return isl_stat_error ; } while (0); |
5662 | } |
5663 | |
5664 | return isl_stat_ok; |
5665 | } |
5666 | |
5667 | struct { |
5668 | __isl_give isl_union_pw_multi_aff *(*fn)( |
5669 | __isl_take isl_union_pw_multi_aff *upma1, |
5670 | __isl_take isl_union_pw_multi_aff *upma2); |
5671 | const char *arg1; |
5672 | const char *arg2; |
5673 | const char *res; |
5674 | } upma_bin_tests[] = { |
5675 | { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }", |
5676 | "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" }, |
5677 | { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }", |
5678 | "{ B[x] -> [2] : x >= 0 }", |
5679 | "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" }, |
5680 | { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff, |
5681 | "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }", |
5682 | "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }", |
5683 | "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; " |
5684 | "D[i] -> B[2] : i >= 5 }" }, |
5685 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
5686 | "{ B[x] -> C[2] : x > 0 }", |
5687 | "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" }, |
5688 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
5689 | "{ B[x] -> A[2] : x >= 0 }", |
5690 | "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" }, |
5691 | { |
5692 | &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff, |
5693 | "{ B[x] -> C[x + 2] }", |
5694 | "{ D[y] -> B[2y] }", |
5695 | "{ }" }, |
5696 | { |
5697 | &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff, |
5698 | "{ [A[x] -> B[x + 1]] -> C[x + 2] }", |
5699 | "{ D[y] -> B[2y] }", |
5700 | "{ }" }, |
5701 | { |
5702 | &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff, |
5703 | "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }", |
5704 | "{ D[y] -> A[2y] }", |
5705 | "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" }, |
5706 | { |
5707 | &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff, |
5708 | "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }", |
5709 | "{ D[y] -> A[2y] }", |
5710 | "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" }, |
5711 | }; |
5712 | |
5713 | /* Perform some basic tests of binary operations on |
5714 | * isl_union_pw_multi_aff objects. |
5715 | */ |
5716 | static int test_bin_upma(isl_ctx *ctx) |
5717 | { |
5718 | int i; |
5719 | isl_union_pw_multi_aff *upma1, *upma2, *res; |
5720 | int ok; |
5721 | |
5722 | for (i = 0; i < ARRAY_SIZE(upma_bin_tests)(sizeof(upma_bin_tests)/sizeof(*upma_bin_tests)); ++i) { |
5723 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
5724 | upma_bin_tests[i].arg1); |
5725 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
5726 | upma_bin_tests[i].arg2); |
5727 | res = isl_union_pw_multi_aff_read_from_str(ctx, |
5728 | upma_bin_tests[i].res); |
5729 | upma1 = upma_bin_tests[i].fn(upma1, upma2); |
5730 | ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res); |
5731 | isl_union_pw_multi_aff_free(upma1); |
5732 | isl_union_pw_multi_aff_free(res); |
5733 | if (ok < 0) |
5734 | return -1; |
5735 | if (!ok) |
5736 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5737); return -1; } while (0) |
5737 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5737); return -1; } while (0); |
5738 | } |
5739 | |
5740 | return 0; |
5741 | } |
5742 | |
5743 | struct { |
5744 | __isl_give isl_union_pw_multi_aff *(*fn)( |
5745 | __isl_take isl_union_pw_multi_aff *upma1, |
5746 | __isl_take isl_union_pw_multi_aff *upma2); |
5747 | const char *arg1; |
5748 | const char *arg2; |
5749 | } upma_bin_fail_tests[] = { |
5750 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
5751 | "{ B[x] -> C[2] : x >= 0 }" }, |
5752 | }; |
5753 | |
5754 | /* Perform some basic tests of binary operations on |
5755 | * isl_union_pw_multi_aff objects that are expected to fail. |
5756 | */ |
5757 | static int test_bin_upma_fail(isl_ctx *ctx) |
5758 | { |
5759 | int i, n; |
5760 | isl_union_pw_multi_aff *upma1, *upma2; |
5761 | int on_error; |
5762 | |
5763 | on_error = isl_options_get_on_error(ctx); |
5764 | isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE1); |
5765 | n = ARRAY_SIZE(upma_bin_fail_tests)(sizeof(upma_bin_fail_tests)/sizeof(*upma_bin_fail_tests)); |
5766 | for (i = 0; i < n; ++i) { |
5767 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
5768 | upma_bin_fail_tests[i].arg1); |
5769 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
5770 | upma_bin_fail_tests[i].arg2); |
5771 | upma1 = upma_bin_fail_tests[i].fn(upma1, upma2); |
5772 | isl_union_pw_multi_aff_free(upma1); |
5773 | if (upma1) |
5774 | break; |
5775 | } |
5776 | isl_options_set_on_error(ctx, on_error); |
5777 | if (i < n) |
5778 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "polly/lib/External/isl/isl_test.c", 5779); return -1; } while (0) |
5779 | "operation not expected to succeed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "polly/lib/External/isl/isl_test.c", 5779); return -1; } while (0); |
5780 | |
5781 | return 0; |
5782 | } |
5783 | |
5784 | /* Inputs for basic tests of binary operations on |
5785 | * pairs of isl_union_pw_multi_aff and isl_union_set objects. |
5786 | * "fn" is the function that is being tested. |
5787 | * "arg1" and "arg2" are string descriptions of the inputs. |
5788 | * "res" is a string description of the expected result. |
5789 | */ |
5790 | struct { |
5791 | __isl_give isl_union_pw_multi_aff *(*fn)( |
5792 | __isl_take isl_union_pw_multi_aff *upma, |
5793 | __isl_take isl_union_set *uset); |
5794 | const char *arg1; |
5795 | const char *arg2; |
5796 | const char *res; |
5797 | } upma_uset_tests[] = { |
5798 | { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, |
5799 | "{ A[i] -> B[i] }", "{ B[0] }", |
5800 | "{ }" }, |
5801 | { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain, |
5802 | "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }", |
5803 | "{ [A[1] -> B[1]] -> C[2] }" }, |
5804 | { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, |
5805 | "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }", |
5806 | "{ [A[0] -> B[0]] -> C[1] }" }, |
5807 | { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, |
5808 | "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }", |
5809 | "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" }, |
5810 | { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, |
5811 | "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }", |
5812 | "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" }, |
5813 | { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, |
5814 | "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }", |
5815 | "{ B[] }", |
5816 | "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" }, |
5817 | }; |
5818 | |
5819 | /* Perform some basic tests of binary operations on |
5820 | * pairs of isl_union_pw_multi_aff and isl_union_set objects. |
5821 | */ |
5822 | static isl_stat test_upma_uset(isl_ctx *ctx) |
5823 | { |
5824 | int i; |
5825 | isl_bool ok; |
5826 | isl_union_pw_multi_aff *upma, *res; |
5827 | isl_union_set *uset; |
5828 | |
5829 | for (i = 0; i < ARRAY_SIZE(upma_uset_tests)(sizeof(upma_uset_tests)/sizeof(*upma_uset_tests)); ++i) { |
5830 | upma = isl_union_pw_multi_aff_read_from_str(ctx, |
5831 | upma_uset_tests[i].arg1); |
5832 | uset = isl_union_set_read_from_str(ctx, |
5833 | upma_uset_tests[i].arg2); |
5834 | res = isl_union_pw_multi_aff_read_from_str(ctx, |
5835 | upma_uset_tests[i].res); |
5836 | upma = upma_uset_tests[i].fn(upma, uset); |
5837 | ok = isl_union_pw_multi_aff_plain_is_equal(upma, res); |
5838 | isl_union_pw_multi_aff_free(upma); |
5839 | isl_union_pw_multi_aff_free(res); |
5840 | if (ok < 0) |
5841 | return isl_stat_error; |
5842 | if (!ok) |
5843 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5844); return isl_stat_error ; } while (0) |
5844 | "unexpected result", return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "polly/lib/External/isl/isl_test.c", 5844); return isl_stat_error ; } while (0); |
5845 | } |
5846 | |
5847 | return isl_stat_ok; |
5848 | } |
5849 | |
5850 | /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects. |
5851 | * "fn" is the function that is tested. |
5852 | * "arg" is a string description of the input. |
5853 | * "res" is a string description of the expected result. |
5854 | */ |
5855 | struct { |
5856 | __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa); |
5857 | const char *arg; |
5858 | const char *res; |
5859 | } mpa_un_tests[] = { |
5860 | { &isl_multi_pw_aff_range_factor_domain, |
5861 | "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }", |
5862 | "{ A[x] -> B[(1 : x >= 5)] }" }, |
5863 | { &isl_multi_pw_aff_range_factor_range, |
5864 | "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }", |
5865 | "{ A[y] -> C[(2 : y <= 10)] }" }, |
5866 | { &isl_multi_pw_aff_range_factor_domain, |
5867 | "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }", |
5868 | "{ A[x] -> B[(1 : x >= 5)] }" }, |
5869 | { &isl_multi_pw_aff_range_factor_range, |
5870 | "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }", |
5871 | "{ A[y] -> C[] }" }, |
5872 | { &isl_multi_pw_aff_range_factor_domain, |
5873 | "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }", |
5874 | "{ A[x] -> B[] }" }, |
5875 | { &isl_multi_pw_aff_range_factor_range, |
5876 | "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }", |
5877 | "{ A[y] -> C[(2 : y <= 10)] }" }, |
5878 | { &isl_multi_pw_aff_range_factor_domain, |
5879 | "{ A[x] -> [B[] -> C[]] }", |