File: | tools/polly/lib/External/isl/isl_test.c |
Warning: | line 9407, column 2 Value stored to 'argc' is never read |
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); |
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)((map) ? (void) (0) : __assert_fail ("map", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 69, __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" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/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" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/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)((pwqp) ? (void) (0) : __assert_fail ("pwqp", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 98, __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)((pwaff) ? (void) (0) : __assert_fail ("pwaff", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 107, __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 | /* Check that printing "mpa" and parsing the output results |
124 | * in the same expression. |
125 | */ |
126 | static isl_stat check_reparse_mpa(isl_ctx *ctx, |
127 | __isl_take isl_multi_pw_aff *mpa) |
128 | { |
129 | char *str; |
130 | isl_bool equal; |
131 | isl_multi_pw_aff *mpa2; |
132 | |
133 | str = isl_multi_pw_aff_to_str(mpa); |
134 | mpa2 = isl_multi_pw_aff_read_from_str(ctx, str); |
135 | free(str); |
136 | equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2); |
137 | isl_multi_pw_aff_free(mpa); |
138 | isl_multi_pw_aff_free(mpa2); |
139 | if (equal < 0) |
140 | return isl_stat_error; |
141 | if (!equal) |
142 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "parsed function not equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 144); return isl_stat_error; } while (0) |
143 | "parsed function not equal to original",do { isl_handle_error(ctx, isl_error_unknown, "parsed function not equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 144); return isl_stat_error; } while (0) |
144 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "parsed function not equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 144); return isl_stat_error; } while (0); |
145 | |
146 | return isl_stat_ok; |
147 | } |
148 | |
149 | /* String descriptions of multi piecewise affine expressions |
150 | * that are used for testing printing and parsing. |
151 | */ |
152 | const char *parse_multi_mpa_tests[] = { |
153 | "{ A[x, y] -> [] : x + y >= 0 }", |
154 | "{ A[x, y] -> B[] : x + y >= 0 }", |
155 | "{ A[x, y] -> [x] : x + y >= 0 }", |
156 | "[N] -> { A[x, y] -> [x] : x + y <= N }", |
157 | "{ A[x, y] -> [x, y] : x + y >= 0 }", |
158 | "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }", |
159 | "[N] -> { [] : N >= 0 }", |
160 | "[N] -> { [] : N >= 0 }", |
161 | "[N] -> { [N] : N >= 0 }", |
162 | "[N] -> { [N, N + 1] : N >= 0 }", |
163 | "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }", |
164 | }; |
165 | |
166 | /* Test parsing of multi piecewise affine expressions by printing |
167 | * the expressions and checking that parsing the output results |
168 | * in the same expression. |
169 | * Do this for a couple of manually constructed expressions and |
170 | * a set of expressions parsed from strings. |
171 | */ |
172 | static int test_parse_mpa(isl_ctx *ctx) |
173 | { |
174 | int i; |
175 | isl_space *space; |
176 | isl_setisl_map *dom; |
177 | isl_multi_pw_aff *mpa; |
178 | isl_stat r; |
179 | |
180 | space = isl_space_set_alloc(ctx, 0, 0); |
181 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
182 | mpa = isl_multi_pw_aff_zero(space); |
183 | r = check_reparse_mpa(ctx, mpa); |
184 | if (r < 0) |
185 | return -1; |
186 | |
187 | space = isl_space_set_alloc(ctx, 1, 0); |
188 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
189 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
190 | dom = isl_set_universe(isl_space_params(isl_space_copy(space))); |
191 | dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5); |
192 | mpa = isl_multi_pw_aff_zero(space); |
193 | mpa = isl_multi_pw_aff_intersect_domain(mpa, dom); |
194 | r = check_reparse_mpa(ctx, mpa); |
195 | if (r < 0) |
196 | return -1; |
197 | |
198 | for (i = 0; i < ARRAY_SIZE(parse_multi_mpa_tests)(sizeof(parse_multi_mpa_tests)/sizeof(*parse_multi_mpa_tests) ); ++i) { |
199 | const char *str; |
200 | |
201 | str = parse_multi_mpa_tests[i]; |
202 | mpa = isl_multi_pw_aff_read_from_str(ctx, str); |
203 | r = check_reparse_mpa(ctx, mpa); |
204 | if (r < 0) |
205 | return -1; |
206 | } |
207 | |
208 | return 0; |
209 | } |
210 | |
211 | /* Check that printing "mupa" and parsing the output results |
212 | * in the same expression. |
213 | */ |
214 | static isl_stat check_reparse_mupa(isl_ctx *ctx, |
215 | __isl_take isl_multi_union_pw_aff *mupa) |
216 | { |
217 | char *str; |
218 | isl_bool equal; |
219 | isl_multi_union_pw_aff *mupa2; |
220 | |
221 | str = isl_multi_union_pw_aff_to_str(mupa); |
222 | mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str); |
223 | free(str); |
224 | equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2); |
225 | isl_multi_union_pw_aff_free(mupa); |
226 | isl_multi_union_pw_aff_free(mupa2); |
227 | if (equal < 0) |
228 | return isl_stat_error; |
229 | if (!equal) |
230 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "parsed function not equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 232); return isl_stat_error; } while (0) |
231 | "parsed function not equal to original",do { isl_handle_error(ctx, isl_error_unknown, "parsed function not equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 232); return isl_stat_error; } while (0) |
232 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "parsed function not equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 232); return isl_stat_error; } while (0); |
233 | |
234 | return isl_stat_ok; |
235 | } |
236 | |
237 | /* String descriptions of multi union piecewise affine expressions |
238 | * that are used for testing printing and parsing. |
239 | */ |
240 | const char *parse_multi_mupa_tests[] = { |
241 | "[]", |
242 | "A[]", |
243 | "A[B[] -> C[]]", |
244 | "(A[] : { S[x] : x > 0; T[y] : y >= 0 })", |
245 | "(A[] : { })", |
246 | "[N] -> (A[] : { })", |
247 | "[N] -> (A[] : { : N >= 0 })", |
248 | "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })", |
249 | "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })", |
250 | "A[{ S[x] -> [x + 1]; T[x] -> [x] }]", |
251 | "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : " |
252 | "{ S[x] : x > 0; T[y] : y >= 0 })", |
253 | }; |
254 | |
255 | /* Test parsing of multi union piecewise affine expressions by printing |
256 | * the expressions and checking that parsing the output results |
257 | * in the same expression. |
258 | * Do this for a couple of manually constructed expressions and |
259 | * a set of expressions parsed from strings. |
260 | */ |
261 | static int test_parse_mupa(isl_ctx *ctx) |
262 | { |
263 | int i; |
264 | isl_space *space; |
265 | isl_multi_union_pw_aff *mupa; |
266 | isl_setisl_map *dom; |
267 | isl_union_set *uset; |
268 | isl_stat r; |
269 | |
270 | space = isl_space_set_alloc(ctx, 0, 0); |
271 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
272 | mupa = isl_multi_union_pw_aff_zero(space); |
273 | r = check_reparse_mupa(ctx, mupa); |
274 | if (r < 0) |
275 | return -1; |
276 | |
277 | space = isl_space_set_alloc(ctx, 1, 0); |
278 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
279 | space = isl_space_set_tuple_name(space, isl_dim_set, "A"); |
280 | dom = isl_set_universe(space); |
281 | dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5); |
282 | uset = isl_union_set_from_set(dom); |
283 | space = isl_space_set_alloc(ctx, 1, 0); |
284 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
285 | space = isl_space_set_tuple_name(space, isl_dim_set, "B"); |
286 | mupa = isl_multi_union_pw_aff_zero(space); |
287 | mupa = isl_multi_union_pw_aff_intersect_domain(mupa, uset); |
288 | r = check_reparse_mupa(ctx, mupa); |
289 | if (r < 0) |
290 | return -1; |
291 | |
292 | for (i = 0; i < ARRAY_SIZE(parse_multi_mupa_tests)(sizeof(parse_multi_mupa_tests)/sizeof(*parse_multi_mupa_tests )); ++i) { |
293 | const char *str; |
294 | |
295 | str = parse_multi_mupa_tests[i]; |
296 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
297 | r = check_reparse_mupa(ctx, mupa); |
298 | if (r < 0) |
299 | return -1; |
300 | } |
301 | |
302 | return 0; |
303 | } |
304 | |
305 | /* Test parsing of multi expressions. |
306 | */ |
307 | static int test_parse_multi(isl_ctx *ctx) |
308 | { |
309 | if (test_parse_mpa(ctx) < 0) |
310 | return -1; |
311 | if (test_parse_mupa(ctx) < 0) |
312 | return -1; |
313 | |
314 | return 0; |
315 | } |
316 | |
317 | /* Pairs of binary relation representations that should represent |
318 | * the same binary relations. |
319 | */ |
320 | struct { |
321 | const char *map1; |
322 | const char *map2; |
323 | } parse_map_equal_tests[] = { |
324 | { "{ [x,y] : [([x/2]+y)/3] >= 1 }", |
325 | "{ [x, y] : 2y >= 6 - x }" }, |
326 | { "{ [x,y] : x <= min(y, 2*y+3) }", |
327 | "{ [x,y] : x <= y, 2*y + 3 }" }, |
328 | { "{ [x,y] : x >= min(y, 2*y+3) }", |
329 | "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" }, |
330 | { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }", |
331 | "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" }, |
332 | { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }", |
333 | "{ [i,j] -> [min(i,j)] }" }, |
334 | { "{ [i,j] : i != j }", |
335 | "{ [i,j] : i < j or i > j }" }, |
336 | { "{ [i,j] : (i+1)*2 >= j }", |
337 | "{ [i, j] : j <= 2 + 2i }" }, |
338 | { "{ [i] -> [i > 0 ? 4 : 5] }", |
339 | "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" }, |
340 | { "[N=2,M] -> { [i=[(M+N)/4]] }", |
341 | "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" }, |
342 | { "{ [x] : x >= 0 }", |
343 | "{ [x] : x-0 >= 0 }" }, |
344 | { "{ [i] : ((i > 10)) }", |
345 | "{ [i] : i >= 11 }" }, |
346 | { "{ [i] -> [0] }", |
347 | "{ [i] -> [0 * i] }" }, |
348 | { "{ [a] -> [b] : (not false) }", |
349 | "{ [a] -> [b] : true }" }, |
350 | { "{ [i] : i/2 <= 5 }", |
351 | "{ [i] : i <= 10 }" }, |
352 | { "{Sym=[n] [i] : i <= n }", |
353 | "[n] -> { [i] : i <= n }" }, |
354 | { "{ [*] }", |
355 | "{ [a] }" }, |
356 | { "{ [i] : 2*floor(i/2) = i }", |
357 | "{ [i] : exists a : i = 2 a }" }, |
358 | { "{ [a] -> [b] : a = 5 implies b = 5 }", |
359 | "{ [a] -> [b] : a != 5 or b = 5 }" }, |
360 | { "{ [a] -> [a - 1 : a > 0] }", |
361 | "{ [a] -> [a - 1] : a > 0 }" }, |
362 | { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }", |
363 | "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" }, |
364 | { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }", |
365 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
366 | { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }", |
367 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
368 | { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }", |
369 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
370 | { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }", |
371 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
372 | { "{ [a,b] -> [i,j] : a,b << i,j }", |
373 | "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" }, |
374 | { "{ [a,b] -> [i,j] : a,b <<= i,j }", |
375 | "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" }, |
376 | { "{ [a,b] -> [i,j] : a,b >> i,j }", |
377 | "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" }, |
378 | { "{ [a,b] -> [i,j] : a,b >>= i,j }", |
379 | "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" }, |
380 | { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and " |
381 | "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and " |
382 | "8c < n - 32a and i < n and c >= 0 and " |
383 | "c <= 3 and c >= -4a) }", |
384 | "{ [n] -> [i] : 0 <= i < n }" }, |
385 | { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and " |
386 | "2b <= x - 8a and 2b >= -1 + x - 8a) }", |
387 | "{ [x] -> [] : 0 <= x <= 15 }" }, |
388 | { "{ [x] -> [x] : }", |
389 | "{ [x] -> [x] }" }, |
390 | }; |
391 | |
392 | int test_parse(struct isl_ctx *ctx) |
393 | { |
394 | int i; |
395 | isl_map *map, *map2; |
396 | const char *str, *str2; |
397 | |
398 | if (test_parse_multi_val(ctx, "{ A[B[2] -> C[5, 7]] }") < 0) |
399 | return -1; |
400 | if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0) |
401 | return -1; |
402 | if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0) |
403 | return -1; |
404 | if (test_parse_multi(ctx) < 0) |
405 | return -1; |
406 | |
407 | str = "{ [i] -> [-i] }"; |
408 | map = isl_map_read_from_str(ctx, str); |
409 | assert(map)((map) ? (void) (0) : __assert_fail ("map", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 409, __PRETTY_FUNCTION__)); |
410 | isl_map_free(map); |
411 | |
412 | str = "{ A[i] -> L[([i/3])] }"; |
413 | map = isl_map_read_from_str(ctx, str); |
414 | assert(map)((map) ? (void) (0) : __assert_fail ("map", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 414, __PRETTY_FUNCTION__)); |
415 | isl_map_free(map); |
416 | |
417 | test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}"); |
418 | test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : " |
419 | "p1 = 1 && (y1 <= y2 || y2 = 0) }"); |
420 | |
421 | for (i = 0; i < ARRAY_SIZE(parse_map_equal_tests)(sizeof(parse_map_equal_tests)/sizeof(*parse_map_equal_tests) ); ++i) { |
422 | str = parse_map_equal_tests[i].map1; |
423 | str2 = parse_map_equal_tests[i].map2; |
424 | if (test_parse_map_equal(ctx, str, str2) < 0) |
425 | return -1; |
426 | } |
427 | |
428 | str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}"; |
429 | map = isl_map_read_from_str(ctx, str); |
430 | str = "{ [new, old] -> [o0, o1] : " |
431 | "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: " |
432 | "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and " |
433 | "o0 <= 1 and o1 >= 0 and o1 <= 1) }"; |
434 | map2 = isl_map_read_from_str(ctx, str); |
435 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 435, __PRETTY_FUNCTION__)); |
436 | isl_map_free(map); |
437 | isl_map_free(map2); |
438 | |
439 | str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}"; |
440 | map = isl_map_read_from_str(ctx, str); |
441 | str = "{[new,old] -> [(new+1)%2,(old+1)%2]}"; |
442 | map2 = isl_map_read_from_str(ctx, str); |
443 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 443, __PRETTY_FUNCTION__)); |
444 | isl_map_free(map); |
445 | isl_map_free(map2); |
446 | |
447 | test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }"); |
448 | test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }"); |
449 | test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }"); |
450 | test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }"); |
451 | test_parse_pwaff(ctx, "{ [] -> [(100)] }"); |
452 | |
453 | return 0; |
454 | } |
455 | |
456 | static int test_read(isl_ctx *ctx) |
457 | { |
458 | char *filename; |
459 | FILE *input; |
460 | isl_basic_setisl_basic_map *bset1, *bset2; |
461 | const char *str = "{[y]: Exists ( alpha : 2alpha = y)}"; |
462 | int equal; |
463 | |
464 | filename = get_filename(ctx, "set", "omega"); |
465 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 465, __PRETTY_FUNCTION__)); |
466 | input = fopen(filename, "r"); |
467 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 467, __PRETTY_FUNCTION__)); |
468 | |
469 | bset1 = isl_basic_set_read_from_file(ctx, input); |
470 | bset2 = isl_basic_set_read_from_str(ctx, str); |
471 | |
472 | equal = isl_basic_set_is_equal(bset1, bset2); |
473 | |
474 | isl_basic_set_free(bset1); |
475 | isl_basic_set_free(bset2); |
476 | free(filename); |
477 | |
478 | fclose(input); |
479 | |
480 | if (equal < 0) |
481 | return -1; |
482 | if (!equal) |
483 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "read sets not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 484); return -1; } while (0) |
484 | "read sets not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "read sets not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 484); return -1; } while (0); |
485 | |
486 | return 0; |
487 | } |
488 | |
489 | static int test_bounded(isl_ctx *ctx) |
490 | { |
491 | isl_setisl_map *set; |
492 | isl_bool bounded; |
493 | |
494 | set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }"); |
495 | bounded = isl_set_is_bounded(set); |
496 | isl_set_free(set); |
497 | |
498 | if (bounded < 0) |
499 | return -1; |
500 | if (!bounded) |
501 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set not considered bounded" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 502); return -1; } while (0) |
502 | "set not considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set not considered bounded" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 502); return -1; } while (0); |
503 | |
504 | set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }"); |
505 | bounded = isl_set_is_bounded(set); |
506 | assert(!bounded)((!bounded) ? (void) (0) : __assert_fail ("!bounded", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 506, __PRETTY_FUNCTION__)); |
507 | isl_set_free(set); |
508 | |
509 | if (bounded < 0) |
510 | return -1; |
511 | if (bounded) |
512 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 513); return -1; } while (0) |
513 | "set considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 513); return -1; } while (0); |
514 | |
515 | set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }"); |
516 | bounded = isl_set_is_bounded(set); |
517 | isl_set_free(set); |
518 | |
519 | if (bounded < 0) |
520 | return -1; |
521 | if (bounded) |
522 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 523); return -1; } while (0) |
523 | "set considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 523); return -1; } while (0); |
524 | |
525 | return 0; |
526 | } |
527 | |
528 | /* Construct the basic set { [i] : 5 <= i <= N } */ |
529 | static int test_construction_1(isl_ctx *ctx) |
530 | { |
531 | isl_space *dim; |
532 | isl_local_space *ls; |
533 | isl_basic_setisl_basic_map *bset; |
534 | isl_constraint *c; |
535 | |
536 | dim = isl_space_set_alloc(ctx, 1, 1); |
537 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
538 | ls = isl_local_space_from_space(dim); |
539 | |
540 | c = isl_constraint_alloc_inequality(isl_local_space_copy(ls)); |
541 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
542 | c = isl_constraint_set_coefficient_si(c, isl_dim_param, 0, 1); |
543 | bset = isl_basic_set_add_constraint(bset, c); |
544 | |
545 | c = isl_constraint_alloc_inequality(isl_local_space_copy(ls)); |
546 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
547 | c = isl_constraint_set_constant_si(c, -5); |
548 | bset = isl_basic_set_add_constraint(bset, c); |
549 | |
550 | isl_local_space_free(ls); |
551 | isl_basic_set_free(bset); |
552 | |
553 | return 0; |
554 | } |
555 | |
556 | /* Construct the basic set { [x] : -100 <= x <= 100 } |
557 | * using isl_basic_set_{lower,upper}_bound_val and |
558 | * check that it is equal the same basic set parsed from a string. |
559 | */ |
560 | static int test_construction_2(isl_ctx *ctx) |
561 | { |
562 | isl_bool equal; |
563 | isl_val *v; |
564 | isl_space *space; |
565 | isl_basic_setisl_basic_map *bset1, *bset2; |
566 | |
567 | v = isl_val_int_from_si(ctx, 100); |
568 | space = isl_space_set_alloc(ctx, 0, 1); |
569 | bset1 = isl_basic_set_universe(space); |
570 | bset1 = isl_basic_set_upper_bound_val(bset1, isl_dim_set, 0, |
571 | isl_val_copy(v)); |
572 | bset1 = isl_basic_set_lower_bound_val(bset1, isl_dim_set, 0, |
573 | isl_val_neg(v)); |
574 | bset2 = isl_basic_set_read_from_str(ctx, "{ [x] : -100 <= x <= 100 }"); |
575 | equal = isl_basic_set_is_equal(bset1, bset2); |
576 | isl_basic_set_free(bset1); |
577 | isl_basic_set_free(bset2); |
578 | |
579 | if (equal < 0) |
580 | return -1; |
581 | if (!equal) |
582 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed construction" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 583); return -1; } while (0) |
583 | "failed construction", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed construction" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 583); return -1; } while (0); |
584 | |
585 | return 0; |
586 | } |
587 | |
588 | /* Basic tests for constructing basic sets. |
589 | */ |
590 | static int test_construction(isl_ctx *ctx) |
591 | { |
592 | if (test_construction_1(ctx) < 0) |
593 | return -1; |
594 | if (test_construction_2(ctx) < 0) |
595 | return -1; |
596 | return 0; |
597 | } |
598 | |
599 | static int test_dim(isl_ctx *ctx) |
600 | { |
601 | const char *str; |
602 | isl_map *map1, *map2; |
603 | int equal; |
604 | |
605 | map1 = isl_map_read_from_str(ctx, |
606 | "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }"); |
607 | map1 = isl_map_add_dims(map1, isl_dim_in, 1); |
608 | map2 = isl_map_read_from_str(ctx, |
609 | "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }"); |
610 | equal = isl_map_is_equal(map1, map2); |
611 | isl_map_free(map2); |
612 | |
613 | map1 = isl_map_project_out(map1, isl_dim_in, 0, 1); |
614 | map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }"); |
615 | if (equal >= 0 && equal) |
616 | equal = isl_map_is_equal(map1, map2); |
617 | |
618 | isl_map_free(map1); |
619 | isl_map_free(map2); |
620 | |
621 | if (equal < 0) |
622 | return -1; |
623 | if (!equal) |
624 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 625); return -1; } while (0) |
625 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 625); return -1; } while (0); |
626 | |
627 | str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }"; |
628 | map1 = isl_map_read_from_str(ctx, str); |
629 | str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }"; |
630 | map2 = isl_map_read_from_str(ctx, str); |
631 | map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1); |
632 | equal = isl_map_is_equal(map1, map2); |
633 | isl_map_free(map1); |
634 | isl_map_free(map2); |
635 | |
636 | if (equal < 0) |
637 | return -1; |
638 | if (!equal) |
639 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 640); return -1; } while (0) |
640 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 640); return -1; } while (0); |
641 | |
642 | return 0; |
643 | } |
644 | |
645 | /* Check that "val" is equal to the value described by "str". |
646 | * If "str" is "NaN", then check for a NaN value explicitly. |
647 | */ |
648 | static isl_stat val_check_equal(__isl_keep isl_val *val, const char *str) |
649 | { |
650 | isl_bool ok, is_nan; |
651 | isl_ctx *ctx; |
652 | isl_val *res; |
653 | |
654 | if (!val) |
655 | return isl_stat_error; |
656 | |
657 | ctx = isl_val_get_ctx(val); |
658 | res = isl_val_read_from_str(ctx, str); |
659 | is_nan = isl_val_is_nan(res); |
660 | if (is_nan < 0) |
661 | ok = isl_bool_error; |
662 | else if (is_nan) |
663 | ok = isl_val_is_nan(val); |
664 | else |
665 | ok = isl_val_eq(val, res); |
666 | isl_val_free(res); |
667 | if (ok < 0) |
668 | return isl_stat_error; |
669 | if (!ok) |
670 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 671); return isl_stat_error; } while (0) |
671 | "unexpected result", return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 671); return isl_stat_error; } while (0); |
672 | return isl_stat_ok; |
673 | } |
674 | |
675 | struct { |
676 | __isl_give isl_val *(*op)(__isl_take isl_val *v); |
677 | const char *arg; |
678 | const char *res; |
679 | } val_un_tests[] = { |
680 | { &isl_val_neg, "0", "0" }, |
681 | { &isl_val_abs, "0", "0" }, |
682 | { &isl_val_pow2, "0", "1" }, |
683 | { &isl_val_floor, "0", "0" }, |
684 | { &isl_val_ceil, "0", "0" }, |
685 | { &isl_val_neg, "1", "-1" }, |
686 | { &isl_val_neg, "-1", "1" }, |
687 | { &isl_val_neg, "1/2", "-1/2" }, |
688 | { &isl_val_neg, "-1/2", "1/2" }, |
689 | { &isl_val_neg, "infty", "-infty" }, |
690 | { &isl_val_neg, "-infty", "infty" }, |
691 | { &isl_val_neg, "NaN", "NaN" }, |
692 | { &isl_val_abs, "1", "1" }, |
693 | { &isl_val_abs, "-1", "1" }, |
694 | { &isl_val_abs, "1/2", "1/2" }, |
695 | { &isl_val_abs, "-1/2", "1/2" }, |
696 | { &isl_val_abs, "infty", "infty" }, |
697 | { &isl_val_abs, "-infty", "infty" }, |
698 | { &isl_val_abs, "NaN", "NaN" }, |
699 | { &isl_val_floor, "1", "1" }, |
700 | { &isl_val_floor, "-1", "-1" }, |
701 | { &isl_val_floor, "1/2", "0" }, |
702 | { &isl_val_floor, "-1/2", "-1" }, |
703 | { &isl_val_floor, "infty", "infty" }, |
704 | { &isl_val_floor, "-infty", "-infty" }, |
705 | { &isl_val_floor, "NaN", "NaN" }, |
706 | { &isl_val_ceil, "1", "1" }, |
707 | { &isl_val_ceil, "-1", "-1" }, |
708 | { &isl_val_ceil, "1/2", "1" }, |
709 | { &isl_val_ceil, "-1/2", "0" }, |
710 | { &isl_val_ceil, "infty", "infty" }, |
711 | { &isl_val_ceil, "-infty", "-infty" }, |
712 | { &isl_val_ceil, "NaN", "NaN" }, |
713 | { &isl_val_pow2, "-3", "1/8" }, |
714 | { &isl_val_pow2, "-1", "1/2" }, |
715 | { &isl_val_pow2, "1", "2" }, |
716 | { &isl_val_pow2, "2", "4" }, |
717 | { &isl_val_pow2, "3", "8" }, |
718 | { &isl_val_inv, "1", "1" }, |
719 | { &isl_val_inv, "2", "1/2" }, |
720 | { &isl_val_inv, "1/2", "2" }, |
721 | { &isl_val_inv, "-2", "-1/2" }, |
722 | { &isl_val_inv, "-1/2", "-2" }, |
723 | { &isl_val_inv, "0", "NaN" }, |
724 | { &isl_val_inv, "NaN", "NaN" }, |
725 | { &isl_val_inv, "infty", "0" }, |
726 | { &isl_val_inv, "-infty", "0" }, |
727 | }; |
728 | |
729 | /* Perform some basic tests of unary operations on isl_val objects. |
730 | */ |
731 | static int test_un_val(isl_ctx *ctx) |
732 | { |
733 | int i; |
734 | isl_val *v; |
735 | __isl_give isl_val *(*fn)(__isl_take isl_val *v); |
736 | |
737 | for (i = 0; i < ARRAY_SIZE(val_un_tests)(sizeof(val_un_tests)/sizeof(*val_un_tests)); ++i) { |
738 | isl_stat r; |
739 | |
740 | v = isl_val_read_from_str(ctx, val_un_tests[i].arg); |
741 | fn = val_un_tests[i].op; |
742 | v = fn(v); |
743 | r = val_check_equal(v, val_un_tests[i].res); |
744 | isl_val_free(v); |
745 | if (r < 0) |
746 | return -1; |
747 | } |
748 | |
749 | return 0; |
750 | } |
751 | |
752 | struct { |
753 | __isl_give isl_val *(*fn)(__isl_take isl_val *v1, |
754 | __isl_take isl_val *v2); |
755 | } val_bin_op[] = { |
756 | ['+'] = { &isl_val_add }, |
757 | ['-'] = { &isl_val_sub }, |
758 | ['*'] = { &isl_val_mul }, |
759 | ['/'] = { &isl_val_div }, |
760 | ['g'] = { &isl_val_gcd }, |
761 | ['m'] = { &isl_val_min }, |
762 | ['M'] = { &isl_val_max }, |
763 | }; |
764 | |
765 | struct { |
766 | const char *arg1; |
767 | unsigned char op; |
768 | const char *arg2; |
769 | const char *res; |
770 | } val_bin_tests[] = { |
771 | { "0", '+', "0", "0" }, |
772 | { "1", '+', "0", "1" }, |
773 | { "1", '+', "1", "2" }, |
774 | { "1", '-', "1", "0" }, |
775 | { "1", '*', "1", "1" }, |
776 | { "1", '/', "1", "1" }, |
777 | { "2", '*', "3", "6" }, |
778 | { "2", '*', "1/2", "1" }, |
779 | { "2", '*', "1/3", "2/3" }, |
780 | { "2/3", '*', "3/5", "2/5" }, |
781 | { "2/3", '*', "7/5", "14/15" }, |
782 | { "2", '/', "1/2", "4" }, |
783 | { "-2", '/', "-1/2", "4" }, |
784 | { "-2", '/', "1/2", "-4" }, |
785 | { "2", '/', "-1/2", "-4" }, |
786 | { "2", '/', "2", "1" }, |
787 | { "2", '/', "3", "2/3" }, |
788 | { "2/3", '/', "5/3", "2/5" }, |
789 | { "2/3", '/', "5/7", "14/15" }, |
790 | { "0", '/', "0", "NaN" }, |
791 | { "42", '/', "0", "NaN" }, |
792 | { "-42", '/', "0", "NaN" }, |
793 | { "infty", '/', "0", "NaN" }, |
794 | { "-infty", '/', "0", "NaN" }, |
795 | { "NaN", '/', "0", "NaN" }, |
796 | { "0", '/', "NaN", "NaN" }, |
797 | { "42", '/', "NaN", "NaN" }, |
798 | { "-42", '/', "NaN", "NaN" }, |
799 | { "infty", '/', "NaN", "NaN" }, |
800 | { "-infty", '/', "NaN", "NaN" }, |
801 | { "NaN", '/', "NaN", "NaN" }, |
802 | { "0", '/', "infty", "0" }, |
803 | { "42", '/', "infty", "0" }, |
804 | { "-42", '/', "infty", "0" }, |
805 | { "infty", '/', "infty", "NaN" }, |
806 | { "-infty", '/', "infty", "NaN" }, |
807 | { "NaN", '/', "infty", "NaN" }, |
808 | { "0", '/', "-infty", "0" }, |
809 | { "42", '/', "-infty", "0" }, |
810 | { "-42", '/', "-infty", "0" }, |
811 | { "infty", '/', "-infty", "NaN" }, |
812 | { "-infty", '/', "-infty", "NaN" }, |
813 | { "NaN", '/', "-infty", "NaN" }, |
814 | { "1", '-', "1/3", "2/3" }, |
815 | { "1/3", '+', "1/2", "5/6" }, |
816 | { "1/2", '+', "1/2", "1" }, |
817 | { "3/4", '-', "1/4", "1/2" }, |
818 | { "1/2", '-', "1/3", "1/6" }, |
819 | { "infty", '+', "42", "infty" }, |
820 | { "infty", '+', "infty", "infty" }, |
821 | { "42", '+', "infty", "infty" }, |
822 | { "infty", '-', "infty", "NaN" }, |
823 | { "infty", '*', "infty", "infty" }, |
824 | { "infty", '*', "-infty", "-infty" }, |
825 | { "-infty", '*', "infty", "-infty" }, |
826 | { "-infty", '*', "-infty", "infty" }, |
827 | { "0", '*', "infty", "NaN" }, |
828 | { "1", '*', "infty", "infty" }, |
829 | { "infty", '*', "0", "NaN" }, |
830 | { "infty", '*', "42", "infty" }, |
831 | { "42", '-', "infty", "-infty" }, |
832 | { "infty", '+', "-infty", "NaN" }, |
833 | { "4", 'g', "6", "2" }, |
834 | { "5", 'g', "6", "1" }, |
835 | { "42", 'm', "3", "3" }, |
836 | { "42", 'M', "3", "42" }, |
837 | { "3", 'm', "42", "3" }, |
838 | { "3", 'M', "42", "42" }, |
839 | { "42", 'm', "infty", "42" }, |
840 | { "42", 'M', "infty", "infty" }, |
841 | { "42", 'm', "-infty", "-infty" }, |
842 | { "42", 'M', "-infty", "42" }, |
843 | { "42", 'm', "NaN", "NaN" }, |
844 | { "42", 'M', "NaN", "NaN" }, |
845 | { "infty", 'm', "-infty", "-infty" }, |
846 | { "infty", 'M', "-infty", "infty" }, |
847 | }; |
848 | |
849 | /* Perform some basic tests of binary operations on isl_val objects. |
850 | */ |
851 | static int test_bin_val(isl_ctx *ctx) |
852 | { |
853 | int i; |
854 | isl_val *v1, *v2, *res; |
855 | __isl_give isl_val *(*fn)(__isl_take isl_val *v1, |
856 | __isl_take isl_val *v2); |
857 | int ok; |
858 | |
859 | for (i = 0; i < ARRAY_SIZE(val_bin_tests)(sizeof(val_bin_tests)/sizeof(*val_bin_tests)); ++i) { |
860 | v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1); |
861 | v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2); |
862 | res = isl_val_read_from_str(ctx, val_bin_tests[i].res); |
863 | fn = val_bin_op[val_bin_tests[i].op].fn; |
864 | v1 = fn(v1, v2); |
865 | if (isl_val_is_nan(res)) |
866 | ok = isl_val_is_nan(v1); |
867 | else |
868 | ok = isl_val_eq(v1, res); |
869 | isl_val_free(v1); |
870 | isl_val_free(res); |
871 | if (ok < 0) |
872 | return -1; |
873 | if (!ok) |
874 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 875); return -1; } while (0) |
875 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 875); return -1; } while (0); |
876 | } |
877 | |
878 | return 0; |
879 | } |
880 | |
881 | /* Perform some basic tests on isl_val objects. |
882 | */ |
883 | static int test_val(isl_ctx *ctx) |
884 | { |
885 | if (test_un_val(ctx) < 0) |
886 | return -1; |
887 | if (test_bin_val(ctx) < 0) |
888 | return -1; |
889 | return 0; |
890 | } |
891 | |
892 | /* Sets described using existentially quantified variables that |
893 | * can also be described without. |
894 | */ |
895 | static const char *elimination_tests[] = { |
896 | "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }", |
897 | "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }", |
898 | "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }", |
899 | }; |
900 | |
901 | /* Check that redundant existentially quantified variables are |
902 | * getting removed. |
903 | */ |
904 | static int test_elimination(isl_ctx *ctx) |
905 | { |
906 | int i; |
907 | unsigned n; |
908 | isl_basic_setisl_basic_map *bset; |
909 | |
910 | for (i = 0; i < ARRAY_SIZE(elimination_tests)(sizeof(elimination_tests)/sizeof(*elimination_tests)); ++i) { |
911 | bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]); |
912 | n = isl_basic_set_dim(bset, isl_dim_div); |
913 | isl_basic_set_free(bset); |
914 | if (!bset) |
915 | return -1; |
916 | if (n != 0) |
917 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting no existentials" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 918); return -1; } while (0) |
918 | "expecting no existentials", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting no existentials" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 918); return -1; } while (0); |
919 | } |
920 | |
921 | return 0; |
922 | } |
923 | |
924 | static int test_div(isl_ctx *ctx) |
925 | { |
926 | const char *str; |
927 | int empty; |
928 | isl_space *dim; |
929 | isl_setisl_map *set; |
930 | isl_local_space *ls; |
931 | struct isl_basic_setisl_basic_map *bset; |
932 | struct isl_constraint *c; |
933 | |
934 | /* test 1 */ |
935 | dim = isl_space_set_alloc(ctx, 0, 3); |
936 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
937 | ls = isl_local_space_from_space(dim); |
938 | |
939 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
940 | c = isl_constraint_set_constant_si(c, -1); |
941 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
942 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
943 | bset = isl_basic_set_add_constraint(bset, c); |
944 | |
945 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
946 | c = isl_constraint_set_constant_si(c, 1); |
947 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
948 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3); |
949 | bset = isl_basic_set_add_constraint(bset, c); |
950 | |
951 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
952 | |
953 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 953, __PRETTY_FUNCTION__)); |
954 | isl_local_space_free(ls); |
955 | isl_basic_set_free(bset); |
956 | |
957 | /* test 2 */ |
958 | dim = isl_space_set_alloc(ctx, 0, 3); |
959 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
960 | ls = isl_local_space_from_space(dim); |
961 | |
962 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
963 | c = isl_constraint_set_constant_si(c, 1); |
964 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
965 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
966 | bset = isl_basic_set_add_constraint(bset, c); |
967 | |
968 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
969 | c = isl_constraint_set_constant_si(c, -1); |
970 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
971 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3); |
972 | bset = isl_basic_set_add_constraint(bset, c); |
973 | |
974 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
975 | |
976 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 976, __PRETTY_FUNCTION__)); |
977 | isl_local_space_free(ls); |
978 | isl_basic_set_free(bset); |
979 | |
980 | /* test 3 */ |
981 | dim = isl_space_set_alloc(ctx, 0, 3); |
982 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
983 | ls = isl_local_space_from_space(dim); |
984 | |
985 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
986 | c = isl_constraint_set_constant_si(c, 1); |
987 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
988 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
989 | bset = isl_basic_set_add_constraint(bset, c); |
990 | |
991 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
992 | c = isl_constraint_set_constant_si(c, -3); |
993 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
994 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 4); |
995 | bset = isl_basic_set_add_constraint(bset, c); |
996 | |
997 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
998 | |
999 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 999, __PRETTY_FUNCTION__)); |
1000 | isl_local_space_free(ls); |
1001 | isl_basic_set_free(bset); |
1002 | |
1003 | /* test 4 */ |
1004 | dim = isl_space_set_alloc(ctx, 0, 3); |
1005 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
1006 | ls = isl_local_space_from_space(dim); |
1007 | |
1008 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1009 | c = isl_constraint_set_constant_si(c, 2); |
1010 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1011 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3); |
1012 | bset = isl_basic_set_add_constraint(bset, c); |
1013 | |
1014 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1015 | c = isl_constraint_set_constant_si(c, -1); |
1016 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1017 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6); |
1018 | bset = isl_basic_set_add_constraint(bset, c); |
1019 | |
1020 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
1021 | |
1022 | assert(isl_basic_set_is_empty(bset))((isl_basic_set_is_empty(bset)) ? (void) (0) : __assert_fail ( "isl_basic_set_is_empty(bset)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1022, __PRETTY_FUNCTION__)); |
1023 | isl_local_space_free(ls); |
1024 | isl_basic_set_free(bset); |
1025 | |
1026 | /* test 5 */ |
1027 | dim = isl_space_set_alloc(ctx, 0, 3); |
1028 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
1029 | ls = isl_local_space_from_space(dim); |
1030 | |
1031 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1032 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1033 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3); |
1034 | bset = isl_basic_set_add_constraint(bset, c); |
1035 | |
1036 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1037 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1038 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1039 | bset = isl_basic_set_add_constraint(bset, c); |
1040 | |
1041 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
1042 | |
1043 | assert(bset && bset->n_div == 0)((bset && bset->n_div == 0) ? (void) (0) : __assert_fail ("bset && bset->n_div == 0", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1043, __PRETTY_FUNCTION__)); |
1044 | isl_basic_set_free(bset); |
1045 | isl_local_space_free(ls); |
1046 | |
1047 | /* test 6 */ |
1048 | dim = isl_space_set_alloc(ctx, 0, 3); |
1049 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
1050 | ls = isl_local_space_from_space(dim); |
1051 | |
1052 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1053 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1054 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6); |
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_coefficient_si(c, isl_dim_set, 0, 1); |
1059 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1060 | bset = isl_basic_set_add_constraint(bset, c); |
1061 | |
1062 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
1063 | |
1064 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1064, __PRETTY_FUNCTION__)); |
1065 | isl_basic_set_free(bset); |
1066 | isl_local_space_free(ls); |
1067 | |
1068 | /* test 7 */ |
1069 | /* This test is a bit tricky. We set up an equality |
1070 | * a + 3b + 3c = 6 e0 |
1071 | * Normalization of divs creates _two_ divs |
1072 | * a = 3 e0 |
1073 | * c - b - e0 = 2 e1 |
1074 | * Afterwards e0 is removed again because it has coefficient -1 |
1075 | * and we end up with the original equality and div again. |
1076 | * Perhaps we can avoid the introduction of this temporary div. |
1077 | */ |
1078 | dim = isl_space_set_alloc(ctx, 0, 4); |
1079 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
1080 | ls = isl_local_space_from_space(dim); |
1081 | |
1082 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1083 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1084 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1085 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -3); |
1086 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 6); |
1087 | bset = isl_basic_set_add_constraint(bset, c); |
1088 | |
1089 | bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1); |
1090 | |
1091 | /* Test disabled for now */ |
1092 | /* |
1093 | assert(bset && bset->n_div == 1); |
1094 | */ |
1095 | isl_local_space_free(ls); |
1096 | isl_basic_set_free(bset); |
1097 | |
1098 | /* test 8 */ |
1099 | dim = isl_space_set_alloc(ctx, 0, 5); |
1100 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
1101 | ls = isl_local_space_from_space(dim); |
1102 | |
1103 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1104 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1105 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3); |
1106 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, -3); |
1107 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 4, 6); |
1108 | bset = isl_basic_set_add_constraint(bset, c); |
1109 | |
1110 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1111 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1112 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 1); |
1113 | c = isl_constraint_set_constant_si(c, 1); |
1114 | bset = isl_basic_set_add_constraint(bset, c); |
1115 | |
1116 | bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1); |
1117 | |
1118 | /* Test disabled for now */ |
1119 | /* |
1120 | assert(bset && bset->n_div == 1); |
1121 | */ |
1122 | isl_local_space_free(ls); |
1123 | isl_basic_set_free(bset); |
1124 | |
1125 | /* test 9 */ |
1126 | dim = isl_space_set_alloc(ctx, 0, 4); |
1127 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
1128 | ls = isl_local_space_from_space(dim); |
1129 | |
1130 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1131 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1132 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -1); |
1133 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2); |
1134 | bset = isl_basic_set_add_constraint(bset, c); |
1135 | |
1136 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1137 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1); |
1138 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 3); |
1139 | c = isl_constraint_set_constant_si(c, 2); |
1140 | bset = isl_basic_set_add_constraint(bset, c); |
1141 | |
1142 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2); |
1143 | |
1144 | bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2); |
1145 | |
1146 | assert(!isl_basic_set_is_empty(bset))((!isl_basic_set_is_empty(bset)) ? (void) (0) : __assert_fail ("!isl_basic_set_is_empty(bset)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1146, __PRETTY_FUNCTION__)); |
1147 | |
1148 | isl_local_space_free(ls); |
1149 | isl_basic_set_free(bset); |
1150 | |
1151 | /* test 10 */ |
1152 | dim = isl_space_set_alloc(ctx, 0, 3); |
1153 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
1154 | ls = isl_local_space_from_space(dim); |
1155 | |
1156 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
1157 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1); |
1158 | c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2); |
1159 | bset = isl_basic_set_add_constraint(bset, c); |
1160 | |
1161 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
1162 | |
1163 | bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2); |
1164 | |
1165 | isl_local_space_free(ls); |
1166 | isl_basic_set_free(bset); |
1167 | |
1168 | str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and " |
1169 | "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }"; |
1170 | set = isl_set_read_from_str(ctx, str); |
1171 | set = isl_set_compute_divs(set); |
1172 | isl_set_free(set); |
1173 | if (!set) |
1174 | return -1; |
1175 | |
1176 | if (test_elimination(ctx) < 0) |
1177 | return -1; |
1178 | |
1179 | str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }"; |
1180 | set = isl_set_read_from_str(ctx, str); |
1181 | set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2); |
1182 | set = isl_set_fix_si(set, isl_dim_set, 2, -3); |
1183 | empty = isl_set_is_empty(set); |
1184 | isl_set_free(set); |
1185 | if (empty < 0) |
1186 | return -1; |
1187 | if (!empty) |
1188 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as accurate as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1189); return -1; } while (0) |
1189 | "result not as accurate as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as accurate as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1189); return -1; } while (0); |
1190 | |
1191 | return 0; |
1192 | } |
1193 | |
1194 | void test_application_case(struct isl_ctx *ctx, const char *name) |
1195 | { |
1196 | char *filename; |
1197 | FILE *input; |
1198 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1199 | struct isl_basic_map *bmap; |
1200 | |
1201 | filename = get_filename(ctx, name, "omega"); |
1202 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1202, __PRETTY_FUNCTION__)); |
1203 | input = fopen(filename, "r"); |
1204 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1204, __PRETTY_FUNCTION__)); |
1205 | |
1206 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1207 | bmap = isl_basic_map_read_from_file(ctx, input); |
1208 | |
1209 | bset1 = isl_basic_set_apply(bset1, bmap); |
1210 | |
1211 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1212 | |
1213 | assert(isl_basic_set_is_equal(bset1, bset2) == 1)((isl_basic_set_is_equal(bset1, bset2) == 1) ? (void) (0) : __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1213, __PRETTY_FUNCTION__)); |
1214 | |
1215 | isl_basic_set_free(bset1); |
1216 | isl_basic_set_free(bset2); |
1217 | free(filename); |
1218 | |
1219 | fclose(input); |
1220 | } |
1221 | |
1222 | static int test_application(isl_ctx *ctx) |
1223 | { |
1224 | test_application_case(ctx, "application"); |
1225 | test_application_case(ctx, "application2"); |
1226 | |
1227 | return 0; |
1228 | } |
1229 | |
1230 | void test_affine_hull_case(struct isl_ctx *ctx, const char *name) |
1231 | { |
1232 | char *filename; |
1233 | FILE *input; |
1234 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1235 | |
1236 | filename = get_filename(ctx, name, "polylib"); |
1237 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1237, __PRETTY_FUNCTION__)); |
1238 | input = fopen(filename, "r"); |
1239 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1239, __PRETTY_FUNCTION__)); |
1240 | |
1241 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1242 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1243 | |
1244 | bset1 = isl_basic_set_affine_hull(bset1); |
1245 | |
1246 | assert(isl_basic_set_is_equal(bset1, bset2) == 1)((isl_basic_set_is_equal(bset1, bset2) == 1) ? (void) (0) : __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1246, __PRETTY_FUNCTION__)); |
1247 | |
1248 | isl_basic_set_free(bset1); |
1249 | isl_basic_set_free(bset2); |
1250 | free(filename); |
1251 | |
1252 | fclose(input); |
1253 | } |
1254 | |
1255 | int test_affine_hull(struct isl_ctx *ctx) |
1256 | { |
1257 | const char *str; |
1258 | isl_setisl_map *set; |
1259 | isl_basic_setisl_basic_map *bset, *bset2; |
1260 | int n; |
1261 | int subset; |
1262 | |
1263 | test_affine_hull_case(ctx, "affine2"); |
1264 | test_affine_hull_case(ctx, "affine"); |
1265 | test_affine_hull_case(ctx, "affine3"); |
1266 | |
1267 | str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and " |
1268 | "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and " |
1269 | "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and " |
1270 | "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }"; |
1271 | set = isl_set_read_from_str(ctx, str); |
1272 | bset = isl_set_affine_hull(set); |
1273 | n = isl_basic_set_dim(bset, isl_dim_div); |
1274 | isl_basic_set_free(bset); |
1275 | if (n != 0) |
1276 | isl_die(ctx, isl_error_unknown, "not expecting any divs",do { isl_handle_error(ctx, isl_error_unknown, "not expecting any divs" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1277); return -1; } while (0) |
1277 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "not expecting any divs" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1277); return -1; } while (0); |
1278 | |
1279 | /* Check that isl_map_affine_hull is not confused by |
1280 | * the reordering of divs in isl_map_align_divs. |
1281 | */ |
1282 | str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: " |
1283 | "32e0 = b and 32e1 = c); " |
1284 | "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }"; |
1285 | set = isl_set_read_from_str(ctx, str); |
1286 | bset = isl_set_affine_hull(set); |
1287 | isl_basic_set_free(bset); |
1288 | if (!bset) |
1289 | return -1; |
1290 | |
1291 | str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and " |
1292 | "32e2 = 31 + 31e0 }"; |
1293 | set = isl_set_read_from_str(ctx, str); |
1294 | bset = isl_set_affine_hull(set); |
1295 | str = "{ [a] : exists e : a = 32 e }"; |
1296 | bset2 = isl_basic_set_read_from_str(ctx, str); |
1297 | subset = isl_basic_set_is_subset(bset, bset2); |
1298 | isl_basic_set_free(bset); |
1299 | isl_basic_set_free(bset2); |
1300 | if (subset < 0) |
1301 | return -1; |
1302 | if (!subset) |
1303 | isl_die(ctx, isl_error_unknown, "not as accurate as expected",do { isl_handle_error(ctx, isl_error_unknown, "not as accurate as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1304); return -1; } while (0) |
1304 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "not as accurate as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1304); return -1; } while (0); |
1305 | |
1306 | return 0; |
1307 | } |
1308 | |
1309 | /* Pairs of maps and the corresponding expected results of |
1310 | * isl_map_plain_unshifted_simple_hull. |
1311 | */ |
1312 | struct { |
1313 | const char *map; |
1314 | const char *hull; |
1315 | } plain_unshifted_simple_hull_tests[] = { |
1316 | { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }", |
1317 | "{ [i] -> [j] : i >= 1 }" }, |
1318 | { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or " |
1319 | "(j mod 4 = 2 and k mod 6 = n) }", |
1320 | "{ [n] -> [i,j,k] : j mod 4 = 2 }" }, |
1321 | }; |
1322 | |
1323 | /* Basic tests for isl_map_plain_unshifted_simple_hull. |
1324 | */ |
1325 | static int test_plain_unshifted_simple_hull(isl_ctx *ctx) |
1326 | { |
1327 | int i; |
1328 | isl_map *map; |
1329 | isl_basic_map *hull, *expected; |
1330 | isl_bool equal; |
1331 | |
1332 | for (i = 0; i < ARRAY_SIZE(plain_unshifted_simple_hull_tests)(sizeof(plain_unshifted_simple_hull_tests)/sizeof(*plain_unshifted_simple_hull_tests )); ++i) { |
1333 | const char *str; |
1334 | str = plain_unshifted_simple_hull_tests[i].map; |
1335 | map = isl_map_read_from_str(ctx, str); |
1336 | str = plain_unshifted_simple_hull_tests[i].hull; |
1337 | expected = isl_basic_map_read_from_str(ctx, str); |
1338 | hull = isl_map_plain_unshifted_simple_hull(map); |
1339 | equal = isl_basic_map_is_equal(hull, expected); |
1340 | isl_basic_map_free(hull); |
1341 | isl_basic_map_free(expected); |
1342 | if (equal < 0) |
1343 | return -1; |
1344 | if (!equal) |
1345 | isl_die(ctx, isl_error_unknown, "unexpected hull",do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1346); return -1; } while (0) |
1346 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1346); return -1; } while (0); |
1347 | } |
1348 | |
1349 | return 0; |
1350 | } |
1351 | |
1352 | /* Pairs of sets and the corresponding expected results of |
1353 | * isl_set_unshifted_simple_hull. |
1354 | */ |
1355 | struct { |
1356 | const char *set; |
1357 | const char *hull; |
1358 | } unshifted_simple_hull_tests[] = { |
1359 | { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }", |
1360 | "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" }, |
1361 | }; |
1362 | |
1363 | /* Basic tests for isl_set_unshifted_simple_hull. |
1364 | */ |
1365 | static int test_unshifted_simple_hull(isl_ctx *ctx) |
1366 | { |
1367 | int i; |
1368 | isl_setisl_map *set; |
1369 | isl_basic_setisl_basic_map *hull, *expected; |
1370 | isl_bool equal; |
1371 | |
1372 | for (i = 0; i < ARRAY_SIZE(unshifted_simple_hull_tests)(sizeof(unshifted_simple_hull_tests)/sizeof(*unshifted_simple_hull_tests )); ++i) { |
1373 | const char *str; |
1374 | str = unshifted_simple_hull_tests[i].set; |
1375 | set = isl_set_read_from_str(ctx, str); |
1376 | str = unshifted_simple_hull_tests[i].hull; |
1377 | expected = isl_basic_set_read_from_str(ctx, str); |
1378 | hull = isl_set_unshifted_simple_hull(set); |
1379 | equal = isl_basic_set_is_equal(hull, expected); |
1380 | isl_basic_set_free(hull); |
1381 | isl_basic_set_free(expected); |
1382 | if (equal < 0) |
1383 | return -1; |
1384 | if (!equal) |
1385 | isl_die(ctx, isl_error_unknown, "unexpected hull",do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1386); return -1; } while (0) |
1386 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1386); return -1; } while (0); |
1387 | } |
1388 | |
1389 | return 0; |
1390 | } |
1391 | |
1392 | static int test_simple_hull(struct isl_ctx *ctx) |
1393 | { |
1394 | const char *str; |
1395 | isl_setisl_map *set; |
1396 | isl_basic_setisl_basic_map *bset; |
1397 | isl_bool is_empty; |
1398 | |
1399 | str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;" |
1400 | "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }"; |
1401 | set = isl_set_read_from_str(ctx, str); |
1402 | bset = isl_set_simple_hull(set); |
1403 | is_empty = isl_basic_set_is_empty(bset); |
1404 | isl_basic_set_free(bset); |
1405 | |
1406 | if (is_empty == isl_bool_error) |
1407 | return -1; |
1408 | |
1409 | if (is_empty == isl_bool_false) |
1410 | isl_die(ctx, isl_error_unknown, "Empty set should be detected",do { isl_handle_error(ctx, isl_error_unknown, "Empty set should be detected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1411); return -1; } while (0) |
1411 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "Empty set should be detected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1411); return -1; } while (0); |
1412 | |
1413 | if (test_plain_unshifted_simple_hull(ctx) < 0) |
1414 | return -1; |
1415 | if (test_unshifted_simple_hull(ctx) < 0) |
1416 | return -1; |
1417 | |
1418 | return 0; |
1419 | } |
1420 | |
1421 | void test_convex_hull_case(struct isl_ctx *ctx, const char *name) |
1422 | { |
1423 | char *filename; |
1424 | FILE *input; |
1425 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1426 | struct isl_setisl_map *set; |
1427 | |
1428 | filename = get_filename(ctx, name, "polylib"); |
1429 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1429, __PRETTY_FUNCTION__)); |
1430 | input = fopen(filename, "r"); |
1431 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1431, __PRETTY_FUNCTION__)); |
1432 | |
1433 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1434 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1435 | |
1436 | set = isl_basic_set_union(bset1, bset2); |
1437 | bset1 = isl_set_convex_hull(set); |
1438 | |
1439 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1440 | |
1441 | assert(isl_basic_set_is_equal(bset1, bset2) == 1)((isl_basic_set_is_equal(bset1, bset2) == 1) ? (void) (0) : __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1441, __PRETTY_FUNCTION__)); |
1442 | |
1443 | isl_basic_set_free(bset1); |
1444 | isl_basic_set_free(bset2); |
1445 | free(filename); |
1446 | |
1447 | fclose(input); |
1448 | } |
1449 | |
1450 | struct { |
1451 | const char *set; |
1452 | const char *hull; |
1453 | } convex_hull_tests[] = { |
1454 | { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or " |
1455 | "(i0 = 1 and i1 = 0 and i2 = 1) or " |
1456 | "(i0 = 0 and i1 = 0 and i2 = 0) }", |
1457 | "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" }, |
1458 | { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; " |
1459 | "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and " |
1460 | "i2 <= 5 and i2 >= 4; " |
1461 | "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }", |
1462 | "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and " |
1463 | "i2 <= 5 + i0 and i2 >= i0 }" }, |
1464 | { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }", |
1465 | "{ [x, y] : 1 = 0 }" }, |
1466 | { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; " |
1467 | "[x, y, 0] : x >= 0 and y < 0 }", |
1468 | "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" }, |
1469 | }; |
1470 | |
1471 | static int test_convex_hull_algo(isl_ctx *ctx, int convex) |
1472 | { |
1473 | int i; |
1474 | int orig_convex = ctx->opt->convex; |
1475 | ctx->opt->convex = convex; |
1476 | |
1477 | test_convex_hull_case(ctx, "convex0"); |
1478 | test_convex_hull_case(ctx, "convex1"); |
1479 | test_convex_hull_case(ctx, "convex2"); |
1480 | test_convex_hull_case(ctx, "convex3"); |
1481 | test_convex_hull_case(ctx, "convex4"); |
1482 | test_convex_hull_case(ctx, "convex5"); |
1483 | test_convex_hull_case(ctx, "convex6"); |
1484 | test_convex_hull_case(ctx, "convex7"); |
1485 | test_convex_hull_case(ctx, "convex8"); |
1486 | test_convex_hull_case(ctx, "convex9"); |
1487 | test_convex_hull_case(ctx, "convex10"); |
1488 | test_convex_hull_case(ctx, "convex11"); |
1489 | test_convex_hull_case(ctx, "convex12"); |
1490 | test_convex_hull_case(ctx, "convex13"); |
1491 | test_convex_hull_case(ctx, "convex14"); |
1492 | test_convex_hull_case(ctx, "convex15"); |
1493 | |
1494 | for (i = 0; i < ARRAY_SIZE(convex_hull_tests)(sizeof(convex_hull_tests)/sizeof(*convex_hull_tests)); ++i) { |
1495 | isl_setisl_map *set1, *set2; |
1496 | int equal; |
1497 | |
1498 | set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set); |
1499 | set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull); |
1500 | set1 = isl_set_from_basic_set(isl_set_convex_hull(set1)); |
1501 | equal = isl_set_is_equal(set1, set2); |
1502 | isl_set_free(set1); |
1503 | isl_set_free(set2); |
1504 | |
1505 | if (equal < 0) |
1506 | return -1; |
1507 | if (!equal) |
1508 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected convex hull" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1509); return -1; } while (0) |
1509 | "unexpected convex hull", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected convex hull" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1509); return -1; } while (0); |
1510 | } |
1511 | |
1512 | ctx->opt->convex = orig_convex; |
1513 | |
1514 | return 0; |
1515 | } |
1516 | |
1517 | static int test_convex_hull(isl_ctx *ctx) |
1518 | { |
1519 | if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM1) < 0) |
1520 | return -1; |
1521 | if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP0) < 0) |
1522 | return -1; |
1523 | return 0; |
1524 | } |
1525 | |
1526 | void test_gist_case(struct isl_ctx *ctx, const char *name) |
1527 | { |
1528 | char *filename; |
1529 | FILE *input; |
1530 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1531 | |
1532 | filename = get_filename(ctx, name, "polylib"); |
1533 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1533, __PRETTY_FUNCTION__)); |
1534 | input = fopen(filename, "r"); |
1535 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1535, __PRETTY_FUNCTION__)); |
1536 | |
1537 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1538 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1539 | |
1540 | bset1 = isl_basic_set_gist(bset1, bset2); |
1541 | |
1542 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1543 | |
1544 | assert(isl_basic_set_is_equal(bset1, bset2) == 1)((isl_basic_set_is_equal(bset1, bset2) == 1) ? (void) (0) : __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1544, __PRETTY_FUNCTION__)); |
1545 | |
1546 | isl_basic_set_free(bset1); |
1547 | isl_basic_set_free(bset2); |
1548 | free(filename); |
1549 | |
1550 | fclose(input); |
1551 | } |
1552 | |
1553 | /* Inputs to isl_map_plain_gist_basic_map, along with the expected output. |
1554 | */ |
1555 | struct { |
1556 | const char *map; |
1557 | const char *context; |
1558 | const char *gist; |
1559 | } plain_gist_tests[] = { |
1560 | { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }", |
1561 | "{ [i] -> [j] : i >= 1 }", |
1562 | "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" }, |
1563 | { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or " |
1564 | "(j mod 4 = 2 and k mod 6 = n) }", |
1565 | "{ [n] -> [i,j,k] : j mod 4 = 2 }", |
1566 | "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" }, |
1567 | { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }", |
1568 | "{ [i] -> [j] : i > j }", |
1569 | "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" }, |
1570 | }; |
1571 | |
1572 | /* Basic tests for isl_map_plain_gist_basic_map. |
1573 | */ |
1574 | static int test_plain_gist(isl_ctx *ctx) |
1575 | { |
1576 | int i; |
1577 | |
1578 | for (i = 0; i < ARRAY_SIZE(plain_gist_tests)(sizeof(plain_gist_tests)/sizeof(*plain_gist_tests)); ++i) { |
1579 | const char *str; |
1580 | int equal; |
1581 | isl_map *map, *gist; |
1582 | isl_basic_map *context; |
1583 | |
1584 | map = isl_map_read_from_str(ctx, plain_gist_tests[i].map); |
1585 | str = plain_gist_tests[i].context; |
1586 | context = isl_basic_map_read_from_str(ctx, str); |
1587 | map = isl_map_plain_gist_basic_map(map, context); |
1588 | gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist); |
1589 | equal = isl_map_is_equal(map, gist); |
1590 | isl_map_free(map); |
1591 | isl_map_free(gist); |
1592 | if (equal < 0) |
1593 | return -1; |
1594 | if (!equal) |
1595 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1596); return -1; } while (0) |
1596 | "incorrect gist result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1596); return -1; } while (0); |
1597 | } |
1598 | |
1599 | return 0; |
1600 | } |
1601 | |
1602 | /* Inputs for isl_basic_set_gist tests that are expected to fail. |
1603 | */ |
1604 | struct { |
1605 | const char *set; |
1606 | const char *context; |
1607 | } gist_fail_tests[] = { |
1608 | { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and " |
1609 | "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }", |
1610 | "{ [i] : i >= 0 }" }, |
1611 | }; |
1612 | |
1613 | /* Check that isl_basic_set_gist fails (gracefully) when expected. |
1614 | * In particular, the user should be able to recover from the failure. |
1615 | */ |
1616 | static isl_stat test_gist_fail(struct isl_ctx *ctx) |
1617 | { |
1618 | int i, n; |
1619 | int on_error; |
1620 | |
1621 | on_error = isl_options_get_on_error(ctx); |
1622 | isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE1); |
1623 | n = ARRAY_SIZE(gist_fail_tests)(sizeof(gist_fail_tests)/sizeof(*gist_fail_tests)); |
1624 | for (i = 0; i < n; ++i) { |
1625 | const char *str; |
1626 | isl_basic_setisl_basic_map *bset, *context; |
1627 | |
1628 | bset = isl_basic_set_read_from_str(ctx, gist_fail_tests[i].set); |
1629 | str = gist_fail_tests[i].context; |
1630 | context = isl_basic_set_read_from_str(ctx, str); |
1631 | bset = isl_basic_set_gist(bset, context); |
1632 | isl_basic_set_free(bset); |
1633 | if (bset) |
1634 | break; |
1635 | } |
1636 | isl_options_set_on_error(ctx, on_error); |
1637 | if (i < n) |
1638 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1640); return isl_stat_error; } while (0) |
1639 | "operation not expected to succeed",do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1640); return isl_stat_error; } while (0) |
1640 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1640); return isl_stat_error; } while (0); |
1641 | |
1642 | return isl_stat_ok; |
1643 | } |
1644 | |
1645 | struct { |
1646 | const char *set; |
1647 | const char *context; |
1648 | const char *gist; |
1649 | } gist_tests[] = { |
1650 | { "{ [a, b, c] : a <= 15 and a >= 1 }", |
1651 | "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and " |
1652 | "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }", |
1653 | "{ [a, b, c] : a <= 15 }" }, |
1654 | { "{ : }", "{ : 1 = 0 }", "{ : }" }, |
1655 | { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" }, |
1656 | { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }", |
1657 | "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" }, |
1658 | { "{ [m, n, a, b] : a <= 2147 + n }", |
1659 | "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and " |
1660 | "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or " |
1661 | "(n >= 1 and a >= 0 and b <= 2148 - n - a and " |
1662 | "b >= 0) }", |
1663 | "{ [m, n, ku, kl] }" }, |
1664 | { "{ [a, a, b] : a >= 10 }", |
1665 | "{ [a, b, c] : c >= a and c <= b and c >= 2 }", |
1666 | "{ [a, a, b] : a >= 10 }" }, |
1667 | { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }", |
1668 | "{ [0, j] : j >= 0 }" }, |
1669 | /* Check that no constraints on i6 are introduced in the gist */ |
1670 | { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): " |
1671 | "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and " |
1672 | "5e0 <= 381 - t1 and i4 <= 1) }", |
1673 | "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): " |
1674 | "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }", |
1675 | "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): " |
1676 | "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and " |
1677 | "20e0 >= 1511 - 4t1 - 5i4) }" }, |
1678 | /* Check that no constraints on i6 are introduced in the gist */ |
1679 | { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), " |
1680 | "e1 = floor((1530 - 4t1 - 5i4)/20), " |
1681 | "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), " |
1682 | "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and " |
1683 | "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and " |
1684 | "2e0 <= 1 + i4 and 2e0 >= i4 and " |
1685 | "20e1 <= 1530 - 4t1 - 5i4 and " |
1686 | "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and " |
1687 | "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }", |
1688 | "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), " |
1689 | "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and " |
1690 | "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and " |
1691 | "10e0 <= -91 + 5i4 + 4i6 and " |
1692 | "10e0 >= -105 + 5i4 + 4i6) }", |
1693 | "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), " |
1694 | "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and " |
1695 | "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" }, |
1696 | { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }", |
1697 | "{ [a, b, q, p] : b >= 1 + a }", |
1698 | "{ [a, b, q, p] : false }" }, |
1699 | { "[n] -> { [x] : x = n && x mod 32 = 0 }", |
1700 | "[n] -> { [x] : x mod 32 = 0 }", |
1701 | "[n] -> { [x = n] }" }, |
1702 | { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }", |
1703 | "{ [x] : x mod 2 = 0 }" }, |
1704 | { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }", |
1705 | "{ [x] : x mod 128 = 0 }" }, |
1706 | { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }", |
1707 | "{ [x] : x mod 3200 = 0 }" }, |
1708 | { "{ [a, b, c] : a mod 2 = 0 and a = c }", |
1709 | "{ [a, b, c] : b mod 2 = 0 and b = c }", |
1710 | "{ [a, b, c = a] }" }, |
1711 | { "{ [a, b, c] : a mod 6 = 0 and a = c }", |
1712 | "{ [a, b, c] : b mod 2 = 0 and b = c }", |
1713 | "{ [a, b, c = a] : a mod 3 = 0 }" }, |
1714 | { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }", |
1715 | "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }", |
1716 | "{ [x] }" }, |
1717 | { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }", |
1718 | "{ [x,y] : 1 <= y <= 3 }", |
1719 | "{ [x,y] }" }, |
1720 | }; |
1721 | |
1722 | /* Check that isl_set_gist behaves as expected. |
1723 | * |
1724 | * For the test cases in gist_tests, besides checking that the result |
1725 | * is as expected, also check that applying the gist operation does |
1726 | * not modify the input set (an earlier version of isl would do that) and |
1727 | * that the test case is consistent, i.e., that the gist has the same |
1728 | * intersection with the context as the input set. |
1729 | */ |
1730 | static int test_gist(struct isl_ctx *ctx) |
1731 | { |
1732 | int i; |
1733 | const char *str; |
1734 | isl_basic_setisl_basic_map *bset1, *bset2; |
1735 | isl_map *map1, *map2; |
1736 | int equal; |
1737 | |
1738 | for (i = 0; i < ARRAY_SIZE(gist_tests)(sizeof(gist_tests)/sizeof(*gist_tests)); ++i) { |
1739 | int equal_input, equal_intersection; |
1740 | isl_setisl_map *set1, *set2, *copy, *context; |
1741 | |
1742 | set1 = isl_set_read_from_str(ctx, gist_tests[i].set); |
1743 | context = isl_set_read_from_str(ctx, gist_tests[i].context); |
1744 | copy = isl_set_copy(set1); |
1745 | set1 = isl_set_gist(set1, isl_set_copy(context)); |
1746 | set2 = isl_set_read_from_str(ctx, gist_tests[i].gist); |
1747 | equal = isl_set_is_equal(set1, set2); |
1748 | isl_set_free(set1); |
1749 | set1 = isl_set_read_from_str(ctx, gist_tests[i].set); |
1750 | equal_input = isl_set_is_equal(set1, copy); |
1751 | isl_set_free(copy); |
1752 | set1 = isl_set_intersect(set1, isl_set_copy(context)); |
1753 | set2 = isl_set_intersect(set2, context); |
1754 | equal_intersection = isl_set_is_equal(set1, set2); |
1755 | isl_set_free(set2); |
1756 | isl_set_free(set1); |
1757 | if (equal < 0 || equal_input < 0 || equal_intersection < 0) |
1758 | return -1; |
1759 | if (!equal) |
1760 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1761); return -1; } while (0) |
1761 | "incorrect gist result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1761); return -1; } while (0); |
1762 | if (!equal_input) |
1763 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "gist modified input" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1764); return -1; } while (0) |
1764 | "gist modified input", return -1)do { isl_handle_error(ctx, isl_error_unknown, "gist modified input" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1764); return -1; } while (0); |
1765 | if (!equal_input) |
1766 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1767); return -1; } while (0) |
1767 | "inconsistent gist test case", return -1)do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1767); return -1; } while (0); |
1768 | } |
1769 | |
1770 | if (test_gist_fail(ctx) < 0) |
1771 | return -1; |
1772 | |
1773 | test_gist_case(ctx, "gist1"); |
1774 | |
1775 | str = "[p0, p2, p3, p5, p6, p10] -> { [] : " |
1776 | "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], " |
1777 | "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], " |
1778 | "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and " |
1779 | "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and " |
1780 | "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and " |
1781 | "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and " |
1782 | "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and " |
1783 | "p10 <= 15 and p10 <= -1 + p0 - p6) }"; |
1784 | bset1 = isl_basic_set_read_from_str(ctx, str); |
1785 | str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], " |
1786 | "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], " |
1787 | "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and " |
1788 | "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and " |
1789 | "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and " |
1790 | "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and " |
1791 | "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and " |
1792 | "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }"; |
1793 | bset2 = isl_basic_set_read_from_str(ctx, str); |
1794 | bset1 = isl_basic_set_gist(bset1, bset2); |
1795 | assert(bset1 && bset1->n_div == 0)((bset1 && bset1->n_div == 0) ? (void) (0) : __assert_fail ("bset1 && bset1->n_div == 0", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1795, __PRETTY_FUNCTION__)); |
1796 | isl_basic_set_free(bset1); |
1797 | |
1798 | /* Check that the integer divisions of the second disjunct |
1799 | * do not spread to the first disjunct. |
1800 | */ |
1801 | str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: " |
1802 | "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or " |
1803 | "(exists (e0 = [(-1 + t1)/16], " |
1804 | "e1 = [(-16 + t1 - 16e0)/4294967296]: " |
1805 | "4294967296e1 = -16 + t1 - o0 - 16e0 and " |
1806 | "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and " |
1807 | "o0 <= 4294967295 and t1 <= -1)) }"; |
1808 | map1 = isl_map_read_from_str(ctx, str); |
1809 | str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }"; |
1810 | map2 = isl_map_read_from_str(ctx, str); |
1811 | map1 = isl_map_gist(map1, map2); |
1812 | if (!map1) |
1813 | return -1; |
1814 | if (map1->n != 1) |
1815 | isl_die(ctx, isl_error_unknown, "expecting single disjunct",do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1816); isl_map_free(map1); return -1; } while (0) |
1816 | isl_map_free(map1); return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1816); isl_map_free(map1); return -1; } while (0); |
1817 | if (isl_basic_map_dim(map1->p[0], isl_dim_div) != 1) |
1818 | isl_die(ctx, isl_error_unknown, "expecting single div",do { isl_handle_error(ctx, isl_error_unknown, "expecting single div" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1819); isl_map_free(map1); return -1; } while (0) |
1819 | isl_map_free(map1); return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single div" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1819); isl_map_free(map1); return -1; } while (0); |
1820 | isl_map_free(map1); |
1821 | |
1822 | if (test_plain_gist(ctx) < 0) |
1823 | return -1; |
1824 | |
1825 | return 0; |
1826 | } |
1827 | |
1828 | int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one) |
1829 | { |
1830 | isl_setisl_map *set, *set2; |
1831 | int equal; |
1832 | int one; |
1833 | |
1834 | set = isl_set_read_from_str(ctx, str); |
1835 | set = isl_set_coalesce(set); |
1836 | set2 = isl_set_read_from_str(ctx, str); |
1837 | equal = isl_set_is_equal(set, set2); |
1838 | one = set && set->n == 1; |
1839 | isl_set_free(set); |
1840 | isl_set_free(set2); |
1841 | |
1842 | if (equal < 0) |
1843 | return -1; |
1844 | if (!equal) |
1845 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "coalesced set not equal to input" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1846); return -1; } while (0) |
1846 | "coalesced set not equal to input", return -1)do { isl_handle_error(ctx, isl_error_unknown, "coalesced set not equal to input" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1846); return -1; } while (0); |
1847 | if (check_one && !one) |
1848 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "coalesced set should not be a union" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1849); return -1; } while (0) |
1849 | "coalesced set should not be a union", return -1)do { isl_handle_error(ctx, isl_error_unknown, "coalesced set should not be a union" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 1849); return -1; } while (0); |
1850 | |
1851 | return 0; |
1852 | } |
1853 | |
1854 | /* Inputs for coalescing tests with unbounded wrapping. |
1855 | * "str" is a string representation of the input set. |
1856 | * "single_disjunct" is set if we expect the result to consist of |
1857 | * a single disjunct. |
1858 | */ |
1859 | struct { |
1860 | int single_disjunct; |
1861 | const char *str; |
1862 | } coalesce_unbounded_tests[] = { |
1863 | { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and " |
1864 | "-x - y + 1 >= 0 and -3 <= z <= 3;" |
1865 | "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and " |
1866 | "x-z + 20 >= 0 and x+z + 20 >= 0 and " |
1867 | "-10 <= y <= 0}" }, |
1868 | { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" }, |
1869 | { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" }, |
1870 | { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" }, |
1871 | { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" }, |
1872 | }; |
1873 | |
1874 | /* Test the functionality of isl_set_coalesce with the bounded wrapping |
1875 | * option turned off. |
1876 | */ |
1877 | int test_coalesce_unbounded_wrapping(isl_ctx *ctx) |
1878 | { |
1879 | int i; |
1880 | int r = 0; |
1881 | int bounded; |
1882 | |
1883 | bounded = isl_options_get_coalesce_bounded_wrapping(ctx); |
1884 | isl_options_set_coalesce_bounded_wrapping(ctx, 0); |
1885 | |
1886 | for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests)(sizeof(coalesce_unbounded_tests)/sizeof(*coalesce_unbounded_tests )); ++i) { |
1887 | const char *str = coalesce_unbounded_tests[i].str; |
1888 | int check_one = coalesce_unbounded_tests[i].single_disjunct; |
1889 | if (test_coalesce_set(ctx, str, check_one) >= 0) |
1890 | continue; |
1891 | r = -1; |
1892 | break; |
1893 | } |
1894 | |
1895 | isl_options_set_coalesce_bounded_wrapping(ctx, bounded); |
1896 | |
1897 | return r; |
1898 | } |
1899 | |
1900 | /* Inputs for coalescing tests. |
1901 | * "str" is a string representation of the input set. |
1902 | * "single_disjunct" is set if we expect the result to consist of |
1903 | * a single disjunct. |
1904 | */ |
1905 | struct { |
1906 | int single_disjunct; |
1907 | const char *str; |
1908 | } coalesce_tests[] = { |
1909 | { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or " |
1910 | "y >= x & x >= 2 & 5 >= y }" }, |
1911 | { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or " |
1912 | "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" }, |
1913 | { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or " |
1914 | "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" }, |
1915 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
1916 | "y >= 0 & x >= 6 & x <= 10 & y <= x}" }, |
1917 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
1918 | "y >= 0 & x >= 7 & x <= 10 & y <= x}" }, |
1919 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
1920 | "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" }, |
1921 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" }, |
1922 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" }, |
1923 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" }, |
1924 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" }, |
1925 | { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" }, |
1926 | { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" }, |
1927 | { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" }, |
1928 | { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], " |
1929 | "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], " |
1930 | "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and " |
1931 | "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and " |
1932 | "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and " |
1933 | "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and " |
1934 | "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and " |
1935 | "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);" |
1936 | "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], " |
1937 | "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], " |
1938 | "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and " |
1939 | "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and " |
1940 | "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and " |
1941 | "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and " |
1942 | "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and " |
1943 | "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and " |
1944 | "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and " |
1945 | "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" }, |
1946 | { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and " |
1947 | "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or " |
1948 | "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and " |
1949 | "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" }, |
1950 | { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> " |
1951 | "[o0, o1, o2, o3, o4, o5, o6]] : " |
1952 | "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and " |
1953 | "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and " |
1954 | "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and " |
1955 | "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 " |
1956 | "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and " |
1957 | "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 " |
1958 | "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and " |
1959 | "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 " |
1960 | "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or " |
1961 | "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and " |
1962 | "o6 >= i3 + i6 - o3 and M >= 0 and " |
1963 | "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and " |
1964 | "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" }, |
1965 | { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or " |
1966 | "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or " |
1967 | "(o0 = 0 and M >= 2 and N >= 3) or " |
1968 | "(M = 0 and o0 = 0 and N >= 3) }" }, |
1969 | { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and " |
1970 | "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or " |
1971 | "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and " |
1972 | "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" }, |
1973 | { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" }, |
1974 | { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" }, |
1975 | { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or " |
1976 | "(y = 3 and x = 1) }" }, |
1977 | { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and " |
1978 | "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and " |
1979 | "i1 <= M and i3 <= M and i4 <= M) or " |
1980 | "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and " |
1981 | "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and " |
1982 | "i4 <= -1 + M) }" }, |
1983 | { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or " |
1984 | "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" }, |
1985 | { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" }, |
1986 | { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" }, |
1987 | { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" }, |
1988 | { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" }, |
1989 | { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" }, |
1990 | { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" }, |
1991 | { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" }, |
1992 | { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" }, |
1993 | { 0, "{ [a, b] : exists e : 2e = a and " |
1994 | "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" }, |
1995 | { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and " |
1996 | "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and " |
1997 | "j >= 1 and j' <= i + j - i' and i >= 1; " |
1998 | "[1, 1, 1, 1] }" }, |
1999 | { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; " |
2000 | "[i,j] : exists a : j = 3a }" }, |
2001 | { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and " |
2002 | "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and " |
2003 | "a >= 3) or " |
2004 | "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and " |
2005 | "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" }, |
2006 | { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and " |
2007 | "c <= 6 + 8a and a >= 3; " |
2008 | "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and " |
2009 | "c <= 7 + 8a and a >= 3 and a <= 4 }" }, |
2010 | { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; " |
2011 | "[x,0] : 3 <= x <= 4 }" }, |
2012 | { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; " |
2013 | "[x,0] : 4 <= x <= 5 }" }, |
2014 | { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; " |
2015 | "[x,0] : 3 <= x <= 5 }" }, |
2016 | { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; " |
2017 | "[x,0] : 3 <= x <= 4 }" }, |
2018 | { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and " |
2019 | "i1 <= 0; " |
2020 | "[i0, 0] : i0 >= 123 and i0 <= 124 }" }, |
2021 | { 1, "{ [0,0]; [1,1] }" }, |
2022 | { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" }, |
2023 | { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and " |
2024 | "ii <= k;" |
2025 | "[k, 0, k] : k <= 6 and k >= 1 }" }, |
2026 | { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;" |
2027 | "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" }, |
2028 | { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" }, |
2029 | { 1, "[n] -> { [1] : n >= 0;" |
2030 | "[x] : exists (e0 = floor((x)/2): x >= 2 and " |
2031 | "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" }, |
2032 | { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): " |
2033 | "3e1 = y and x >= 2 and 2e0 >= -1 + x and " |
2034 | "2e0 <= x and 2e0 <= n);" |
2035 | "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and " |
2036 | "n >= 0) }" }, |
2037 | { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): " |
2038 | "128e0 >= -134 + 127t1 and t1 >= 2 and " |
2039 | "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or " |
2040 | "t1 = 1 }" }, |
2041 | { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and " |
2042 | "3e0 >= -1 + 2i and i <= 9 and i >= 1);" |
2043 | "[0, 0] }" }, |
2044 | { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and " |
2045 | "t1 >= 13 and t1 <= 16);" |
2046 | "[t1] : t1 <= 15 and t1 >= 12 }" }, |
2047 | { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" }, |
2048 | { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" }, |
2049 | { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" }, |
2050 | { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" }, |
2051 | { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;" |
2052 | "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and " |
2053 | "i <= 4j + 2 }" }, |
2054 | { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or " |
2055 | "(exists (e0 : 3e0 = -2 + c0)) }" }, |
2056 | { 0, "[n, b0, t0] -> " |
2057 | "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : " |
2058 | "(exists (e0 = floor((-32b0 + i4)/1048576), " |
2059 | "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and " |
2060 | "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and " |
2061 | "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and " |
2062 | "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and " |
2063 | "i8 >= -157 + i0 - 4i4 and i8 >= 0 and " |
2064 | "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or " |
2065 | "(exists (e0 = floor((-32b0 + i4)/1048576), " |
2066 | "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and " |
2067 | "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and " |
2068 | "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and " |
2069 | "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and " |
2070 | "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and " |
2071 | "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));" |
2072 | "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : " |
2073 | "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and " |
2074 | "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and " |
2075 | "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and " |
2076 | "i8 >= -40 + i0 and i8 <= -10 + i0)) }" }, |
2077 | { 0, "{ [i0, i1, i2] : " |
2078 | "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): " |
2079 | "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and " |
2080 | "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and " |
2081 | "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and " |
2082 | "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and " |
2083 | "32e0 <= 31 + i0)) or " |
2084 | "i0 >= 0 }" }, |
2085 | { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" }, |
2086 | { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and " |
2087 | "2*floor((c)/2) = c and 0 <= a <= 192;" |
2088 | "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }" |
2089 | }, |
2090 | { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or " |
2091 | "(0 <= a <= b <= n) }" }, |
2092 | { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and " |
2093 | "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" }, |
2094 | { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" }, |
2095 | { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and " |
2096 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
2097 | "(exists (e0 = floor((-16 + 2c)/9): a = 4 and " |
2098 | "b = 3 and 9e0 <= -19 + 2c)) }" }, |
2099 | { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and " |
2100 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
2101 | "(a = 4 and b = 3 and " |
2102 | "9*floor((-16 + 2c)/9) <= -19 + 2c) }" }, |
2103 | { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or " |
2104 | "(b = -1 + a and 0 < a <= 3 and " |
2105 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
2106 | "(exists (e0 = floor((-16 + 2c)/9): a = 4 and " |
2107 | "b = 3 and 9e0 <= -19 + 2c)) }" }, |
2108 | { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;" |
2109 | "[1, 0] }" }, |
2110 | { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;" |
2111 | "[0, 1] }" }, |
2112 | { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" }, |
2113 | { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" }, |
2114 | { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; " |
2115 | "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; " |
2116 | "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; " |
2117 | "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" }, |
2118 | { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; " |
2119 | "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; " |
2120 | "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" }, |
2121 | { 1, "{ [a] : a <= 8 and " |
2122 | "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" }, |
2123 | { 1, "{ [x, y] : 2y = -x and x <= 0 or " |
2124 | "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" }, |
2125 | { 0, "{ [x, y] : 2y = -x and x <= 0 or " |
2126 | "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" }, |
2127 | { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or " |
2128 | "(a < 0 and 3*floor((a)/3) < a) }" }, |
2129 | { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or " |
2130 | "(a < -1 and 3*floor((a)/3) < a) }" }, |
2131 | { 1, "{ [a, b] : a <= 1024 and b >= 0 and " |
2132 | "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and " |
2133 | "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))" |
2134 | "or (2 <= a <= 15 and b < a)) }" }, |
2135 | { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and " |
2136 | "32*floor((a)/32) < a) or a <= 15) }" }, |
2137 | { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and " |
2138 | "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;" |
2139 | "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and " |
2140 | "10 - a <= c <= 5 and 5 <= d <= 73 - c }" }, |
2141 | { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and " |
2142 | "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; " |
2143 | "S_0[n] : n <= m <= 2 + n }" }, |
2144 | { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and " |
2145 | "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and " |
2146 | "2e0 <= a + b); " |
2147 | "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and " |
2148 | "2e0 >= -1 - a + b and 2e0 <= -a + b and " |
2149 | "2e0 < -a + 2b) }" }, |
2150 | { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; " |
2151 | "[i, 0, i] : 0 <= i <= 7 }" }, |
2152 | { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" }, |
2153 | { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" }, |
2154 | { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" }, |
2155 | { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" }, |
2156 | { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" }, |
2157 | { 0, "{ [a, c] : (2 + a) mod 4 = 0 or " |
2158 | "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or " |
2159 | "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and " |
2160 | "a > 0 and a <= 5) }" }, |
2161 | { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" }, |
2162 | }; |
2163 | |
2164 | /* A specialized coalescing test case that would result |
2165 | * in a segmentation fault or a failed assertion in earlier versions of isl. |
2166 | */ |
2167 | static int test_coalesce_special(struct isl_ctx *ctx) |
2168 | { |
2169 | const char *str; |
2170 | isl_map *map1, *map2; |
2171 | |
2172 | str = "[y] -> { [S_L220_OUT[] -> T7[]] -> " |
2173 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : " |
2174 | "(y = 201 and o1 <= 239 and o1 >= 212) or " |
2175 | "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and " |
2176 | "o1 <= 239 and o1 >= 212)) or " |
2177 | "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and " |
2178 | "o1 <= 241 and o1 >= 240));" |
2179 | "[S_L220_OUT[] -> T7[]] -> " |
2180 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : " |
2181 | "(y = 2 and o1 <= 241 and o1 >= 212) or " |
2182 | "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and " |
2183 | "y >= 5 and o1 <= 241 and o1 >= 212)) }"; |
2184 | map1 = isl_map_read_from_str(ctx, str); |
2185 | map1 = isl_map_align_divs_internal(map1); |
2186 | map1 = isl_map_coalesce(map1); |
2187 | str = "[y] -> { [S_L220_OUT[] -> T7[]] -> " |
2188 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : " |
2189 | "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and " |
2190 | "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and " |
2191 | "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }"; |
2192 | map2 = isl_map_read_from_str(ctx, str); |
2193 | map2 = isl_map_union(map2, map1); |
2194 | map2 = isl_map_align_divs_internal(map2); |
2195 | map2 = isl_map_coalesce(map2); |
2196 | isl_map_free(map2); |
2197 | if (!map2) |
2198 | return -1; |
2199 | |
2200 | return 0; |
2201 | } |
2202 | |
2203 | /* A specialized coalescing test case that would result in an assertion |
2204 | * in an earlier version of isl. |
2205 | * The explicit call to isl_basic_set_union prevents the implicit |
2206 | * equality constraints in the first basic map from being detected prior |
2207 | * to the call to isl_set_coalesce, at least at the point |
2208 | * where this test case was introduced. |
2209 | */ |
2210 | static int test_coalesce_special2(struct isl_ctx *ctx) |
2211 | { |
2212 | const char *str; |
2213 | isl_basic_setisl_basic_map *bset1, *bset2; |
2214 | isl_setisl_map *set; |
2215 | |
2216 | str = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }"; |
2217 | bset1 = isl_basic_set_read_from_str(ctx, str); |
2218 | str = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ; |
2219 | bset2 = isl_basic_set_read_from_str(ctx, str); |
2220 | set = isl_basic_set_union(bset1, bset2); |
2221 | set = isl_set_coalesce(set); |
2222 | isl_set_free(set); |
2223 | |
2224 | if (!set) |
2225 | return -1; |
2226 | return 0; |
2227 | } |
2228 | |
2229 | /* Check that calling isl_set_coalesce does not leave other sets |
2230 | * that may share some information with the input to isl_set_coalesce |
2231 | * in an inconsistent state. |
2232 | * In particular, older versions of isl would modify all copies |
2233 | * of the basic sets in the isl_set_coalesce input in a way |
2234 | * that could leave them in an inconsistent state. |
2235 | * The result of printing any other set containing one of these |
2236 | * basic sets would then result in an invalid set description. |
2237 | */ |
2238 | static int test_coalesce_special3(isl_ctx *ctx) |
2239 | { |
2240 | const char *str; |
2241 | char *s; |
2242 | isl_setisl_map *set1, *set2; |
2243 | isl_printer *p; |
2244 | |
2245 | set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }"); |
2246 | str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }"; |
2247 | set2 = isl_set_read_from_str(ctx, str); |
2248 | set1 = isl_set_union(set1, isl_set_copy(set2)); |
2249 | set1 = isl_set_coalesce(set1); |
2250 | isl_set_free(set1); |
2251 | |
2252 | p = isl_printer_to_str(ctx); |
2253 | p = isl_printer_print_set(p, set2); |
2254 | isl_set_free(set2); |
2255 | s = isl_printer_get_str(p); |
2256 | isl_printer_free(p); |
2257 | set1 = isl_set_read_from_str(ctx, s); |
2258 | free(s); |
2259 | isl_set_free(set1); |
2260 | |
2261 | if (!set1) |
2262 | return -1; |
2263 | |
2264 | return 0; |
2265 | } |
2266 | |
2267 | /* Test the functionality of isl_set_coalesce. |
2268 | * That is, check that the output is always equal to the input |
2269 | * and in some cases that the result consists of a single disjunct. |
2270 | */ |
2271 | static int test_coalesce(struct isl_ctx *ctx) |
2272 | { |
2273 | int i; |
2274 | |
2275 | for (i = 0; i < ARRAY_SIZE(coalesce_tests)(sizeof(coalesce_tests)/sizeof(*coalesce_tests)); ++i) { |
2276 | const char *str = coalesce_tests[i].str; |
2277 | int check_one = coalesce_tests[i].single_disjunct; |
2278 | if (test_coalesce_set(ctx, str, check_one) < 0) |
2279 | return -1; |
2280 | } |
2281 | |
2282 | if (test_coalesce_unbounded_wrapping(ctx) < 0) |
2283 | return -1; |
2284 | if (test_coalesce_special(ctx) < 0) |
2285 | return -1; |
2286 | if (test_coalesce_special2(ctx) < 0) |
2287 | return -1; |
2288 | if (test_coalesce_special3(ctx) < 0) |
2289 | return -1; |
2290 | |
2291 | return 0; |
2292 | } |
2293 | |
2294 | /* Construct a representation of the graph on the right of Figure 1 |
2295 | * in "Computing the Transitive Closure of a Union of |
2296 | * Affine Integer Tuple Relations". |
2297 | */ |
2298 | static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx) |
2299 | { |
2300 | isl_setisl_map *dom; |
2301 | isl_map *up, *right; |
2302 | |
2303 | dom = isl_set_read_from_str(ctx, |
2304 | "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and " |
2305 | "2 x - 3 y + 3 >= 0 }"); |
2306 | right = isl_map_read_from_str(ctx, |
2307 | "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }"); |
2308 | up = isl_map_read_from_str(ctx, |
2309 | "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }"); |
2310 | right = isl_map_intersect_domain(right, isl_set_copy(dom)); |
2311 | right = isl_map_intersect_range(right, isl_set_copy(dom)); |
2312 | up = isl_map_intersect_domain(up, isl_set_copy(dom)); |
2313 | up = isl_map_intersect_range(up, dom); |
2314 | return isl_map_union(up, right); |
2315 | } |
2316 | |
2317 | /* Construct a representation of the power of the graph |
2318 | * on the right of Figure 1 in "Computing the Transitive Closure of |
2319 | * a Union of Affine Integer Tuple Relations". |
2320 | */ |
2321 | static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx) |
2322 | { |
2323 | return isl_map_read_from_str(ctx, |
2324 | "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; " |
2325 | " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; " |
2326 | " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }"); |
2327 | } |
2328 | |
2329 | /* Construct a representation of the transitive closure of the graph |
2330 | * on the right of Figure 1 in "Computing the Transitive Closure of |
2331 | * a Union of Affine Integer Tuple Relations". |
2332 | */ |
2333 | static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx) |
2334 | { |
2335 | return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx))); |
2336 | } |
2337 | |
2338 | static int test_closure(isl_ctx *ctx) |
2339 | { |
2340 | const char *str; |
2341 | isl_map *map, *map2; |
2342 | int exact, equal; |
2343 | |
2344 | /* COCOA example 1 */ |
2345 | map = isl_map_read_from_str(ctx, |
2346 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and " |
2347 | "1 <= i and i < n and 1 <= j and j < n or " |
2348 | "i2 = i + 1 and j2 = j - 1 and " |
2349 | "1 <= i and i < n and 2 <= j and j <= n }"); |
2350 | map = isl_map_power(map, &exact); |
2351 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2351, __PRETTY_FUNCTION__)); |
2352 | isl_map_free(map); |
2353 | |
2354 | /* COCOA example 1 */ |
2355 | map = isl_map_read_from_str(ctx, |
2356 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and " |
2357 | "1 <= i and i < n and 1 <= j and j < n or " |
2358 | "i2 = i + 1 and j2 = j - 1 and " |
2359 | "1 <= i and i < n and 2 <= j and j <= n }"); |
2360 | map = isl_map_transitive_closure(map, &exact); |
2361 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2361, __PRETTY_FUNCTION__)); |
2362 | map2 = isl_map_read_from_str(ctx, |
2363 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : " |
2364 | "1 <= i and i < n and 1 <= j and j <= n and " |
2365 | "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and " |
2366 | "i2 = i + k1 + k2 and j2 = j + k1 - k2 and " |
2367 | "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}"); |
2368 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2368, __PRETTY_FUNCTION__)); |
2369 | isl_map_free(map2); |
2370 | isl_map_free(map); |
2371 | |
2372 | map = isl_map_read_from_str(ctx, |
2373 | "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and " |
2374 | " 0 <= y and y <= n }"); |
2375 | map = isl_map_transitive_closure(map, &exact); |
2376 | map2 = isl_map_read_from_str(ctx, |
2377 | "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and " |
2378 | " 0 <= y and y <= n }"); |
2379 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2379, __PRETTY_FUNCTION__)); |
2380 | isl_map_free(map2); |
2381 | isl_map_free(map); |
2382 | |
2383 | /* COCOA example 2 */ |
2384 | map = isl_map_read_from_str(ctx, |
2385 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and " |
2386 | "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or " |
2387 | "i2 = i + 2 and j2 = j - 2 and " |
2388 | "1 <= i and i < n - 1 and 3 <= j and j <= n }"); |
2389 | map = isl_map_transitive_closure(map, &exact); |
2390 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2390, __PRETTY_FUNCTION__)); |
2391 | map2 = isl_map_read_from_str(ctx, |
2392 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : " |
2393 | "1 <= i and i < n - 1 and 1 <= j and j <= n and " |
2394 | "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and " |
2395 | "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and " |
2396 | "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }"); |
2397 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2397, __PRETTY_FUNCTION__)); |
2398 | isl_map_free(map); |
2399 | isl_map_free(map2); |
2400 | |
2401 | /* COCOA Fig.2 left */ |
2402 | map = isl_map_read_from_str(ctx, |
2403 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and " |
2404 | "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and " |
2405 | "j <= n or " |
2406 | "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and " |
2407 | "j <= 2 i - 3 and j <= n - 2 or " |
2408 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2409 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2410 | map = isl_map_transitive_closure(map, &exact); |
2411 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2411, __PRETTY_FUNCTION__)); |
2412 | isl_map_free(map); |
2413 | |
2414 | /* COCOA Fig.2 right */ |
2415 | map = isl_map_read_from_str(ctx, |
2416 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and " |
2417 | "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and " |
2418 | "j <= n or " |
2419 | "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and " |
2420 | "j <= 2 i - 4 and j <= n - 3 or " |
2421 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2422 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2423 | map = isl_map_power(map, &exact); |
2424 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2424, __PRETTY_FUNCTION__)); |
2425 | isl_map_free(map); |
2426 | |
2427 | /* COCOA Fig.2 right */ |
2428 | map = isl_map_read_from_str(ctx, |
2429 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and " |
2430 | "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and " |
2431 | "j <= n or " |
2432 | "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and " |
2433 | "j <= 2 i - 4 and j <= n - 3 or " |
2434 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2435 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2436 | map = isl_map_transitive_closure(map, &exact); |
2437 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2437, __PRETTY_FUNCTION__)); |
2438 | map2 = isl_map_read_from_str(ctx, |
2439 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : " |
2440 | "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and " |
2441 | "j <= n and 3 + i + 2 j <= 3 n and " |
2442 | "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and " |
2443 | "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and " |
2444 | "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and " |
2445 | "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and " |
2446 | "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }"); |
2447 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2447, __PRETTY_FUNCTION__)); |
2448 | isl_map_free(map2); |
2449 | isl_map_free(map); |
2450 | |
2451 | map = cocoa_fig_1_right_graph(ctx); |
2452 | map = isl_map_transitive_closure(map, &exact); |
2453 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2453, __PRETTY_FUNCTION__)); |
2454 | map2 = cocoa_fig_1_right_tc(ctx); |
2455 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2455, __PRETTY_FUNCTION__)); |
2456 | isl_map_free(map2); |
2457 | isl_map_free(map); |
2458 | |
2459 | map = cocoa_fig_1_right_graph(ctx); |
2460 | map = isl_map_power(map, &exact); |
2461 | map2 = cocoa_fig_1_right_power(ctx); |
2462 | equal = isl_map_is_equal(map, map2); |
2463 | isl_map_free(map2); |
2464 | isl_map_free(map); |
2465 | if (equal < 0) |
2466 | return -1; |
2467 | if (!exact) |
2468 | isl_die(ctx, isl_error_unknown, "power not exact", return -1)do { isl_handle_error(ctx, isl_error_unknown, "power not exact" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2468); return -1; } while (0); |
2469 | if (!equal) |
2470 | isl_die(ctx, isl_error_unknown, "unexpected power", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected power" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2470); return -1; } while (0); |
2471 | |
2472 | /* COCOA Theorem 1 counter example */ |
2473 | map = isl_map_read_from_str(ctx, |
2474 | "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and " |
2475 | "i2 = 1 and j2 = j or " |
2476 | "i = 0 and j = 0 and i2 = 0 and j2 = 1 }"); |
2477 | map = isl_map_transitive_closure(map, &exact); |
2478 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2478, __PRETTY_FUNCTION__)); |
2479 | isl_map_free(map); |
2480 | |
2481 | map = isl_map_read_from_str(ctx, |
2482 | "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and " |
2483 | "1 <= i,i2 <= n and 1 <= j,j2 <= m or " |
2484 | "i2 = i + 1 and 3 <= j2 - j <= 4 and " |
2485 | "1 <= i,i2 <= n and 1 <= j,j2 <= m }"); |
2486 | map = isl_map_transitive_closure(map, &exact); |
2487 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2487, __PRETTY_FUNCTION__)); |
2488 | isl_map_free(map); |
2489 | |
2490 | /* Kelly et al 1996, fig 12 */ |
2491 | map = isl_map_read_from_str(ctx, |
2492 | "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and " |
2493 | "1 <= i,j,j+1 <= n or " |
2494 | "j = n and j2 = 1 and i2 = i + 1 and " |
2495 | "1 <= i,i+1 <= n }"); |
2496 | map = isl_map_transitive_closure(map, &exact); |
2497 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2497, __PRETTY_FUNCTION__)); |
2498 | map2 = isl_map_read_from_str(ctx, |
2499 | "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and " |
2500 | "1 <= i <= n and i = i2 or " |
2501 | "1 <= i < i2 <= n and 1 <= j <= n and " |
2502 | "1 <= j2 <= n }"); |
2503 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2503, __PRETTY_FUNCTION__)); |
2504 | isl_map_free(map2); |
2505 | isl_map_free(map); |
2506 | |
2507 | /* Omega's closure4 */ |
2508 | map = isl_map_read_from_str(ctx, |
2509 | "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and " |
2510 | "1 <= x,y <= 10 or " |
2511 | "x2 = x + 1 and y2 = y and " |
2512 | "1 <= x <= 20 && 5 <= y <= 15 }"); |
2513 | map = isl_map_transitive_closure(map, &exact); |
2514 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2514, __PRETTY_FUNCTION__)); |
2515 | isl_map_free(map); |
2516 | |
2517 | map = isl_map_read_from_str(ctx, |
2518 | "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }"); |
2519 | map = isl_map_transitive_closure(map, &exact); |
2520 | assert(!exact)((!exact) ? (void) (0) : __assert_fail ("!exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2520, __PRETTY_FUNCTION__)); |
2521 | map2 = isl_map_read_from_str(ctx, |
2522 | "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }"); |
2523 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2523, __PRETTY_FUNCTION__)); |
2524 | isl_map_free(map); |
2525 | isl_map_free(map2); |
2526 | |
2527 | str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : " |
2528 | "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and " |
2529 | "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and " |
2530 | "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }"; |
2531 | map = isl_map_read_from_str(ctx, str); |
2532 | map = isl_map_transitive_closure(map, &exact); |
2533 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2533, __PRETTY_FUNCTION__)); |
2534 | map2 = isl_map_read_from_str(ctx, str); |
2535 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2535, __PRETTY_FUNCTION__)); |
2536 | isl_map_free(map); |
2537 | isl_map_free(map2); |
2538 | |
2539 | str = "{[0] -> [1]; [2] -> [3]}"; |
2540 | map = isl_map_read_from_str(ctx, str); |
2541 | map = isl_map_transitive_closure(map, &exact); |
2542 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2542, __PRETTY_FUNCTION__)); |
2543 | map2 = isl_map_read_from_str(ctx, str); |
2544 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2544, __PRETTY_FUNCTION__)); |
2545 | isl_map_free(map); |
2546 | isl_map_free(map2); |
2547 | |
2548 | str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> " |
2549 | "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : " |
2550 | "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and " |
2551 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2552 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2553 | "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> " |
2554 | "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : " |
2555 | "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and " |
2556 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2557 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2558 | "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> " |
2559 | "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : " |
2560 | "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and " |
2561 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2562 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2563 | "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> " |
2564 | "[[i0, i1, 1, 0, i0] -> [i5, 1]] : " |
2565 | "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and " |
2566 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2567 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }"; |
2568 | map = isl_map_read_from_str(ctx, str); |
2569 | map = isl_map_transitive_closure(map, NULL((void*)0)); |
2570 | assert(map)((map) ? (void) (0) : __assert_fail ("map", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2570, __PRETTY_FUNCTION__)); |
2571 | isl_map_free(map); |
2572 | |
2573 | return 0; |
2574 | } |
2575 | |
2576 | static int test_lex(struct isl_ctx *ctx) |
2577 | { |
2578 | isl_space *dim; |
2579 | isl_map *map; |
2580 | int empty; |
2581 | |
2582 | dim = isl_space_set_alloc(ctx, 0, 0); |
2583 | map = isl_map_lex_le(dim); |
2584 | empty = isl_map_is_empty(map); |
2585 | isl_map_free(map); |
2586 | |
2587 | if (empty < 0) |
2588 | return -1; |
2589 | if (empty) |
2590 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2591); return -1; } while (0) |
2591 | "expecting non-empty result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2591); return -1; } while (0); |
2592 | |
2593 | return 0; |
2594 | } |
2595 | |
2596 | /* Inputs for isl_map_lexmin tests. |
2597 | * "map" is the input and "lexmin" is the expected result. |
2598 | */ |
2599 | struct { |
2600 | const char *map; |
2601 | const char *lexmin; |
2602 | } lexmin_tests [] = { |
2603 | { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }", |
2604 | "{ [x] -> [5] : 6 <= x <= 8; " |
2605 | "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" }, |
2606 | { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }", |
2607 | "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" }, |
2608 | { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }", |
2609 | "{ [x] -> [y] : (4y = x and x >= 0) or " |
2610 | "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and " |
2611 | "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or " |
2612 | "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" }, |
2613 | { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }", |
2614 | "{ T[a] -> S[b, c] : 2b = a and 2c = a }" }, |
2615 | /* Check that empty pieces are properly combined. */ |
2616 | { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and " |
2617 | "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and " |
2618 | "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }", |
2619 | "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and " |
2620 | "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and " |
2621 | "x >= 4 }" }, |
2622 | { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and " |
2623 | "a <= 255 and c <= 255 and d <= 255 - j and " |
2624 | "255 - j <= 7d <= 7 - i and 240d <= 239 + a and " |
2625 | "247d <= 247 + k - j and 247d <= 247 + k - b and " |
2626 | "247d <= 247 + i and 248 - b <= 248d <= c and " |
2627 | "254d >= i - a + b and 254d >= -a + b and " |
2628 | "255d >= -i + a - b and 1792d >= -63736 + 257b }", |
2629 | "{ [i, k, j] -> " |
2630 | "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : " |
2631 | "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and " |
2632 | "247j >= 62738 - i and 509j <= 129795 + i and " |
2633 | "742j >= 188724 - i; " |
2634 | "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" }, |
2635 | { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and " |
2636 | "16*floor((8 + b)/16) <= 7 + b; " |
2637 | "[a] -> [1] }", |
2638 | "{ [a] -> [b = 1] : a >= 510 or a <= 0; " |
2639 | "[a] -> [b = 0] : 0 < a <= 509 }" }, |
2640 | { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" }, |
2641 | { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" }, |
2642 | }; |
2643 | |
2644 | static int test_lexmin(struct isl_ctx *ctx) |
2645 | { |
2646 | int i; |
2647 | int equal; |
2648 | const char *str; |
2649 | isl_basic_map *bmap; |
2650 | isl_map *map, *map2; |
2651 | isl_setisl_map *set; |
2652 | isl_setisl_map *set2; |
2653 | isl_pw_multi_aff *pma; |
2654 | |
2655 | str = "[p0, p1] -> { [] -> [] : " |
2656 | "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], " |
2657 | "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: " |
2658 | "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and " |
2659 | "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and " |
2660 | "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and " |
2661 | "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and " |
2662 | "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and " |
2663 | "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and " |
2664 | "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and " |
2665 | "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and " |
2666 | "e2 <= e1 and e3 >= 1 and e4 <= e2) }"; |
2667 | map = isl_map_read_from_str(ctx, str); |
2668 | map = isl_map_lexmin(map); |
2669 | isl_map_free(map); |
2670 | |
2671 | str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and " |
2672 | "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }"; |
2673 | set = isl_set_read_from_str(ctx, str); |
2674 | set = isl_set_lexmax(set); |
2675 | str = "[C] -> { [obj,a,b,c] : C = 8 }"; |
2676 | set2 = isl_set_read_from_str(ctx, str); |
2677 | set = isl_set_intersect(set, set2); |
2678 | assert(!isl_set_is_empty(set))((!isl_set_is_empty(set)) ? (void) (0) : __assert_fail ("!isl_set_is_empty(set)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2678, __PRETTY_FUNCTION__)); |
2679 | isl_set_free(set); |
2680 | |
2681 | for (i = 0; i < ARRAY_SIZE(lexmin_tests)(sizeof(lexmin_tests)/sizeof(*lexmin_tests)); ++i) { |
2682 | map = isl_map_read_from_str(ctx, lexmin_tests[i].map); |
2683 | map = isl_map_lexmin(map); |
2684 | map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin); |
2685 | equal = isl_map_is_equal(map, map2); |
2686 | isl_map_free(map); |
2687 | isl_map_free(map2); |
2688 | |
2689 | if (equal < 0) |
2690 | return -1; |
2691 | if (!equal) |
2692 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2693); return -1; } while (0) |
2693 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2693); return -1; } while (0); |
2694 | } |
2695 | |
2696 | str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and " |
2697 | " 8i' <= i and 8i' >= -7 + i }"; |
2698 | bmap = isl_basic_map_read_from_str(ctx, str); |
2699 | pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap)); |
2700 | map2 = isl_map_from_pw_multi_aff(pma); |
2701 | map = isl_map_from_basic_map(bmap); |
2702 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2702, __PRETTY_FUNCTION__)); |
2703 | isl_map_free(map); |
2704 | isl_map_free(map2); |
2705 | |
2706 | str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and " |
2707 | " 8i' <= i and 8i' >= -7 + i }"; |
2708 | set = isl_set_read_from_str(ctx, str); |
2709 | pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set)); |
2710 | set2 = isl_set_from_pw_multi_aff(pma); |
2711 | equal = isl_set_is_equal(set, set2); |
2712 | isl_set_free(set); |
2713 | isl_set_free(set2); |
2714 | if (equal < 0) |
2715 | return -1; |
2716 | if (!equal) |
2717 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2719); return -1; } while (0) |
2718 | "unexpected difference between set and "do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2719); return -1; } while (0) |
2719 | "piecewise affine expression", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2719); return -1; } while (0); |
2720 | |
2721 | return 0; |
2722 | } |
2723 | |
2724 | /* A specialized isl_set_min_val test case that would return the wrong result |
2725 | * in earlier versions of isl. |
2726 | * The explicit call to isl_basic_set_union prevents the second basic set |
2727 | * from being determined to be empty prior to the call to isl_set_min_val, |
2728 | * at least at the point where this test case was introduced. |
2729 | */ |
2730 | static int test_min_special(isl_ctx *ctx) |
2731 | { |
2732 | const char *str; |
2733 | isl_basic_setisl_basic_map *bset1, *bset2; |
2734 | isl_setisl_map *set; |
2735 | isl_aff *obj; |
2736 | isl_val *res; |
2737 | int ok; |
2738 | |
2739 | str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }"; |
2740 | bset1 = isl_basic_set_read_from_str(ctx, str); |
2741 | str = "{ [a, b] : 1 <= a, b and a + b <= 1 }"; |
2742 | bset2 = isl_basic_set_read_from_str(ctx, str); |
2743 | set = isl_basic_set_union(bset1, bset2); |
2744 | obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }"); |
2745 | |
2746 | res = isl_set_min_val(set, obj); |
2747 | ok = isl_val_cmp_si(res, 5) == 0; |
2748 | |
2749 | isl_aff_free(obj); |
2750 | isl_set_free(set); |
2751 | isl_val_free(res); |
2752 | |
2753 | if (!res) |
2754 | return -1; |
2755 | if (!ok) |
2756 | isl_die(ctx, isl_error_unknown, "unexpected minimum",do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2757); return -1; } while (0) |
2757 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2757); return -1; } while (0); |
2758 | |
2759 | return 0; |
2760 | } |
2761 | |
2762 | /* A specialized isl_set_min_val test case that would return an error |
2763 | * in earlier versions of isl. |
2764 | */ |
2765 | static int test_min_special2(isl_ctx *ctx) |
2766 | { |
2767 | const char *str; |
2768 | isl_basic_setisl_basic_map *bset; |
2769 | isl_aff *obj; |
2770 | isl_val *res; |
2771 | |
2772 | str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }"; |
2773 | bset = isl_basic_set_read_from_str(ctx, str); |
2774 | |
2775 | obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }"); |
2776 | |
2777 | res = isl_basic_set_max_val(bset, obj); |
2778 | |
2779 | isl_basic_set_free(bset); |
2780 | isl_aff_free(obj); |
2781 | isl_val_free(res); |
2782 | |
2783 | if (!res) |
2784 | return -1; |
2785 | |
2786 | return 0; |
2787 | } |
2788 | |
2789 | struct { |
2790 | const char *set; |
2791 | const char *obj; |
2792 | __isl_give isl_val *(*fn)(__isl_keep isl_setisl_map *set, |
2793 | __isl_keep isl_aff *obj); |
2794 | const char *res; |
2795 | } opt_tests[] = { |
2796 | { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" }, |
2797 | { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" }, |
2798 | { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}", |
2799 | "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }", |
2800 | &isl_set_max_val, "30" }, |
2801 | |
2802 | }; |
2803 | |
2804 | /* Perform basic isl_set_min_val and isl_set_max_val tests. |
2805 | * In particular, check the results on non-convex inputs. |
2806 | */ |
2807 | static int test_min(struct isl_ctx *ctx) |
2808 | { |
2809 | int i; |
2810 | isl_setisl_map *set; |
2811 | isl_aff *obj; |
2812 | isl_val *val, *res; |
2813 | isl_bool ok; |
2814 | |
2815 | for (i = 0; i < ARRAY_SIZE(opt_tests)(sizeof(opt_tests)/sizeof(*opt_tests)); ++i) { |
2816 | set = isl_set_read_from_str(ctx, opt_tests[i].set); |
2817 | obj = isl_aff_read_from_str(ctx, opt_tests[i].obj); |
2818 | res = isl_val_read_from_str(ctx, opt_tests[i].res); |
2819 | val = opt_tests[i].fn(set, obj); |
2820 | ok = isl_val_eq(res, val); |
2821 | isl_val_free(res); |
2822 | isl_val_free(val); |
2823 | isl_aff_free(obj); |
2824 | isl_set_free(set); |
2825 | |
2826 | if (ok < 0) |
2827 | return -1; |
2828 | if (!ok) |
2829 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2830); return -1; } while (0) |
2830 | "unexpected optimum", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2830); return -1; } while (0); |
2831 | } |
2832 | |
2833 | if (test_min_special(ctx) < 0) |
2834 | return -1; |
2835 | if (test_min_special2(ctx) < 0) |
2836 | return -1; |
2837 | |
2838 | return 0; |
2839 | } |
2840 | |
2841 | struct must_may { |
2842 | isl_map *must; |
2843 | isl_map *may; |
2844 | }; |
2845 | |
2846 | static isl_stat collect_must_may(__isl_take isl_map *dep, int must, |
2847 | void *dep_user, void *user) |
2848 | { |
2849 | struct must_may *mm = (struct must_may *)user; |
2850 | |
2851 | if (must) |
2852 | mm->must = isl_map_union(mm->must, dep); |
2853 | else |
2854 | mm->may = isl_map_union(mm->may, dep); |
2855 | |
2856 | return isl_stat_ok; |
2857 | } |
2858 | |
2859 | static int common_space(void *first, void *second) |
2860 | { |
2861 | int depth = *(int *)first; |
2862 | return 2 * depth; |
2863 | } |
2864 | |
2865 | static int map_is_equal(__isl_keep isl_map *map, const char *str) |
2866 | { |
2867 | isl_map *map2; |
2868 | int equal; |
2869 | |
2870 | if (!map) |
2871 | return -1; |
2872 | |
2873 | map2 = isl_map_read_from_str(map->ctx, str); |
2874 | equal = isl_map_is_equal(map, map2); |
2875 | isl_map_free(map2); |
2876 | |
2877 | return equal; |
2878 | } |
2879 | |
2880 | static int map_check_equal(__isl_keep isl_map *map, const char *str) |
2881 | { |
2882 | int equal; |
2883 | |
2884 | equal = map_is_equal(map, str); |
2885 | if (equal < 0) |
2886 | return -1; |
2887 | if (!equal) |
2888 | 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", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2889); return -1; } while (0) |
2889 | "result not as expected", return -1)do { isl_handle_error(isl_map_get_ctx(map), isl_error_unknown , "result not as expected", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2889); return -1; } while (0); |
2890 | return 0; |
2891 | } |
2892 | |
2893 | static int test_dep(struct isl_ctx *ctx) |
2894 | { |
2895 | const char *str; |
2896 | isl_space *dim; |
2897 | isl_map *map; |
2898 | isl_access_info *ai; |
2899 | isl_flow *flow; |
2900 | int depth; |
2901 | struct must_may mm; |
2902 | |
2903 | depth = 3; |
2904 | |
2905 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
2906 | map = isl_map_read_from_str(ctx, str); |
2907 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2908 | |
2909 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2910 | map = isl_map_read_from_str(ctx, str); |
2911 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
2912 | |
2913 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
2914 | map = isl_map_read_from_str(ctx, str); |
2915 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
2916 | |
2917 | flow = isl_access_info_compute_flow(ai); |
2918 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2919 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2920 | mm.may = isl_map_empty(dim); |
2921 | |
2922 | isl_flow_foreach(flow, collect_must_may, &mm); |
2923 | |
2924 | str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); " |
2925 | " [1,10,0] -> [2,5,0] }"; |
2926 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2926, __PRETTY_FUNCTION__)); |
2927 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
2928 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2928, __PRETTY_FUNCTION__)); |
2929 | |
2930 | isl_map_free(mm.must); |
2931 | isl_map_free(mm.may); |
2932 | isl_flow_free(flow); |
2933 | |
2934 | |
2935 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
2936 | map = isl_map_read_from_str(ctx, str); |
2937 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2938 | |
2939 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2940 | map = isl_map_read_from_str(ctx, str); |
2941 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
2942 | |
2943 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
2944 | map = isl_map_read_from_str(ctx, str); |
2945 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2946 | |
2947 | flow = isl_access_info_compute_flow(ai); |
2948 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2949 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2950 | mm.may = isl_map_empty(dim); |
2951 | |
2952 | isl_flow_foreach(flow, collect_must_may, &mm); |
2953 | |
2954 | str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }"; |
2955 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2955, __PRETTY_FUNCTION__)); |
2956 | str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }"; |
2957 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2957, __PRETTY_FUNCTION__)); |
2958 | |
2959 | isl_map_free(mm.must); |
2960 | isl_map_free(mm.may); |
2961 | isl_flow_free(flow); |
2962 | |
2963 | |
2964 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
2965 | map = isl_map_read_from_str(ctx, str); |
2966 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2967 | |
2968 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2969 | map = isl_map_read_from_str(ctx, str); |
2970 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2971 | |
2972 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
2973 | map = isl_map_read_from_str(ctx, str); |
2974 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2975 | |
2976 | flow = isl_access_info_compute_flow(ai); |
2977 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2978 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2979 | mm.may = isl_map_empty(dim); |
2980 | |
2981 | isl_flow_foreach(flow, collect_must_may, &mm); |
2982 | |
2983 | str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; " |
2984 | " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }"; |
2985 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2985, __PRETTY_FUNCTION__)); |
2986 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
2987 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 2987, __PRETTY_FUNCTION__)); |
2988 | |
2989 | isl_map_free(mm.must); |
2990 | isl_map_free(mm.may); |
2991 | isl_flow_free(flow); |
2992 | |
2993 | |
2994 | str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }"; |
2995 | map = isl_map_read_from_str(ctx, str); |
2996 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2997 | |
2998 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2999 | map = isl_map_read_from_str(ctx, str); |
3000 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3001 | |
3002 | str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }"; |
3003 | map = isl_map_read_from_str(ctx, str); |
3004 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3005 | |
3006 | flow = isl_access_info_compute_flow(ai); |
3007 | dim = isl_space_alloc(ctx, 0, 3, 3); |
3008 | mm.must = isl_map_empty(isl_space_copy(dim)); |
3009 | mm.may = isl_map_empty(dim); |
3010 | |
3011 | isl_flow_foreach(flow, collect_must_may, &mm); |
3012 | |
3013 | str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; " |
3014 | " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }"; |
3015 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3015, __PRETTY_FUNCTION__)); |
3016 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
3017 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3017, __PRETTY_FUNCTION__)); |
3018 | |
3019 | isl_map_free(mm.must); |
3020 | isl_map_free(mm.may); |
3021 | isl_flow_free(flow); |
3022 | |
3023 | |
3024 | str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }"; |
3025 | map = isl_map_read_from_str(ctx, str); |
3026 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
3027 | |
3028 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
3029 | map = isl_map_read_from_str(ctx, str); |
3030 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3031 | |
3032 | str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }"; |
3033 | map = isl_map_read_from_str(ctx, str); |
3034 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
3035 | |
3036 | flow = isl_access_info_compute_flow(ai); |
3037 | dim = isl_space_alloc(ctx, 0, 3, 3); |
3038 | mm.must = isl_map_empty(isl_space_copy(dim)); |
3039 | mm.may = isl_map_empty(dim); |
3040 | |
3041 | isl_flow_foreach(flow, collect_must_may, &mm); |
3042 | |
3043 | str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; " |
3044 | " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }"; |
3045 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3045, __PRETTY_FUNCTION__)); |
3046 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
3047 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3047, __PRETTY_FUNCTION__)); |
3048 | |
3049 | isl_map_free(mm.must); |
3050 | isl_map_free(mm.may); |
3051 | isl_flow_free(flow); |
3052 | |
3053 | |
3054 | depth = 5; |
3055 | |
3056 | str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }"; |
3057 | map = isl_map_read_from_str(ctx, str); |
3058 | ai = isl_access_info_alloc(map, &depth, &common_space, 1); |
3059 | |
3060 | str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }"; |
3061 | map = isl_map_read_from_str(ctx, str); |
3062 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
3063 | |
3064 | flow = isl_access_info_compute_flow(ai); |
3065 | dim = isl_space_alloc(ctx, 0, 5, 5); |
3066 | mm.must = isl_map_empty(isl_space_copy(dim)); |
3067 | mm.may = isl_map_empty(dim); |
3068 | |
3069 | isl_flow_foreach(flow, collect_must_may, &mm); |
3070 | |
3071 | str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }"; |
3072 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3072, __PRETTY_FUNCTION__)); |
3073 | str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }"; |
3074 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3074, __PRETTY_FUNCTION__)); |
3075 | |
3076 | isl_map_free(mm.must); |
3077 | isl_map_free(mm.may); |
3078 | isl_flow_free(flow); |
3079 | |
3080 | return 0; |
3081 | } |
3082 | |
3083 | /* Check that the dependence analysis proceeds without errors. |
3084 | * Earlier versions of isl would break down during the analysis |
3085 | * due to the use of the wrong spaces. |
3086 | */ |
3087 | static int test_flow(isl_ctx *ctx) |
3088 | { |
3089 | const char *str; |
3090 | isl_union_map *access, *schedule; |
3091 | isl_union_map *must_dep, *may_dep; |
3092 | int r; |
3093 | |
3094 | str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }"; |
3095 | access = isl_union_map_read_from_str(ctx, str); |
3096 | str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; " |
3097 | "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; " |
3098 | "S2[] -> [1,0,0,0]; " |
3099 | "S3[] -> [-1,0,0,0] }"; |
3100 | schedule = isl_union_map_read_from_str(ctx, str); |
3101 | r = isl_union_map_compute_flow(access, isl_union_map_copy(access), |
3102 | isl_union_map_copy(access), schedule, |
3103 | &must_dep, &may_dep, NULL((void*)0), NULL((void*)0)); |
3104 | isl_union_map_free(may_dep); |
3105 | isl_union_map_free(must_dep); |
3106 | |
3107 | return r; |
3108 | } |
3109 | |
3110 | struct { |
3111 | const char *map; |
3112 | int sv; |
3113 | } sv_tests[] = { |
3114 | { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 }, |
3115 | { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 }, |
3116 | { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 }, |
3117 | { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 }, |
3118 | { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 }, |
3119 | { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 }, |
3120 | { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 }, |
3121 | { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 }, |
3122 | { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 }, |
3123 | }; |
3124 | |
3125 | int test_sv(isl_ctx *ctx) |
3126 | { |
3127 | isl_union_map *umap; |
3128 | int i; |
3129 | int sv; |
3130 | |
3131 | for (i = 0; i < ARRAY_SIZE(sv_tests)(sizeof(sv_tests)/sizeof(*sv_tests)); ++i) { |
3132 | umap = isl_union_map_read_from_str(ctx, sv_tests[i].map); |
3133 | sv = isl_union_map_is_single_valued(umap); |
3134 | isl_union_map_free(umap); |
3135 | if (sv < 0) |
3136 | return -1; |
3137 | if (sv_tests[i].sv && !sv) |
3138 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as single valued" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3139); return -1; } while (0) |
3139 | "map not detected as single valued", return -1)do { isl_handle_error(ctx, isl_error_internal, "map not detected as single valued" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3139); return -1; } while (0); |
3140 | if (!sv_tests[i].sv && sv) |
3141 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3142); return -1; } while (0) |
3142 | "map detected as single valued", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3142); return -1; } while (0); |
3143 | } |
3144 | |
3145 | return 0; |
3146 | } |
3147 | |
3148 | struct { |
3149 | const char *str; |
3150 | int bijective; |
3151 | } bijective_tests[] = { |
3152 | { "[N,M]->{[i,j] -> [i]}", 0 }, |
3153 | { "[N,M]->{[i,j] -> [i] : j=i}", 1 }, |
3154 | { "[N,M]->{[i,j] -> [i] : j=0}", 1 }, |
3155 | { "[N,M]->{[i,j] -> [i] : j=N}", 1 }, |
3156 | { "[N,M]->{[i,j] -> [j,i]}", 1 }, |
3157 | { "[N,M]->{[i,j] -> [i+j]}", 0 }, |
3158 | { "[N,M]->{[i,j] -> []}", 0 }, |
3159 | { "[N,M]->{[i,j] -> [i,j,N]}", 1 }, |
3160 | { "[N,M]->{[i,j] -> [2i]}", 0 }, |
3161 | { "[N,M]->{[i,j] -> [i,i]}", 0 }, |
3162 | { "[N,M]->{[i,j] -> [2i,i]}", 0 }, |
3163 | { "[N,M]->{[i,j] -> [2i,j]}", 1 }, |
3164 | { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 }, |
3165 | }; |
3166 | |
3167 | static int test_bijective(struct isl_ctx *ctx) |
3168 | { |
3169 | isl_map *map; |
3170 | int i; |
3171 | int bijective; |
3172 | |
3173 | for (i = 0; i < ARRAY_SIZE(bijective_tests)(sizeof(bijective_tests)/sizeof(*bijective_tests)); ++i) { |
3174 | map = isl_map_read_from_str(ctx, bijective_tests[i].str); |
3175 | bijective = isl_map_is_bijective(map); |
3176 | isl_map_free(map); |
3177 | if (bijective < 0) |
3178 | return -1; |
3179 | if (bijective_tests[i].bijective && !bijective) |
3180 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3181); return -1; } while (0) |
3181 | "map not detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3181); return -1; } while (0); |
3182 | if (!bijective_tests[i].bijective && bijective) |
3183 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3184); return -1; } while (0) |
3184 | "map detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3184); return -1; } while (0); |
3185 | } |
3186 | |
3187 | return 0; |
3188 | } |
3189 | |
3190 | /* Inputs for isl_pw_qpolynomial_gist tests. |
3191 | * "pwqp" is the input, "set" is the context and "gist" is the expected result. |
3192 | */ |
3193 | struct { |
3194 | const char *pwqp; |
3195 | const char *set; |
3196 | const char *gist; |
3197 | } pwqp_gist_tests[] = { |
3198 | { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" }, |
3199 | { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" }, |
3200 | { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }", |
3201 | "{ [i] -> -1/2 + 1/2 * i }" }, |
3202 | { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" }, |
3203 | }; |
3204 | |
3205 | static int test_pwqp(struct isl_ctx *ctx) |
3206 | { |
3207 | int i; |
3208 | const char *str; |
3209 | isl_setisl_map *set; |
3210 | isl_pw_qpolynomial *pwqp1, *pwqp2; |
3211 | int equal; |
3212 | |
3213 | str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }"; |
3214 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3215 | |
3216 | pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0, |
3217 | isl_dim_in, 1, 1); |
3218 | |
3219 | str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }"; |
3220 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3221 | |
3222 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3223 | |
3224 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3224, __PRETTY_FUNCTION__)); |
3225 | |
3226 | isl_pw_qpolynomial_free(pwqp1); |
3227 | |
3228 | for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests)(sizeof(pwqp_gist_tests)/sizeof(*pwqp_gist_tests)); ++i) { |
3229 | str = pwqp_gist_tests[i].pwqp; |
3230 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3231 | str = pwqp_gist_tests[i].set; |
3232 | set = isl_set_read_from_str(ctx, str); |
3233 | pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set); |
3234 | str = pwqp_gist_tests[i].gist; |
3235 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3236 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3237 | equal = isl_pw_qpolynomial_is_zero(pwqp1); |
3238 | isl_pw_qpolynomial_free(pwqp1); |
3239 | |
3240 | if (equal < 0) |
3241 | return -1; |
3242 | if (!equal) |
3243 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3244); return -1; } while (0) |
3244 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3244); return -1; } while (0); |
3245 | } |
3246 | |
3247 | str = "{ [i] -> ([([i/2] + [i/2])/5]) }"; |
3248 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3249 | str = "{ [i] -> ([(2 * [i/2])/5]) }"; |
3250 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3251 | |
3252 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3253 | |
3254 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3254, __PRETTY_FUNCTION__)); |
3255 | |
3256 | isl_pw_qpolynomial_free(pwqp1); |
3257 | |
3258 | str = "{ [x] -> ([x/2] + [(x+1)/2]) }"; |
3259 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3260 | str = "{ [x] -> x }"; |
3261 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3262 | |
3263 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3264 | |
3265 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3265, __PRETTY_FUNCTION__)); |
3266 | |
3267 | isl_pw_qpolynomial_free(pwqp1); |
3268 | |
3269 | str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }"; |
3270 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3271 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3272 | pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1); |
3273 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
3274 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3274, __PRETTY_FUNCTION__)); |
3275 | isl_pw_qpolynomial_free(pwqp1); |
3276 | |
3277 | str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }"; |
3278 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3279 | str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }"; |
3280 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3281 | set = isl_set_read_from_str(ctx, "{ [a,b,a] }"); |
3282 | pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set); |
3283 | equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2); |
3284 | isl_pw_qpolynomial_free(pwqp1); |
3285 | isl_pw_qpolynomial_free(pwqp2); |
3286 | if (equal < 0) |
3287 | return -1; |
3288 | if (!equal) |
3289 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3289); return -1; } while (0); |
3290 | |
3291 | str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }"; |
3292 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3293 | str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }"; |
3294 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
3295 | pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1, |
3296 | isl_val_one(ctx)); |
3297 | equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2); |
3298 | isl_pw_qpolynomial_free(pwqp1); |
3299 | isl_pw_qpolynomial_free(pwqp2); |
3300 | if (equal < 0) |
3301 | return -1; |
3302 | if (!equal) |
3303 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3303); return -1; } while (0); |
3304 | |
3305 | return 0; |
3306 | } |
3307 | |
3308 | static int test_split_periods(isl_ctx *ctx) |
3309 | { |
3310 | const char *str; |
3311 | isl_pw_qpolynomial *pwqp; |
3312 | |
3313 | str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : " |
3314 | "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and " |
3315 | "U >= 0; [U,V] -> U^2 : U >= 100 }"; |
3316 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3317 | |
3318 | pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2); |
3319 | |
3320 | isl_pw_qpolynomial_free(pwqp); |
3321 | |
3322 | if (!pwqp) |
3323 | return -1; |
3324 | |
3325 | return 0; |
3326 | } |
3327 | |
3328 | static int test_union(isl_ctx *ctx) |
3329 | { |
3330 | const char *str; |
3331 | isl_union_set *uset1, *uset2; |
3332 | isl_union_map *umap1, *umap2; |
3333 | int equal; |
3334 | |
3335 | str = "{ [i] : 0 <= i <= 1 }"; |
3336 | uset1 = isl_union_set_read_from_str(ctx, str); |
3337 | str = "{ [1] -> [0] }"; |
3338 | umap1 = isl_union_map_read_from_str(ctx, str); |
3339 | |
3340 | umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1); |
3341 | equal = isl_union_map_is_equal(umap1, umap2); |
3342 | |
3343 | isl_union_map_free(umap1); |
3344 | isl_union_map_free(umap2); |
3345 | |
3346 | if (equal < 0) |
3347 | return -1; |
3348 | if (!equal) |
3349 | isl_die(ctx, isl_error_unknown, "union maps not equal",do { isl_handle_error(ctx, isl_error_unknown, "union maps not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3350); return -1; } while (0) |
3350 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "union maps not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3350); return -1; } while (0); |
3351 | |
3352 | str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }"; |
3353 | umap1 = isl_union_map_read_from_str(ctx, str); |
3354 | str = "{ A[i]; B[i] }"; |
3355 | uset1 = isl_union_set_read_from_str(ctx, str); |
3356 | |
3357 | uset2 = isl_union_map_domain(umap1); |
3358 | |
3359 | equal = isl_union_set_is_equal(uset1, uset2); |
3360 | |
3361 | isl_union_set_free(uset1); |
3362 | isl_union_set_free(uset2); |
3363 | |
3364 | if (equal < 0) |
3365 | return -1; |
3366 | if (!equal) |
3367 | isl_die(ctx, isl_error_unknown, "union sets not equal",do { isl_handle_error(ctx, isl_error_unknown, "union sets not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3368); return -1; } while (0) |
3368 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "union sets not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3368); return -1; } while (0); |
3369 | |
3370 | return 0; |
3371 | } |
3372 | |
3373 | /* Check that computing a bound of a non-zero polynomial over an unbounded |
3374 | * domain does not produce a rational value. |
3375 | * In particular, check that the upper bound is infinity. |
3376 | */ |
3377 | static int test_bound_unbounded_domain(isl_ctx *ctx) |
3378 | { |
3379 | const char *str; |
3380 | isl_pw_qpolynomial *pwqp; |
3381 | isl_pw_qpolynomial_fold *pwf, *pwf2; |
3382 | isl_bool equal; |
3383 | |
3384 | str = "{ [m,n] -> -m * n }"; |
3385 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3386 | pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3387 | str = "{ infty }"; |
3388 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3389 | pwf2 = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3390 | equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf, pwf2); |
3391 | isl_pw_qpolynomial_fold_free(pwf); |
3392 | isl_pw_qpolynomial_fold_free(pwf2); |
3393 | |
3394 | if (equal < 0) |
3395 | return -1; |
3396 | if (!equal) |
3397 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting infinite polynomial bound" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3398); return -1; } while (0) |
3398 | "expecting infinite polynomial bound", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting infinite polynomial bound" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3398); return -1; } while (0); |
3399 | |
3400 | return 0; |
3401 | } |
3402 | |
3403 | static int test_bound(isl_ctx *ctx) |
3404 | { |
3405 | const char *str; |
3406 | unsigned dim; |
3407 | isl_pw_qpolynomial *pwqp; |
3408 | isl_pw_qpolynomial_fold *pwf; |
3409 | |
3410 | if (test_bound_unbounded_domain(ctx) < 0) |
3411 | return -1; |
3412 | |
3413 | str = "{ [[a, b, c, d] -> [e]] -> 0 }"; |
3414 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3415 | pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3416 | dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in); |
3417 | isl_pw_qpolynomial_fold_free(pwf); |
3418 | if (dim != 4) |
3419 | isl_die(ctx, isl_error_unknown, "unexpected input dimension",do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3420); return -1; } while (0) |
3420 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3420); return -1; } while (0); |
3421 | |
3422 | str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }"; |
3423 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3424 | pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3425 | dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in); |
3426 | isl_pw_qpolynomial_fold_free(pwf); |
3427 | if (dim != 1) |
3428 | isl_die(ctx, isl_error_unknown, "unexpected input dimension",do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3429); return -1; } while (0) |
3429 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3429); return -1; } while (0); |
3430 | |
3431 | return 0; |
3432 | } |
3433 | |
3434 | /* Check that the conversion from 'set' to 'basic set list' works as expected. |
3435 | */ |
3436 | static isl_stat test_get_list_bset_from_set(isl_ctx *ctx) |
3437 | { |
3438 | int i; |
3439 | isl_bool equal; |
3440 | isl_setisl_map *set, *set2; |
3441 | isl_basic_set_listisl_basic_map_list *bset_list; |
3442 | |
3443 | set = isl_set_read_from_str(ctx, "{ [0]; [2]; [3] }"); |
3444 | bset_list = isl_set_get_basic_set_list(set); |
3445 | |
3446 | set2 = isl_set_empty(isl_set_get_space(set)); |
3447 | |
3448 | for (i = 0; i < isl_basic_set_list_n_basic_set(bset_list); i++) { |
3449 | isl_basic_setisl_basic_map *bset; |
3450 | bset = isl_basic_set_list_get_basic_set(bset_list, i); |
3451 | set2 = isl_set_union(set2, isl_set_from_basic_set(bset)); |
3452 | } |
3453 | |
3454 | equal = isl_set_is_equal(set, set2); |
3455 | |
3456 | isl_set_free(set); |
3457 | isl_set_free(set2); |
3458 | isl_basic_set_list_free(bset_list); |
3459 | |
3460 | if (equal < 0) |
3461 | return isl_stat_error; |
3462 | |
3463 | if (!equal) |
3464 | isl_die(ctx, isl_error_unknown, "sets are not equal",do { isl_handle_error(ctx, isl_error_unknown, "sets are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3465); return isl_stat_error; } while (0) |
3465 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "sets are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3465); return isl_stat_error; } while (0); |
3466 | |
3467 | return isl_stat_ok; |
3468 | } |
3469 | |
3470 | /* Check that the conversion from 'union set' to 'basic set list' works as |
3471 | * expected. |
3472 | */ |
3473 | static isl_stat test_get_list_bset_from_uset(isl_ctx *ctx) |
3474 | { |
3475 | int i; |
3476 | isl_bool equal; |
3477 | isl_union_set *uset, *uset2; |
3478 | isl_basic_set_listisl_basic_map_list *bset_list; |
3479 | |
3480 | uset = isl_union_set_read_from_str(ctx, "{ A[0]; B[2]; B[3] }"); |
3481 | bset_list = isl_union_set_get_basic_set_list(uset); |
3482 | |
3483 | uset2 = isl_union_set_empty(isl_union_set_get_space(uset)); |
3484 | |
3485 | for (i = 0; i < isl_basic_set_list_n_basic_set(bset_list); i++) { |
3486 | isl_basic_setisl_basic_map *bset; |
3487 | bset = isl_basic_set_list_get_basic_set(bset_list, i); |
3488 | uset2 = isl_union_set_union(uset2, |
3489 | isl_union_set_from_basic_set(bset)); |
3490 | } |
3491 | |
3492 | equal = isl_union_set_is_equal(uset, uset2); |
3493 | |
3494 | isl_union_set_free(uset); |
3495 | isl_union_set_free(uset2); |
3496 | isl_basic_set_list_free(bset_list); |
3497 | |
3498 | if (equal < 0) |
3499 | return isl_stat_error; |
3500 | |
3501 | if (!equal) |
3502 | isl_die(ctx, isl_error_unknown, "sets are not equal",do { isl_handle_error(ctx, isl_error_unknown, "sets are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3503); return isl_stat_error; } while (0) |
3503 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "sets are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3503); return isl_stat_error; } while (0); |
3504 | |
3505 | return isl_stat_ok; |
3506 | } |
3507 | |
3508 | /* Check that the conversion from 'union set' to 'set list' works as expected. |
3509 | */ |
3510 | static isl_stat test_get_list_set_from_uset(isl_ctx *ctx) |
3511 | { |
3512 | int i; |
3513 | isl_bool equal; |
3514 | isl_union_set *uset, *uset2; |
3515 | isl_set_listisl_map_list *set_list; |
3516 | |
3517 | uset = isl_union_set_read_from_str(ctx, "{ A[0]; A[2]; B[3] }"); |
3518 | set_list = isl_union_set_get_set_list(uset); |
3519 | |
3520 | uset2 = isl_union_set_empty(isl_union_set_get_space(uset)); |
3521 | |
3522 | for (i = 0; i < isl_set_list_n_set(set_list); i++) { |
3523 | isl_setisl_map *set; |
3524 | set = isl_set_list_get_set(set_list, i); |
3525 | uset2 = isl_union_set_union(uset2, isl_union_set_from_set(set)); |
3526 | } |
3527 | |
3528 | equal = isl_union_set_is_equal(uset, uset2); |
3529 | |
3530 | isl_union_set_free(uset); |
3531 | isl_union_set_free(uset2); |
3532 | isl_set_list_free(set_list); |
3533 | |
3534 | if (equal < 0) |
3535 | return isl_stat_error; |
3536 | |
3537 | if (!equal) |
3538 | isl_die(ctx, isl_error_unknown, "union sets are not equal",do { isl_handle_error(ctx, isl_error_unknown, "union sets are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3539); return isl_stat_error; } while (0) |
3539 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "union sets are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3539); return isl_stat_error; } while (0); |
3540 | |
3541 | return isl_stat_ok; |
3542 | } |
3543 | |
3544 | /* Check that the conversion from 'map' to 'basic map list' works as expected. |
3545 | */ |
3546 | static isl_stat test_get_list_bmap_from_map(isl_ctx *ctx) |
3547 | { |
3548 | int i; |
3549 | isl_bool equal; |
3550 | isl_map *map, *map2; |
3551 | isl_basic_map_list *bmap_list; |
3552 | |
3553 | map = isl_map_read_from_str(ctx, |
3554 | "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"); |
3555 | bmap_list = isl_map_get_basic_map_list(map); |
3556 | |
3557 | map2 = isl_map_empty(isl_map_get_space(map)); |
3558 | |
3559 | for (i = 0; i < isl_basic_map_list_n_basic_map(bmap_list); i++) { |
3560 | isl_basic_map *bmap; |
3561 | bmap = isl_basic_map_list_get_basic_map(bmap_list, i); |
3562 | map2 = isl_map_union(map2, isl_map_from_basic_map(bmap)); |
3563 | } |
3564 | |
3565 | equal = isl_map_is_equal(map, map2); |
3566 | |
3567 | isl_map_free(map); |
3568 | isl_map_free(map2); |
3569 | isl_basic_map_list_free(bmap_list); |
3570 | |
3571 | if (equal < 0) |
3572 | return isl_stat_error; |
3573 | |
3574 | if (!equal) |
3575 | isl_die(ctx, isl_error_unknown, "maps are not equal",do { isl_handle_error(ctx, isl_error_unknown, "maps are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3576); return isl_stat_error; } while (0) |
3576 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "maps are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3576); return isl_stat_error; } while (0); |
3577 | |
3578 | return isl_stat_ok; |
3579 | } |
3580 | |
3581 | /* Check that the conversion from 'union map' to 'map list' works as expected. |
3582 | */ |
3583 | static isl_stat test_get_list_map_from_umap(isl_ctx *ctx) |
3584 | { |
3585 | int i; |
3586 | isl_bool equal; |
3587 | isl_union_map *umap, *umap2; |
3588 | isl_map_list *map_list; |
3589 | |
3590 | umap = isl_union_map_read_from_str(ctx, |
3591 | "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"); |
3592 | map_list = isl_union_map_get_map_list(umap); |
3593 | |
3594 | umap2 = isl_union_map_empty(isl_union_map_get_space(umap)); |
3595 | |
3596 | for (i = 0; i < isl_map_list_n_map(map_list); i++) { |
3597 | isl_map *map; |
3598 | map = isl_map_list_get_map(map_list, i); |
3599 | umap2 = isl_union_map_union(umap2, isl_union_map_from_map(map)); |
3600 | } |
3601 | |
3602 | equal = isl_union_map_is_equal(umap, umap2); |
3603 | |
3604 | isl_union_map_free(umap); |
3605 | isl_union_map_free(umap2); |
3606 | isl_map_list_free(map_list); |
3607 | |
3608 | if (equal < 0) |
3609 | return isl_stat_error; |
3610 | |
3611 | if (!equal) |
3612 | isl_die(ctx, isl_error_unknown, "union maps are not equal",do { isl_handle_error(ctx, isl_error_unknown, "union maps are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3613); return isl_stat_error; } while (0) |
3613 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "union maps are not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3613); return isl_stat_error; } while (0); |
3614 | |
3615 | return isl_stat_ok; |
3616 | } |
3617 | |
3618 | /* Check that the conversion from isl objects to lists works as expected. |
3619 | */ |
3620 | static int test_get_list(isl_ctx *ctx) |
3621 | { |
3622 | if (test_get_list_bset_from_set(ctx)) |
3623 | return -1; |
3624 | if (test_get_list_bset_from_uset(ctx)) |
3625 | return -1; |
3626 | if (test_get_list_set_from_uset(ctx)) |
3627 | return -1; |
3628 | if (test_get_list_bmap_from_map(ctx)) |
3629 | return -1; |
3630 | if (test_get_list_map_from_umap(ctx)) |
3631 | return -1; |
3632 | |
3633 | return 0; |
3634 | } |
3635 | |
3636 | static int test_lift(isl_ctx *ctx) |
3637 | { |
3638 | const char *str; |
3639 | isl_basic_map *bmap; |
3640 | isl_basic_setisl_basic_map *bset; |
3641 | |
3642 | str = "{ [i0] : exists e0 : i0 = 4e0 }"; |
3643 | bset = isl_basic_set_read_from_str(ctx, str); |
3644 | bset = isl_basic_set_lift(bset); |
3645 | bmap = isl_basic_map_from_range(bset); |
3646 | bset = isl_basic_map_domain(bmap); |
3647 | isl_basic_set_free(bset); |
3648 | |
3649 | return 0; |
3650 | } |
3651 | |
3652 | /* Check that isl_set_is_subset is not confused by identical |
3653 | * integer divisions. |
3654 | * The call to isl_set_normalize ensures that the equality constraints |
3655 | * a = b = 0 are discovered, turning e0 and e1 into identical |
3656 | * integer divisions. Any further simplification would remove |
3657 | * the duplicate integer divisions. |
3658 | */ |
3659 | static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx) |
3660 | { |
3661 | const char *str; |
3662 | isl_bool is_subset; |
3663 | isl_setisl_map *set1, *set2; |
3664 | |
3665 | str = "{ [a, b, c, d] : " |
3666 | "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), " |
3667 | "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), " |
3668 | "e3 = floor((-d + 4*floor((d)/4))/10): " |
3669 | "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and " |
3670 | "b >= 0 and a <= 0 and b <= a) }"; |
3671 | set1 = isl_set_read_from_str(ctx, str); |
3672 | set2 = isl_set_read_from_str(ctx, str); |
3673 | set2 = isl_set_normalize(set2); |
3674 | |
3675 | is_subset = isl_set_is_subset(set1, set2); |
3676 | |
3677 | isl_set_free(set1); |
3678 | isl_set_free(set2); |
3679 | |
3680 | if (is_subset < 0) |
3681 | return isl_stat_error; |
3682 | if (!is_subset) |
3683 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set is not considered to be a subset of itself" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3685); return isl_stat_error; } while (0) |
3684 | "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" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3685); return isl_stat_error; } while (0) |
3685 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "set is not considered to be a subset of itself" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3685); return isl_stat_error; } while (0); |
3686 | |
3687 | return isl_stat_ok; |
3688 | } |
3689 | |
3690 | struct { |
3691 | const char *set1; |
3692 | const char *set2; |
3693 | int subset; |
3694 | } subset_tests[] = { |
3695 | { "{ [112, 0] }", |
3696 | "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: " |
3697 | "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and " |
3698 | "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 }, |
3699 | { "{ [65] }", |
3700 | "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], " |
3701 | "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], " |
3702 | "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: " |
3703 | "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and " |
3704 | "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and " |
3705 | "256e0 <= 255i and 256e0 >= -255 + 255i and " |
3706 | "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and " |
3707 | "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and " |
3708 | "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 }, |
3709 | { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 }, |
3710 | { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 }, |
3711 | { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 }, |
3712 | { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 }, |
3713 | { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and " |
3714 | "4e0 >= -1 + t and i >= 57 and i <= 62 and " |
3715 | "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and " |
3716 | "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and " |
3717 | "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }", |
3718 | "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and " |
3719 | "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and " |
3720 | "4e0 <= -57 + i0 + i1)) or " |
3721 | "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and " |
3722 | "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and " |
3723 | "4e0 >= -61 + i0 + i1)) or " |
3724 | "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 }, |
3725 | { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 }, |
3726 | }; |
3727 | |
3728 | static int test_subset(isl_ctx *ctx) |
3729 | { |
3730 | int i; |
3731 | isl_setisl_map *set1, *set2; |
3732 | int subset; |
3733 | |
3734 | if (test_subset_duplicate_integer_divisions(ctx) < 0) |
3735 | return -1; |
3736 | |
3737 | for (i = 0; i < ARRAY_SIZE(subset_tests)(sizeof(subset_tests)/sizeof(*subset_tests)); ++i) { |
3738 | set1 = isl_set_read_from_str(ctx, subset_tests[i].set1); |
3739 | set2 = isl_set_read_from_str(ctx, subset_tests[i].set2); |
3740 | subset = isl_set_is_subset(set1, set2); |
3741 | isl_set_free(set1); |
3742 | isl_set_free(set2); |
3743 | if (subset < 0) |
3744 | return -1; |
3745 | if (subset != subset_tests[i].subset) |
3746 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3747); return -1; } while (0) |
3747 | "incorrect subset result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3747); return -1; } while (0); |
3748 | } |
3749 | |
3750 | return 0; |
3751 | } |
3752 | |
3753 | struct { |
3754 | const char *minuend; |
3755 | const char *subtrahend; |
3756 | const char *difference; |
3757 | } subtract_domain_tests[] = { |
3758 | { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" }, |
3759 | { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" }, |
3760 | { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" }, |
3761 | }; |
3762 | |
3763 | static int test_subtract(isl_ctx *ctx) |
3764 | { |
3765 | int i; |
3766 | isl_union_map *umap1, *umap2; |
3767 | isl_union_pw_multi_aff *upma1, *upma2; |
3768 | isl_union_set *uset; |
3769 | int equal; |
3770 | |
3771 | for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests) ); ++i) { |
3772 | umap1 = isl_union_map_read_from_str(ctx, |
3773 | subtract_domain_tests[i].minuend); |
3774 | uset = isl_union_set_read_from_str(ctx, |
3775 | subtract_domain_tests[i].subtrahend); |
3776 | umap2 = isl_union_map_read_from_str(ctx, |
3777 | subtract_domain_tests[i].difference); |
3778 | umap1 = isl_union_map_subtract_domain(umap1, uset); |
3779 | equal = isl_union_map_is_equal(umap1, umap2); |
3780 | isl_union_map_free(umap1); |
3781 | isl_union_map_free(umap2); |
3782 | if (equal < 0) |
3783 | return -1; |
3784 | if (!equal) |
3785 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3786); return -1; } while (0) |
3786 | "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3786); return -1; } while (0); |
3787 | } |
3788 | |
3789 | for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests) ); ++i) { |
3790 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
3791 | subtract_domain_tests[i].minuend); |
3792 | uset = isl_union_set_read_from_str(ctx, |
3793 | subtract_domain_tests[i].subtrahend); |
3794 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
3795 | subtract_domain_tests[i].difference); |
3796 | upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset); |
3797 | equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2); |
3798 | isl_union_pw_multi_aff_free(upma1); |
3799 | isl_union_pw_multi_aff_free(upma2); |
3800 | if (equal < 0) |
3801 | return -1; |
3802 | if (!equal) |
3803 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3804); return -1; } while (0) |
3804 | "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3804); return -1; } while (0); |
3805 | } |
3806 | |
3807 | return 0; |
3808 | } |
3809 | |
3810 | /* Check that intersecting the empty basic set with another basic set |
3811 | * does not increase the number of constraints. In particular, |
3812 | * the empty basic set should maintain its canonical representation. |
3813 | */ |
3814 | static int test_intersect_1(isl_ctx *ctx) |
3815 | { |
3816 | int n1, n2; |
3817 | isl_basic_setisl_basic_map *bset1, *bset2; |
3818 | |
3819 | bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }"); |
3820 | bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }"); |
3821 | n1 = isl_basic_set_n_constraint(bset1); |
3822 | bset1 = isl_basic_set_intersect(bset1, bset2); |
3823 | n2 = isl_basic_set_n_constraint(bset1); |
3824 | isl_basic_set_free(bset1); |
3825 | if (!bset1) |
3826 | return -1; |
3827 | if (n1 != n2) |
3828 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3830); return -1; } while (0) |
3829 | "number of constraints of empty set changed",do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3830); return -1; } while (0) |
3830 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3830); return -1; } while (0); |
3831 | |
3832 | return 0; |
3833 | } |
3834 | |
3835 | /* Check that intersecting a set with itself does not cause |
3836 | * an explosion in the number of disjuncts. |
3837 | */ |
3838 | static isl_stat test_intersect_2(isl_ctx *ctx) |
3839 | { |
3840 | int i; |
3841 | isl_setisl_map *set; |
3842 | |
3843 | set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }"); |
3844 | for (i = 0; i < 100; ++i) |
3845 | set = isl_set_intersect(set, isl_set_copy(set)); |
3846 | isl_set_free(set); |
3847 | if (!set) |
3848 | return isl_stat_error; |
3849 | return isl_stat_ok; |
3850 | } |
3851 | |
3852 | /* Perform some intersection tests. |
3853 | */ |
3854 | static int test_intersect(isl_ctx *ctx) |
3855 | { |
3856 | if (test_intersect_1(ctx) < 0) |
3857 | return -1; |
3858 | if (test_intersect_2(ctx) < 0) |
3859 | return -1; |
3860 | |
3861 | return 0; |
3862 | } |
3863 | |
3864 | int test_factorize(isl_ctx *ctx) |
3865 | { |
3866 | const char *str; |
3867 | isl_basic_setisl_basic_map *bset; |
3868 | isl_factorizer *f; |
3869 | |
3870 | str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and " |
3871 | "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and " |
3872 | "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and " |
3873 | "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and " |
3874 | "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and " |
3875 | "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and " |
3876 | "3i5 >= -2i0 - i2 + 3i4 }"; |
3877 | bset = isl_basic_set_read_from_str(ctx, str); |
3878 | f = isl_basic_set_factorizer(bset); |
3879 | isl_basic_set_free(bset); |
3880 | isl_factorizer_free(f); |
3881 | if (!f) |
3882 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3883); return -1; } while (0) |
3883 | "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3883); return -1; } while (0); |
3884 | |
3885 | str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : " |
3886 | "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and " |
3887 | "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and " |
3888 | "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and " |
3889 | "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and " |
3890 | "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and " |
3891 | "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and " |
3892 | "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and " |
3893 | "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and " |
3894 | "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }"; |
3895 | bset = isl_basic_set_read_from_str(ctx, str); |
3896 | f = isl_basic_set_factorizer(bset); |
3897 | isl_basic_set_free(bset); |
3898 | isl_factorizer_free(f); |
3899 | if (!f) |
3900 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3901); return -1; } while (0) |
3901 | "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 3901); return -1; } while (0); |
3902 | |
3903 | return 0; |
3904 | } |
3905 | |
3906 | static isl_stat check_injective(__isl_take isl_map *map, void *user) |
3907 | { |
3908 | int *injective = user; |
3909 | |
3910 | *injective = isl_map_is_injective(map); |
3911 | isl_map_free(map); |
3912 | |
3913 | if (*injective < 0 || !*injective) |
3914 | return isl_stat_error; |
3915 | |
3916 | return isl_stat_ok; |
3917 | } |
3918 | |
3919 | int test_one_schedule(isl_ctx *ctx, const char *d, const char *w, |
3920 | const char *r, const char *s, int tilable, int parallel) |
3921 | { |
3922 | int i; |
3923 | isl_union_set *D; |
3924 | isl_union_map *W, *R, *S; |
3925 | isl_union_map *empty; |
3926 | isl_union_map *dep_raw, *dep_war, *dep_waw, *dep; |
3927 | isl_union_map *validity, *proximity, *coincidence; |
3928 | isl_union_map *schedule; |
3929 | isl_union_map *test; |
3930 | isl_union_set *delta; |
3931 | isl_union_set *domain; |
3932 | isl_setisl_map *delta_set; |
3933 | isl_setisl_map *slice; |
3934 | isl_setisl_map *origin; |
3935 | isl_schedule_constraints *sc; |
3936 | isl_schedule *sched; |
3937 | int is_nonneg, is_parallel, is_tilable, is_injection, is_complete; |
3938 | |
3939 | D = isl_union_set_read_from_str(ctx, d); |
3940 | W = isl_union_map_read_from_str(ctx, w); |
3941 | R = isl_union_map_read_from_str(ctx, r); |
3942 | S = isl_union_map_read_from_str(ctx, s); |
3943 | |
3944 | W = isl_union_map_intersect_domain(W, isl_union_set_copy(D)); |
3945 | R = isl_union_map_intersect_domain(R, isl_union_set_copy(D)); |
3946 | |
3947 | empty = isl_union_map_empty(isl_union_map_get_space(S)); |
3948 | isl_union_map_compute_flow(isl_union_map_copy(R), |
3949 | isl_union_map_copy(W), empty, |
3950 | isl_union_map_copy(S), |
3951 | &dep_raw, NULL((void*)0), NULL((void*)0), NULL((void*)0)); |
3952 | isl_union_map_compute_flow(isl_union_map_copy(W), |
3953 | isl_union_map_copy(W), |
3954 | isl_union_map_copy(R), |
3955 | isl_union_map_copy(S), |
3956 | &dep_waw, &dep_war, NULL((void*)0), NULL((void*)0)); |
3957 | |
3958 | dep = isl_union_map_union(dep_waw, dep_war); |
3959 | dep = isl_union_map_union(dep, dep_raw); |
3960 | validity = isl_union_map_copy(dep); |
3961 | coincidence = isl_union_map_copy(dep); |
3962 | proximity = isl_union_map_copy(dep); |
3963 | |
3964 | sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D)); |
3965 | sc = isl_schedule_constraints_set_validity(sc, validity); |
3966 | sc = isl_schedule_constraints_set_coincidence(sc, coincidence); |
3967 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
3968 | sched = isl_schedule_constraints_compute_schedule(sc); |
3969 | schedule = isl_schedule_get_map(sched); |
3970 | isl_schedule_free(sched); |
3971 | isl_union_map_free(W); |
3972 | isl_union_map_free(R); |
3973 | isl_union_map_free(S); |
3974 | |
3975 | is_injection = 1; |
3976 | isl_union_map_foreach_map(schedule, &check_injective, &is_injection); |
3977 | |
3978 | domain = isl_union_map_domain(isl_union_map_copy(schedule)); |
3979 | is_complete = isl_union_set_is_subset(D, domain); |
3980 | isl_union_set_free(D); |
3981 | isl_union_set_free(domain); |
3982 | |
3983 | test = isl_union_map_reverse(isl_union_map_copy(schedule)); |
3984 | test = isl_union_map_apply_range(test, dep); |
3985 | test = isl_union_map_apply_range(test, schedule); |
3986 | |
3987 | delta = isl_union_map_deltas(test); |
3988 | if (isl_union_set_n_set(delta) == 0) { |
3989 | is_tilable = 1; |
3990 | is_parallel = 1; |
3991 | is_nonneg = 1; |
3992 | isl_union_set_free(delta); |
3993 | } else { |
3994 | delta_set = isl_set_from_union_set(delta); |
3995 | |
3996 | slice = isl_set_universe(isl_set_get_space(delta_set)); |
3997 | for (i = 0; i < tilable; ++i) |
3998 | slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0); |
3999 | is_tilable = isl_set_is_subset(delta_set, slice); |
4000 | isl_set_free(slice); |
4001 | |
4002 | slice = isl_set_universe(isl_set_get_space(delta_set)); |
4003 | for (i = 0; i < parallel; ++i) |
4004 | slice = isl_set_fix_si(slice, isl_dim_set, i, 0); |
4005 | is_parallel = isl_set_is_subset(delta_set, slice); |
4006 | isl_set_free(slice); |
4007 | |
4008 | origin = isl_set_universe(isl_set_get_space(delta_set)); |
4009 | for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i) |
4010 | origin = isl_set_fix_si(origin, isl_dim_set, i, 0); |
4011 | |
4012 | delta_set = isl_set_union(delta_set, isl_set_copy(origin)); |
4013 | delta_set = isl_set_lexmin(delta_set); |
4014 | |
4015 | is_nonneg = isl_set_is_equal(delta_set, origin); |
4016 | |
4017 | isl_set_free(origin); |
4018 | isl_set_free(delta_set); |
4019 | } |
4020 | |
4021 | if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 || |
4022 | is_injection < 0 || is_complete < 0) |
4023 | return -1; |
4024 | if (!is_complete) |
4025 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4026); return -1; } while (0) |
4026 | "generated schedule incomplete", return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4026); return -1; } while (0); |
4027 | if (!is_injection) |
4028 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4030); return -1; } while (0) |
4029 | "generated schedule not injective on each statement",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4030); return -1; } while (0) |
4030 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4030); return -1; } while (0); |
4031 | if (!is_nonneg) |
4032 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4034); return -1; } while (0) |
4033 | "negative dependences in generated schedule",do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4034); return -1; } while (0) |
4034 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4034); return -1; } while (0); |
4035 | if (!is_tilable) |
4036 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4038); return -1; } while (0) |
4037 | "generated schedule not as tilable as expected",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4038); return -1; } while (0) |
4038 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4038); return -1; } while (0); |
4039 | if (!is_parallel) |
4040 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4042); return -1; } while (0) |
4041 | "generated schedule not as parallel as expected",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4042); return -1; } while (0) |
4042 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4042); return -1; } while (0); |
4043 | |
4044 | return 0; |
4045 | } |
4046 | |
4047 | /* Compute a schedule for the given instance set, validity constraints, |
4048 | * proximity constraints and context and return a corresponding union map |
4049 | * representation. |
4050 | */ |
4051 | static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx, |
4052 | const char *domain, const char *validity, const char *proximity, |
4053 | const char *context) |
4054 | { |
4055 | isl_setisl_map *con; |
4056 | isl_union_set *dom; |
4057 | isl_union_map *dep; |
4058 | isl_union_map *prox; |
4059 | isl_schedule_constraints *sc; |
4060 | isl_schedule *schedule; |
4061 | isl_union_map *sched; |
4062 | |
4063 | con = isl_set_read_from_str(ctx, context); |
4064 | dom = isl_union_set_read_from_str(ctx, domain); |
4065 | dep = isl_union_map_read_from_str(ctx, validity); |
4066 | prox = isl_union_map_read_from_str(ctx, proximity); |
4067 | sc = isl_schedule_constraints_on_domain(dom); |
4068 | sc = isl_schedule_constraints_set_context(sc, con); |
4069 | sc = isl_schedule_constraints_set_validity(sc, dep); |
4070 | sc = isl_schedule_constraints_set_proximity(sc, prox); |
4071 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4072 | sched = isl_schedule_get_map(schedule); |
4073 | isl_schedule_free(schedule); |
4074 | |
4075 | return sched; |
4076 | } |
4077 | |
4078 | /* Compute a schedule for the given instance set, validity constraints and |
4079 | * proximity constraints and return a corresponding union map representation. |
4080 | */ |
4081 | static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx, |
4082 | const char *domain, const char *validity, const char *proximity) |
4083 | { |
4084 | return compute_schedule_with_context(ctx, domain, validity, proximity, |
4085 | "{ : }"); |
4086 | } |
4087 | |
4088 | /* Check that a schedule can be constructed on the given domain |
4089 | * with the given validity and proximity constraints. |
4090 | */ |
4091 | static int test_has_schedule(isl_ctx *ctx, const char *domain, |
4092 | const char *validity, const char *proximity) |
4093 | { |
4094 | isl_union_map *sched; |
4095 | |
4096 | sched = compute_schedule(ctx, domain, validity, proximity); |
4097 | if (!sched) |
4098 | return -1; |
4099 | |
4100 | isl_union_map_free(sched); |
4101 | return 0; |
4102 | } |
4103 | |
4104 | int test_special_schedule(isl_ctx *ctx, const char *domain, |
4105 | const char *validity, const char *proximity, const char *expected_sched) |
4106 | { |
4107 | isl_union_map *sched1, *sched2; |
4108 | int equal; |
4109 | |
4110 | sched1 = compute_schedule(ctx, domain, validity, proximity); |
4111 | sched2 = isl_union_map_read_from_str(ctx, expected_sched); |
4112 | |
4113 | equal = isl_union_map_is_equal(sched1, sched2); |
4114 | isl_union_map_free(sched1); |
4115 | isl_union_map_free(sched2); |
4116 | |
4117 | if (equal < 0) |
4118 | return -1; |
4119 | if (!equal) |
4120 | isl_die(ctx, isl_error_unknown, "unexpected schedule",do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4121); return -1; } while (0) |
4121 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4121); return -1; } while (0); |
4122 | |
4123 | return 0; |
4124 | } |
4125 | |
4126 | /* Check that the schedule map is properly padded, i.e., that the range |
4127 | * lives in a single space. |
4128 | */ |
4129 | static int test_padded_schedule(isl_ctx *ctx) |
4130 | { |
4131 | const char *str; |
4132 | isl_union_set *D; |
4133 | isl_union_map *validity, *proximity; |
4134 | isl_schedule_constraints *sc; |
4135 | isl_schedule *sched; |
4136 | isl_union_map *umap; |
4137 | isl_union_set *range; |
4138 | isl_setisl_map *set; |
4139 | |
4140 | str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }"; |
4141 | D = isl_union_set_read_from_str(ctx, str); |
4142 | validity = isl_union_map_empty(isl_union_set_get_space(D)); |
4143 | proximity = isl_union_map_copy(validity); |
4144 | sc = isl_schedule_constraints_on_domain(D); |
4145 | sc = isl_schedule_constraints_set_validity(sc, validity); |
4146 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
4147 | sched = isl_schedule_constraints_compute_schedule(sc); |
4148 | umap = isl_schedule_get_map(sched); |
4149 | isl_schedule_free(sched); |
4150 | range = isl_union_map_range(umap); |
4151 | set = isl_set_from_union_set(range); |
4152 | isl_set_free(set); |
4153 | |
4154 | if (!set) |
4155 | return -1; |
4156 | |
4157 | return 0; |
4158 | } |
4159 | |
4160 | /* Check that conditional validity constraints are also taken into |
4161 | * account across bands. |
4162 | * In particular, try to make sure that live ranges D[1,0]->C[2,1] and |
4163 | * D[2,0]->C[3,0] are not local in the outer band of the generated schedule |
4164 | * and then check that the adjacent order constraint C[2,1]->D[2,0] |
4165 | * is enforced by the rest of the schedule. |
4166 | */ |
4167 | static int test_special_conditional_schedule_constraints(isl_ctx *ctx) |
4168 | { |
4169 | const char *str; |
4170 | isl_union_set *domain; |
4171 | isl_union_map *validity, *proximity, *condition; |
4172 | isl_union_map *sink, *source, *dep; |
4173 | isl_schedule_constraints *sc; |
4174 | isl_schedule *schedule; |
4175 | isl_union_access_info *access; |
4176 | isl_union_flow *flow; |
4177 | int empty; |
4178 | |
4179 | str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; " |
4180 | "A[k] : k >= 1 and k <= -1 + n; " |
4181 | "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; " |
4182 | "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }"; |
4183 | domain = isl_union_set_read_from_str(ctx, str); |
4184 | sc = isl_schedule_constraints_on_domain(domain); |
4185 | str = "[n] -> { D[k, i] -> C[1 + k, k - i] : " |
4186 | "k <= -2 + n and i >= 1 and i <= -1 + k; " |
4187 | "D[k, i] -> C[1 + k, i] : " |
4188 | "k <= -2 + n and i >= 1 and i <= -1 + k; " |
4189 | "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; " |
4190 | "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }"; |
4191 | validity = isl_union_map_read_from_str(ctx, str); |
4192 | sc = isl_schedule_constraints_set_validity(sc, validity); |
4193 | str = "[n] -> { C[k, i] -> D[k, i] : " |
4194 | "0 <= i <= -1 + k and k <= -1 + n }"; |
4195 | proximity = isl_union_map_read_from_str(ctx, str); |
4196 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
4197 | str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : " |
4198 | "i <= -1 + k and i >= 1 and k <= -2 + n; " |
4199 | "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : " |
4200 | "k <= -1 + n and i >= 0 and i <= -2 + k }"; |
4201 | condition = isl_union_map_read_from_str(ctx, str); |
4202 | str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : " |
4203 | "i >= 0 and i <= -1 + k and k <= -1 + n; " |
4204 | "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : " |
4205 | "i >= 0 and i <= -1 + k and k <= -1 + n and " |
4206 | "k' <= -1 + n and k' >= k - i and k' >= 1 + k; " |
4207 | "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : " |
4208 | "i >= 0 and i <= -1 + k and k <= -1 + n; " |
4209 | "[B[k, i] -> c[]] -> [A[k'] -> d[]] : " |
4210 | "k <= -1 + n and i >= 0 and i <= -1 + k and " |
4211 | "k' >= 1 and k' <= -1 + n and k' >= 1 + k }"; |
4212 | validity = isl_union_map_read_from_str(ctx, str); |
4213 | sc = isl_schedule_constraints_set_conditional_validity(sc, condition, |
4214 | validity); |
4215 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4216 | str = "{ D[2,0] -> [] }"; |
4217 | sink = isl_union_map_read_from_str(ctx, str); |
4218 | access = isl_union_access_info_from_sink(sink); |
4219 | str = "{ C[2,1] -> [] }"; |
4220 | source = isl_union_map_read_from_str(ctx, str); |
4221 | access = isl_union_access_info_set_must_source(access, source); |
4222 | access = isl_union_access_info_set_schedule(access, schedule); |
4223 | flow = isl_union_access_info_compute_flow(access); |
4224 | dep = isl_union_flow_get_must_dependence(flow); |
4225 | isl_union_flow_free(flow); |
4226 | empty = isl_union_map_is_empty(dep); |
4227 | isl_union_map_free(dep); |
4228 | |
4229 | if (empty < 0) |
4230 | return -1; |
4231 | if (empty) |
4232 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4233); return -1; } while (0) |
4233 | "conditional validity not respected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4233); return -1; } while (0); |
4234 | |
4235 | return 0; |
4236 | } |
4237 | |
4238 | /* Check that the test for violated conditional validity constraints |
4239 | * is not confused by domain compression. |
4240 | * In particular, earlier versions of isl would apply |
4241 | * a schedule on the compressed domains to the original domains, |
4242 | * resulting in a failure to detect that the default schedule |
4243 | * violates the conditional validity constraints. |
4244 | */ |
4245 | static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx) |
4246 | { |
4247 | const char *str; |
4248 | isl_bool empty; |
4249 | isl_union_set *domain; |
4250 | isl_union_map *validity, *condition; |
4251 | isl_schedule_constraints *sc; |
4252 | isl_schedule *schedule; |
4253 | isl_union_map *umap; |
4254 | isl_map *map, *ge; |
4255 | |
4256 | str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }"; |
4257 | domain = isl_union_set_read_from_str(ctx, str); |
4258 | sc = isl_schedule_constraints_on_domain(domain); |
4259 | str = "{ B[1, i] -> A[0, i + 1] }"; |
4260 | condition = isl_union_map_read_from_str(ctx, str); |
4261 | str = "{ A[0, i] -> B[1, i - 1] }"; |
4262 | validity = isl_union_map_read_from_str(ctx, str); |
4263 | sc = isl_schedule_constraints_set_conditional_validity(sc, condition, |
4264 | isl_union_map_copy(validity)); |
4265 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4266 | umap = isl_schedule_get_map(schedule); |
4267 | isl_schedule_free(schedule); |
4268 | validity = isl_union_map_apply_domain(validity, |
4269 | isl_union_map_copy(umap)); |
4270 | validity = isl_union_map_apply_range(validity, umap); |
4271 | map = isl_map_from_union_map(validity); |
4272 | ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map))); |
4273 | map = isl_map_intersect(map, ge); |
4274 | empty = isl_map_is_empty(map); |
4275 | isl_map_free(map); |
4276 | |
4277 | if (empty < 0) |
4278 | return -1; |
4279 | if (!empty) |
4280 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4282); return -1; } while (0) |
4281 | "conditional validity constraints not satisfied",do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4282); return -1; } while (0) |
4282 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4282); return -1; } while (0); |
4283 | |
4284 | return 0; |
4285 | } |
4286 | |
4287 | /* Input for testing of schedule construction based on |
4288 | * conditional constraints. |
4289 | * |
4290 | * domain is the iteration domain |
4291 | * flow are the flow dependences, which determine the validity and |
4292 | * proximity constraints |
4293 | * condition are the conditions on the conditional validity constraints |
4294 | * conditional_validity are the conditional validity constraints |
4295 | * outer_band_n is the expected number of members in the outer band |
4296 | */ |
4297 | struct { |
4298 | const char *domain; |
4299 | const char *flow; |
4300 | const char *condition; |
4301 | const char *conditional_validity; |
4302 | int outer_band_n; |
4303 | } live_range_tests[] = { |
4304 | /* Contrived example that illustrates that we need to keep |
4305 | * track of tagged condition dependences and |
4306 | * tagged conditional validity dependences |
4307 | * in isl_sched_edge separately. |
4308 | * In particular, the conditional validity constraints on A |
4309 | * cannot be satisfied, |
4310 | * but they can be ignored because there are no corresponding |
4311 | * condition constraints. However, we do have an additional |
4312 | * conditional validity constraint that maps to the same |
4313 | * dependence relation |
4314 | * as the condition constraint on B. If we did not make a distinction |
4315 | * between tagged condition and tagged conditional validity |
4316 | * dependences, then we |
4317 | * could end up treating this shared dependence as an condition |
4318 | * constraint on A, forcing a localization of the conditions, |
4319 | * which is impossible. |
4320 | */ |
4321 | { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }", |
4322 | "{ S[i] -> S[i+1] : 0 <= i < 99 }", |
4323 | "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }", |
4324 | "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';" |
4325 | "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';" |
4326 | "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }", |
4327 | 1 |
4328 | }, |
4329 | /* TACO 2013 Fig. 7 */ |
4330 | { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }", |
4331 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
4332 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
4333 | "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;" |
4334 | "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : " |
4335 | "0 <= i < n and 0 <= j < n - 1 }", |
4336 | "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : " |
4337 | "0 <= i < n and 0 <= j < j' < n;" |
4338 | "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : " |
4339 | "0 <= i < i' < n and 0 <= j,j' < n;" |
4340 | "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : " |
4341 | "0 <= i,j,j' < n and j < j' }", |
4342 | 2 |
4343 | }, |
4344 | /* TACO 2013 Fig. 7, without tags */ |
4345 | { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }", |
4346 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
4347 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
4348 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
4349 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
4350 | "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;" |
4351 | "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;" |
4352 | "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }", |
4353 | 1 |
4354 | }, |
4355 | /* TACO 2013 Fig. 12 */ |
4356 | { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;" |
4357 | "S3[i,3] : 0 <= i <= 1 }", |
4358 | "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;" |
4359 | "S2[i,1] -> S2[i,2] : 0 <= i <= 1;" |
4360 | "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }", |
4361 | "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;" |
4362 | "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;" |
4363 | "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }", |
4364 | "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;" |
4365 | "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;" |
4366 | "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;" |
4367 | "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;" |
4368 | "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }", |
4369 | 1 |
4370 | } |
4371 | }; |
4372 | |
4373 | /* Test schedule construction based on conditional constraints. |
4374 | * In particular, check the number of members in the outer band node |
4375 | * as an indication of whether tiling is possible or not. |
4376 | */ |
4377 | static int test_conditional_schedule_constraints(isl_ctx *ctx) |
4378 | { |
4379 | int i; |
4380 | isl_union_set *domain; |
4381 | isl_union_map *condition; |
4382 | isl_union_map *flow; |
4383 | isl_union_map *validity; |
4384 | isl_schedule_constraints *sc; |
4385 | isl_schedule *schedule; |
4386 | isl_schedule_node *node; |
4387 | int n_member; |
4388 | |
4389 | if (test_special_conditional_schedule_constraints(ctx) < 0) |
4390 | return -1; |
4391 | if (test_special_conditional_schedule_constraints_2(ctx) < 0) |
4392 | return -1; |
4393 | |
4394 | for (i = 0; i < ARRAY_SIZE(live_range_tests)(sizeof(live_range_tests)/sizeof(*live_range_tests)); ++i) { |
4395 | domain = isl_union_set_read_from_str(ctx, |
4396 | live_range_tests[i].domain); |
4397 | flow = isl_union_map_read_from_str(ctx, |
4398 | live_range_tests[i].flow); |
4399 | condition = isl_union_map_read_from_str(ctx, |
4400 | live_range_tests[i].condition); |
4401 | validity = isl_union_map_read_from_str(ctx, |
4402 | live_range_tests[i].conditional_validity); |
4403 | sc = isl_schedule_constraints_on_domain(domain); |
4404 | sc = isl_schedule_constraints_set_validity(sc, |
4405 | isl_union_map_copy(flow)); |
4406 | sc = isl_schedule_constraints_set_proximity(sc, flow); |
4407 | sc = isl_schedule_constraints_set_conditional_validity(sc, |
4408 | condition, validity); |
4409 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4410 | node = isl_schedule_get_root(schedule); |
4411 | while (node && |
4412 | isl_schedule_node_get_type(node) != isl_schedule_node_band) |
4413 | node = isl_schedule_node_first_child(node); |
4414 | n_member = isl_schedule_node_band_n_member(node); |
4415 | isl_schedule_node_free(node); |
4416 | isl_schedule_free(schedule); |
4417 | |
4418 | if (!schedule) |
4419 | return -1; |
4420 | if (n_member != live_range_tests[i].outer_band_n) |
4421 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4423); return -1; } while (0) |
4422 | "unexpected number of members in outer band",do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4423); return -1; } while (0) |
4423 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4423); return -1; } while (0); |
4424 | } |
4425 | return 0; |
4426 | } |
4427 | |
4428 | /* Check that the schedule computed for the given instance set and |
4429 | * dependence relation strongly satisfies the dependences. |
4430 | * In particular, check that no instance is scheduled before |
4431 | * or together with an instance on which it depends. |
4432 | * Earlier versions of isl would produce a schedule that |
4433 | * only weakly satisfies the dependences. |
4434 | */ |
4435 | static int test_strongly_satisfying_schedule(isl_ctx *ctx) |
4436 | { |
4437 | const char *domain, *dep; |
4438 | isl_union_map *D, *schedule; |
4439 | isl_map *map, *ge; |
4440 | int empty; |
4441 | |
4442 | domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; " |
4443 | "A[i0] : 0 <= i0 <= 1 }"; |
4444 | dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; " |
4445 | "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }"; |
4446 | schedule = compute_schedule(ctx, domain, dep, dep); |
4447 | D = isl_union_map_read_from_str(ctx, dep); |
4448 | D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule)); |
4449 | D = isl_union_map_apply_range(D, schedule); |
4450 | map = isl_map_from_union_map(D); |
4451 | ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map))); |
4452 | map = isl_map_intersect(map, ge); |
4453 | empty = isl_map_is_empty(map); |
4454 | isl_map_free(map); |
4455 | |
4456 | if (empty < 0) |
4457 | return -1; |
4458 | if (!empty) |
4459 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4460); return -1; } while (0) |
4460 | "dependences not strongly satisfied", return -1)do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4460); return -1; } while (0); |
4461 | |
4462 | return 0; |
4463 | } |
4464 | |
4465 | /* Compute a schedule for input where the instance set constraints |
4466 | * conflict with the context constraints. |
4467 | * Earlier versions of isl did not properly handle this situation. |
4468 | */ |
4469 | static int test_conflicting_context_schedule(isl_ctx *ctx) |
4470 | { |
4471 | isl_union_map *schedule; |
4472 | const char *domain, *context; |
4473 | |
4474 | domain = "[n] -> { A[] : n >= 0 }"; |
4475 | context = "[n] -> { : n < 0 }"; |
4476 | schedule = compute_schedule_with_context(ctx, |
4477 | domain, "{}", "{}", context); |
4478 | isl_union_map_free(schedule); |
4479 | |
4480 | if (!schedule) |
4481 | return -1; |
4482 | |
4483 | return 0; |
4484 | } |
4485 | |
4486 | /* Check that a set of schedule constraints that only allow for |
4487 | * a coalescing schedule still produces a schedule even if the user |
4488 | * request a non-coalescing schedule. Earlier versions of isl |
4489 | * would not handle this case correctly. |
4490 | */ |
4491 | static int test_coalescing_schedule(isl_ctx *ctx) |
4492 | { |
4493 | const char *domain, *dep; |
4494 | isl_union_set *I; |
4495 | isl_union_map *D; |
4496 | isl_schedule_constraints *sc; |
4497 | isl_schedule *schedule; |
4498 | int treat_coalescing; |
4499 | |
4500 | domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }"; |
4501 | dep = "{ S[a, b] -> S[a + b, 1 - b] }"; |
4502 | I = isl_union_set_read_from_str(ctx, domain); |
4503 | D = isl_union_map_read_from_str(ctx, dep); |
4504 | sc = isl_schedule_constraints_on_domain(I); |
4505 | sc = isl_schedule_constraints_set_validity(sc, D); |
4506 | treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx); |
4507 | isl_options_set_schedule_treat_coalescing(ctx, 1); |
4508 | schedule = isl_schedule_constraints_compute_schedule(sc); |
4509 | isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing); |
4510 | isl_schedule_free(schedule); |
4511 | if (!schedule) |
4512 | return -1; |
4513 | return 0; |
4514 | } |
4515 | |
4516 | /* Check that the scheduler does not perform any needless |
4517 | * compound skewing. Earlier versions of isl would compute |
4518 | * schedules in terms of transformed schedule coefficients and |
4519 | * would not accurately keep track of the sum of the original |
4520 | * schedule coefficients. It could then produce the schedule |
4521 | * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k] |
4522 | * for the input below instead of the schedule below. |
4523 | */ |
4524 | static int test_skewing_schedule(isl_ctx *ctx) |
4525 | { |
4526 | const char *D, *V, *P, *S; |
4527 | |
4528 | D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }"; |
4529 | V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and " |
4530 | "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and " |
4531 | "-1 <= a-i + b-j + c-k <= 1 }"; |
4532 | P = "{ }"; |
4533 | S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }"; |
4534 | |
4535 | return test_special_schedule(ctx, D, V, P, S); |
4536 | } |
4537 | |
4538 | int test_schedule(isl_ctx *ctx) |
4539 | { |
4540 | const char *D, *W, *R, *V, *P, *S; |
4541 | int max_coincidence; |
4542 | int treat_coalescing; |
4543 | |
4544 | /* Handle resulting schedule with zero bands. */ |
4545 | if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0) |
4546 | return -1; |
4547 | |
4548 | /* Jacobi */ |
4549 | D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }"; |
4550 | W = "{ S1[t,i] -> a[t,i] }"; |
4551 | R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; " |
4552 | "S1[t,i] -> a[t-1,i+1] }"; |
4553 | S = "{ S1[t,i] -> [t,i] }"; |
4554 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
4555 | return -1; |
4556 | |
4557 | /* Fig. 5 of CC2008 */ |
4558 | D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and " |
4559 | "j <= -1 + N }"; |
4560 | W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and " |
4561 | "j >= 2 and j <= -1 + N }"; |
4562 | R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and " |
4563 | "j >= 2 and j <= -1 + N; " |
4564 | "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and " |
4565 | "j >= 2 and j <= -1 + N }"; |
4566 | S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }"; |
4567 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
4568 | return -1; |
4569 | |
4570 | D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }"; |
4571 | W = "{ S1[i] -> a[i] }"; |
4572 | R = "{ S2[i] -> a[i+1] }"; |
4573 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
4574 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
4575 | return -1; |
4576 | |
4577 | D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }"; |
4578 | W = "{ S1[i] -> a[i] }"; |
4579 | R = "{ S2[i] -> a[9-i] }"; |
4580 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
4581 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
4582 | return -1; |
4583 | |
4584 | D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }"; |
4585 | W = "{ S1[i] -> a[i] }"; |
4586 | R = "[N] -> { S2[i] -> a[N-1-i] }"; |
4587 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
4588 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
4589 | return -1; |
4590 | |
4591 | D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }"; |
4592 | W = "{ S1[i] -> a[i]; S2[i] -> b[i] }"; |
4593 | R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }"; |
4594 | S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }"; |
4595 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4596 | return -1; |
4597 | |
4598 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }"; |
4599 | W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }"; |
4600 | R = "{ S2[i,j] -> a[i-1,j] }"; |
4601 | S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }"; |
4602 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
4603 | return -1; |
4604 | |
4605 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }"; |
4606 | W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }"; |
4607 | R = "{ S2[i,j] -> a[i,j-1] }"; |
4608 | S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }"; |
4609 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
4610 | return -1; |
4611 | |
4612 | D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }"; |
4613 | W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; " |
4614 | "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }"; |
4615 | R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }"; |
4616 | S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; " |
4617 | "S_0[] -> [0, 0, 0] }"; |
4618 | if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0) |
4619 | return -1; |
4620 | ctx->opt->schedule_parametric = 0; |
4621 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4622 | return -1; |
4623 | ctx->opt->schedule_parametric = 1; |
4624 | |
4625 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; " |
4626 | "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }"; |
4627 | W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }"; |
4628 | R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; " |
4629 | "S4[i] -> a[i,N] }"; |
4630 | S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; " |
4631 | "S4[i] -> [4,i,0] }"; |
4632 | max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx); |
4633 | isl_options_set_schedule_maximize_coincidence(ctx, 0); |
4634 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
4635 | return -1; |
4636 | isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence); |
4637 | |
4638 | D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }"; |
4639 | W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and " |
4640 | "j <= N }"; |
4641 | R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and " |
4642 | "j <= N; " |
4643 | "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and " |
4644 | "j <= N }"; |
4645 | S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }"; |
4646 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4647 | return -1; |
4648 | |
4649 | D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; " |
4650 | " S_2[t] : t >= 0 and t <= -1 + N; " |
4651 | " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and " |
4652 | "i <= -1 + N }"; |
4653 | W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; " |
4654 | " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; " |
4655 | " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and " |
4656 | "i >= 0 and i <= -1 + N }"; |
4657 | R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and " |
4658 | "i >= 0 and i <= -1 + N; " |
4659 | " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }"; |
4660 | S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; " |
4661 | " S_0[t] -> [0, t, 0] }"; |
4662 | |
4663 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
4664 | return -1; |
4665 | ctx->opt->schedule_parametric = 0; |
4666 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4667 | return -1; |
4668 | ctx->opt->schedule_parametric = 1; |
4669 | |
4670 | D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }"; |
4671 | S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }"; |
4672 | if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0) |
4673 | return -1; |
4674 | |
4675 | D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; " |
4676 | "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }"; |
4677 | W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and " |
4678 | "j >= 0 and j <= -1 + N; " |
4679 | "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }"; |
4680 | R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and " |
4681 | "j >= 0 and j <= -1 + N; " |
4682 | "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }"; |
4683 | S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }"; |
4684 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4685 | return -1; |
4686 | |
4687 | D = "{ S_0[i] : i >= 0 }"; |
4688 | W = "{ S_0[i] -> a[i] : i >= 0 }"; |
4689 | R = "{ S_0[i] -> a[0] : i >= 0 }"; |
4690 | S = "{ S_0[i] -> [0, i, 0] }"; |
4691 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4692 | return -1; |
4693 | |
4694 | D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }"; |
4695 | W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }"; |
4696 | R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }"; |
4697 | S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }"; |
4698 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4699 | return -1; |
4700 | |
4701 | D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and " |
4702 | "k <= -1 + n and k >= 0 }"; |
4703 | W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }"; |
4704 | R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " |
4705 | "k <= -1 + n and k >= 0; " |
4706 | "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and " |
4707 | "k <= -1 + n and k >= 0; " |
4708 | "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and " |
4709 | "k <= -1 + n and k >= 0 }"; |
4710 | S = "[n] -> { S_0[j, k] -> [2, j, k] }"; |
4711 | ctx->opt->schedule_outer_coincidence = 1; |
4712 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4713 | return -1; |
4714 | ctx->opt->schedule_outer_coincidence = 0; |
4715 | |
4716 | D = "{Stmt_for_body24[i0, i1, i2, i3]:" |
4717 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and " |
4718 | "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;" |
4719 | "Stmt_for_body24[i0, i1, 1, 0]:" |
4720 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;" |
4721 | "Stmt_for_body7[i0, i1, i2]:" |
4722 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and " |
4723 | "i2 <= 7 }"; |
4724 | |
4725 | V = "{Stmt_for_body24[0, i1, i2, i3] -> " |
4726 | "Stmt_for_body24[1, i1, i2, i3]:" |
4727 | "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and " |
4728 | "i2 >= 1;" |
4729 | "Stmt_for_body24[0, i1, i2, i3] -> " |
4730 | "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:" |
4731 | "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and " |
4732 | "i3 >= 0;" |
4733 | "Stmt_for_body24[0, i1, i2, i3] ->" |
4734 | "Stmt_for_body7[1, i1, 1 + i1 + i3]:" |
4735 | "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;" |
4736 | "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:" |
4737 | "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or " |
4738 | "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or " |
4739 | "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);" |
4740 | "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:" |
4741 | "i1 <= 6 and i1 >= 0;" |
4742 | "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];" |
4743 | "Stmt_for_body7[i0, i1, i2] -> " |
4744 | "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:" |
4745 | "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and " |
4746 | "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;" |
4747 | "Stmt_for_body7[i0, i1, i2] -> " |
4748 | "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:" |
4749 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and " |
4750 | "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }"; |
4751 | P = V; |
4752 | |
4753 | treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx); |
4754 | isl_options_set_schedule_treat_coalescing(ctx, 0); |
4755 | if (test_has_schedule(ctx, D, V, P) < 0) |
4756 | return -1; |
4757 | isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing); |
4758 | |
4759 | D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }"; |
4760 | V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and " |
4761 | "j >= 1 and j <= 7;" |
4762 | "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and " |
4763 | "j >= 1 and j <= 8 }"; |
4764 | P = "{ }"; |
4765 | S = "{ S_0[i, j] -> [i + j, i] }"; |
4766 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4767 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4768 | return -1; |
4769 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4770 | |
4771 | /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */ |
4772 | D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and " |
4773 | "j >= 0 and j <= -1 + i }"; |
4774 | V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and " |
4775 | "i <= -1 + N and j >= 0;" |
4776 | "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and " |
4777 | "i <= -2 + N }"; |
4778 | P = "{ }"; |
4779 | S = "{ S_0[i, j] -> [i, j] }"; |
4780 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4781 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4782 | return -1; |
4783 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4784 | |
4785 | /* Test both algorithms on a case with only proximity dependences. */ |
4786 | D = "{ S[i,j] : 0 <= i <= 10 }"; |
4787 | V = "{ }"; |
4788 | P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }"; |
4789 | S = "{ S[i, j] -> [j, i] }"; |
4790 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4791 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4792 | return -1; |
4793 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4794 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4795 | return -1; |
4796 | |
4797 | D = "{ A[a]; B[] }"; |
4798 | V = "{}"; |
4799 | P = "{ A[a] -> B[] }"; |
4800 | if (test_has_schedule(ctx, D, V, P) < 0) |
4801 | return -1; |
4802 | |
4803 | if (test_padded_schedule(ctx) < 0) |
4804 | return -1; |
4805 | |
4806 | /* Check that check for progress is not confused by rational |
4807 | * solution. |
4808 | */ |
4809 | D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }"; |
4810 | V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and " |
4811 | "i0 <= -2 + N; " |
4812 | "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and " |
4813 | "i0 <= N and i1 >= 0 and i1 <= -1 + N }"; |
4814 | P = "{}"; |
4815 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4816 | if (test_has_schedule(ctx, D, V, P) < 0) |
4817 | return -1; |
4818 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4819 | |
4820 | /* Check that we allow schedule rows that are only non-trivial |
4821 | * on some full-dimensional domains. |
4822 | */ |
4823 | D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }"; |
4824 | V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];" |
4825 | "S1[j] -> S2[1] : 0 <= j <= 1 }"; |
4826 | P = "{}"; |
4827 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4828 | if (test_has_schedule(ctx, D, V, P) < 0) |
4829 | return -1; |
4830 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4831 | |
4832 | if (test_conditional_schedule_constraints(ctx) < 0) |
4833 | return -1; |
4834 | |
4835 | if (test_strongly_satisfying_schedule(ctx) < 0) |
4836 | return -1; |
4837 | |
4838 | if (test_conflicting_context_schedule(ctx) < 0) |
4839 | return -1; |
4840 | |
4841 | if (test_coalescing_schedule(ctx) < 0) |
4842 | return -1; |
4843 | if (test_skewing_schedule(ctx) < 0) |
4844 | return -1; |
4845 | |
4846 | return 0; |
4847 | } |
4848 | |
4849 | /* Perform scheduling tests using the whole component scheduler. |
4850 | */ |
4851 | static int test_schedule_whole(isl_ctx *ctx) |
4852 | { |
4853 | int whole; |
4854 | int r; |
4855 | |
4856 | whole = isl_options_get_schedule_whole_component(ctx); |
4857 | isl_options_set_schedule_whole_component(ctx, 1); |
4858 | r = test_schedule(ctx); |
4859 | isl_options_set_schedule_whole_component(ctx, whole); |
4860 | |
4861 | return r; |
4862 | } |
4863 | |
4864 | /* Perform scheduling tests using the incremental scheduler. |
4865 | */ |
4866 | static int test_schedule_incremental(isl_ctx *ctx) |
4867 | { |
4868 | int whole; |
4869 | int r; |
4870 | |
4871 | whole = isl_options_get_schedule_whole_component(ctx); |
4872 | isl_options_set_schedule_whole_component(ctx, 0); |
4873 | r = test_schedule(ctx); |
4874 | isl_options_set_schedule_whole_component(ctx, whole); |
4875 | |
4876 | return r; |
4877 | } |
4878 | |
4879 | int test_plain_injective(isl_ctx *ctx, const char *str, int injective) |
4880 | { |
4881 | isl_union_map *umap; |
4882 | int test; |
4883 | |
4884 | umap = isl_union_map_read_from_str(ctx, str); |
4885 | test = isl_union_map_plain_is_injective(umap); |
4886 | isl_union_map_free(umap); |
4887 | if (test < 0) |
4888 | return -1; |
4889 | if (test == injective) |
4890 | return 0; |
4891 | if (injective) |
4892 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4893); return -1; } while (0) |
4893 | "map not detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4893); return -1; } while (0); |
4894 | else |
4895 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4896); return -1; } while (0) |
4896 | "map detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4896); return -1; } while (0); |
4897 | } |
4898 | |
4899 | int test_injective(isl_ctx *ctx) |
4900 | { |
4901 | const char *str; |
4902 | |
4903 | if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0)) |
4904 | return -1; |
4905 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1)) |
4906 | return -1; |
4907 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1)) |
4908 | return -1; |
4909 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0)) |
4910 | return -1; |
4911 | if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1)) |
4912 | return -1; |
4913 | if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0)) |
4914 | return -1; |
4915 | if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1)) |
4916 | return -1; |
4917 | if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1)) |
4918 | return -1; |
4919 | |
4920 | str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}"; |
4921 | if (test_plain_injective(ctx, str, 1)) |
4922 | return -1; |
4923 | str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}"; |
4924 | if (test_plain_injective(ctx, str, 0)) |
4925 | return -1; |
4926 | |
4927 | return 0; |
4928 | } |
4929 | |
4930 | static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str) |
4931 | { |
4932 | isl_aff *aff2; |
4933 | int equal; |
4934 | |
4935 | if (!aff) |
4936 | return -1; |
4937 | |
4938 | aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str); |
4939 | equal = isl_aff_plain_is_equal(aff, aff2); |
4940 | isl_aff_free(aff2); |
4941 | |
4942 | return equal; |
4943 | } |
4944 | |
4945 | static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str) |
4946 | { |
4947 | int equal; |
4948 | |
4949 | equal = aff_plain_is_equal(aff, str); |
4950 | if (equal < 0) |
4951 | return -1; |
4952 | if (!equal) |
4953 | isl_die(isl_aff_get_ctx(aff), isl_error_unknown,do { isl_handle_error(isl_aff_get_ctx(aff), isl_error_unknown , "result not as expected", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4954); return -1; } while (0) |
4954 | "result not as expected", return -1)do { isl_handle_error(isl_aff_get_ctx(aff), isl_error_unknown , "result not as expected", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4954); return -1; } while (0); |
4955 | return 0; |
4956 | } |
4957 | |
4958 | /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"? |
4959 | */ |
4960 | static isl_bool union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff *upa, |
4961 | const char *str) |
4962 | { |
4963 | isl_ctx *ctx; |
4964 | isl_union_pw_aff *upa2; |
4965 | isl_bool equal; |
4966 | |
4967 | if (!upa) |
4968 | return isl_bool_error; |
4969 | |
4970 | ctx = isl_union_pw_aff_get_ctx(upa); |
4971 | upa2 = isl_union_pw_aff_read_from_str(ctx, str); |
4972 | equal = isl_union_pw_aff_plain_is_equal(upa, upa2); |
4973 | isl_union_pw_aff_free(upa2); |
4974 | |
4975 | return equal; |
4976 | } |
4977 | |
4978 | /* Check that "upa" is obviously equal to the isl_union_pw_aff |
4979 | * represented by "str". |
4980 | */ |
4981 | static isl_stat union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff *upa, |
4982 | const char *str) |
4983 | { |
4984 | isl_bool equal; |
4985 | |
4986 | equal = union_pw_aff_plain_is_equal(upa, str); |
4987 | if (equal < 0) |
4988 | return isl_stat_error; |
4989 | if (!equal) |
4990 | isl_die(isl_union_pw_aff_get_ctx(upa), isl_error_unknown,do { isl_handle_error(isl_union_pw_aff_get_ctx(upa), isl_error_unknown , "result not as expected", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4991); return isl_stat_error; } while (0) |
4991 | "result not as expected", return isl_stat_error)do { isl_handle_error(isl_union_pw_aff_get_ctx(upa), isl_error_unknown , "result not as expected", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 4991); return isl_stat_error; } while (0); |
4992 | return isl_stat_ok; |
4993 | } |
4994 | |
4995 | /* Basic tests on isl_union_pw_aff. |
4996 | * |
4997 | * In particular, check that isl_union_pw_aff_aff_on_domain |
4998 | * aligns the parameters of the input objects and |
4999 | * that isl_union_pw_aff_param_on_domain_id properly |
5000 | * introduces the parameter. |
5001 | */ |
5002 | static int test_upa(isl_ctx *ctx) |
5003 | { |
5004 | const char *str; |
5005 | isl_id *id; |
5006 | isl_aff *aff; |
5007 | isl_union_set *domain; |
5008 | isl_union_pw_aff *upa; |
5009 | isl_stat ok; |
5010 | |
5011 | aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }"); |
5012 | str = "[M] -> { A[i] : 0 <= i < M; B[] }"; |
5013 | domain = isl_union_set_read_from_str(ctx, str); |
5014 | upa = isl_union_pw_aff_aff_on_domain(domain, aff); |
5015 | str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }"; |
5016 | ok = union_pw_aff_check_plain_equal(upa, str); |
5017 | isl_union_pw_aff_free(upa); |
5018 | if (ok < 0) |
5019 | return -1; |
5020 | |
5021 | id = isl_id_alloc(ctx, "N", NULL((void*)0)); |
5022 | str = "[M] -> { A[i] : 0 <= i < M; B[] }"; |
5023 | domain = isl_union_set_read_from_str(ctx, str); |
5024 | upa = isl_union_pw_aff_param_on_domain_id(domain, id); |
5025 | str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }"; |
5026 | ok = union_pw_aff_check_plain_equal(upa, str); |
5027 | isl_union_pw_aff_free(upa); |
5028 | if (ok < 0) |
5029 | return -1; |
5030 | |
5031 | return 0; |
5032 | } |
5033 | |
5034 | struct { |
5035 | __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1, |
5036 | __isl_take isl_aff *aff2); |
5037 | } aff_bin_op[] = { |
5038 | ['+'] = { &isl_aff_add }, |
5039 | ['-'] = { &isl_aff_sub }, |
5040 | ['*'] = { &isl_aff_mul }, |
5041 | ['/'] = { &isl_aff_div }, |
5042 | }; |
5043 | |
5044 | struct { |
5045 | const char *arg1; |
5046 | unsigned char op; |
5047 | const char *arg2; |
5048 | const char *res; |
5049 | } aff_bin_tests[] = { |
5050 | { "{ [i] -> [i] }", '+', "{ [i] -> [i] }", |
5051 | "{ [i] -> [2i] }" }, |
5052 | { "{ [i] -> [i] }", '-', "{ [i] -> [i] }", |
5053 | "{ [i] -> [0] }" }, |
5054 | { "{ [i] -> [i] }", '*', "{ [i] -> [2] }", |
5055 | "{ [i] -> [2i] }" }, |
5056 | { "{ [i] -> [2] }", '*', "{ [i] -> [i] }", |
5057 | "{ [i] -> [2i] }" }, |
5058 | { "{ [i] -> [i] }", '/', "{ [i] -> [2] }", |
5059 | "{ [i] -> [i/2] }" }, |
5060 | { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }", |
5061 | "{ [i] -> [i] }" }, |
5062 | { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }", |
5063 | "{ [i] -> [NaN] }" }, |
5064 | { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }", |
5065 | "{ [i] -> [NaN] }" }, |
5066 | { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }", |
5067 | "{ [i] -> [NaN] }" }, |
5068 | { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }", |
5069 | "{ [i] -> [NaN] }" }, |
5070 | { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }", |
5071 | "{ [i] -> [NaN] }" }, |
5072 | { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }", |
5073 | "{ [i] -> [NaN] }" }, |
5074 | { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }", |
5075 | "{ [i] -> [NaN] }" }, |
5076 | { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }", |
5077 | "{ [i] -> [NaN] }" }, |
5078 | { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }", |
5079 | "{ [i] -> [NaN] }" }, |
5080 | { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }", |
5081 | "{ [i] -> [NaN] }" }, |
5082 | { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }", |
5083 | "{ [i] -> [NaN] }" }, |
5084 | { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }", |
5085 | "{ [i] -> [NaN] }" }, |
5086 | }; |
5087 | |
5088 | /* Perform some basic tests of binary operations on isl_aff objects. |
5089 | */ |
5090 | static int test_bin_aff(isl_ctx *ctx) |
5091 | { |
5092 | int i; |
5093 | isl_aff *aff1, *aff2, *res; |
5094 | __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1, |
5095 | __isl_take isl_aff *aff2); |
5096 | int ok; |
5097 | |
5098 | for (i = 0; i < ARRAY_SIZE(aff_bin_tests)(sizeof(aff_bin_tests)/sizeof(*aff_bin_tests)); ++i) { |
5099 | aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1); |
5100 | aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2); |
5101 | res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res); |
5102 | fn = aff_bin_op[aff_bin_tests[i].op].fn; |
5103 | aff1 = fn(aff1, aff2); |
5104 | if (isl_aff_is_nan(res)) |
5105 | ok = isl_aff_is_nan(aff1); |
5106 | else |
5107 | ok = isl_aff_plain_is_equal(aff1, res); |
5108 | isl_aff_free(aff1); |
5109 | isl_aff_free(res); |
5110 | if (ok < 0) |
5111 | return -1; |
5112 | if (!ok) |
5113 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5114); return -1; } while (0) |
5114 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5114); return -1; } while (0); |
5115 | } |
5116 | |
5117 | return 0; |
5118 | } |
5119 | |
5120 | struct { |
5121 | __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1, |
5122 | __isl_take isl_pw_aff *pa2); |
5123 | } pw_aff_bin_op[] = { |
5124 | ['m'] = { &isl_pw_aff_min }, |
5125 | ['M'] = { &isl_pw_aff_max }, |
5126 | }; |
5127 | |
5128 | /* Inputs for binary isl_pw_aff operation tests. |
5129 | * "arg1" and "arg2" are the two arguments, "op" identifies the operation |
5130 | * defined by pw_aff_bin_op, and "res" is the expected result. |
5131 | */ |
5132 | struct { |
5133 | const char *arg1; |
5134 | unsigned char op; |
5135 | const char *arg2; |
5136 | const char *res; |
5137 | } pw_aff_bin_tests[] = { |
5138 | { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }", |
5139 | "{ [i] -> [i] }" }, |
5140 | { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }", |
5141 | "{ [i] -> [i] }" }, |
5142 | { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }", |
5143 | "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" }, |
5144 | { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }", |
5145 | "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" }, |
5146 | { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }", |
5147 | "{ [i] -> [NaN] }" }, |
5148 | { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }", |
5149 | "{ [i] -> [NaN] }" }, |
5150 | }; |
5151 | |
5152 | /* Perform some basic tests of binary operations on isl_pw_aff objects. |
5153 | */ |
5154 | static int test_bin_pw_aff(isl_ctx *ctx) |
5155 | { |
5156 | int i; |
5157 | isl_bool ok; |
5158 | isl_pw_aff *pa1, *pa2, *res; |
5159 | |
5160 | for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests)(sizeof(pw_aff_bin_tests)/sizeof(*pw_aff_bin_tests)); ++i) { |
5161 | pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1); |
5162 | pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2); |
5163 | res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res); |
5164 | pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2); |
5165 | if (isl_pw_aff_involves_nan(res)) |
5166 | ok = isl_pw_aff_involves_nan(pa1); |
5167 | else |
5168 | ok = isl_pw_aff_plain_is_equal(pa1, res); |
5169 | isl_pw_aff_free(pa1); |
5170 | isl_pw_aff_free(res); |
5171 | if (ok < 0) |
5172 | return -1; |
5173 | if (!ok) |
5174 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5175); return -1; } while (0) |
5175 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5175); return -1; } while (0); |
5176 | } |
5177 | |
5178 | return 0; |
5179 | } |
5180 | |
5181 | struct { |
5182 | __isl_give isl_union_pw_multi_aff *(*fn)( |
5183 | __isl_take isl_union_pw_multi_aff *upma1, |
5184 | __isl_take isl_union_pw_multi_aff *upma2); |
5185 | const char *arg1; |
5186 | const char *arg2; |
5187 | const char *res; |
5188 | } upma_bin_tests[] = { |
5189 | { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }", |
5190 | "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" }, |
5191 | { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }", |
5192 | "{ B[x] -> [2] : x >= 0 }", |
5193 | "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" }, |
5194 | { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff, |
5195 | "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }", |
5196 | "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }", |
5197 | "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; " |
5198 | "D[i] -> B[2] : i >= 5 }" }, |
5199 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
5200 | "{ B[x] -> C[2] : x > 0 }", |
5201 | "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" }, |
5202 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
5203 | "{ B[x] -> A[2] : x >= 0 }", |
5204 | "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" }, |
5205 | }; |
5206 | |
5207 | /* Perform some basic tests of binary operations on |
5208 | * isl_union_pw_multi_aff objects. |
5209 | */ |
5210 | static int test_bin_upma(isl_ctx *ctx) |
5211 | { |
5212 | int i; |
5213 | isl_union_pw_multi_aff *upma1, *upma2, *res; |
5214 | int ok; |
5215 | |
5216 | for (i = 0; i < ARRAY_SIZE(upma_bin_tests)(sizeof(upma_bin_tests)/sizeof(*upma_bin_tests)); ++i) { |
5217 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
5218 | upma_bin_tests[i].arg1); |
5219 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
5220 | upma_bin_tests[i].arg2); |
5221 | res = isl_union_pw_multi_aff_read_from_str(ctx, |
5222 | upma_bin_tests[i].res); |
5223 | upma1 = upma_bin_tests[i].fn(upma1, upma2); |
5224 | ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res); |
5225 | isl_union_pw_multi_aff_free(upma1); |
5226 | isl_union_pw_multi_aff_free(res); |
5227 | if (ok < 0) |
5228 | return -1; |
5229 | if (!ok) |
5230 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5231); return -1; } while (0) |
5231 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5231); return -1; } while (0); |
5232 | } |
5233 | |
5234 | return 0; |
5235 | } |
5236 | |
5237 | struct { |
5238 | __isl_give isl_union_pw_multi_aff *(*fn)( |
5239 | __isl_take isl_union_pw_multi_aff *upma1, |
5240 | __isl_take isl_union_pw_multi_aff *upma2); |
5241 | const char *arg1; |
5242 | const char *arg2; |
5243 | } upma_bin_fail_tests[] = { |
5244 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
5245 | "{ B[x] -> C[2] : x >= 0 }" }, |
5246 | }; |
5247 | |
5248 | /* Perform some basic tests of binary operations on |
5249 | * isl_union_pw_multi_aff objects that are expected to fail. |
5250 | */ |
5251 | static int test_bin_upma_fail(isl_ctx *ctx) |
5252 | { |
5253 | int i, n; |
5254 | isl_union_pw_multi_aff *upma1, *upma2; |
5255 | int on_error; |
5256 | |
5257 | on_error = isl_options_get_on_error(ctx); |
5258 | isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE1); |
5259 | n = ARRAY_SIZE(upma_bin_fail_tests)(sizeof(upma_bin_fail_tests)/sizeof(*upma_bin_fail_tests)); |
5260 | for (i = 0; i < n; ++i) { |
5261 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
5262 | upma_bin_fail_tests[i].arg1); |
5263 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
5264 | upma_bin_fail_tests[i].arg2); |
5265 | upma1 = upma_bin_fail_tests[i].fn(upma1, upma2); |
5266 | isl_union_pw_multi_aff_free(upma1); |
5267 | if (upma1) |
5268 | break; |
5269 | } |
5270 | isl_options_set_on_error(ctx, on_error); |
5271 | if (i < n) |
5272 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5273); return -1; } while (0) |
5273 | "operation not expected to succeed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5273); return -1; } while (0); |
5274 | |
5275 | return 0; |
5276 | } |
5277 | |
5278 | /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects. |
5279 | * "fn" is the function that is tested. |
5280 | * "arg" is a string description of the input. |
5281 | * "res" is a string description of the expected result. |
5282 | */ |
5283 | struct { |
5284 | __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa); |
5285 | const char *arg; |
5286 | const char *res; |
5287 | } mpa_un_tests[] = { |
5288 | { &isl_multi_pw_aff_range_factor_domain, |
5289 | "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }", |
5290 | "{ A[x] -> B[(1 : x >= 5)] }" }, |
5291 | { &isl_multi_pw_aff_range_factor_range, |
5292 | "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }", |
5293 | "{ A[y] -> C[(2 : y <= 10)] }" }, |
5294 | { &isl_multi_pw_aff_range_factor_domain, |
5295 | "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }", |
5296 | "{ A[x] -> B[(1 : x >= 5)] }" }, |
5297 | { &isl_multi_pw_aff_range_factor_range, |
5298 | "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }", |
5299 | "{ A[y] -> C[] }" }, |
5300 | { &isl_multi_pw_aff_range_factor_domain, |
5301 | "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }", |
5302 | "{ A[x] -> B[] }" }, |
5303 | { &isl_multi_pw_aff_range_factor_range, |
5304 | "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }", |
5305 | "{ A[y] -> C[(2 : y <= 10)] }" }, |
5306 | { &isl_multi_pw_aff_range_factor_domain, |
5307 | "{ A[x] -> [B[] -> C[]] }", |
5308 | "{ A[x] -> B[] }" }, |
5309 | { &isl_multi_pw_aff_range_factor_range, |
5310 | "{ A[x] -> [B[] -> C[]] }", |
5311 | "{ A[y] -> C[] }" }, |
5312 | { &isl_multi_pw_aff_factor_range, |
5313 | "{ [B[] -> C[]] }", |
5314 | "{ C[] }" }, |
5315 | { &isl_multi_pw_aff_range_factor_domain, |
5316 | "{ A[x] -> [B[] -> C[]] : x >= 0 }", |
5317 | "{ A[x] -> B[] : x >= 0 }" }, |
5318 | { &isl_multi_pw_aff_range_factor_range, |
5319 | "{ A[x] -> [B[] -> C[]] : x >= 0 }", |
5320 | "{ A[y] -> C[] : y >= 0 }" }, |
5321 | { &isl_multi_pw_aff_factor_range, |
5322 | "[N] -> { [B[] -> C[]] : N >= 0 }", |
5323 | "[N] -> { C[] : N >= 0 }" }, |
5324 | }; |
5325 | |
5326 | /* Perform some basic tests of unary operations on isl_multi_pw_aff objects. |
5327 | */ |
5328 | static int test_un_mpa(isl_ctx *ctx) |
5329 | { |
5330 | int i; |
5331 | isl_bool ok; |
5332 | isl_multi_pw_aff *mpa, *res; |
5333 | |
5334 | for (i = 0; i < ARRAY_SIZE(mpa_un_tests)(sizeof(mpa_un_tests)/sizeof(*mpa_un_tests)); ++i) { |
5335 | mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg); |
5336 | res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res); |
5337 | mpa = mpa_un_tests[i].fn(mpa); |
5338 | ok = isl_multi_pw_aff_plain_is_equal(mpa, res); |
5339 | isl_multi_pw_aff_free(mpa); |
5340 | isl_multi_pw_aff_free(res); |
5341 | if (ok < 0) |
5342 | return -1; |
5343 | if (!ok) |
5344 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5345); return -1; } while (0) |
5345 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5345); return -1; } while (0); |
5346 | } |
5347 | |
5348 | return 0; |
5349 | } |
5350 | |
5351 | /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects. |
5352 | * "fn" is the function that is tested. |
5353 | * "arg1" and "arg2" are string descriptions of the inputs. |
5354 | * "res" is a string description of the expected result. |
5355 | */ |
5356 | struct { |
5357 | __isl_give isl_multi_pw_aff *(*fn)( |
5358 | __isl_take isl_multi_pw_aff *mpa1, |
5359 | __isl_take isl_multi_pw_aff *mpa2); |
5360 | const char *arg1; |
5361 | const char *arg2; |
5362 | const char *res; |
5363 | } mpa_bin_tests[] = { |
5364 | { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }", |
5365 | "{ A[] -> [3] }" }, |
5366 | { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }", |
5367 | "{ A[x] -> [(x : x <= 10)] }", |
5368 | "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" }, |
5369 | { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }", |
5370 | "{ A[x] -> [] : x <= 10 }", |
5371 | "{ A[x] -> [] : 5 <= x <= 10 }" }, |
5372 | { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }", |
5373 | "[N] -> { A[x] -> [] : x <= N }", |
5374 | "[N] -> { A[x] -> [] : 5 <= x <= N }" }, |
5375 | { &isl_multi_pw_aff_add, |
5376 | "[N] -> { A[x] -> [] : x <= N }", |
5377 | "{ A[x] -> [] : x >= 5 }", |
5378 | "[N] -> { A[x] -> [] : 5 <= x <= N }" }, |
5379 | { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }", |
5380 | "{ A[y] -> C[(2 : y <= 10)] }", |
5381 | "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" }, |
5382 | { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }", |
5383 | "{ A[y] -> C[2] : y <= 10 }", |
5384 | "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" }, |
5385 | { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }", |
5386 | "[N] -> { A[y] -> C[2] : y <= N }", |
5387 | "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" }, |
5388 | { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }", |
5389 | "{ A[y] -> C[2] : y <= 10 }", |
5390 | "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" }, |
5391 | { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }", |
5392 | "{ A[] -> [B[1] -> C[2]] }" }, |
5393 | { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }", |
5394 | "{ A[] -> [B[] -> C[]] }" }, |
5395 | { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }", |
5396 | "{ A[y] -> C[] : y <= 10 }", |
5397 | "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" }, |
5398 | { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }", |
5399 | "{ A[x] -> B[(1 : x >= 5)] }", |
5400 | "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" }, |
5401 | { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }", |
5402 | "{ A[y] -> C[(2 : y <= 10)] }", |
5403 | "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" }, |
5404 | { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }", |
5405 | "{ A[y] -> C[] : y <= 10 }", |
5406 | "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" }, |
5407 | { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }", |
5408 | "{ A[x] -> B[(1 : x >= 5)] }", |
5409 | "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" }, |
5410 | { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }", |
5411 | "[N] -> { A[y] -> C[] : y <= N }", |
5412 | "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" }, |
5413 | { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }", |
5414 | "{ A[x] -> B[(1 : x >= 5)] }", |
5415 | "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" }, |
5416 | { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }", |
5417 | "{ A[y] -> C[] : y <= 10 }", |
5418 | "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" }, |
5419 | { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }", |
5420 | "{ [A[] -> A[]] -> [B[1] -> C[2]] }" }, |
5421 | { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }", |
5422 | "{ [A[] -> A[]] -> [B[] -> C[]] }" }, |
5423 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5424 | "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }", |
5425 | "{ A[a,b] -> C[b + 2a] }" }, |
5426 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5427 | "{ B[i,j] -> C[i + 2j] }", |
5428 | "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", |
5429 | "{ A[a,b] -> C[(b + 2a : b > a)] }" }, |
5430 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5431 | "{ B[i,j] -> C[(i + 2j : j > 4)] }", |
5432 | "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", |
5433 | "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" }, |
5434 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5435 | "{ B[i,j] -> C[] }", |
5436 | "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", |
5437 | "{ A[a,b] -> C[] }" }, |
5438 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5439 | "{ B[i,j] -> C[] : i > j }", |
5440 | "{ A[a,b] -> B[b,a] }", |
5441 | "{ A[a,b] -> C[] : b > a }" }, |
5442 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5443 | "{ B[i,j] -> C[] : j > 5 }", |
5444 | "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", |
5445 | "{ A[a,b] -> C[] : b > a > 5 }" }, |
5446 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5447 | "[N] -> { B[i,j] -> C[] : j > N }", |
5448 | "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", |
5449 | "[N] -> { A[a,b] -> C[] : b > a > N }" }, |
5450 | { &isl_multi_pw_aff_pullback_multi_pw_aff, |
5451 | "[M,N] -> { B[] -> C[] : N > 5 }", |
5452 | "[M,N] -> { A[] -> B[] : M > N }", |
5453 | "[M,N] -> { A[] -> C[] : M > N > 5 }" }, |
5454 | }; |
5455 | |
5456 | /* Perform some basic tests of binary operations on isl_multi_pw_aff objects. |
5457 | */ |
5458 | static int test_bin_mpa(isl_ctx *ctx) |
5459 | { |
5460 | int i; |
5461 | isl_bool ok; |
5462 | isl_multi_pw_aff *mpa1, *mpa2, *res; |
5463 | |
5464 | for (i = 0; i < ARRAY_SIZE(mpa_bin_tests)(sizeof(mpa_bin_tests)/sizeof(*mpa_bin_tests)); ++i) { |
5465 | mpa1 = isl_multi_pw_aff_read_from_str(ctx, |
5466 | mpa_bin_tests[i].arg1); |
5467 | mpa2 = isl_multi_pw_aff_read_from_str(ctx, |
5468 | mpa_bin_tests[i].arg2); |
5469 | res = isl_multi_pw_aff_read_from_str(ctx, |
5470 | mpa_bin_tests[i].res); |
5471 | mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2); |
5472 | ok = isl_multi_pw_aff_plain_is_equal(mpa1, res); |
5473 | isl_multi_pw_aff_free(mpa1); |
5474 | isl_multi_pw_aff_free(res); |
5475 | if (ok < 0) |
5476 | return -1; |
5477 | if (!ok) |
5478 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5479); return -1; } while (0) |
5479 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5479); return -1; } while (0); |
5480 | } |
5481 | |
5482 | return 0; |
5483 | } |
5484 | |
5485 | /* Inputs for basic tests of unary operations on |
5486 | * isl_multi_union_pw_aff objects. |
5487 | * "fn" is the function that is tested. |
5488 | * "arg" is a string description of the input. |
5489 | * "res" is a string description of the expected result. |
5490 | */ |
5491 | struct { |
5492 | __isl_give isl_multi_union_pw_aff *(*fn)( |
5493 | __isl_take isl_multi_union_pw_aff *mupa); |
5494 | const char *arg; |
5495 | const char *res; |
5496 | } mupa_un_tests[] = { |
5497 | { &isl_multi_union_pw_aff_factor_range, |
5498 | "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]", |
5499 | "C[{ A[] -> [2] }]" }, |
5500 | { &isl_multi_union_pw_aff_factor_range, |
5501 | "[B[] -> C[{ A[] -> [2] }]]", |
5502 | "C[{ A[] -> [2] }]" }, |
5503 | { &isl_multi_union_pw_aff_factor_range, |
5504 | "[B[{ A[] -> [1] }] -> C[]]", |
5505 | "C[]" }, |
5506 | { &isl_multi_union_pw_aff_factor_range, |
5507 | "[B[] -> C[]]", |
5508 | "C[]" }, |
5509 | { &isl_multi_union_pw_aff_factor_range, |
5510 | "([B[] -> C[]] : { A[x] : x >= 0 })", |
5511 | "(C[] : { A[x] : x >= 0 })" }, |
5512 | { &isl_multi_union_pw_aff_factor_range, |
5513 | "[N] -> ([B[] -> C[]] : { A[x] : x <= N })", |
5514 | "[N] -> (C[] : { A[x] : x <= N })" }, |
5515 | { &isl_multi_union_pw_aff_factor_range, |
5516 | "[N] -> ([B[] -> C[]] : { : N >= 0 })", |
5517 | "[N] -> (C[] : { : N >= 0 })" }, |
5518 | }; |
5519 | |
5520 | /* Perform some basic tests of unary operations on |
5521 | * isl_multi_union_pw_aff objects. |
5522 | */ |
5523 | static int test_un_mupa(isl_ctx *ctx) |
5524 | { |
5525 | int i; |
5526 | isl_bool ok; |
5527 | isl_multi_union_pw_aff *mupa, *res; |
5528 | |
5529 | for (i = 0; i < ARRAY_SIZE(mupa_un_tests)(sizeof(mupa_un_tests)/sizeof(*mupa_un_tests)); ++i) { |
5530 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
5531 | mupa_un_tests[i].arg); |
5532 | res = isl_multi_union_pw_aff_read_from_str(ctx, |
5533 | mupa_un_tests[i].res); |
5534 | mupa = mupa_un_tests[i].fn(mupa); |
5535 | ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); |
5536 | isl_multi_union_pw_aff_free(mupa); |
5537 | isl_multi_union_pw_aff_free(res); |
5538 | if (ok < 0) |
5539 | return -1; |
5540 | if (!ok) |
5541 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5542); return -1; } while (0) |
5542 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5542); return -1; } while (0); |
5543 | } |
5544 | |
5545 | return 0; |
5546 | } |
5547 | |
5548 | /* Inputs for basic tests of binary operations on |
5549 | * isl_multi_union_pw_aff objects. |
5550 | * "fn" is the function that is tested. |
5551 | * "arg1" and "arg2" are string descriptions of the inputs. |
5552 | * "res" is a string description of the expected result. |
5553 | */ |
5554 | struct { |
5555 | __isl_give isl_multi_union_pw_aff *(*fn)( |
5556 | __isl_take isl_multi_union_pw_aff *mupa1, |
5557 | __isl_take isl_multi_union_pw_aff *mupa2); |
5558 | const char *arg1; |
5559 | const char *arg2; |
5560 | const char *res; |
5561 | } mupa_bin_tests[] = { |
5562 | { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]", |
5563 | "[{ A[] -> [3] }]" }, |
5564 | { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]", |
5565 | "[{ A[] -> [-1] }]" }, |
5566 | { &isl_multi_union_pw_aff_add, |
5567 | "[{ A[] -> [1]; B[] -> [4] }]", |
5568 | "[{ A[] -> [2]; C[] -> [5] }]", |
5569 | "[{ A[] -> [3] }]" }, |
5570 | { &isl_multi_union_pw_aff_union_add, |
5571 | "[{ A[] -> [1]; B[] -> [4] }]", |
5572 | "[{ A[] -> [2]; C[] -> [5] }]", |
5573 | "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" }, |
5574 | { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]", |
5575 | "[{ A[x] -> [(x)] : x <= 10 }]", |
5576 | "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" }, |
5577 | { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })", |
5578 | "([] : { A[x] : x <= 10 })", |
5579 | "([] : { A[x] : 5 <= x <= 10 })" }, |
5580 | { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })", |
5581 | "[N] -> ([] : { A[x] : x <= N })", |
5582 | "[N] -> ([] : { A[x] : 5 <= x <= N })" }, |
5583 | { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })", |
5584 | "([] : { A[x] : x <= 10 })", |
5585 | "[N] -> ([] : { A[x] : N <= x <= 10 })" }, |
5586 | { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]", |
5587 | "[{ A[x] -> [(x)] : x <= 10 }]", |
5588 | "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; " |
5589 | "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" }, |
5590 | { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })", |
5591 | "([] : { A[x] : x <= 10 })", |
5592 | "([] : { A[x] })" }, |
5593 | { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })", |
5594 | "[N] -> ([] : { A[x] : x >= N })", |
5595 | "[N] -> ([] : { A[x] : x >= 0 or x >= N })" }, |
5596 | { &isl_multi_union_pw_aff_union_add, |
5597 | "[N] -> ([] : { A[] : N >= 0})", |
5598 | "[N] -> ([] : { A[] : N <= 0})", |
5599 | "[N] -> ([] : { A[] })" }, |
5600 | { &isl_multi_union_pw_aff_union_add, |
5601 | "[N] -> ([] : { A[] })", |
5602 | "[N] -> ([] : { : })", |
5603 | "[N] -> ([] : { : })" }, |
5604 | { &isl_multi_union_pw_aff_union_add, |
5605 | "[N] -> ([] : { : })", |
5606 | "[N] -> ([] : { A[] })", |
5607 | "[N] -> ([] : { : })" }, |
5608 | { &isl_multi_union_pw_aff_union_add, |
5609 | "[N] -> ([] : { : N >= 0})", |
5610 | "[N] -> ([] : { : N <= 0})", |
5611 | "[N] -> ([] : { : })" }, |
5612 | { &isl_multi_union_pw_aff_range_product, |
5613 | "B[{ A[] -> [1] }]", |
5614 | "C[{ A[] -> [2] }]", |
5615 | "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" }, |
5616 | { &isl_multi_union_pw_aff_range_product, |
5617 | "(B[] : { A[x] : x >= 5 })", |
5618 | "(C[] : { A[x] : x <= 10 })", |
5619 | "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" }, |
5620 | { &isl_multi_union_pw_aff_range_product, |
5621 | "B[{ A[x] -> [x + 1] : x >= 5 }]", |
5622 | "(C[] : { A[x] : x <= 10 })", |
5623 | "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" }, |
5624 | { &isl_multi_union_pw_aff_range_product, |
5625 | "(C[] : { A[x] : x <= 10 })", |
5626 | "B[{ A[x] -> [x + 1] : x >= 5 }]", |
5627 | "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" }, |
5628 | { &isl_multi_union_pw_aff_range_product, |
5629 | "B[{ A[x] -> [x + 1] : x >= 5 }]", |
5630 | "[N] -> (C[] : { A[x] : x <= N })", |
5631 | "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" }, |
5632 | { &isl_multi_union_pw_aff_range_product, |
5633 | "[N] -> (C[] : { A[x] : x <= N })", |
5634 | "B[{ A[x] -> [x + 1] : x >= 5 }]", |
5635 | "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" }, |
5636 | { &isl_multi_union_pw_aff_range_product, |
5637 | "B[{ A[] -> [1]; D[] -> [3] }]", |
5638 | "C[{ A[] -> [2] }]", |
5639 | "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" }, |
5640 | { &isl_multi_union_pw_aff_range_product, |
5641 | "B[] }]", |
5642 | "(C[] : { A[x] })", |
5643 | "([B[] -> C[]] : { A[x] })" }, |
5644 | { &isl_multi_union_pw_aff_range_product, |
5645 | "(B[] : { A[x] })", |
5646 | "C[] }]", |
5647 | "([B[] -> C[]] : { A[x] })" }, |
5648 | }; |
5649 | |
5650 | /* Perform some basic tests of binary operations on |
5651 | * isl_multi_union_pw_aff objects. |
5652 | */ |
5653 | static int test_bin_mupa(isl_ctx *ctx) |
5654 | { |
5655 | int i; |
5656 | isl_bool ok; |
5657 | isl_multi_union_pw_aff *mupa1, *mupa2, *res; |
5658 | |
5659 | for (i = 0; i < ARRAY_SIZE(mupa_bin_tests)(sizeof(mupa_bin_tests)/sizeof(*mupa_bin_tests)); ++i) { |
5660 | mupa1 = isl_multi_union_pw_aff_read_from_str(ctx, |
5661 | mupa_bin_tests[i].arg1); |
5662 | mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, |
5663 | mupa_bin_tests[i].arg2); |
5664 | res = isl_multi_union_pw_aff_read_from_str(ctx, |
5665 | mupa_bin_tests[i].res); |
5666 | mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2); |
5667 | ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res); |
5668 | isl_multi_union_pw_aff_free(mupa1); |
5669 | isl_multi_union_pw_aff_free(res); |
5670 | if (ok < 0) |
5671 | return -1; |
5672 | if (!ok) |
5673 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5674); return -1; } while (0) |
5674 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5674); return -1; } while (0); |
5675 | } |
5676 | |
5677 | return 0; |
5678 | } |
5679 | |
5680 | /* Inputs for basic tests of binary operations on |
5681 | * pairs of isl_multi_union_pw_aff and isl_set objects. |
5682 | * "fn" is the function that is tested. |
5683 | * "arg1" and "arg2" are string descriptions of the inputs. |
5684 | * "res" is a string description of the expected result. |
5685 | */ |
5686 | struct { |
5687 | __isl_give isl_multi_union_pw_aff *(*fn)( |
5688 | __isl_take isl_multi_union_pw_aff *mupa, |
5689 | __isl_take isl_setisl_map *set); |
5690 | const char *arg1; |
5691 | const char *arg2; |
5692 | const char *res; |
5693 | } mupa_set_tests[] = { |
5694 | { &isl_multi_union_pw_aff_intersect_range, |
5695 | "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }", |
5696 | "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" }, |
5697 | { &isl_multi_union_pw_aff_intersect_range, |
5698 | "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }", |
5699 | "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" }, |
5700 | { &isl_multi_union_pw_aff_intersect_range, |
5701 | "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }", |
5702 | "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" }, |
5703 | { &isl_multi_union_pw_aff_intersect_range, |
5704 | "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }", |
5705 | "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" }, |
5706 | { &isl_multi_union_pw_aff_intersect_range, |
5707 | "C[]", "{ C[] }", "C[]" }, |
5708 | { &isl_multi_union_pw_aff_intersect_range, |
5709 | "[N] -> (C[] : { : N >= 0 })", |
5710 | "{ C[] }", |
5711 | "[N] -> (C[] : { : N >= 0 })" }, |
5712 | { &isl_multi_union_pw_aff_intersect_range, |
5713 | "(C[] : { A[a,b] })", |
5714 | "{ C[] }", |
5715 | "(C[] : { A[a,b] })" }, |
5716 | { &isl_multi_union_pw_aff_intersect_range, |
5717 | "[N] -> (C[] : { A[a,b] : a,b <= N })", |
5718 | "{ C[] }", |
5719 | "[N] -> (C[] : { A[a,b] : a,b <= N })" }, |
5720 | { &isl_multi_union_pw_aff_intersect_range, |
5721 | "C[]", |
5722 | "[N] -> { C[] : N >= 0 }", |
5723 | "[N] -> (C[] : { : N >= 0 })" }, |
5724 | { &isl_multi_union_pw_aff_intersect_range, |
5725 | "(C[] : { A[a,b] })", |
5726 | "[N] -> { C[] : N >= 0 }", |
5727 | "[N] -> (C[] : { A[a,b] : N >= 0 })" }, |
5728 | { &isl_multi_union_pw_aff_intersect_range, |
5729 | "[N] -> (C[] : { : N >= 0 })", |
5730 | "[N] -> { C[] : N < 1024 }", |
5731 | "[N] -> (C[] : { : 0 <= N < 1024 })" }, |
5732 | { &isl_multi_union_pw_aff_intersect_params, |
5733 | "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }", |
5734 | "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" }, |
5735 | { &isl_multi_union_pw_aff_intersect_params, |
5736 | "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }", |
5737 | "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" }, |
5738 | { &isl_multi_union_pw_aff_intersect_params, |
5739 | "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }", |
5740 | "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" }, |
5741 | { &isl_multi_union_pw_aff_intersect_params, |
5742 | "C[]", "[N] -> { : N >= 0 }", |
5743 | "[N] -> (C[] : { : N >= 0 })" }, |
5744 | { &isl_multi_union_pw_aff_intersect_params, |
5745 | "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }", |
5746 | "[N] -> (C[] : { A[a,b] : N >= 0 })" }, |
5747 | { &isl_multi_union_pw_aff_intersect_params, |
5748 | "[N] -> (C[] : { A[a,N] })", "{ : }", |
5749 | "[N] -> (C[] : { A[a,N] })" }, |
5750 | { &isl_multi_union_pw_aff_intersect_params, |
5751 | "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }", |
5752 | "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" }, |
5753 | }; |
5754 | |
5755 | /* Perform some basic tests of binary operations on |
5756 | * pairs of isl_multi_union_pw_aff and isl_set objects. |
5757 | */ |
5758 | static int test_mupa_set(isl_ctx *ctx) |
5759 | { |
5760 | int i; |
5761 | isl_bool ok; |
5762 | isl_multi_union_pw_aff *mupa, *res; |
5763 | isl_setisl_map *set; |
5764 | |
5765 | for (i = 0; i < ARRAY_SIZE(mupa_set_tests)(sizeof(mupa_set_tests)/sizeof(*mupa_set_tests)); ++i) { |
5766 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
5767 | mupa_set_tests[i].arg1); |
5768 | set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2); |
5769 | res = isl_multi_union_pw_aff_read_from_str(ctx, |
5770 | mupa_set_tests[i].res); |
5771 | mupa = mupa_set_tests[i].fn(mupa, set); |
5772 | ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); |
5773 | isl_multi_union_pw_aff_free(mupa); |
5774 | isl_multi_union_pw_aff_free(res); |
5775 | if (ok < 0) |
5776 | return -1; |
5777 | if (!ok) |
5778 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5779); return -1; } while (0) |
5779 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5779); return -1; } while (0); |
5780 | } |
5781 | |
5782 | return 0; |
5783 | } |
5784 | |
5785 | /* Inputs for basic tests of binary operations on |
5786 | * pairs of isl_multi_union_pw_aff and isl_union_set objects. |
5787 | * "fn" is the function that is tested. |
5788 | * "arg1" and "arg2" are string descriptions of the inputs. |
5789 | * "res" is a string description of the expected result. |
5790 | */ |
5791 | struct { |
5792 | __isl_give isl_multi_union_pw_aff *(*fn)( |
5793 | __isl_take isl_multi_union_pw_aff *mupa, |
5794 | __isl_take isl_union_set *uset); |
5795 | const char *arg1; |
5796 | const char *arg2; |
5797 | const char *res; |
5798 | } mupa_uset_tests[] = { |
5799 | { &isl_multi_union_pw_aff_intersect_domain, |
5800 | "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }", |
5801 | "C[{ B[i,i] -> [3i] }]" }, |
5802 | { &isl_multi_union_pw_aff_intersect_domain, |
5803 | "(C[] : { B[i,j] })", "{ B[i,i] }", |
5804 | "(C[] : { B[i,i] })" }, |
5805 | { &isl_multi_union_pw_aff_intersect_domain, |
5806 | "(C[] : { B[i,j] })", "[N] -> { B[N,N] }", |
5807 | "[N] -> (C[] : { B[N,N] })" }, |
5808 | { &isl_multi_union_pw_aff_intersect_domain, |
5809 | "C[]", "{ B[i,i] }", |
5810 | "(C[] : { B[i,i] })" }, |
5811 | { &isl_multi_union_pw_aff_intersect_domain, |
5812 | "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }", |
5813 | "[N] -> (C[] : { B[i,i] : N >= 0 })" }, |
5814 | }; |
5815 | |
5816 | /* Perform some basic tests of binary operations on |
5817 | * pairs of isl_multi_union_pw_aff and isl_union_set objects. |
5818 | */ |
5819 | static int test_mupa_uset(isl_ctx *ctx) |
5820 | { |
5821 | int i; |
5822 | isl_bool ok; |
5823 | isl_multi_union_pw_aff *mupa, *res; |
5824 | isl_union_set *uset; |
5825 | |
5826 | for (i = 0; i < ARRAY_SIZE(mupa_uset_tests)(sizeof(mupa_uset_tests)/sizeof(*mupa_uset_tests)); ++i) { |
5827 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
5828 | mupa_uset_tests[i].arg1); |
5829 | uset = isl_union_set_read_from_str(ctx, |
5830 | mupa_uset_tests[i].arg2); |
5831 | res = isl_multi_union_pw_aff_read_from_str(ctx, |
5832 | mupa_uset_tests[i].res); |
5833 | mupa = mupa_uset_tests[i].fn(mupa, uset); |
5834 | ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); |
5835 | isl_multi_union_pw_aff_free(mupa); |
5836 | isl_multi_union_pw_aff_free(res); |
5837 | if (ok < 0) |
5838 | return -1; |
5839 | if (!ok) |
5840 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5841); return -1; } while (0) |
5841 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5841); return -1; } while (0); |
5842 | } |
5843 | |
5844 | return 0; |
5845 | } |
5846 | |
5847 | /* Inputs for basic tests of binary operations on |
5848 | * pairs of isl_multi_union_pw_aff and isl_multi_aff objects. |
5849 | * "fn" is the function that is tested. |
5850 | * "arg1" and "arg2" are string descriptions of the inputs. |
5851 | * "res" is a string description of the expected result. |
5852 | */ |
5853 | struct { |
5854 | __isl_give isl_multi_union_pw_aff *(*fn)( |
5855 | __isl_take isl_multi_union_pw_aff *mupa, |
5856 | __isl_take isl_multi_aff *ma); |
5857 | const char *arg1; |
5858 | const char *arg2; |
5859 | const char *res; |
5860 | } mupa_ma_tests[] = { |
5861 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5862 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, " |
5863 | "{ A[i,j] -> [j]; B[i,j] -> [i] }]", |
5864 | "{ C[a,b] -> D[b,a] }", |
5865 | "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, " |
5866 | "{ A[i,j] -> [i]; B[i,j] -> [j] }]" }, |
5867 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5868 | "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, " |
5869 | "{ A[i,j] -> [j]; B[i,j] -> [i] }]", |
5870 | "{ C[a,b] -> D[b,a] }", |
5871 | "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, " |
5872 | "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" }, |
5873 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5874 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", |
5875 | "[N] -> { C[a] -> D[a + N] }", |
5876 | "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " }, |
5877 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5878 | "C[]", |
5879 | "{ C[] -> D[] }", |
5880 | "D[]" }, |
5881 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5882 | "[N] -> (C[] : { : N >= 0 })", |
5883 | "{ C[] -> D[] }", |
5884 | "[N] -> (D[] : { : N >= 0 })" }, |
5885 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5886 | "C[]", |
5887 | "[N] -> { C[] -> D[N] }", |
5888 | "[N] -> D[{ [N] }]" }, |
5889 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5890 | "(C[] : { A[i,j] : i >= j })", |
5891 | "{ C[] -> D[] }", |
5892 | "(D[] : { A[i,j] : i >= j })" }, |
5893 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5894 | "[N] -> (C[] : { A[i,j] : N >= 0 })", |
5895 | "{ C[] -> D[] }", |
5896 | "[N] -> (D[] : { A[i,j] : N >= 0 })" }, |
5897 | { &isl_multi_union_pw_aff_apply_multi_aff, |
5898 | "(C[] : { A[i,j] : i >= j })", |
5899 | "[N] -> { C[] -> D[N] }", |
5900 | "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" }, |
5901 | }; |
5902 | |
5903 | /* Perform some basic tests of binary operations on |
5904 | * pairs of isl_multi_union_pw_aff and isl_multi_aff objects. |
5905 | */ |
5906 | static int test_mupa_ma(isl_ctx *ctx) |
5907 | { |
5908 | int i; |
5909 | isl_bool ok; |
5910 | isl_multi_union_pw_aff *mupa, *res; |
5911 | isl_multi_aff *ma; |
5912 | |
5913 | for (i = 0; i < ARRAY_SIZE(mupa_ma_tests)(sizeof(mupa_ma_tests)/sizeof(*mupa_ma_tests)); ++i) { |
5914 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
5915 | mupa_ma_tests[i].arg1); |
5916 | ma = isl_multi_aff_read_from_str(ctx, mupa_ma_tests[i].arg2); |
5917 | res = isl_multi_union_pw_aff_read_from_str(ctx, |
5918 | mupa_ma_tests[i].res); |
5919 | mupa = mupa_ma_tests[i].fn(mupa, ma); |
5920 | ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); |
5921 | isl_multi_union_pw_aff_free(mupa); |
5922 | isl_multi_union_pw_aff_free(res); |
5923 | if (ok < 0) |
5924 | return -1; |
5925 | if (!ok) |
5926 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5927); return -1; } while (0) |
5927 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 5927); return -1; } while (0); |
5928 | } |
5929 | |
5930 | return 0; |
5931 | } |
5932 | |
5933 | /* Inputs for basic tests of binary operations on |
5934 | * pairs of isl_multi_union_pw_aff and isl_pw_aff objects. |
5935 | * "fn" is the function that is tested. |
5936 | * "arg1" and "arg2" are string descriptions of the inputs. |
5937 | * "res" is a string description of the expected result. |
5938 | */ |
5939 | struct { |
5940 | __isl_give isl_union_pw_aff *(*fn)( |
5941 | __isl_take isl_multi_union_pw_aff *mupa, |
5942 | __isl_take isl_pw_aff *pa); |
5943 | const char *arg1; |
5944 | const char *arg2; |
5945 | const char *res; |
5946 | } mupa_pa_tests[] = { |
5947 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5948 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", |
5949 | "[N] -> { C[a] -> [a + N] }", |
5950 | "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" }, |
5951 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5952 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", |
5953 | "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }", |
5954 | "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; " |
5955 | "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" }, |
5956 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5957 | "C[]", |
5958 | "[N] -> { C[] -> [N] }", |
5959 | "[N] -> { [N] }" }, |
5960 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5961 | "C[]", |
5962 | "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }", |
5963 | "[N] -> { [N] : N >= 0; [-N] : N < 0 }" }, |
5964 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5965 | "[N] -> (C[] : { : N >= 0 })", |
5966 | "[N] -> { C[] -> [N] }", |
5967 | "[N] -> { [N] : N >= 0 }" }, |
5968 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5969 | "[N] -> (C[] : { : N >= 0 })", |
5970 | "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }", |
5971 | "[N] -> { [N] : N >= 0 }" }, |
5972 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5973 | "[N] -> (C[] : { : N >= 0 })", |
5974 | "{ C[] -> [0] }", |
5975 | "[N] -> { [0] : N >= 0 }" }, |
5976 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5977 | "(C[] : { A[i,j] : i >= j })", |
5978 | "[N] -> { C[] -> [N] }", |
5979 | "[N] -> { A[i,j] -> [N] : i >= j }" }, |
5980 | { &isl_multi_union_pw_aff_apply_pw_aff, |
5981 | "(C[] : { A[i,j] : i >= j })", |
5982 | "[N] -> { C[] -> [N] : N >= 0 }", |
5983 | "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" }, |
5984 | }; |
5985 | |
5986 | /* Perform some basic tests of binary operations on |
5987 | * pairs of isl_multi_union_pw_aff and isl_pw_aff objects. |
5988 | */ |
5989 | static int test_mupa_pa(isl_ctx *ctx) |
5990 | { |
5991 | int i; |
5992 | isl_bool ok; |
5993 | isl_multi_union_pw_aff *mupa; |
5994 | isl_union_pw_aff *upa, *res; |
5995 | isl_pw_aff *pa; |
5996 | |
5997 | for (i = 0; i < ARRAY_SIZE(mupa_pa_tests)(sizeof(mupa_pa_tests)/sizeof(*mupa_pa_tests)); ++i) { |
5998 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
5999 | mupa_pa_tests[i].arg1); |
6000 | pa = isl_pw_aff_read_from_str(ctx, mupa_pa_tests[i].arg2); |
6001 | res = isl_union_pw_aff_read_from_str(ctx, |
6002 | mupa_pa_tests[i].res); |
6003 | upa = mupa_pa_tests[i].fn(mupa, pa); |
6004 | ok = isl_union_pw_aff_plain_is_equal(upa, res); |
6005 | isl_union_pw_aff_free(upa); |
6006 | isl_union_pw_aff_free(res); |
6007 | if (ok < 0) |
6008 | return -1; |
6009 | if (!ok) |
6010 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6011); return -1; } while (0) |
6011 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6011); return -1; } while (0); |
6012 | } |
6013 | |
6014 | return 0; |
6015 | } |
6016 | |
6017 | /* Inputs for basic tests of binary operations on |
6018 | * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects. |
6019 | * "fn" is the function that is tested. |
6020 | * "arg1" and "arg2" are string descriptions of the inputs. |
6021 | * "res" is a string description of the expected result. |
6022 | */ |
6023 | struct { |
6024 | __isl_give isl_multi_union_pw_aff *(*fn)( |
6025 | __isl_take isl_multi_union_pw_aff *mupa, |
6026 | __isl_take isl_pw_multi_aff *pma); |
6027 | const char *arg1; |
6028 | const char *arg2; |
6029 | const char *res; |
6030 | } mupa_pma_tests[] = { |
6031 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6032 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, " |
6033 | "{ A[i,j] -> [j]; B[i,j] -> [i] }]", |
6034 | "{ C[a,b] -> D[b,a] }", |
6035 | "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, " |
6036 | "{ A[i,j] -> [i]; B[i,j] -> [j] }]" }, |
6037 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6038 | "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, " |
6039 | "{ A[i,j] -> [j]; B[i,j] -> [i] }]", |
6040 | "{ C[a,b] -> D[b,a] }", |
6041 | "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, " |
6042 | "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" }, |
6043 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6044 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", |
6045 | "[N] -> { C[a] -> D[a + N] }", |
6046 | "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" }, |
6047 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6048 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", |
6049 | "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }", |
6050 | "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; " |
6051 | "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" }, |
6052 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6053 | "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, " |
6054 | "{ A[i,j] -> [j]; B[i,j] -> [i] }]", |
6055 | "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }", |
6056 | "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; " |
6057 | "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, " |
6058 | "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; " |
6059 | "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" }, |
6060 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6061 | "C[]", |
6062 | "{ C[] -> D[] }", |
6063 | "D[]" }, |
6064 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6065 | "[N] -> (C[] : { : N >= 0 })", |
6066 | "{ C[] -> D[] }", |
6067 | "[N] -> (D[] : { : N >= 0 })" }, |
6068 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6069 | "C[]", |
6070 | "[N] -> { C[] -> D[N] }", |
6071 | "[N] -> D[{ [N] }]" }, |
6072 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6073 | "(C[] : { A[i,j] : i >= j })", |
6074 | "{ C[] -> D[] }", |
6075 | "(D[] : { A[i,j] : i >= j })" }, |
6076 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6077 | "[N] -> (C[] : { A[i,j] : N >= 0 })", |
6078 | "{ C[] -> D[] }", |
6079 | "[N] -> (D[] : { A[i,j] : N >= 0 })" }, |
6080 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6081 | "(C[] : { A[i,j] : i >= j })", |
6082 | "[N] -> { C[] -> D[N] }", |
6083 | "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" }, |
6084 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6085 | "C[]", |
6086 | "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }", |
6087 | "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" }, |
6088 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6089 | "[N] -> (C[] : { : N >= 0 })", |
6090 | "[N] -> { C[] -> D[N] }", |
6091 | "[N] -> D[{ [N] : N >= 0 }]" }, |
6092 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6093 | "[N] -> (C[] : { : N >= 0 })", |
6094 | "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }", |
6095 | "[N] -> D[{ [N] : N >= 0 }]" }, |
6096 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6097 | "[N] -> (C[] : { : N >= 0 })", |
6098 | "{ C[] -> D[0] }", |
6099 | "[N] -> D[{ [0] : N >= 0 }]" }, |
6100 | { &isl_multi_union_pw_aff_apply_pw_multi_aff, |
6101 | "(C[] : { A[i,j] : i >= j })", |
6102 | "[N] -> { C[] -> D[N] : N >= 0 }", |
6103 | "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" }, |
6104 | }; |
6105 | |
6106 | /* Perform some basic tests of binary operations on |
6107 | * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects. |
6108 | */ |
6109 | static int test_mupa_pma(isl_ctx *ctx) |
6110 | { |
6111 | int i; |
6112 | isl_bool ok; |
6113 | isl_multi_union_pw_aff *mupa, *res; |
6114 | isl_pw_multi_aff *pma; |
6115 | |
6116 | for (i = 0; i < ARRAY_SIZE(mupa_pma_tests)(sizeof(mupa_pma_tests)/sizeof(*mupa_pma_tests)); ++i) { |
6117 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
6118 | mupa_pma_tests[i].arg1); |
6119 | pma = isl_pw_multi_aff_read_from_str(ctx, |
6120 | mupa_pma_tests[i].arg2); |
6121 | res = isl_multi_union_pw_aff_read_from_str(ctx, |
6122 | mupa_pma_tests[i].res); |
6123 | mupa = mupa_pma_tests[i].fn(mupa, pma); |
6124 | ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); |
6125 | isl_multi_union_pw_aff_free(mupa); |
6126 | isl_multi_union_pw_aff_free(res); |
6127 | if (ok < 0) |
6128 | return -1; |
6129 | if (!ok) |
6130 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6131); return -1; } while (0) |
6131 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6131); return -1; } while (0); |
6132 | } |
6133 | |
6134 | return 0; |
6135 | } |
6136 | |
6137 | /* Inputs for basic tests of binary operations on |
6138 | * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects. |
6139 | * "fn" is the function that is tested. |
6140 | * "arg1" and "arg2" are string descriptions of the inputs. |
6141 | * "res" is a string description of the expected result. |
6142 | */ |
6143 | struct { |
6144 | __isl_give isl_multi_union_pw_aff *(*fn)( |
6145 | __isl_take isl_multi_union_pw_aff *mupa, |
6146 | __isl_take isl_union_pw_multi_aff *upma); |
6147 | const char *arg1; |
6148 | const char *arg2; |
6149 | const char *res; |
6150 | } mupa_upma_tests[] = { |
6151 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6152 | "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }", |
6153 | "C[{ A[a,b] -> [b + 2a] }]" }, |
6154 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6155 | "C[{ B[i,j] -> [i + 2j] }]", |
6156 | "{ A[a,b] -> B[b,a] : b > a }", |
6157 | "C[{ A[a,b] -> [b + 2a] : b > a }]" }, |
6158 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6159 | "C[{ B[i,j] -> [i + 2j] : j > 4 }]", |
6160 | "{ A[a,b] -> B[b,a] : b > a }", |
6161 | "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" }, |
6162 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6163 | "C[{ B[i,j] -> [i + 2j] }]", |
6164 | "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }", |
6165 | "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" }, |
6166 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6167 | "(C[] : { B[a,b] })", |
6168 | "{ A[a,b] -> B[b,a] }", |
6169 | "(C[] : { A[a,b] })" }, |
6170 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6171 | "(C[] : { B[a,b] })", |
6172 | "{ B[a,b] -> A[b,a] }", |
6173 | "(C[] : { })" }, |
6174 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6175 | "(C[] : { B[a,b] })", |
6176 | "{ A[a,b] -> B[b,a] : a > b }", |
6177 | "(C[] : { A[a,b] : a > b })" }, |
6178 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6179 | "(C[] : { B[a,b] : a > b })", |
6180 | "{ A[a,b] -> B[b,a] }", |
6181 | "(C[] : { A[a,b] : b > a })" }, |
6182 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6183 | "[N] -> (C[] : { B[a,b] : a > N })", |
6184 | "{ A[a,b] -> B[b,a] : a > b }", |
6185 | "[N] -> (C[] : { A[a,b] : a > b > N })" }, |
6186 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6187 | "(C[] : { B[a,b] : a > b })", |
6188 | "[N] -> { A[a,b] -> B[b,a] : a > N }", |
6189 | "[N] -> (C[] : { A[a,b] : b > a > N })" }, |
6190 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6191 | "C[]", |
6192 | "{ A[a,b] -> B[b,a] }", |
6193 | "C[]" }, |
6194 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6195 | "[N] -> (C[] : { : N >= 0 })", |
6196 | "{ A[a,b] -> B[b,a] }", |
6197 | "[N] -> (C[] : { : N >= 0 })" }, |
6198 | { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, |
6199 | "C[]", |
6200 | "[N] -> { A[a,b] -> B[b,a] : N >= 0 }", |
6201 | "[N] -> (C[] : { : N >= 0 })" }, |
6202 | }; |
6203 | |
6204 | /* Perform some basic tests of binary operations on |
6205 | * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects. |
6206 | */ |
6207 | static int test_mupa_upma(isl_ctx *ctx) |
6208 | { |
6209 | int i; |
6210 | isl_bool ok; |
6211 | isl_multi_union_pw_aff *mupa, *res; |
6212 | isl_union_pw_multi_aff *upma; |
6213 | |
6214 | for (i = 0; i < ARRAY_SIZE(mupa_upma_tests)(sizeof(mupa_upma_tests)/sizeof(*mupa_upma_tests)); ++i) { |
6215 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
6216 | mupa_upma_tests[i].arg1); |
6217 | upma = isl_union_pw_multi_aff_read_from_str(ctx, |
6218 | mupa_upma_tests[i].arg2); |
6219 | res = isl_multi_union_pw_aff_read_from_str(ctx, |
6220 | mupa_upma_tests[i].res); |
6221 | mupa = mupa_upma_tests[i].fn(mupa, upma); |
6222 | ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); |
6223 | isl_multi_union_pw_aff_free(mupa); |
6224 | isl_multi_union_pw_aff_free(res); |
6225 | if (ok < 0) |
6226 | return -1; |
6227 | if (!ok) |
6228 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6229); return -1; } while (0) |
6229 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6229); return -1; } while (0); |
6230 | } |
6231 | |
6232 | return 0; |
6233 | } |
6234 | |
6235 | /* Check that the input tuple of an isl_aff can be set properly. |
6236 | */ |
6237 | static isl_stat test_aff_set_tuple_id(isl_ctx *ctx) |
6238 | { |
6239 | isl_id *id; |
6240 | isl_aff *aff; |
6241 | int equal; |
6242 | |
6243 | aff = isl_aff_read_from_str(ctx, "{ [x] -> [x + 1] }"); |
6244 | id = isl_id_alloc(ctx, "A", NULL((void*)0)); |
6245 | aff = isl_aff_set_tuple_id(aff, isl_dim_in, id); |
6246 | equal = aff_check_plain_equal(aff, "{ A[x] -> [x + 1] }"); |
6247 | isl_aff_free(aff); |
6248 | if (equal < 0) |
6249 | return isl_stat_error; |
6250 | |
6251 | return isl_stat_ok; |
6252 | } |
6253 | |
6254 | int test_aff(isl_ctx *ctx) |
6255 | { |
6256 | const char *str; |
6257 | isl_setisl_map *set; |
6258 | isl_space *space; |
6259 | isl_local_space *ls; |
6260 | isl_aff *aff; |
6261 | int zero, equal; |
6262 | |
6263 | if (test_upa(ctx) < 0) |
6264 | return -1; |
6265 | if (test_bin_aff(ctx) < 0) |
6266 | return -1; |
6267 | if (test_bin_pw_aff(ctx) < 0) |
6268 | return -1; |
6269 | if (test_bin_upma(ctx) < 0) |
6270 | return -1; |
6271 | if (test_bin_upma_fail(ctx) < 0) |
6272 | return -1; |
6273 | if (test_un_mpa(ctx) < 0) |
6274 | return -1; |
6275 | if (test_bin_mpa(ctx) < 0) |
6276 | return -1; |
6277 | if (test_un_mupa(ctx) < 0) |
6278 | return -1; |
6279 | if (test_bin_mupa(ctx) < 0) |
6280 | return -1; |
6281 | if (test_mupa_set(ctx) < 0) |
6282 | return -1; |
6283 | if (test_mupa_uset(ctx) < 0) |
6284 | return -1; |
6285 | if (test_mupa_ma(ctx) < 0) |
6286 | return -1; |
6287 | if (test_mupa_pa(ctx) < 0) |
6288 | return -1; |
6289 | if (test_mupa_pma(ctx) < 0) |
6290 | return -1; |
6291 | if (test_mupa_upma(ctx) < 0) |
6292 | return -1; |
6293 | |
6294 | space = isl_space_set_alloc(ctx, 0, 1); |
6295 | ls = isl_local_space_from_space(space); |
6296 | aff = isl_aff_zero_on_domain(ls); |
6297 | |
6298 | aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); |
6299 | aff = isl_aff_scale_down_ui(aff, 3); |
6300 | aff = isl_aff_floor(aff); |
6301 | aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); |
6302 | aff = isl_aff_scale_down_ui(aff, 2); |
6303 | aff = isl_aff_floor(aff); |
6304 | aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); |
6305 | |
6306 | str = "{ [10] }"; |
6307 | set = isl_set_read_from_str(ctx, str); |
6308 | aff = isl_aff_gist(aff, set); |
6309 | |
6310 | aff = isl_aff_add_constant_si(aff, -16); |
6311 | zero = isl_aff_plain_is_zero(aff); |
6312 | isl_aff_free(aff); |
6313 | |
6314 | if (zero < 0) |
6315 | return -1; |
6316 | if (!zero) |
6317 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6317); return -1; } while (0); |
6318 | |
6319 | aff = isl_aff_read_from_str(ctx, "{ [-1] }"); |
6320 | aff = isl_aff_scale_down_ui(aff, 64); |
6321 | aff = isl_aff_floor(aff); |
6322 | equal = aff_check_plain_equal(aff, "{ [-1] }"); |
6323 | isl_aff_free(aff); |
6324 | if (equal < 0) |
6325 | return -1; |
6326 | |
6327 | if (test_aff_set_tuple_id(ctx) < 0) |
6328 | return -1; |
6329 | |
6330 | return 0; |
6331 | } |
6332 | |
6333 | /* Check that "pa" consists of a single expression. |
6334 | */ |
6335 | static int check_single_piece(isl_ctx *ctx, __isl_take isl_pw_aff *pa) |
6336 | { |
6337 | int n; |
6338 | |
6339 | n = isl_pw_aff_n_piece(pa); |
6340 | isl_pw_aff_free(pa); |
6341 | |
6342 | if (!pa) |
6343 | return -1; |
6344 | if (n != 1) |
6345 | isl_die(ctx, isl_error_unknown, "expecting single expression",do { isl_handle_error(ctx, isl_error_unknown, "expecting single expression" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6346); return -1; } while (0) |
6346 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single expression" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6346); return -1; } while (0); |
6347 | |
6348 | return 0; |
6349 | } |
6350 | |
6351 | /* Check that the computation below results in a single expression. |
6352 | * One or two expressions may result depending on which constraint |
6353 | * ends up being considered as redundant with respect to the other |
6354 | * constraints after the projection that is performed internally |
6355 | * by isl_set_dim_min. |
6356 | */ |
6357 | static int test_dim_max_1(isl_ctx *ctx) |
6358 | { |
6359 | const char *str; |
6360 | isl_setisl_map *set; |
6361 | isl_pw_aff *pa; |
6362 | |
6363 | str = "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and " |
6364 | "-4a <= b <= 3 and b < n - 4a }"; |
6365 | set = isl_set_read_from_str(ctx, str); |
6366 | pa = isl_set_dim_min(set, 0); |
6367 | return check_single_piece(ctx, pa); |
6368 | } |
6369 | |
6370 | /* Check that the computation below results in a single expression. |
6371 | * The PIP problem corresponding to these constraints has a row |
6372 | * that causes a split of the solution domain. The solver should |
6373 | * first pick rows that split off empty parts such that the actual |
6374 | * solution domain does not get split. |
6375 | * Note that the description contains some redundant constraints. |
6376 | * If these constraints get removed first, then the row mentioned |
6377 | * above does not appear in the PIP problem. |
6378 | */ |
6379 | static int test_dim_max_2(isl_ctx *ctx) |
6380 | { |
6381 | const char *str; |
6382 | isl_setisl_map *set; |
6383 | isl_pw_aff *pa; |
6384 | |
6385 | str = "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and " |
6386 | "N > 0 and P >= 0 }"; |
6387 | set = isl_set_read_from_str(ctx, str); |
6388 | pa = isl_set_dim_max(set, 0); |
6389 | return check_single_piece(ctx, pa); |
6390 | } |
6391 | |
6392 | int test_dim_max(isl_ctx *ctx) |
6393 | { |
6394 | int equal; |
6395 | const char *str; |
6396 | isl_setisl_map *set1, *set2; |
6397 | isl_setisl_map *set; |
6398 | isl_map *map; |
6399 | isl_pw_aff *pwaff; |
6400 | |
6401 | if (test_dim_max_1(ctx) < 0) |
6402 | return -1; |
6403 | if (test_dim_max_2(ctx) < 0) |
6404 | return -1; |
6405 | |
6406 | str = "[N] -> { [i] : 0 <= i <= min(N,10) }"; |
6407 | set = isl_set_read_from_str(ctx, str); |
6408 | pwaff = isl_set_dim_max(set, 0); |
6409 | set1 = isl_set_from_pw_aff(pwaff); |
6410 | str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }"; |
6411 | set2 = isl_set_read_from_str(ctx, str); |
6412 | equal = isl_set_is_equal(set1, set2); |
6413 | isl_set_free(set1); |
6414 | isl_set_free(set2); |
6415 | if (equal < 0) |
6416 | return -1; |
6417 | if (!equal) |
6418 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6418); return -1; } while (0); |
6419 | |
6420 | str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }"; |
6421 | set = isl_set_read_from_str(ctx, str); |
6422 | pwaff = isl_set_dim_max(set, 0); |
6423 | set1 = isl_set_from_pw_aff(pwaff); |
6424 | str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }"; |
6425 | set2 = isl_set_read_from_str(ctx, str); |
6426 | equal = isl_set_is_equal(set1, set2); |
6427 | isl_set_free(set1); |
6428 | isl_set_free(set2); |
6429 | if (equal < 0) |
6430 | return -1; |
6431 | if (!equal) |
6432 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6432); return -1; } while (0); |
6433 | |
6434 | str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }"; |
6435 | set = isl_set_read_from_str(ctx, str); |
6436 | pwaff = isl_set_dim_max(set, 0); |
6437 | set1 = isl_set_from_pw_aff(pwaff); |
6438 | str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }"; |
6439 | set2 = isl_set_read_from_str(ctx, str); |
6440 | equal = isl_set_is_equal(set1, set2); |
6441 | isl_set_free(set1); |
6442 | isl_set_free(set2); |
6443 | if (equal < 0) |
6444 | return -1; |
6445 | if (!equal) |
6446 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6446); return -1; } while (0); |
6447 | |
6448 | str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : " |
6449 | "0 <= i < N and 0 <= j < M }"; |
6450 | map = isl_map_read_from_str(ctx, str); |
6451 | set = isl_map_range(map); |
6452 | |
6453 | pwaff = isl_set_dim_max(isl_set_copy(set), 0); |
6454 | set1 = isl_set_from_pw_aff(pwaff); |
6455 | str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }"; |
6456 | set2 = isl_set_read_from_str(ctx, str); |
6457 | equal = isl_set_is_equal(set1, set2); |
6458 | isl_set_free(set1); |
6459 | isl_set_free(set2); |
6460 | |
6461 | pwaff = isl_set_dim_max(isl_set_copy(set), 3); |
6462 | set1 = isl_set_from_pw_aff(pwaff); |
6463 | str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }"; |
6464 | set2 = isl_set_read_from_str(ctx, str); |
6465 | if (equal >= 0 && equal) |
6466 | equal = isl_set_is_equal(set1, set2); |
6467 | isl_set_free(set1); |
6468 | isl_set_free(set2); |
6469 | |
6470 | isl_set_free(set); |
6471 | |
6472 | if (equal < 0) |
6473 | return -1; |
6474 | if (!equal) |
6475 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6475); return -1; } while (0); |
6476 | |
6477 | /* Check that solutions are properly merged. */ |
6478 | str = "[n] -> { [a, b, c] : c >= -4a - 2b and " |
6479 | "c <= -1 + n - 4a - 2b and c >= -2b and " |
6480 | "4a >= -4 + n and c >= 0 }"; |
6481 | set = isl_set_read_from_str(ctx, str); |
6482 | pwaff = isl_set_dim_min(set, 2); |
6483 | set1 = isl_set_from_pw_aff(pwaff); |
6484 | str = "[n] -> { [(0)] : n >= 1 }"; |
6485 | set2 = isl_set_read_from_str(ctx, str); |
6486 | equal = isl_set_is_equal(set1, set2); |
6487 | isl_set_free(set1); |
6488 | isl_set_free(set2); |
6489 | |
6490 | if (equal < 0) |
6491 | return -1; |
6492 | if (!equal) |
6493 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6493); return -1; } while (0); |
6494 | |
6495 | /* Check that empty solution lie in the right space. */ |
6496 | str = "[n] -> { [t,a] : 1 = 0 }"; |
6497 | set = isl_set_read_from_str(ctx, str); |
6498 | pwaff = isl_set_dim_max(set, 0); |
6499 | set1 = isl_set_from_pw_aff(pwaff); |
6500 | str = "[n] -> { [t] : 1 = 0 }"; |
6501 | set2 = isl_set_read_from_str(ctx, str); |
6502 | equal = isl_set_is_equal(set1, set2); |
6503 | isl_set_free(set1); |
6504 | isl_set_free(set2); |
6505 | |
6506 | if (equal < 0) |
6507 | return -1; |
6508 | if (!equal) |
6509 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6509); return -1; } while (0); |
6510 | |
6511 | return 0; |
6512 | } |
6513 | |
6514 | /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"? |
6515 | */ |
6516 | static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff *pma, |
6517 | const char *str) |
6518 | { |
6519 | isl_ctx *ctx; |
6520 | isl_pw_multi_aff *pma2; |
6521 | int equal; |
6522 | |
6523 | if (!pma) |
6524 | return -1; |
6525 | |
6526 | ctx = isl_pw_multi_aff_get_ctx(pma); |
6527 | pma2 = isl_pw_multi_aff_read_from_str(ctx, str); |
6528 | equal = isl_pw_multi_aff_plain_is_equal(pma, pma2); |
6529 | isl_pw_multi_aff_free(pma2); |
6530 | |
6531 | return equal; |
6532 | } |
6533 | |
6534 | /* Check that "pma" is obviously equal to the isl_pw_multi_aff |
6535 | * represented by "str". |
6536 | */ |
6537 | static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff *pma, |
6538 | const char *str) |
6539 | { |
6540 | int equal; |
6541 | |
6542 | equal = pw_multi_aff_plain_is_equal(pma, str); |
6543 | if (equal < 0) |
6544 | return -1; |
6545 | if (!equal) |
6546 | isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown,do { isl_handle_error(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown , "result not as expected", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6547); return -1; } while (0) |
6547 | "result not as expected", return -1)do { isl_handle_error(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown , "result not as expected", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6547); return -1; } while (0); |
6548 | return 0; |
6549 | } |
6550 | |
6551 | /* Basic test for isl_pw_multi_aff_product. |
6552 | * |
6553 | * Check that multiple pieces are properly handled. |
6554 | */ |
6555 | static int test_product_pma(isl_ctx *ctx) |
6556 | { |
6557 | int equal; |
6558 | const char *str; |
6559 | isl_pw_multi_aff *pma1, *pma2; |
6560 | |
6561 | str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }"; |
6562 | pma1 = isl_pw_multi_aff_read_from_str(ctx, str); |
6563 | str = "{ C[] -> D[] }"; |
6564 | pma2 = isl_pw_multi_aff_read_from_str(ctx, str); |
6565 | pma1 = isl_pw_multi_aff_product(pma1, pma2); |
6566 | str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;" |
6567 | "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }"; |
6568 | equal = pw_multi_aff_check_plain_equal(pma1, str); |
6569 | isl_pw_multi_aff_free(pma1); |
6570 | if (equal < 0) |
6571 | return -1; |
6572 | |
6573 | return 0; |
6574 | } |
6575 | |
6576 | int test_product(isl_ctx *ctx) |
6577 | { |
6578 | const char *str; |
6579 | isl_setisl_map *set; |
6580 | isl_union_set *uset1, *uset2; |
6581 | int ok; |
6582 | |
6583 | str = "{ A[i] }"; |
6584 | set = isl_set_read_from_str(ctx, str); |
6585 | set = isl_set_product(set, isl_set_copy(set)); |
6586 | ok = isl_set_is_wrapping(set); |
6587 | isl_set_free(set); |
6588 | if (ok < 0) |
6589 | return -1; |
6590 | if (!ok) |
6591 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6591); return -1; } while (0); |
6592 | |
6593 | str = "{ [] }"; |
6594 | uset1 = isl_union_set_read_from_str(ctx, str); |
6595 | uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1)); |
6596 | str = "{ [[] -> []] }"; |
6597 | uset2 = isl_union_set_read_from_str(ctx, str); |
6598 | ok = isl_union_set_is_equal(uset1, uset2); |
6599 | isl_union_set_free(uset1); |
6600 | isl_union_set_free(uset2); |
6601 | if (ok < 0) |
6602 | return -1; |
6603 | if (!ok) |
6604 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6604); return -1; } while (0); |
6605 | |
6606 | if (test_product_pma(ctx) < 0) |
6607 | return -1; |
6608 | |
6609 | return 0; |
6610 | } |
6611 | |
6612 | /* Check that two sets are not considered disjoint just because |
6613 | * they have a different set of (named) parameters. |
6614 | */ |
6615 | static int test_disjoint(isl_ctx *ctx) |
6616 | { |
6617 | const char *str; |
6618 | isl_setisl_map *set, *set2; |
6619 | int disjoint; |
6620 | |
6621 | str = "[n] -> { [[]->[]] }"; |
6622 | set = isl_set_read_from_str(ctx, str); |
6623 | str = "{ [[]->[]] }"; |
6624 | set2 = isl_set_read_from_str(ctx, str); |
6625 | disjoint = isl_set_is_disjoint(set, set2); |
6626 | isl_set_free(set); |
6627 | isl_set_free(set2); |
6628 | if (disjoint < 0) |
6629 | return -1; |
6630 | if (disjoint) |
6631 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6631); return -1; } while (0); |
6632 | |
6633 | return 0; |
6634 | } |
6635 | |
6636 | /* Inputs for isl_pw_multi_aff_is_equal tests. |
6637 | * "f1" and "f2" are the two function that need to be compared. |
6638 | * "equal" is the expected result. |
6639 | */ |
6640 | struct { |
6641 | int equal; |
6642 | const char *f1; |
6643 | const char *f2; |
6644 | } pma_equal_tests[] = { |
6645 | { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }", |
6646 | "[N] -> { [0] : 0 <= N <= 1 }" }, |
6647 | { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }", |
6648 | "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" }, |
6649 | { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }", |
6650 | "[N] -> { [0] : 0 <= N <= 1 }" }, |
6651 | { 0, "{ [NaN] }", "{ [NaN] }" }, |
6652 | }; |
6653 | |
6654 | int test_equal(isl_ctx *ctx) |
6655 | { |
6656 | int i; |
6657 | const char *str; |
6658 | isl_setisl_map *set, *set2; |
6659 | int equal; |
6660 | |
6661 | str = "{ S_6[i] }"; |
6662 | set = isl_set_read_from_str(ctx, str); |
6663 | str = "{ S_7[i] }"; |
6664 | set2 = isl_set_read_from_str(ctx, str); |
6665 | equal = isl_set_is_equal(set, set2); |
6666 | isl_set_free(set); |
6667 | isl_set_free(set2); |
6668 | if (equal < 0) |
6669 | return -1; |
6670 | if (equal) |
6671 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6671); return -1; } while (0); |
6672 | |
6673 | for (i = 0; i < ARRAY_SIZE(pma_equal_tests)(sizeof(pma_equal_tests)/sizeof(*pma_equal_tests)); ++i) { |
6674 | int expected = pma_equal_tests[i].equal; |
6675 | isl_pw_multi_aff *f1, *f2; |
6676 | |
6677 | f1 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f1); |
6678 | f2 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f2); |
6679 | equal = isl_pw_multi_aff_is_equal(f1, f2); |
6680 | isl_pw_multi_aff_free(f1); |
6681 | isl_pw_multi_aff_free(f2); |
6682 | if (equal < 0) |
6683 | return -1; |
6684 | if (equal != expected) |
6685 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected equality result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6686); return -1; } while (0) |
6686 | "unexpected equality result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected equality result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6686); return -1; } while (0); |
6687 | } |
6688 | |
6689 | return 0; |
6690 | } |
6691 | |
6692 | static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map, |
6693 | enum isl_dim_type type, unsigned pos, int fixed) |
6694 | { |
6695 | isl_bool test; |
6696 | |
6697 | test = isl_map_plain_is_fixed(map, type, pos, NULL((void*)0)); |
6698 | isl_map_free(map); |
6699 | if (test < 0) |
6700 | return -1; |
6701 | if (test == fixed) |
6702 | return 0; |
6703 | if (fixed) |
6704 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map not detected as fixed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6705); return -1; } while (0) |
6705 | "map not detected as fixed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map not detected as fixed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6705); return -1; } while (0); |
6706 | else |
6707 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map detected as fixed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6708); return -1; } while (0) |
6708 | "map detected as fixed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map detected as fixed" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6708); return -1; } while (0); |
6709 | } |
6710 | |
6711 | int test_fixed(isl_ctx *ctx) |
6712 | { |
6713 | const char *str; |
6714 | isl_map *map; |
6715 | |
6716 | str = "{ [i] -> [i] }"; |
6717 | map = isl_map_read_from_str(ctx, str); |
6718 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0)) |
6719 | return -1; |
6720 | str = "{ [i] -> [1] }"; |
6721 | map = isl_map_read_from_str(ctx, str); |
6722 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1)) |
6723 | return -1; |
6724 | str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }"; |
6725 | map = isl_map_read_from_str(ctx, str); |
6726 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1)) |
6727 | return -1; |
6728 | map = isl_map_read_from_str(ctx, str); |
6729 | map = isl_map_neg(map); |
6730 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1)) |
6731 | return -1; |
6732 | |
6733 | return 0; |
6734 | } |
6735 | |
6736 | struct isl_vertices_test_data { |
6737 | const char *set; |
6738 | int n; |
6739 | const char *vertex[6]; |
6740 | } vertices_tests[] = { |
6741 | { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }", |
6742 | 2, { "{ A[12, 4] }", "{ A[12, 12] }" } }, |
6743 | { "{ A[t, i] : t = 14 and i = 1 }", |
6744 | 1, { "{ A[14, 1] }" } }, |
6745 | { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and " |
6746 | "c <= m and m <= n and m > 0 }", |
6747 | 6, { |
6748 | "[n, m] -> { [n, m, m] : 0 < m <= n }", |
6749 | "[n, m] -> { [n, 1, m] : 0 < m <= n }", |
6750 | "[n, m] -> { [n, 1, 1] : 0 < m <= n }", |
6751 | "[n, m] -> { [m, m, m] : 0 < m <= n }", |
6752 | "[n, m] -> { [1, 1, m] : 0 < m <= n }", |
6753 | "[n, m] -> { [1, 1, 1] : 0 < m <= n }" |
6754 | } }, |
6755 | }; |
6756 | |
6757 | /* Check that "vertex" corresponds to one of the vertices in data->vertex. |
6758 | */ |
6759 | static isl_stat find_vertex(__isl_take isl_vertex *vertex, void *user) |
6760 | { |
6761 | struct isl_vertices_test_data *data = user; |
6762 | isl_ctx *ctx; |
6763 | isl_multi_aff *ma; |
6764 | isl_basic_setisl_basic_map *bset; |
6765 | isl_pw_multi_aff *pma; |
6766 | int i; |
6767 | isl_bool equal; |
6768 | |
6769 | ctx = isl_vertex_get_ctx(vertex); |
6770 | bset = isl_vertex_get_domain(vertex); |
6771 | ma = isl_vertex_get_expr(vertex); |
6772 | pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma); |
6773 | |
6774 | for (i = 0; i < data->n; ++i) { |
6775 | isl_pw_multi_aff *pma_i; |
6776 | |
6777 | pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]); |
6778 | equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i); |
6779 | isl_pw_multi_aff_free(pma_i); |
6780 | |
6781 | if (equal < 0 || equal) |
6782 | break; |
6783 | } |
6784 | |
6785 | isl_pw_multi_aff_free(pma); |
6786 | isl_vertex_free(vertex); |
6787 | |
6788 | if (equal < 0) |
6789 | return isl_stat_error; |
6790 | |
6791 | return equal ? isl_stat_ok : isl_stat_error; |
6792 | } |
6793 | |
6794 | int test_vertices(isl_ctx *ctx) |
6795 | { |
6796 | int i; |
6797 | |
6798 | for (i = 0; i < ARRAY_SIZE(vertices_tests)(sizeof(vertices_tests)/sizeof(*vertices_tests)); ++i) { |
6799 | isl_basic_setisl_basic_map *bset; |
6800 | isl_vertices *vertices; |
6801 | int ok = 1; |
6802 | int n; |
6803 | |
6804 | bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set); |
6805 | vertices = isl_basic_set_compute_vertices(bset); |
6806 | n = isl_vertices_get_n_vertices(vertices); |
6807 | if (vertices_tests[i].n != n) |
6808 | ok = 0; |
6809 | if (isl_vertices_foreach_vertex(vertices, &find_vertex, |
6810 | &vertices_tests[i]) < 0) |
6811 | ok = 0; |
6812 | isl_vertices_free(vertices); |
6813 | isl_basic_set_free(bset); |
6814 | |
6815 | if (!vertices) |
6816 | return -1; |
6817 | if (!ok) |
6818 | isl_die(ctx, isl_error_unknown, "unexpected vertices",do { isl_handle_error(ctx, isl_error_unknown, "unexpected vertices" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6819); return -1; } while (0) |
6819 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected vertices" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6819); return -1; } while (0); |
6820 | } |
6821 | |
6822 | return 0; |
6823 | } |
6824 | |
6825 | int test_union_pw(isl_ctx *ctx) |
6826 | { |
6827 | int equal; |
6828 | const char *str; |
6829 | isl_union_set *uset; |
6830 | isl_union_pw_qpolynomial *upwqp1, *upwqp2; |
6831 | |
6832 | str = "{ [x] -> x^2 }"; |
6833 | upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str); |
6834 | upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1); |
6835 | uset = isl_union_pw_qpolynomial_domain(upwqp1); |
6836 | upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2); |
6837 | upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset); |
6838 | equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2); |
6839 | isl_union_pw_qpolynomial_free(upwqp1); |
6840 | isl_union_pw_qpolynomial_free(upwqp2); |
6841 | if (equal < 0) |
6842 | return -1; |
6843 | if (!equal) |
6844 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6844); return -1; } while (0); |
6845 | |
6846 | return 0; |
6847 | } |
6848 | |
6849 | /* Inputs for basic tests of functions that select |
6850 | * subparts of the domain of an isl_multi_union_pw_aff. |
6851 | * "fn" is the function that is tested. |
6852 | * "arg" is a string description of the input. |
6853 | * "res" is a string description of the expected result. |
6854 | */ |
6855 | struct { |
6856 | __isl_give isl_union_set *(*fn)( |
6857 | __isl_take isl_multi_union_pw_aff *mupa); |
6858 | const char *arg; |
6859 | const char *res; |
6860 | } un_locus_tests[] = { |
6861 | { &isl_multi_union_pw_aff_zero_union_set, |
6862 | "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]", |
6863 | "{ A[0,j]; B[0,j] }" }, |
6864 | { &isl_multi_union_pw_aff_zero_union_set, |
6865 | "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]", |
6866 | "{ A[i,i]; B[i,i] : i >= 0 }" }, |
6867 | { &isl_multi_union_pw_aff_zero_union_set, |
6868 | "(F[] : { A[i,j]; B[i,i] : i >= 0 })", |
6869 | "{ A[i,j]; B[i,i] : i >= 0 }" }, |
6870 | }; |
6871 | |
6872 | /* Perform some basic tests of functions that select |
6873 | * subparts of the domain of an isl_multi_union_pw_aff. |
6874 | */ |
6875 | static int test_un_locus(isl_ctx *ctx) |
6876 | { |
6877 | int i; |
6878 | isl_bool ok; |
6879 | isl_union_set *uset, *res; |
6880 | isl_multi_union_pw_aff *mupa; |
6881 | |
6882 | for (i = 0; i < ARRAY_SIZE(un_locus_tests)(sizeof(un_locus_tests)/sizeof(*un_locus_tests)); ++i) { |
6883 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
6884 | un_locus_tests[i].arg); |
6885 | res = isl_union_set_read_from_str(ctx, un_locus_tests[i].res); |
6886 | uset = un_locus_tests[i].fn(mupa); |
6887 | ok = isl_union_set_is_equal(uset, res); |
6888 | isl_union_set_free(uset); |
6889 | isl_union_set_free(res); |
6890 | if (ok < 0) |
6891 | return -1; |
6892 | if (!ok) |
6893 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6894); return -1; } while (0) |
6894 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6894); return -1; } while (0); |
6895 | } |
6896 | |
6897 | return 0; |
6898 | } |
6899 | |
6900 | /* Inputs for basic tests of functions that select |
6901 | * subparts of an isl_union_map based on a relation |
6902 | * specified by an isl_multi_union_pw_aff. |
6903 | * "fn" is the function that is tested. |
6904 | * "arg1" and "arg2" are string descriptions of the inputs. |
6905 | * "res" is a string description of the expected result. |
6906 | */ |
6907 | struct { |
6908 | __isl_give isl_union_map *(*fn)( |
6909 | __isl_take isl_union_map *umap, |
6910 | __isl_take isl_multi_union_pw_aff *mupa); |
6911 | const char *arg1; |
6912 | const char *arg2; |
6913 | const char *res; |
6914 | } bin_locus_tests[] = { |
6915 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6916 | "{ A[i,j] -> B[i',j'] }", |
6917 | "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]", |
6918 | "{ A[i,j] -> B[i,j'] }" }, |
6919 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6920 | "{ A[i,j] -> B[i',j'] }", |
6921 | "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, " |
6922 | "{ A[i,j] -> [j]; B[i,j] -> [j] }]", |
6923 | "{ A[i,j] -> B[i,j] }" }, |
6924 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6925 | "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }", |
6926 | "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]", |
6927 | "{ A[i,j] -> B[i,j'] }" }, |
6928 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6929 | "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }", |
6930 | "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]", |
6931 | "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" }, |
6932 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6933 | "{ A[i,j] -> B[i',j'] }", |
6934 | "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]", |
6935 | "{ A[i,j] -> B[i,j'] : i > j }" }, |
6936 | { &isl_union_map_lex_lt_at_multi_union_pw_aff, |
6937 | "{ A[i,j] -> B[i',j'] }", |
6938 | "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, " |
6939 | "{ A[i,j] -> [j]; B[i,j] -> [j] }]", |
6940 | "{ A[i,j] -> B[i',j'] : i,j << i',j' }" }, |
6941 | { &isl_union_map_lex_gt_at_multi_union_pw_aff, |
6942 | "{ A[i,j] -> B[i',j'] }", |
6943 | "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, " |
6944 | "{ A[i,j] -> [j]; B[i,j] -> [j] }]", |
6945 | "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" }, |
6946 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6947 | "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }", |
6948 | "(F[] : { A[i,j]; B[i,j] })", |
6949 | "{ A[i,j] -> B[i',j'] }" }, |
6950 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6951 | "{ A[i,j] -> B[i',j'] }", |
6952 | "(F[] : { A[i,j] : i > j; B[i,j] : i < j })", |
6953 | "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" }, |
6954 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6955 | "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }", |
6956 | "(F[] : { A[i,j] : i > j; B[i,j] : i < j })", |
6957 | "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" }, |
6958 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6959 | "{ A[i,j] -> B[i',j'] }", |
6960 | "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })", |
6961 | "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" }, |
6962 | { &isl_union_map_eq_at_multi_union_pw_aff, |
6963 | "{ A[i,j] -> B[i',j'] }", |
6964 | "[N] -> (F[] : { : N >= 0 })", |
6965 | "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" }, |
6966 | }; |
6967 | |
6968 | /* Perform some basic tests of functions that select |
6969 | * subparts of an isl_union_map based on a relation |
6970 | * specified by an isl_multi_union_pw_aff. |
6971 | */ |
6972 | static int test_bin_locus(isl_ctx *ctx) |
6973 | { |
6974 | int i; |
6975 | isl_bool ok; |
6976 | isl_union_map *umap, *res; |
6977 | isl_multi_union_pw_aff *mupa; |
6978 | |
6979 | for (i = 0; i < ARRAY_SIZE(bin_locus_tests)(sizeof(bin_locus_tests)/sizeof(*bin_locus_tests)); ++i) { |
6980 | umap = isl_union_map_read_from_str(ctx, |
6981 | bin_locus_tests[i].arg1); |
6982 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, |
6983 | bin_locus_tests[i].arg2); |
6984 | res = isl_union_map_read_from_str(ctx, bin_locus_tests[i].res); |
6985 | umap = bin_locus_tests[i].fn(umap, mupa); |
6986 | ok = isl_union_map_is_equal(umap, res); |
6987 | isl_union_map_free(umap); |
6988 | isl_union_map_free(res); |
6989 | if (ok < 0) |
6990 | return -1; |
6991 | if (!ok) |
6992 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6993); return -1; } while (0) |
6993 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 6993); return -1; } while (0); |
6994 | } |
6995 | |
6996 | return 0; |
6997 | } |
6998 | |
6999 | /* Perform basic locus tests. |
7000 | */ |
7001 | static int test_locus(isl_ctx *ctx) |
7002 | { |
7003 | if (test_un_locus(ctx) < 0) |
7004 | return -1; |
7005 | if (test_bin_locus(ctx) < 0) |
7006 | return -1; |
7007 | return 0; |
7008 | } |
7009 | |
7010 | /* Test that isl_union_pw_qpolynomial_eval picks up the function |
7011 | * defined over the correct domain space. |
7012 | */ |
7013 | static int test_eval_1(isl_ctx *ctx) |
7014 | { |
7015 | const char *str; |
7016 | isl_point *pnt; |
7017 | isl_setisl_map *set; |
7018 | isl_union_pw_qpolynomial *upwqp; |
7019 | isl_val *v; |
7020 | int cmp; |
7021 | |
7022 | str = "{ A[x] -> x^2; B[x] -> -x^2 }"; |
7023 | upwqp = isl_union_pw_qpolynomial_read_from_str(ctx, str); |
7024 | str = "{ A[6] }"; |
7025 | set = isl_set_read_from_str(ctx, str); |
7026 | pnt = isl_set_sample_point(set); |
7027 | v = isl_union_pw_qpolynomial_eval(upwqp, pnt); |
7028 | cmp = isl_val_cmp_si(v, 36); |
7029 | isl_val_free(v); |
7030 | |
7031 | if (!v) |
7032 | return -1; |
7033 | if (cmp != 0) |
7034 | isl_die(ctx, isl_error_unknown, "unexpected value", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected value" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7034); return -1; } while (0); |
7035 | |
7036 | return 0; |
7037 | } |
7038 | |
7039 | /* Check that isl_qpolynomial_eval handles getting called on a void point. |
7040 | */ |
7041 | static int test_eval_2(isl_ctx *ctx) |
7042 | { |
7043 | const char *str; |
7044 | isl_point *pnt; |
7045 | isl_setisl_map *set; |
7046 | isl_qpolynomial *qp; |
7047 | isl_val *v; |
7048 | isl_bool ok; |
7049 | |
7050 | str = "{ A[x] -> [x] }"; |
7051 | qp = isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx, str)); |
7052 | str = "{ A[x] : false }"; |
7053 | set = isl_set_read_from_str(ctx, str); |
7054 | pnt = isl_set_sample_point(set); |
7055 | v = isl_qpolynomial_eval(qp, pnt); |
7056 | ok = isl_val_is_nan(v); |
7057 | isl_val_free(v); |
7058 | |
7059 | if (ok < 0) |
7060 | return -1; |
7061 | if (!ok) |
7062 | isl_die(ctx, isl_error_unknown, "expecting NaN", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting NaN" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7062); return -1; } while (0); |
7063 | |
7064 | return 0; |
7065 | } |
7066 | |
7067 | /* Inputs for isl_pw_aff_eval test. |
7068 | * "f" is the affine function. |
7069 | * "p" is the point where the function should be evaluated. |
7070 | * "res" is the expected result. |
7071 | */ |
7072 | struct { |
7073 | const char *f; |
7074 | const char *p; |
7075 | const char *res; |
7076 | } aff_eval_tests[] = { |
7077 | { "{ [i] -> [2 * i] }", "{ [4] }", "8" }, |
7078 | { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" }, |
7079 | { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" }, |
7080 | { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" }, |
7081 | { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" }, |
7082 | { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" }, |
7083 | { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" }, |
7084 | { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" }, |
7085 | { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" }, |
7086 | { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" }, |
7087 | { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" }, |
7088 | { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" }, |
7089 | { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" }, |
7090 | { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" }, |
7091 | { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" }, |
7092 | { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" }, |
7093 | { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" }, |
7094 | { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" }, |
7095 | { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" }, |
7096 | { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" }, |
7097 | { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" }, |
7098 | { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" }, |
7099 | { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" }, |
7100 | }; |
7101 | |
7102 | /* Perform basic isl_pw_aff_eval tests. |
7103 | */ |
7104 | static int test_eval_aff(isl_ctx *ctx) |
7105 | { |
7106 | int i; |
7107 | |
7108 | for (i = 0; i < ARRAY_SIZE(aff_eval_tests)(sizeof(aff_eval_tests)/sizeof(*aff_eval_tests)); ++i) { |
7109 | isl_stat r; |
7110 | isl_pw_aff *pa; |
7111 | isl_setisl_map *set; |
7112 | isl_point *pnt; |
7113 | isl_val *v; |
7114 | |
7115 | pa = isl_pw_aff_read_from_str(ctx, aff_eval_tests[i].f); |
7116 | set = isl_set_read_from_str(ctx, aff_eval_tests[i].p); |
7117 | pnt = isl_set_sample_point(set); |
7118 | v = isl_pw_aff_eval(pa, pnt); |
7119 | r = val_check_equal(v, aff_eval_tests[i].res); |
7120 | isl_val_free(v); |
7121 | if (r < 0) |
7122 | return -1; |
7123 | } |
7124 | return 0; |
7125 | } |
7126 | |
7127 | /* Perform basic evaluation tests. |
7128 | */ |
7129 | static int test_eval(isl_ctx *ctx) |
7130 | { |
7131 | if (test_eval_1(ctx) < 0) |
7132 | return -1; |
7133 | if (test_eval_2(ctx) < 0) |
7134 | return -1; |
7135 | if (test_eval_aff(ctx) < 0) |
7136 | return -1; |
7137 | return 0; |
7138 | } |
7139 | |
7140 | /* Descriptions of sets that are tested for reparsing after printing. |
7141 | */ |
7142 | const char *output_tests[] = { |
7143 | "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }", |
7144 | "{ [x] : 1 = 0 }", |
7145 | "{ [x] : false }", |
7146 | "{ [x] : x mod 2 = 0 }", |
7147 | "{ [x] : x mod 2 = 1 }", |
7148 | "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }", |
7149 | "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }", |
7150 | "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }", |
7151 | "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }", |
7152 | "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }", |
7153 | "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }", |
7154 | }; |
7155 | |
7156 | /* Check that printing a set and reparsing a set from the printed output |
7157 | * results in the same set. |
7158 | */ |
7159 | static int test_output_set(isl_ctx *ctx) |
7160 | { |
7161 | int i; |
7162 | char *str; |
7163 | isl_setisl_map *set1, *set2; |
7164 | isl_bool equal; |
7165 | |
7166 | for (i = 0; i < ARRAY_SIZE(output_tests)(sizeof(output_tests)/sizeof(*output_tests)); ++i) { |
7167 | set1 = isl_set_read_from_str(ctx, output_tests[i]); |
7168 | str = isl_set_to_str(set1); |
7169 | set2 = isl_set_read_from_str(ctx, str); |
7170 | free(str); |
7171 | equal = isl_set_is_equal(set1, set2); |
7172 | isl_set_free(set1); |
7173 | isl_set_free(set2); |
7174 | if (equal < 0) |
7175 | return -1; |
7176 | if (!equal) |
7177 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "parsed output not the same" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7178); return -1; } while (0) |
7178 | "parsed output not the same", return -1)do { isl_handle_error(ctx, isl_error_unknown, "parsed output not the same" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7178); return -1; } while (0); |
7179 | } |
7180 | |
7181 | return 0; |
7182 | } |
7183 | |
7184 | /* Check that an isl_multi_aff is printed using a consistent space. |
7185 | */ |
7186 | static isl_stat test_output_ma(isl_ctx *ctx) |
7187 | { |
7188 | char *str; |
7189 | isl_bool equal; |
7190 | isl_aff *aff; |
7191 | isl_multi_aff *ma, *ma2; |
7192 | |
7193 | ma = isl_multi_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }"); |
7194 | aff = isl_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }"); |
7195 | ma = isl_multi_aff_set_aff(ma, 0, aff); |
7196 | str = isl_multi_aff_to_str(ma); |
7197 | ma2 = isl_multi_aff_read_from_str(ctx, str); |
7198 | free(str); |
7199 | equal = isl_multi_aff_plain_is_equal(ma, ma2); |
7200 | isl_multi_aff_free(ma2); |
7201 | isl_multi_aff_free(ma); |
7202 | |
7203 | if (equal < 0) |
7204 | return isl_stat_error; |
7205 | if (!equal) |
7206 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7207); return isl_stat_error; } while (0) |
7207 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7207); return isl_stat_error; } while (0); |
7208 | |
7209 | return isl_stat_ok; |
7210 | } |
7211 | |
7212 | /* Check that an isl_multi_pw_aff is printed using a consistent space. |
7213 | */ |
7214 | static isl_stat test_output_mpa(isl_ctx *ctx) |
7215 | { |
7216 | char *str; |
7217 | isl_bool equal; |
7218 | isl_pw_aff *pa; |
7219 | isl_multi_pw_aff *mpa, *mpa2; |
7220 | |
7221 | mpa = isl_multi_pw_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }"); |
7222 | pa = isl_pw_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }"); |
7223 | mpa = isl_multi_pw_aff_set_pw_aff(mpa, 0, pa); |
7224 | str = isl_multi_pw_aff_to_str(mpa); |
7225 | mpa2 = isl_multi_pw_aff_read_from_str(ctx, str); |
7226 | free(str); |
7227 | equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2); |
7228 | isl_multi_pw_aff_free(mpa2); |
7229 | isl_multi_pw_aff_free(mpa); |
7230 | |
7231 | if (equal < 0) |
7232 | return isl_stat_error; |
7233 | if (!equal) |
7234 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7235); return isl_stat_error; } while (0) |
7235 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7235); return isl_stat_error; } while (0); |
7236 | |
7237 | return isl_stat_ok; |
7238 | } |
7239 | |
7240 | int test_output(isl_ctx *ctx) |
7241 | { |
7242 | char *s; |
7243 | const char *str; |
7244 | isl_pw_aff *pa; |
7245 | isl_printer *p; |
7246 | int equal; |
7247 | |
7248 | if (test_output_set(ctx) < 0) |
7249 | return -1; |
7250 | if (test_output_ma(ctx) < 0) |
7251 | return -1; |
7252 | if (test_output_mpa(ctx) < 0) |
7253 | return -1; |
7254 | |
7255 | str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }"; |
7256 | pa = isl_pw_aff_read_from_str(ctx, str); |
7257 | |
7258 | p = isl_printer_to_str(ctx); |
7259 | p = isl_printer_set_output_format(p, ISL_FORMAT_C4); |
7260 | p = isl_printer_print_pw_aff(p, pa); |
7261 | s = isl_printer_get_str(p); |
7262 | isl_printer_free(p); |
7263 | isl_pw_aff_free(pa); |
7264 | if (!s) |
7265 | equal = -1; |
7266 | else |
7267 | equal = !strcmp(s, "4 * floord(x, 4) + 2 >= x ? 1 : 2")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (s) && __builtin_constant_p ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ) && (__s1_len = __builtin_strlen (s), __s2_len = __builtin_strlen ("4 * floord(x, 4) + 2 >= x ? 1 : 2"), (!((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("4 * floord(x, 4) + 2 >= x ? 1 : 2" ) + 1) - (size_t)(const void *)("4 * floord(x, 4) + 2 >= x ? 1 : 2" ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (s, "4 * floord(x, 4) + 2 >= x ? 1 : 2" ) : (__builtin_constant_p (s) && ((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) && (__s1_len = __builtin_strlen (s), __s1_len < 4) ? (__builtin_constant_p ("4 * floord(x, 4) + 2 >= x ? 1 : 2") && ((size_t )(const void *)(("4 * floord(x, 4) + 2 >= x ? 1 : 2") + 1) - (size_t)(const void *)("4 * floord(x, 4) + 2 >= x ? 1 : 2" ) == 1) ? __builtin_strcmp (s, "4 * floord(x, 4) + 2 >= x ? 1 : 2" ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ); int __result = (((const unsigned char *) (const char *) (s ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (s))[ 1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (s))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (s))[3] - __s2[3] ); } } __result; }))) : (__builtin_constant_p ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ) && ((size_t)(const void *)(("4 * floord(x, 4) + 2 >= x ? 1 : 2" ) + 1) - (size_t)(const void *)("4 * floord(x, 4) + 2 >= x ? 1 : 2" ) == 1) && (__s2_len = __builtin_strlen ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ), __s2_len < 4) ? (__builtin_constant_p (s) && (( size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) ? __builtin_strcmp (s, "4 * floord(x, 4) + 2 >= x ? 1 : 2" ) : -(__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (s); int __result = (((const unsigned char *) (const char *) ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ))[1] - __s2[1]); if (__s2_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) ("4 * floord(x, 4) + 2 >= x ? 1 : 2" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp (s, "4 * floord(x, 4) + 2 >= x ? 1 : 2" )))); }); |
7268 | free(s); |
7269 | if (equal < 0) |
7270 | return -1; |
7271 | if (!equal) |
7272 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7272); return -1; } while (0); |
7273 | |
7274 | return 0; |
7275 | } |
7276 | |
7277 | int test_sample(isl_ctx *ctx) |
7278 | { |
7279 | const char *str; |
7280 | isl_basic_setisl_basic_map *bset1, *bset2; |
7281 | int empty, subset; |
7282 | |
7283 | str = "{ [a, b, c, d, e, f, g, h, i, j, k] : " |
7284 | "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and " |
7285 | "3i >= -1 + 3221225466b + c + d - 3221225466e - f and " |
7286 | "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and " |
7287 | "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and " |
7288 | "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and " |
7289 | "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and " |
7290 | "3h >= a + 2147483646b + 2c - 2147483646e - 2f and " |
7291 | "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and " |
7292 | "f >= 1 - a + 1073741822b + c + d - 1073741822e and " |
7293 | "3i >= 1 + 2b - 2c + e + 2f + 3g and " |
7294 | "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +" |
7295 | "d - 1073741821e and " |
7296 | "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and " |
7297 | "3j >= 1 - a + b + 2e and " |
7298 | "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and " |
7299 | "3i <= 4 - a + 4b - e and " |
7300 | "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and " |
7301 | "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and " |
7302 | "c <= -1 + a and 3i >= -2 - a + 3e and " |
7303 | "1073741822e <= 1073741823 - a + 1073741822b + c and " |
7304 | "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and " |
7305 | "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and " |
7306 | "1073741823e >= 1 + 1073741823b - d and " |
7307 | "3i >= 1073741823b + c - 1073741823e - f and " |
7308 | "3i >= 1 + 2b + e + 3g }"; |
7309 | bset1 = isl_basic_set_read_from_str(ctx, str); |
7310 | bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1)); |
7311 | empty = isl_basic_set_is_empty(bset2); |
7312 | subset = isl_basic_set_is_subset(bset2, bset1); |
7313 | isl_basic_set_free(bset1); |
7314 | isl_basic_set_free(bset2); |
7315 | if (empty < 0 || subset < 0) |
7316 | return -1; |
7317 | if (empty) |
7318 | isl_die(ctx, isl_error_unknown, "point not found", return -1)do { isl_handle_error(ctx, isl_error_unknown, "point not found" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7318); return -1; } while (0); |
7319 | if (!subset) |
7320 | isl_die(ctx, isl_error_unknown, "bad point found", return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad point found" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7320); return -1; } while (0); |
7321 | |
7322 | return 0; |
7323 | } |
7324 | |
7325 | int test_fixed_power(isl_ctx *ctx) |
7326 | { |
7327 | const char *str; |
7328 | isl_map *map; |
7329 | isl_val *exp; |
7330 | int equal; |
7331 | |
7332 | str = "{ [i] -> [i + 1] }"; |
7333 | map = isl_map_read_from_str(ctx, str); |
7334 | exp = isl_val_int_from_si(ctx, 23); |
7335 | map = isl_map_fixed_power_val(map, exp); |
7336 | equal = map_check_equal(map, "{ [i] -> [i + 23] }"); |
7337 | isl_map_free(map); |
7338 | if (equal < 0) |
7339 | return -1; |
7340 | |
7341 | return 0; |
7342 | } |
7343 | |
7344 | int test_slice(isl_ctx *ctx) |
7345 | { |
7346 | const char *str; |
7347 | isl_map *map; |
7348 | int equal; |
7349 | |
7350 | str = "{ [i] -> [j] }"; |
7351 | map = isl_map_read_from_str(ctx, str); |
7352 | map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0); |
7353 | equal = map_check_equal(map, "{ [i] -> [i] }"); |
7354 | isl_map_free(map); |
7355 | if (equal < 0) |
7356 | return -1; |
7357 | |
7358 | str = "{ [i] -> [j] }"; |
7359 | map = isl_map_read_from_str(ctx, str); |
7360 | map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0); |
7361 | equal = map_check_equal(map, "{ [i] -> [j] }"); |
7362 | isl_map_free(map); |
7363 | if (equal < 0) |
7364 | return -1; |
7365 | |
7366 | str = "{ [i] -> [j] }"; |
7367 | map = isl_map_read_from_str(ctx, str); |
7368 | map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0); |
7369 | equal = map_check_equal(map, "{ [i] -> [-i] }"); |
7370 | isl_map_free(map); |
7371 | if (equal < 0) |
7372 | return -1; |
7373 | |
7374 | str = "{ [i] -> [j] }"; |
7375 | map = isl_map_read_from_str(ctx, str); |
7376 | map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0); |
7377 | equal = map_check_equal(map, "{ [0] -> [j] }"); |
7378 | isl_map_free(map); |
7379 | if (equal < 0) |
7380 | return -1; |
7381 | |
7382 | str = "{ [i] -> [j] }"; |
7383 | map = isl_map_read_from_str(ctx, str); |
7384 | map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0); |
7385 | equal = map_check_equal(map, "{ [i] -> [j] : i > j }"); |
7386 | isl_map_free(map); |
7387 | if (equal < 0) |
7388 | return -1; |
7389 | |
7390 | str = "{ [i] -> [j] }"; |
7391 | map = isl_map_read_from_str(ctx, str); |
7392 | map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0); |
7393 | equal = map_check_equal(map, "{ [i] -> [j] : false }"); |
7394 | isl_map_free(map); |
7395 | if (equal < 0) |
7396 | return -1; |
7397 | |
7398 | return 0; |
7399 | } |
7400 | |
7401 | int test_eliminate(isl_ctx *ctx) |
7402 | { |
7403 | const char *str; |
7404 | isl_map *map; |
7405 | int equal; |
7406 | |
7407 | str = "{ [i] -> [j] : i = 2j }"; |
7408 | map = isl_map_read_from_str(ctx, str); |
7409 | map = isl_map_eliminate(map, isl_dim_out, 0, 1); |
7410 | equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }"); |
7411 | isl_map_free(map); |
7412 | if (equal < 0) |
7413 | return -1; |
7414 | |
7415 | return 0; |
7416 | } |
7417 | |
7418 | /* Check that isl_set_dim_residue_class detects that the values of j |
7419 | * in the set below are all odd and that it does not detect any spurious |
7420 | * strides. |
7421 | */ |
7422 | static int test_residue_class(isl_ctx *ctx) |
7423 | { |
7424 | const char *str; |
7425 | isl_setisl_map *set; |
7426 | isl_int m, r; |
7427 | isl_stat res; |
7428 | |
7429 | str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; " |
7430 | "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }"; |
7431 | set = isl_set_read_from_str(ctx, str); |
7432 | isl_int_init(m)isl_sioimath_init((m)); |
7433 | isl_int_init(r)isl_sioimath_init((r)); |
7434 | res = isl_set_dim_residue_class(set, 1, &m, &r); |
7435 | if (res >= 0 && |
7436 | (isl_int_cmp_si(m, 2)isl_sioimath_cmp_si(*(m), 2) != 0 || isl_int_cmp_si(r, 1)isl_sioimath_cmp_si(*(r), 1) != 0)) |
7437 | isl_die(ctx, isl_error_unknown, "incorrect residue class",do { isl_handle_error(ctx, isl_error_unknown, "incorrect residue class" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7438); res = isl_stat_error; } while (0) |
7438 | res = isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "incorrect residue class" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7438); res = isl_stat_error; } while (0); |
7439 | isl_int_clear(r)isl_sioimath_clear((r)); |
7440 | isl_int_clear(m)isl_sioimath_clear((m)); |
7441 | isl_set_free(set); |
7442 | |
7443 | return res; |
7444 | } |
7445 | |
7446 | static int test_align_parameters_1(isl_ctx *ctx) |
7447 | { |
7448 | const char *str; |
7449 | isl_space *space; |
7450 | isl_multi_aff *ma1, *ma2; |
7451 | int equal; |
7452 | |
7453 | str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }"; |
7454 | ma1 = isl_multi_aff_read_from_str(ctx, str); |
7455 | |
7456 | space = isl_space_params_alloc(ctx, 1); |
7457 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
7458 | ma1 = isl_multi_aff_align_params(ma1, space); |
7459 | |
7460 | str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }"; |
7461 | ma2 = isl_multi_aff_read_from_str(ctx, str); |
7462 | |
7463 | equal = isl_multi_aff_plain_is_equal(ma1, ma2); |
7464 | |
7465 | isl_multi_aff_free(ma1); |
7466 | isl_multi_aff_free(ma2); |
7467 | |
7468 | if (equal < 0) |
7469 | return -1; |
7470 | if (!equal) |
7471 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7472); return -1; } while (0) |
7472 | "result not as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7472); return -1; } while (0); |
7473 | |
7474 | return 0; |
7475 | } |
7476 | |
7477 | /* Check the isl_multi_*_from_*_list operation in case inputs |
7478 | * have unaligned parameters. |
7479 | * In particular, older versions of isl would simply fail |
7480 | * (without printing any error message). |
7481 | */ |
7482 | static isl_stat test_align_parameters_2(isl_ctx *ctx) |
7483 | { |
7484 | isl_space *space; |
7485 | isl_map *map; |
7486 | isl_aff *aff; |
7487 | isl_multi_aff *ma; |
7488 | |
7489 | map = isl_map_read_from_str(ctx, "{ A[] -> M[x] }"); |
7490 | space = isl_map_get_space(map); |
7491 | isl_map_free(map); |
7492 | |
7493 | aff = isl_aff_read_from_str(ctx, "[N] -> { A[] -> [N] }"); |
7494 | ma = isl_multi_aff_from_aff_list(space, isl_aff_list_from_aff(aff)); |
7495 | isl_multi_aff_free(ma); |
7496 | |
7497 | if (!ma) |
7498 | return isl_stat_error; |
7499 | return isl_stat_ok; |
7500 | } |
7501 | |
7502 | /* Perform basic parameter alignment tests. |
7503 | */ |
7504 | static int test_align_parameters(isl_ctx *ctx) |
7505 | { |
7506 | if (test_align_parameters_1(ctx) < 0) |
7507 | return -1; |
7508 | if (test_align_parameters_2(ctx) < 0) |
7509 | return -1; |
7510 | |
7511 | return 0; |
7512 | } |
7513 | |
7514 | /* Check that isl_*_drop_unused_params actually drops the unused parameters |
7515 | * by comparing the result using isl_*_plain_is_equal. |
7516 | * Note that this assumes that isl_*_plain_is_equal does not consider |
7517 | * objects that only differ by unused parameters to be equal. |
7518 | */ |
7519 | int test_drop_unused_parameters(isl_ctx *ctx) |
7520 | { |
7521 | const char *str_with, *str_without; |
7522 | isl_basic_setisl_basic_map *bset1, *bset2; |
7523 | isl_setisl_map *set1, *set2; |
7524 | isl_pw_aff *pwa1, *pwa2; |
7525 | int equal; |
7526 | |
7527 | str_with = "[n, m, o] -> { [m] }"; |
7528 | str_without = "[m] -> { [m] }"; |
7529 | |
7530 | bset1 = isl_basic_set_read_from_str(ctx, str_with); |
7531 | bset2 = isl_basic_set_read_from_str(ctx, str_without); |
7532 | bset1 = isl_basic_set_drop_unused_params(bset1); |
7533 | equal = isl_basic_set_plain_is_equal(bset1, bset2); |
7534 | isl_basic_set_free(bset1); |
7535 | isl_basic_set_free(bset2); |
7536 | |
7537 | if (equal < 0) |
7538 | return -1; |
7539 | if (!equal) |
7540 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7541); return -1; } while (0) |
7541 | "result not as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7541); return -1; } while (0); |
7542 | |
7543 | set1 = isl_set_read_from_str(ctx, str_with); |
7544 | set2 = isl_set_read_from_str(ctx, str_without); |
7545 | set1 = isl_set_drop_unused_params(set1); |
7546 | equal = isl_set_plain_is_equal(set1, set2); |
7547 | isl_set_free(set1); |
7548 | isl_set_free(set2); |
7549 | |
7550 | if (equal < 0) |
7551 | return -1; |
7552 | if (!equal) |
7553 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7554); return -1; } while (0) |
7554 | "result not as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7554); return -1; } while (0); |
7555 | |
7556 | pwa1 = isl_pw_aff_read_from_str(ctx, str_with); |
7557 | pwa2 = isl_pw_aff_read_from_str(ctx, str_without); |
7558 | pwa1 = isl_pw_aff_drop_unused_params(pwa1); |
7559 | equal = isl_pw_aff_plain_is_equal(pwa1, pwa2); |
7560 | isl_pw_aff_free(pwa1); |
7561 | isl_pw_aff_free(pwa2); |
7562 | |
7563 | if (equal < 0) |
7564 | return -1; |
7565 | if (!equal) |
7566 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7567); return -1; } while (0) |
7567 | "result not as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7567); return -1; } while (0); |
7568 | |
7569 | return 0; |
7570 | } |
7571 | |
7572 | static int test_list(isl_ctx *ctx) |
7573 | { |
7574 | isl_id *a, *b, *c, *d, *id; |
7575 | isl_id_list *list; |
7576 | int ok; |
7577 | |
7578 | a = isl_id_alloc(ctx, "a", NULL((void*)0)); |
7579 | b = isl_id_alloc(ctx, "b", NULL((void*)0)); |
7580 | c = isl_id_alloc(ctx, "c", NULL((void*)0)); |
7581 | d = isl_id_alloc(ctx, "d", NULL((void*)0)); |
7582 | |
7583 | list = isl_id_list_alloc(ctx, 4); |
7584 | list = isl_id_list_add(list, b); |
7585 | list = isl_id_list_insert(list, 0, a); |
7586 | list = isl_id_list_add(list, c); |
7587 | list = isl_id_list_add(list, d); |
7588 | list = isl_id_list_drop(list, 1, 1); |
7589 | |
7590 | if (!list) |
7591 | return -1; |
7592 | if (isl_id_list_n_id(list) != 3) { |
7593 | isl_id_list_free(list); |
7594 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of elements in list" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7595); return -1; } while (0) |
7595 | "unexpected number of elements in list", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of elements in list" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7595); return -1; } while (0); |
7596 | } |
7597 | |
7598 | id = isl_id_list_get_id(list, 0); |
7599 | ok = id == a; |
7600 | isl_id_free(id); |
7601 | id = isl_id_list_get_id(list, 1); |
7602 | ok = ok && id == c; |
7603 | isl_id_free(id); |
7604 | id = isl_id_list_get_id(list, 2); |
7605 | ok = ok && id == d; |
7606 | isl_id_free(id); |
7607 | |
7608 | isl_id_list_free(list); |
7609 | |
7610 | if (!ok) |
7611 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected elements in list" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7612); return -1; } while (0) |
7612 | "unexpected elements in list", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected elements in list" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7612); return -1; } while (0); |
7613 | |
7614 | return 0; |
7615 | } |
7616 | |
7617 | const char *set_conversion_tests[] = { |
7618 | "[N] -> { [i] : N - 1 <= 2 i <= N }", |
7619 | "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }", |
7620 | "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }", |
7621 | "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }", |
7622 | "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }", |
7623 | "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and " |
7624 | "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and " |
7625 | "-3 + c <= d <= 28 + c) }", |
7626 | }; |
7627 | |
7628 | /* Check that converting from isl_set to isl_pw_multi_aff and back |
7629 | * to isl_set produces the original isl_set. |
7630 | */ |
7631 | static int test_set_conversion(isl_ctx *ctx) |
7632 | { |
7633 | int i; |
7634 | const char *str; |
7635 | isl_setisl_map *set1, *set2; |
7636 | isl_pw_multi_aff *pma; |
7637 | int equal; |
7638 | |
7639 | for (i = 0; i < ARRAY_SIZE(set_conversion_tests)(sizeof(set_conversion_tests)/sizeof(*set_conversion_tests)); ++i) { |
7640 | str = set_conversion_tests[i]; |
7641 | set1 = isl_set_read_from_str(ctx, str); |
7642 | pma = isl_pw_multi_aff_from_set(isl_set_copy(set1)); |
7643 | set2 = isl_set_from_pw_multi_aff(pma); |
7644 | equal = isl_set_is_equal(set1, set2); |
7645 | isl_set_free(set1); |
7646 | isl_set_free(set2); |
7647 | |
7648 | if (equal < 0) |
7649 | return -1; |
7650 | if (!equal) |
7651 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7652); return -1; } while (0) |
7652 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7652); return -1; } while (0); |
7653 | } |
7654 | |
7655 | return 0; |
7656 | } |
7657 | |
7658 | const char *conversion_tests[] = { |
7659 | "{ [a, b, c, d] -> s0[a, b, e, f] : " |
7660 | "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], " |
7661 | "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and " |
7662 | "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and " |
7663 | "9e <= -2 - 2a) }", |
7664 | "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): " |
7665 | "5e0 = -a - b + c and c >= -a and c <= 4 - a) }", |
7666 | "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }", |
7667 | }; |
7668 | |
7669 | /* Check that converting from isl_map to isl_pw_multi_aff and back |
7670 | * to isl_map produces the original isl_map. |
7671 | */ |
7672 | static int test_map_conversion(isl_ctx *ctx) |
7673 | { |
7674 | int i; |
7675 | isl_map *map1, *map2; |
7676 | isl_pw_multi_aff *pma; |
7677 | int equal; |
7678 | |
7679 | for (i = 0; i < ARRAY_SIZE(conversion_tests)(sizeof(conversion_tests)/sizeof(*conversion_tests)); ++i) { |
7680 | map1 = isl_map_read_from_str(ctx, conversion_tests[i]); |
7681 | pma = isl_pw_multi_aff_from_map(isl_map_copy(map1)); |
7682 | map2 = isl_map_from_pw_multi_aff(pma); |
7683 | equal = isl_map_is_equal(map1, map2); |
7684 | isl_map_free(map1); |
7685 | isl_map_free(map2); |
7686 | |
7687 | if (equal < 0) |
7688 | return -1; |
7689 | if (!equal) |
7690 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7691); return -1; } while (0) |
7691 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7691); return -1; } while (0); |
7692 | } |
7693 | |
7694 | return 0; |
7695 | } |
7696 | |
7697 | /* Descriptions of isl_pw_multi_aff objects for testing conversion |
7698 | * to isl_multi_pw_aff and back. |
7699 | */ |
7700 | const char *mpa_conversion_tests[] = { |
7701 | "{ [x] -> A[x] }", |
7702 | "{ [x] -> A[x] : x >= 0 }", |
7703 | "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }", |
7704 | "{ [x] -> A[x, x + 1] }", |
7705 | "{ [x] -> A[] }", |
7706 | "{ [x] -> A[] : x >= 0 }", |
7707 | }; |
7708 | |
7709 | /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and |
7710 | * back to isl_pw_multi_aff preserves the original meaning. |
7711 | */ |
7712 | static int test_mpa_conversion(isl_ctx *ctx) |
7713 | { |
7714 | int i; |
7715 | isl_pw_multi_aff *pma1, *pma2; |
7716 | isl_multi_pw_aff *mpa; |
7717 | int equal; |
7718 | |
7719 | for (i = 0; i < ARRAY_SIZE(mpa_conversion_tests)(sizeof(mpa_conversion_tests)/sizeof(*mpa_conversion_tests)); ++i) { |
7720 | const char *str; |
7721 | str = mpa_conversion_tests[i]; |
7722 | pma1 = isl_pw_multi_aff_read_from_str(ctx, str); |
7723 | pma2 = isl_pw_multi_aff_copy(pma1); |
7724 | mpa = isl_multi_pw_aff_from_pw_multi_aff(pma1); |
7725 | pma1 = isl_pw_multi_aff_from_multi_pw_aff(mpa); |
7726 | equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2); |
7727 | isl_pw_multi_aff_free(pma1); |
7728 | isl_pw_multi_aff_free(pma2); |
7729 | |
7730 | if (equal < 0) |
7731 | return -1; |
7732 | if (!equal) |
7733 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7734); return -1; } while (0) |
7734 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7734); return -1; } while (0); |
7735 | } |
7736 | |
7737 | return 0; |
7738 | } |
7739 | |
7740 | /* Descriptions of union maps that should be convertible |
7741 | * to an isl_multi_union_pw_aff. |
7742 | */ |
7743 | const char *umap_mupa_conversion_tests[] = { |
7744 | "{ [a, b, c, d] -> s0[a, b, e, f] : " |
7745 | "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], " |
7746 | "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and " |
7747 | "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and " |
7748 | "9e <= -2 - 2a) }", |
7749 | "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): " |
7750 | "5e0 = -a - b + c and c >= -a and c <= 4 - a) }", |
7751 | "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }", |
7752 | "{ A[] -> B[0]; C[] -> B[1] }", |
7753 | "{ A[] -> B[]; C[] -> B[] }", |
7754 | }; |
7755 | |
7756 | /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back |
7757 | * to isl_union_map produces the original isl_union_map. |
7758 | */ |
7759 | static int test_union_map_mupa_conversion(isl_ctx *ctx) |
7760 | { |
7761 | int i; |
7762 | isl_union_map *umap1, *umap2; |
7763 | isl_multi_union_pw_aff *mupa; |
7764 | int equal; |
7765 | |
7766 | for (i = 0; i < ARRAY_SIZE(umap_mupa_conversion_tests)(sizeof(umap_mupa_conversion_tests)/sizeof(*umap_mupa_conversion_tests )); ++i) { |
7767 | const char *str; |
7768 | str = umap_mupa_conversion_tests[i]; |
7769 | umap1 = isl_union_map_read_from_str(ctx, str); |
7770 | umap2 = isl_union_map_copy(umap1); |
7771 | mupa = isl_multi_union_pw_aff_from_union_map(umap2); |
7772 | umap2 = isl_union_map_from_multi_union_pw_aff(mupa); |
7773 | equal = isl_union_map_is_equal(umap1, umap2); |
7774 | isl_union_map_free(umap1); |
7775 | isl_union_map_free(umap2); |
7776 | |
7777 | if (equal < 0) |
7778 | return -1; |
7779 | if (!equal) |
7780 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7781); return -1; } while (0) |
7781 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7781); return -1; } while (0); |
7782 | } |
7783 | |
7784 | return 0; |
7785 | } |
7786 | |
7787 | static int test_conversion(isl_ctx *ctx) |
7788 | { |
7789 | if (test_set_conversion(ctx) < 0) |
7790 | return -1; |
7791 | if (test_map_conversion(ctx) < 0) |
7792 | return -1; |
7793 | if (test_mpa_conversion(ctx) < 0) |
7794 | return -1; |
7795 | if (test_union_map_mupa_conversion(ctx) < 0) |
7796 | return -1; |
7797 | return 0; |
7798 | } |
7799 | |
7800 | /* Check that isl_basic_map_curry does not modify input. |
7801 | */ |
7802 | static int test_curry(isl_ctx *ctx) |
7803 | { |
7804 | const char *str; |
7805 | isl_basic_map *bmap1, *bmap2; |
7806 | int equal; |
7807 | |
7808 | str = "{ [A[] -> B[]] -> C[] }"; |
7809 | bmap1 = isl_basic_map_read_from_str(ctx, str); |
7810 | bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1)); |
7811 | equal = isl_basic_map_is_equal(bmap1, bmap2); |
7812 | isl_basic_map_free(bmap1); |
7813 | isl_basic_map_free(bmap2); |
7814 | |
7815 | if (equal < 0) |
7816 | return -1; |
7817 | if (equal) |
7818 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "curried map should not be equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7820); return -1; } while (0) |
7819 | "curried map should not be equal to original",do { isl_handle_error(ctx, isl_error_unknown, "curried map should not be equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7820); return -1; } while (0) |
7820 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "curried map should not be equal to original" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7820); return -1; } while (0); |
7821 | |
7822 | return 0; |
7823 | } |
7824 | |
7825 | struct { |
7826 | const char *set; |
7827 | const char *ma; |
7828 | const char *res; |
7829 | } preimage_tests[] = { |
7830 | { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }", |
7831 | "{ A[j,i] -> B[i,j] }", |
7832 | "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" }, |
7833 | { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }", |
7834 | "{ A[a,b] -> B[a/2,b/6] }", |
7835 | "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" }, |
7836 | { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }", |
7837 | "{ A[a,b] -> B[a/2,b/6] }", |
7838 | "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and " |
7839 | "exists i,j : a = 2 i and b = 6 j }" }, |
7840 | { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }", |
7841 | "[n] -> { : 0 <= n <= 100 }" }, |
7842 | { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }", |
7843 | "{ A[a] -> B[2a] }", |
7844 | "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" }, |
7845 | { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }", |
7846 | "{ A[a] -> B[([a/2])] }", |
7847 | "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" }, |
7848 | { "{ B[i,j,k] : 0 <= i,j,k <= 100 }", |
7849 | "{ A[a] -> B[a,a,a/3] }", |
7850 | "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" }, |
7851 | { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }", |
7852 | "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" }, |
7853 | }; |
7854 | |
7855 | static int test_preimage_basic_set(isl_ctx *ctx) |
7856 | { |
7857 | int i; |
7858 | isl_basic_setisl_basic_map *bset1, *bset2; |
7859 | isl_multi_aff *ma; |
7860 | int equal; |
7861 | |
7862 | for (i = 0; i < ARRAY_SIZE(preimage_tests)(sizeof(preimage_tests)/sizeof(*preimage_tests)); ++i) { |
7863 | bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set); |
7864 | ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma); |
7865 | bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res); |
7866 | bset1 = isl_basic_set_preimage_multi_aff(bset1, ma); |
7867 | equal = isl_basic_set_is_equal(bset1, bset2); |
7868 | isl_basic_set_free(bset1); |
7869 | isl_basic_set_free(bset2); |
7870 | if (equal < 0) |
7871 | return -1; |
7872 | if (!equal) |
7873 | isl_die(ctx, isl_error_unknown, "bad preimage",do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7874); return -1; } while (0) |
7874 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7874); return -1; } while (0); |
7875 | } |
7876 | |
7877 | return 0; |
7878 | } |
7879 | |
7880 | struct { |
7881 | const char *map; |
7882 | const char *ma; |
7883 | const char *res; |
7884 | } preimage_domain_tests[] = { |
7885 | { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }", |
7886 | "{ A[j,i] -> B[i,j] }", |
7887 | "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" }, |
7888 | { "{ B[i] -> C[i]; D[i] -> E[i] }", |
7889 | "{ A[i] -> B[i + 1] }", |
7890 | "{ A[i] -> C[i + 1] }" }, |
7891 | { "{ B[i] -> C[i]; B[i] -> E[i] }", |
7892 | "{ A[i] -> B[i + 1] }", |
7893 | "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" }, |
7894 | { "{ B[i] -> C[([i/2])] }", |
7895 | "{ A[i] -> B[2i] }", |
7896 | "{ A[i] -> C[i] }" }, |
7897 | { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }", |
7898 | "{ A[i] -> B[([i/5]), ([i/7])] }", |
7899 | "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" }, |
7900 | { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }", |
7901 | "[N] -> { A[] -> B[([N/5])] }", |
7902 | "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" }, |
7903 | { "{ B[i] -> C[i] : exists a : i = 5 a }", |
7904 | "{ A[i] -> B[2i] }", |
7905 | "{ A[i] -> C[2i] : exists a : 2i = 5 a }" }, |
7906 | { "{ B[i] -> C[i] : exists a : i = 2 a; " |
7907 | "B[i] -> D[i] : exists a : i = 2 a + 1 }", |
7908 | "{ A[i] -> B[2i] }", |
7909 | "{ A[i] -> C[2i] }" }, |
7910 | { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }", |
7911 | "{ C[i] -> B[j] : 2j = i + floor(i/3) }" }, |
7912 | }; |
7913 | |
7914 | static int test_preimage_union_map(isl_ctx *ctx) |
7915 | { |
7916 | int i; |
7917 | isl_union_map *umap1, *umap2; |
7918 | isl_multi_aff *ma; |
7919 | int equal; |
7920 | |
7921 | for (i = 0; i < ARRAY_SIZE(preimage_domain_tests)(sizeof(preimage_domain_tests)/sizeof(*preimage_domain_tests) ); ++i) { |
7922 | umap1 = isl_union_map_read_from_str(ctx, |
7923 | preimage_domain_tests[i].map); |
7924 | ma = isl_multi_aff_read_from_str(ctx, |
7925 | preimage_domain_tests[i].ma); |
7926 | umap2 = isl_union_map_read_from_str(ctx, |
7927 | preimage_domain_tests[i].res); |
7928 | umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma); |
7929 | equal = isl_union_map_is_equal(umap1, umap2); |
7930 | isl_union_map_free(umap1); |
7931 | isl_union_map_free(umap2); |
7932 | if (equal < 0) |
7933 | return -1; |
7934 | if (!equal) |
7935 | isl_die(ctx, isl_error_unknown, "bad preimage",do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7936); return -1; } while (0) |
7936 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7936); return -1; } while (0); |
7937 | } |
7938 | |
7939 | return 0; |
7940 | } |
7941 | |
7942 | static int test_preimage(isl_ctx *ctx) |
7943 | { |
7944 | if (test_preimage_basic_set(ctx) < 0) |
7945 | return -1; |
7946 | if (test_preimage_union_map(ctx) < 0) |
7947 | return -1; |
7948 | |
7949 | return 0; |
7950 | } |
7951 | |
7952 | struct { |
7953 | const char *ma1; |
7954 | const char *ma; |
7955 | const char *res; |
7956 | } pullback_tests[] = { |
7957 | { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }", |
7958 | "{ A[a,b] -> C[b + 2a] }" }, |
7959 | { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" }, |
7960 | { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" }, |
7961 | { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }", |
7962 | "{ A[a] -> C[(a)/6] }" }, |
7963 | { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" }, |
7964 | { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }", |
7965 | "{ A[a] -> C[(2a)/3] }" }, |
7966 | { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"}, |
7967 | { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }", |
7968 | "{ A[i,j] -> C[i + j, i + j] }"}, |
7969 | { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" }, |
7970 | { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }", |
7971 | "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", }, |
7972 | { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }", |
7973 | "{ [i, j] -> [floor((i)/3), j] }", |
7974 | "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" }, |
7975 | }; |
7976 | |
7977 | static int test_pullback(isl_ctx *ctx) |
7978 | { |
7979 | int i; |
7980 | isl_multi_aff *ma1, *ma2; |
7981 | isl_multi_aff *ma; |
7982 | int equal; |
7983 | |
7984 | for (i = 0; i < ARRAY_SIZE(pullback_tests)(sizeof(pullback_tests)/sizeof(*pullback_tests)); ++i) { |
7985 | ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1); |
7986 | ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma); |
7987 | ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res); |
7988 | ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma); |
7989 | equal = isl_multi_aff_plain_is_equal(ma1, ma2); |
7990 | isl_multi_aff_free(ma1); |
7991 | isl_multi_aff_free(ma2); |
7992 | if (equal < 0) |
7993 | return -1; |
7994 | if (!equal) |
7995 | isl_die(ctx, isl_error_unknown, "bad pullback",do { isl_handle_error(ctx, isl_error_unknown, "bad pullback", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7996); return -1; } while (0) |
7996 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad pullback", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 7996); return -1; } while (0); |
7997 | } |
7998 | |
7999 | return 0; |
8000 | } |
8001 | |
8002 | /* Check that negation is printed correctly and that equal expressions |
8003 | * are correctly identified. |
8004 | */ |
8005 | static int test_ast(isl_ctx *ctx) |
8006 | { |
8007 | isl_ast_expr *expr, *expr1, *expr2, *expr3; |
8008 | char *str; |
8009 | int ok, equal; |
8010 | |
8011 | expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL((void*)0))); |
8012 | expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL((void*)0))); |
8013 | expr = isl_ast_expr_add(expr1, expr2); |
8014 | expr2 = isl_ast_expr_copy(expr); |
8015 | expr = isl_ast_expr_neg(expr); |
8016 | expr2 = isl_ast_expr_neg(expr2); |
8017 | equal = isl_ast_expr_is_equal(expr, expr2); |
8018 | str = isl_ast_expr_to_C_str(expr); |
8019 | ok = str ? !strcmp(str, "-(A + B)")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (str) && __builtin_constant_p ("-(A + B)") && (__s1_len = __builtin_strlen (str), __s2_len = __builtin_strlen ("-(A + B)"), (!((size_t)(const void *)((str) + 1) - (size_t )(const void *)(str) == 1) || __s1_len >= 4) && (! ((size_t)(const void *)(("-(A + B)") + 1) - (size_t)(const void *)("-(A + B)") == 1) || __s2_len >= 4)) ? __builtin_strcmp (str, "-(A + B)") : (__builtin_constant_p (str) && ( (size_t)(const void *)((str) + 1) - (size_t)(const void *)(str ) == 1) && (__s1_len = __builtin_strlen (str), __s1_len < 4) ? (__builtin_constant_p ("-(A + B)") && ((size_t )(const void *)(("-(A + B)") + 1) - (size_t)(const void *)("-(A + B)" ) == 1) ? __builtin_strcmp (str, "-(A + B)") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("-(A + B)"); int __result = (((const unsigned char * ) (const char *) (str))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (str))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (str))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (str))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("-(A + B)") && ((size_t)(const void *)(("-(A + B)") + 1) - (size_t)(const void *)("-(A + B)") == 1) && ( __s2_len = __builtin_strlen ("-(A + B)"), __s2_len < 4) ? ( __builtin_constant_p (str) && ((size_t)(const void *) ((str) + 1) - (size_t)(const void *)(str) == 1) ? __builtin_strcmp (str, "-(A + B)") : -(__extension__ ({ const unsigned char * __s2 = (const unsigned char *) (const char *) (str); int __result = (((const unsigned char *) (const char *) ("-(A + B)"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("-(A + B)"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("-(A + B)"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("-(A + B)"))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp (str, "-(A + B)" )))); }) : -1; |
8020 | free(str); |
8021 | isl_ast_expr_free(expr); |
8022 | isl_ast_expr_free(expr2); |
8023 | |
8024 | if (ok < 0 || equal < 0) |
8025 | return -1; |
8026 | if (!equal) |
8027 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "equal expressions not considered equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8028); return -1; } while (0) |
8028 | "equal expressions not considered equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "equal expressions not considered equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8028); return -1; } while (0); |
8029 | if (!ok) |
8030 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8031); return -1; } while (0) |
8031 | "isl_ast_expr printed incorrectly", return -1)do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8031); return -1; } while (0); |
8032 | |
8033 | expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL((void*)0))); |
8034 | expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL((void*)0))); |
8035 | expr = isl_ast_expr_add(expr1, expr2); |
8036 | expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL((void*)0))); |
8037 | expr = isl_ast_expr_sub(expr3, expr); |
8038 | str = isl_ast_expr_to_C_str(expr); |
8039 | ok = str ? !strcmp(str, "C - (A + B)")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (str) && __builtin_constant_p ("C - (A + B)") && (__s1_len = __builtin_strlen (str), __s2_len = __builtin_strlen ("C - (A + B)"), (!((size_t)(const void *)((str) + 1) - (size_t )(const void *)(str) == 1) || __s1_len >= 4) && (! ((size_t)(const void *)(("C - (A + B)") + 1) - (size_t)(const void *)("C - (A + B)") == 1) || __s2_len >= 4)) ? __builtin_strcmp (str, "C - (A + B)") : (__builtin_constant_p (str) && ((size_t)(const void *)((str) + 1) - (size_t)(const void *)( str) == 1) && (__s1_len = __builtin_strlen (str), __s1_len < 4) ? (__builtin_constant_p ("C - (A + B)") && ( (size_t)(const void *)(("C - (A + B)") + 1) - (size_t)(const void *)("C - (A + B)") == 1) ? __builtin_strcmp (str, "C - (A + B)" ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("C - (A + B)"); int __result = (((const unsigned char *) (const char *) (str))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (str))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (str))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (str))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("C - (A + B)") && ((size_t)(const void *)(("C - (A + B)" ) + 1) - (size_t)(const void *)("C - (A + B)") == 1) && (__s2_len = __builtin_strlen ("C - (A + B)"), __s2_len < 4 ) ? (__builtin_constant_p (str) && ((size_t)(const void *)((str) + 1) - (size_t)(const void *)(str) == 1) ? __builtin_strcmp (str, "C - (A + B)") : -(__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (str); int __result = (((const unsigned char *) (const char *) ("C - (A + B)"))[ 0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("C - (A + B)" ))[1] - __s2[1]); if (__s2_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) ("C - (A + B)" ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) ("C - (A + B)" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp (str, "C - (A + B)")))); }) : -1; |
8040 | free(str); |
8041 | isl_ast_expr_free(expr); |
8042 | |
8043 | if (ok < 0) |
8044 | return -1; |
8045 | if (!ok) |
8046 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8047); return -1; } while (0) |
8047 | "isl_ast_expr printed incorrectly", return -1)do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8047); return -1; } while (0); |
8048 | |
8049 | return 0; |
8050 | } |
8051 | |
8052 | /* Check that isl_ast_build_expr_from_set returns a valid expression |
8053 | * for an empty set. Note that isl_ast_build_expr_from_set getting |
8054 | * called on an empty set probably indicates a bug in the caller. |
8055 | */ |
8056 | static int test_ast_build(isl_ctx *ctx) |
8057 | { |
8058 | isl_setisl_map *set; |
8059 | isl_ast_build *build; |
8060 | isl_ast_expr *expr; |
8061 | |
8062 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
8063 | build = isl_ast_build_from_context(set); |
8064 | |
8065 | set = isl_set_empty(isl_space_params_alloc(ctx, 0)); |
8066 | expr = isl_ast_build_expr_from_set(build, set); |
8067 | |
8068 | isl_ast_expr_free(expr); |
8069 | isl_ast_build_free(build); |
8070 | |
8071 | if (!expr) |
8072 | return -1; |
8073 | |
8074 | return 0; |
8075 | } |
8076 | |
8077 | /* Internal data structure for before_for and after_for callbacks. |
8078 | * |
8079 | * depth is the current depth |
8080 | * before is the number of times before_for has been called |
8081 | * after is the number of times after_for has been called |
8082 | */ |
8083 | struct isl_test_codegen_data { |
8084 | int depth; |
8085 | int before; |
8086 | int after; |
8087 | }; |
8088 | |
8089 | /* This function is called before each for loop in the AST generated |
8090 | * from test_ast_gen1. |
8091 | * |
8092 | * Increment the number of calls and the depth. |
8093 | * Check that the space returned by isl_ast_build_get_schedule_space |
8094 | * matches the target space of the schedule returned by |
8095 | * isl_ast_build_get_schedule. |
8096 | * Return an isl_id that is checked by the corresponding call |
8097 | * to after_for. |
8098 | */ |
8099 | static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build, |
8100 | void *user) |
8101 | { |
8102 | struct isl_test_codegen_data *data = user; |
8103 | isl_ctx *ctx; |
8104 | isl_space *space; |
8105 | isl_union_map *schedule; |
8106 | isl_union_set *uset; |
8107 | isl_setisl_map *set; |
8108 | int empty; |
8109 | char name[] = "d0"; |
8110 | |
8111 | ctx = isl_ast_build_get_ctx(build); |
8112 | |
8113 | if (data->before >= 3) |
8114 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8115); return ((void*)0); } while (0) |
8115 | "unexpected number of for nodes", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8115); return ((void*)0); } while (0); |
8116 | if (data->depth >= 2) |
8117 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected depth" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8118); return ((void*)0); } while (0) |
8118 | "unexpected depth", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "unexpected depth" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8118); return ((void*)0); } while (0); |
8119 | |
8120 | snprintf(name, sizeof(name), "d%d", data->depth); |
8121 | data->before++; |
8122 | data->depth++; |
8123 | |
8124 | schedule = isl_ast_build_get_schedule(build); |
8125 | uset = isl_union_map_range(schedule); |
8126 | if (!uset) |
8127 | return NULL((void*)0); |
8128 | if (isl_union_set_n_set(uset) != 1) { |
8129 | isl_union_set_free(uset); |
8130 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting single range space" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8131); return ((void*)0); } while (0) |
8131 | "expecting single range space", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "expecting single range space" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8131); return ((void*)0); } while (0); |
8132 | } |
8133 | |
8134 | space = isl_ast_build_get_schedule_space(build); |
8135 | set = isl_union_set_extract_set(uset, space); |
8136 | isl_union_set_free(uset); |
8137 | empty = isl_set_is_empty(set); |
8138 | isl_set_free(set); |
8139 | |
8140 | if (empty < 0) |
8141 | return NULL((void*)0); |
8142 | if (empty) |
8143 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "spaces don't match" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8144); return ((void*)0); } while (0) |
8144 | "spaces don't match", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "spaces don't match" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8144); return ((void*)0); } while (0); |
8145 | |
8146 | return isl_id_alloc(ctx, name, NULL((void*)0)); |
8147 | } |
8148 | |
8149 | /* This function is called after each for loop in the AST generated |
8150 | * from test_ast_gen1. |
8151 | * |
8152 | * Increment the number of calls and decrement the depth. |
8153 | * Check that the annotation attached to the node matches |
8154 | * the isl_id returned by the corresponding call to before_for. |
8155 | */ |
8156 | static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node, |
8157 | __isl_keep isl_ast_build *build, void *user) |
8158 | { |
8159 | struct isl_test_codegen_data *data = user; |
8160 | isl_id *id; |
8161 | const char *name; |
8162 | int valid; |
8163 | |
8164 | data->after++; |
8165 | data->depth--; |
8166 | |
8167 | if (data->after > data->before) |
8168 | isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "mismatch in number of for nodes", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8170); return isl_ast_node_free(node); } while (0) |
8169 | "mismatch in number of for nodes",do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "mismatch in number of for nodes", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8170); return isl_ast_node_free(node); } while (0) |
8170 | return isl_ast_node_free(node))do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "mismatch in number of for nodes", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8170); return isl_ast_node_free(node); } while (0); |
8171 | |
8172 | id = isl_ast_node_get_annotation(node); |
8173 | if (!id) |
8174 | isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "missing annotation", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8175); return isl_ast_node_free(node); } while (0) |
8175 | "missing annotation", return isl_ast_node_free(node))do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "missing annotation", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8175); return isl_ast_node_free(node); } while (0); |
8176 | |
8177 | name = isl_id_get_name(id); |
8178 | valid = name && atoi(name + 1) == data->depth; |
8179 | isl_id_free(id); |
8180 | |
8181 | if (!valid) |
8182 | isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "wrong annotation", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8183); return isl_ast_node_free(node); } while (0) |
8183 | "wrong annotation", return isl_ast_node_free(node))do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "wrong annotation", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8183); return isl_ast_node_free(node); } while (0); |
8184 | |
8185 | return node; |
8186 | } |
8187 | |
8188 | /* Check that the before_each_for and after_each_for callbacks |
8189 | * are called for each for loop in the generated code, |
8190 | * that they are called in the right order and that the isl_id |
8191 | * returned from the before_each_for callback is attached to |
8192 | * the isl_ast_node passed to the corresponding after_each_for call. |
8193 | */ |
8194 | static int test_ast_gen1(isl_ctx *ctx) |
8195 | { |
8196 | const char *str; |
8197 | isl_setisl_map *set; |
8198 | isl_union_map *schedule; |
8199 | isl_ast_build *build; |
8200 | isl_ast_node *tree; |
8201 | struct isl_test_codegen_data data; |
8202 | |
8203 | str = "[N] -> { : N >= 10 }"; |
8204 | set = isl_set_read_from_str(ctx, str); |
8205 | str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; " |
8206 | "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }"; |
8207 | schedule = isl_union_map_read_from_str(ctx, str); |
8208 | |
8209 | data.before = 0; |
8210 | data.after = 0; |
8211 | data.depth = 0; |
8212 | build = isl_ast_build_from_context(set); |
8213 | build = isl_ast_build_set_before_each_for(build, |
8214 | &before_for, &data); |
8215 | build = isl_ast_build_set_after_each_for(build, |
8216 | &after_for, &data); |
8217 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
8218 | isl_ast_build_free(build); |
8219 | if (!tree) |
8220 | return -1; |
8221 | |
8222 | isl_ast_node_free(tree); |
8223 | |
8224 | if (data.before != 3 || data.after != 3) |
8225 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8226); return -1; } while (0) |
8226 | "unexpected number of for nodes", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8226); return -1; } while (0); |
8227 | |
8228 | return 0; |
8229 | } |
8230 | |
8231 | /* Check that the AST generator handles domains that are integrally disjoint |
8232 | * but not rationally disjoint. |
8233 | */ |
8234 | static int test_ast_gen2(isl_ctx *ctx) |
8235 | { |
8236 | const char *str; |
8237 | isl_setisl_map *set; |
8238 | isl_union_map *schedule; |
8239 | isl_union_map *options; |
8240 | isl_ast_build *build; |
8241 | isl_ast_node *tree; |
8242 | |
8243 | str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }"; |
8244 | schedule = isl_union_map_read_from_str(ctx, str); |
8245 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
8246 | build = isl_ast_build_from_context(set); |
8247 | |
8248 | str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }"; |
8249 | options = isl_union_map_read_from_str(ctx, str); |
8250 | build = isl_ast_build_set_options(build, options); |
8251 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
8252 | isl_ast_build_free(build); |
8253 | if (!tree) |
8254 | return -1; |
8255 | isl_ast_node_free(tree); |
8256 | |
8257 | return 0; |
8258 | } |
8259 | |
8260 | /* Increment *user on each call. |
8261 | */ |
8262 | static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node, |
8263 | __isl_keep isl_ast_build *build, void *user) |
8264 | { |
8265 | int *n = user; |
8266 | |
8267 | (*n)++; |
8268 | |
8269 | return node; |
8270 | } |
8271 | |
8272 | /* Test that unrolling tries to minimize the number of instances. |
8273 | * In particular, for the schedule given below, make sure it generates |
8274 | * 3 nodes (rather than 101). |
8275 | */ |
8276 | static int test_ast_gen3(isl_ctx *ctx) |
8277 | { |
8278 | const char *str; |
8279 | isl_setisl_map *set; |
8280 | isl_union_map *schedule; |
8281 | isl_union_map *options; |
8282 | isl_ast_build *build; |
8283 | isl_ast_node *tree; |
8284 | int n_domain = 0; |
8285 | |
8286 | str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }"; |
8287 | schedule = isl_union_map_read_from_str(ctx, str); |
8288 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
8289 | |
8290 | str = "{ [i] -> unroll[0] }"; |
8291 | options = isl_union_map_read_from_str(ctx, str); |
8292 | |
8293 | build = isl_ast_build_from_context(set); |
8294 | build = isl_ast_build_set_options(build, options); |
8295 | build = isl_ast_build_set_at_each_domain(build, |
8296 | &count_domains, &n_domain); |
8297 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
8298 | isl_ast_build_free(build); |
8299 | if (!tree) |
8300 | return -1; |
8301 | |
8302 | isl_ast_node_free(tree); |
8303 | |
8304 | if (n_domain != 3) |
8305 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8306); return -1; } while (0) |
8306 | "unexpected number of for nodes", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8306); return -1; } while (0); |
8307 | |
8308 | return 0; |
8309 | } |
8310 | |
8311 | /* Check that if the ast_build_exploit_nested_bounds options is set, |
8312 | * we do not get an outer if node in the generated AST, |
8313 | * while we do get such an outer if node if the options is not set. |
8314 | */ |
8315 | static int test_ast_gen4(isl_ctx *ctx) |
8316 | { |
8317 | const char *str; |
8318 | isl_setisl_map *set; |
8319 | isl_union_map *schedule; |
8320 | isl_ast_build *build; |
8321 | isl_ast_node *tree; |
8322 | enum isl_ast_node_type type; |
8323 | int enb; |
8324 | |
8325 | enb = isl_options_get_ast_build_exploit_nested_bounds(ctx); |
8326 | str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }"; |
8327 | |
8328 | isl_options_set_ast_build_exploit_nested_bounds(ctx, 1); |
8329 | |
8330 | schedule = isl_union_map_read_from_str(ctx, str); |
8331 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
8332 | build = isl_ast_build_from_context(set); |
8333 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
8334 | isl_ast_build_free(build); |
8335 | if (!tree) |
8336 | return -1; |
8337 | |
8338 | type = isl_ast_node_get_type(tree); |
8339 | isl_ast_node_free(tree); |
8340 | |
8341 | if (type == isl_ast_node_if) |
8342 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "not expecting if node" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8343); return -1; } while (0) |
8343 | "not expecting if node", return -1)do { isl_handle_error(ctx, isl_error_unknown, "not expecting if node" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8343); return -1; } while (0); |
8344 | |
8345 | isl_options_set_ast_build_exploit_nested_bounds(ctx, 0); |
8346 | |
8347 | schedule = isl_union_map_read_from_str(ctx, str); |
8348 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
8349 | build = isl_ast_build_from_context(set); |
8350 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
8351 | isl_ast_build_free(build); |
8352 | if (!tree) |
8353 | return -1; |
8354 | |
8355 | type = isl_ast_node_get_type(tree); |
8356 | isl_ast_node_free(tree); |
8357 | |
8358 | if (type != isl_ast_node_if) |
8359 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting if node" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8360); return -1; } while (0) |
8360 | "expecting if node", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting if node" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8360); return -1; } while (0); |
8361 | |
8362 | isl_options_set_ast_build_exploit_nested_bounds(ctx, enb); |
8363 | |
8364 | return 0; |
8365 | } |
8366 | |
8367 | /* This function is called for each leaf in the AST generated |
8368 | * from test_ast_gen5. |
8369 | * |
8370 | * We finalize the AST generation by extending the outer schedule |
8371 | * with a zero-dimensional schedule. If this results in any for loops, |
8372 | * then this means that we did not pass along enough information |
8373 | * about the outer schedule to the inner AST generation. |
8374 | */ |
8375 | static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build, |
8376 | void *user) |
8377 | { |
8378 | isl_union_map *schedule, *extra; |
8379 | isl_ast_node *tree; |
8380 | |
8381 | schedule = isl_ast_build_get_schedule(build); |
8382 | extra = isl_union_map_copy(schedule); |
8383 | extra = isl_union_map_from_domain(isl_union_map_domain(extra)); |
8384 | schedule = isl_union_map_range_product(schedule, extra); |
8385 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
8386 | isl_ast_build_free(build); |
8387 | |
8388 | if (!tree) |
8389 | return NULL((void*)0); |
8390 | |
8391 | if (isl_ast_node_get_type(tree) == isl_ast_node_for) |
8392 | isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,do { isl_handle_error(isl_ast_node_get_ctx(tree), isl_error_unknown , "code should not contain any for loop", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8394); return isl_ast_node_free(tree); } while (0) |
8393 | "code should not contain any for loop",do { isl_handle_error(isl_ast_node_get_ctx(tree), isl_error_unknown , "code should not contain any for loop", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8394); return isl_ast_node_free(tree); } while (0) |
8394 | return isl_ast_node_free(tree))do { isl_handle_error(isl_ast_node_get_ctx(tree), isl_error_unknown , "code should not contain any for loop", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8394); return isl_ast_node_free(tree); } while (0); |
8395 | |
8396 | return tree; |
8397 | } |
8398 | |
8399 | /* Check that we do not lose any information when going back and |
8400 | * forth between internal and external schedule. |
8401 | * |
8402 | * In particular, we create an AST where we unroll the only |
8403 | * non-constant dimension in the schedule. We therefore do |
8404 | * not expect any for loops in the AST. However, older versions |
8405 | * of isl would not pass along enough information about the outer |
8406 | * schedule when performing an inner code generation from a create_leaf |
8407 | * callback, resulting in the inner code generation producing a for loop. |
8408 | */ |
8409 | static int test_ast_gen5(isl_ctx *ctx) |
8410 | { |
8411 | const char *str; |
8412 | isl_setisl_map *set; |
8413 | isl_union_map *schedule, *options; |
8414 | isl_ast_build *build; |
8415 | isl_ast_node *tree; |
8416 | |
8417 | str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }"; |
8418 | schedule = isl_union_map_read_from_str(ctx, str); |
8419 | |
8420 | str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: " |
8421 | "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }"; |
8422 | options = isl_union_map_read_from_str(ctx, str); |
8423 | |
8424 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
8425 | build = isl_ast_build_from_context(set); |
8426 | build = isl_ast_build_set_options(build, options); |
8427 | build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL((void*)0)); |
8428 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
8429 | isl_ast_build_free(build); |
8430 | isl_ast_node_free(tree); |
8431 | if (!tree) |
8432 | return -1; |
8433 | |
8434 | return 0; |
8435 | } |
8436 | |
8437 | /* Check that the expression |
8438 | * |
8439 | * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 } |
8440 | * |
8441 | * is not combined into |
8442 | * |
8443 | * min(n/2, 0) |
8444 | * |
8445 | * as this would result in n/2 being evaluated in parts of |
8446 | * the definition domain where n is not a multiple of 2. |
8447 | */ |
8448 | static int test_ast_expr(isl_ctx *ctx) |
8449 | { |
8450 | const char *str; |
8451 | isl_pw_aff *pa; |
8452 | isl_ast_build *build; |
8453 | isl_ast_expr *expr; |
8454 | int min_max; |
8455 | int is_min; |
8456 | |
8457 | min_max = isl_options_get_ast_build_detect_min_max(ctx); |
8458 | isl_options_set_ast_build_detect_min_max(ctx, 1); |
8459 | |
8460 | str = "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }"; |
8461 | pa = isl_pw_aff_read_from_str(ctx, str); |
8462 | build = isl_ast_build_alloc(ctx); |
8463 | expr = isl_ast_build_expr_from_pw_aff(build, pa); |
8464 | is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op && |
8465 | isl_ast_expr_get_op_type(expr) == isl_ast_op_min; |
8466 | isl_ast_build_free(build); |
8467 | isl_ast_expr_free(expr); |
8468 | |
8469 | isl_options_set_ast_build_detect_min_max(ctx, min_max); |
8470 | |
8471 | if (!expr) |
8472 | return -1; |
8473 | if (is_min) |
8474 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions should not be combined" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8475); return -1; } while (0) |
8475 | "expressions should not be combined", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions should not be combined" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8475); return -1; } while (0); |
8476 | |
8477 | return 0; |
8478 | } |
8479 | |
8480 | static int test_ast_gen(isl_ctx *ctx) |
8481 | { |
8482 | if (test_ast_gen1(ctx) < 0) |
8483 | return -1; |
8484 | if (test_ast_gen2(ctx) < 0) |
8485 | return -1; |
8486 | if (test_ast_gen3(ctx) < 0) |
8487 | return -1; |
8488 | if (test_ast_gen4(ctx) < 0) |
8489 | return -1; |
8490 | if (test_ast_gen5(ctx) < 0) |
8491 | return -1; |
8492 | if (test_ast_expr(ctx) < 0) |
8493 | return -1; |
8494 | return 0; |
8495 | } |
8496 | |
8497 | /* Check if dropping output dimensions from an isl_pw_multi_aff |
8498 | * works properly. |
8499 | */ |
8500 | static int test_pw_multi_aff(isl_ctx *ctx) |
8501 | { |
8502 | const char *str; |
8503 | isl_pw_multi_aff *pma1, *pma2; |
8504 | int equal; |
8505 | |
8506 | str = "{ [i,j] -> [i+j, 4i-j] }"; |
8507 | pma1 = isl_pw_multi_aff_read_from_str(ctx, str); |
8508 | str = "{ [i,j] -> [4i-j] }"; |
8509 | pma2 = isl_pw_multi_aff_read_from_str(ctx, str); |
8510 | |
8511 | pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1); |
8512 | |
8513 | equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2); |
8514 | |
8515 | isl_pw_multi_aff_free(pma1); |
8516 | isl_pw_multi_aff_free(pma2); |
8517 | if (equal < 0) |
8518 | return -1; |
8519 | if (!equal) |
8520 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8521); return -1; } while (0) |
8521 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8521); return -1; } while (0); |
8522 | |
8523 | return 0; |
8524 | } |
8525 | |
8526 | /* Check that we can properly parse multi piecewise affine expressions |
8527 | * where the piecewise affine expressions have different domains. |
8528 | */ |
8529 | static int test_multi_pw_aff_1(isl_ctx *ctx) |
8530 | { |
8531 | const char *str; |
8532 | isl_setisl_map *dom, *dom2; |
8533 | isl_multi_pw_aff *mpa1, *mpa2; |
8534 | isl_pw_aff *pa; |
8535 | int equal; |
8536 | int equal_domain; |
8537 | |
8538 | mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }"); |
8539 | dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }"); |
8540 | mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom); |
8541 | mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }"); |
8542 | mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2); |
8543 | str = "{ [i] -> [(i : i > 0), 2i] }"; |
8544 | mpa1 = isl_multi_pw_aff_read_from_str(ctx, str); |
8545 | |
8546 | equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2); |
8547 | |
8548 | pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0); |
8549 | dom = isl_pw_aff_domain(pa); |
8550 | pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1); |
8551 | dom2 = isl_pw_aff_domain(pa); |
8552 | equal_domain = isl_set_is_equal(dom, dom2); |
8553 | |
8554 | isl_set_free(dom); |
8555 | isl_set_free(dom2); |
8556 | isl_multi_pw_aff_free(mpa1); |
8557 | isl_multi_pw_aff_free(mpa2); |
8558 | |
8559 | if (equal < 0) |
8560 | return -1; |
8561 | if (!equal) |
8562 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8563); return -1; } while (0) |
8563 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8563); return -1; } while (0); |
8564 | |
8565 | if (equal_domain < 0) |
8566 | return -1; |
8567 | if (equal_domain) |
8568 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "domains unexpectedly equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8569); return -1; } while (0) |
8569 | "domains unexpectedly equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "domains unexpectedly equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8569); return -1; } while (0); |
8570 | |
8571 | return 0; |
8572 | } |
8573 | |
8574 | /* Check that the dimensions in the explicit domain |
8575 | * of a multi piecewise affine expression are properly |
8576 | * taken into account. |
8577 | */ |
8578 | static int test_multi_pw_aff_2(isl_ctx *ctx) |
8579 | { |
8580 | const char *str; |
8581 | isl_bool involves1, involves2, involves3, equal; |
8582 | isl_multi_pw_aff *mpa, *mpa1, *mpa2; |
8583 | |
8584 | str = "{ A[x,y] -> B[] : x >= y }"; |
8585 | mpa = isl_multi_pw_aff_read_from_str(ctx, str); |
8586 | involves1 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 2); |
8587 | mpa1 = isl_multi_pw_aff_copy(mpa); |
8588 | |
8589 | mpa = isl_multi_pw_aff_insert_dims(mpa, isl_dim_in, 0, 1); |
8590 | involves2 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 1); |
8591 | involves3 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 1, 2); |
8592 | str = "{ [a,x,y] -> B[] : x >= y }"; |
8593 | mpa2 = isl_multi_pw_aff_read_from_str(ctx, str); |
8594 | equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2); |
8595 | isl_multi_pw_aff_free(mpa2); |
8596 | |
8597 | mpa = isl_multi_pw_aff_drop_dims(mpa, isl_dim_in, 0, 1); |
8598 | mpa = isl_multi_pw_aff_set_tuple_name(mpa, isl_dim_in, "A"); |
8599 | if (equal >= 0 && equal) |
8600 | equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa1); |
8601 | isl_multi_pw_aff_free(mpa1); |
8602 | isl_multi_pw_aff_free(mpa); |
8603 | |
8604 | if (involves1 < 0 || involves2 < 0 || involves3 < 0 || equal < 0) |
8605 | return -1; |
8606 | if (!equal) |
8607 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect result of dimension insertion/removal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8609); return isl_stat_error; } while (0) |
8608 | "incorrect result of dimension insertion/removal",do { isl_handle_error(ctx, isl_error_unknown, "incorrect result of dimension insertion/removal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8609); return isl_stat_error; } while (0) |
8609 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "incorrect result of dimension insertion/removal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8609); return isl_stat_error; } while (0); |
8610 | if (!involves1 || involves2 || !involves3) |
8611 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect characterization of involved dimensions" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8613); return isl_stat_error; } while (0) |
8612 | "incorrect characterization of involved dimensions",do { isl_handle_error(ctx, isl_error_unknown, "incorrect characterization of involved dimensions" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8613); return isl_stat_error; } while (0) |
8613 | return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "incorrect characterization of involved dimensions" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8613); return isl_stat_error; } while (0); |
8614 | |
8615 | return 0; |
8616 | } |
8617 | |
8618 | /* Check that isl_multi_union_pw_aff_multi_val_on_domain |
8619 | * sets the explicit domain of a zero-dimensional result, |
8620 | * such that it can be converted to an isl_union_map. |
8621 | */ |
8622 | static isl_stat test_multi_pw_aff_3(isl_ctx *ctx) |
8623 | { |
8624 | isl_space *space; |
8625 | isl_union_set *dom; |
8626 | isl_multi_val *mv; |
8627 | isl_multi_union_pw_aff *mupa; |
8628 | isl_union_map *umap; |
8629 | |
8630 | dom = isl_union_set_read_from_str(ctx, "{ A[]; B[] }"); |
8631 | space = isl_union_set_get_space(dom); |
8632 | mv = isl_multi_val_zero(isl_space_set_from_params(space)); |
8633 | mupa = isl_multi_union_pw_aff_multi_val_on_domain(dom, mv); |
8634 | umap = isl_union_map_from_multi_union_pw_aff(mupa); |
8635 | isl_union_map_free(umap); |
8636 | if (!umap) |
8637 | return isl_stat_error; |
8638 | |
8639 | return isl_stat_ok; |
8640 | } |
8641 | |
8642 | /* Perform some tests on multi piecewise affine expressions. |
8643 | */ |
8644 | static int test_multi_pw_aff(isl_ctx *ctx) |
8645 | { |
8646 | if (test_multi_pw_aff_1(ctx) < 0) |
8647 | return -1; |
8648 | if (test_multi_pw_aff_2(ctx) < 0) |
8649 | return -1; |
8650 | if (test_multi_pw_aff_3(ctx) < 0) |
8651 | return -1; |
8652 | return 0; |
8653 | } |
8654 | |
8655 | /* This is a regression test for a bug where isl_basic_map_simplify |
8656 | * would end up in an infinite loop. In particular, we construct |
8657 | * an empty basic set that is not obviously empty. |
8658 | * isl_basic_set_is_empty marks the basic set as empty. |
8659 | * After projecting out i3, the variable can be dropped completely, |
8660 | * but isl_basic_map_simplify refrains from doing so if the basic set |
8661 | * is empty and would end up in an infinite loop if it didn't test |
8662 | * explicitly for empty basic maps in the outer loop. |
8663 | */ |
8664 | static int test_simplify_1(isl_ctx *ctx) |
8665 | { |
8666 | const char *str; |
8667 | isl_basic_setisl_basic_map *bset; |
8668 | int empty; |
8669 | |
8670 | str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and " |
8671 | "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and " |
8672 | "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and " |
8673 | "i3 >= i2 }"; |
8674 | bset = isl_basic_set_read_from_str(ctx, str); |
8675 | empty = isl_basic_set_is_empty(bset); |
8676 | bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1); |
8677 | isl_basic_set_free(bset); |
8678 | if (!bset) |
8679 | return -1; |
8680 | if (!empty) |
8681 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "basic set should be empty" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8682); return -1; } while (0) |
8682 | "basic set should be empty", return -1)do { isl_handle_error(ctx, isl_error_unknown, "basic set should be empty" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8682); return -1; } while (0); |
8683 | |
8684 | return 0; |
8685 | } |
8686 | |
8687 | /* Check that the equality in the set description below |
8688 | * is simplified away. |
8689 | */ |
8690 | static int test_simplify_2(isl_ctx *ctx) |
8691 | { |
8692 | const char *str; |
8693 | isl_basic_setisl_basic_map *bset; |
8694 | isl_bool universe; |
8695 | |
8696 | str = "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }"; |
8697 | bset = isl_basic_set_read_from_str(ctx, str); |
8698 | universe = isl_basic_set_plain_is_universe(bset); |
8699 | isl_basic_set_free(bset); |
8700 | |
8701 | if (universe < 0) |
8702 | return -1; |
8703 | if (!universe) |
8704 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "equality not simplified away" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8705); return -1; } while (0) |
8705 | "equality not simplified away", return -1)do { isl_handle_error(ctx, isl_error_unknown, "equality not simplified away" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8705); return -1; } while (0); |
8706 | return 0; |
8707 | } |
8708 | |
8709 | /* Some simplification tests. |
8710 | */ |
8711 | static int test_simplify(isl_ctx *ctx) |
8712 | { |
8713 | if (test_simplify_1(ctx) < 0) |
8714 | return -1; |
8715 | if (test_simplify_2(ctx) < 0) |
8716 | return -1; |
8717 | return 0; |
8718 | } |
8719 | |
8720 | /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt |
8721 | * with gbr context would fail to disable the use of the shifted tableau |
8722 | * when transferring equalities for the input to the context, resulting |
8723 | * in invalid sample values. |
8724 | */ |
8725 | static int test_partial_lexmin(isl_ctx *ctx) |
8726 | { |
8727 | const char *str; |
8728 | isl_basic_setisl_basic_map *bset; |
8729 | isl_basic_map *bmap; |
8730 | isl_map *map; |
8731 | |
8732 | str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }"; |
8733 | bmap = isl_basic_map_read_from_str(ctx, str); |
8734 | str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }"; |
8735 | bset = isl_basic_set_read_from_str(ctx, str); |
8736 | map = isl_basic_map_partial_lexmin(bmap, bset, NULL((void*)0)); |
8737 | isl_map_free(map); |
8738 | |
8739 | if (!map) |
8740 | return -1; |
8741 | |
8742 | return 0; |
8743 | } |
8744 | |
8745 | /* Check that the variable compression performed on the existentially |
8746 | * quantified variables inside isl_basic_set_compute_divs is not confused |
8747 | * by the implicit equalities among the parameters. |
8748 | */ |
8749 | static int test_compute_divs(isl_ctx *ctx) |
8750 | { |
8751 | const char *str; |
8752 | isl_basic_setisl_basic_map *bset; |
8753 | isl_setisl_map *set; |
8754 | |
8755 | str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and " |
8756 | "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and " |
8757 | "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and " |
8758 | "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }"; |
8759 | bset = isl_basic_set_read_from_str(ctx, str); |
8760 | set = isl_basic_set_compute_divs(bset); |
8761 | isl_set_free(set); |
8762 | if (!set) |
8763 | return -1; |
8764 | |
8765 | return 0; |
8766 | } |
8767 | |
8768 | /* Check that isl_schedule_get_map is not confused by a schedule tree |
8769 | * with divergent filter node parameters, as can result from a call |
8770 | * to isl_schedule_intersect_domain. |
8771 | */ |
8772 | static int test_schedule_tree(isl_ctx *ctx) |
8773 | { |
8774 | const char *str; |
8775 | isl_union_set *uset; |
8776 | isl_schedule *sched1, *sched2; |
8777 | isl_union_map *umap; |
8778 | |
8779 | uset = isl_union_set_read_from_str(ctx, "{ A[i] }"); |
8780 | sched1 = isl_schedule_from_domain(uset); |
8781 | uset = isl_union_set_read_from_str(ctx, "{ B[] }"); |
8782 | sched2 = isl_schedule_from_domain(uset); |
8783 | |
8784 | sched1 = isl_schedule_sequence(sched1, sched2); |
8785 | str = "[n] -> { A[i] : 0 <= i < n; B[] }"; |
8786 | uset = isl_union_set_read_from_str(ctx, str); |
8787 | sched1 = isl_schedule_intersect_domain(sched1, uset); |
8788 | umap = isl_schedule_get_map(sched1); |
8789 | isl_schedule_free(sched1); |
8790 | isl_union_map_free(umap); |
8791 | if (!umap) |
8792 | return -1; |
8793 | |
8794 | return 0; |
8795 | } |
8796 | |
8797 | /* Check that a zero-dimensional prefix schedule keeps track |
8798 | * of the domain and outer filters. |
8799 | */ |
8800 | static int test_schedule_tree_prefix(isl_ctx *ctx) |
8801 | { |
8802 | const char *str; |
8803 | isl_bool equal; |
8804 | isl_union_set *uset; |
8805 | isl_union_set_list *filters; |
8806 | isl_multi_union_pw_aff *mupa, *mupa2; |
8807 | isl_schedule_node *node; |
8808 | |
8809 | str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }"; |
8810 | uset = isl_union_set_read_from_str(ctx, str); |
8811 | node = isl_schedule_node_from_domain(uset); |
8812 | node = isl_schedule_node_child(node, 0); |
8813 | |
8814 | str = "{ S1[i,j] : i > j }"; |
8815 | uset = isl_union_set_read_from_str(ctx, str); |
8816 | filters = isl_union_set_list_from_union_set(uset); |
8817 | str = "{ S1[i,j] : i <= j; S2[i,j] }"; |
8818 | uset = isl_union_set_read_from_str(ctx, str); |
8819 | filters = isl_union_set_list_add(filters, uset); |
8820 | node = isl_schedule_node_insert_sequence(node, filters); |
8821 | |
8822 | node = isl_schedule_node_child(node, 0); |
8823 | node = isl_schedule_node_child(node, 0); |
8824 | mupa = isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node); |
8825 | str = "([] : { S1[i,j] : i > j })"; |
8826 | mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str); |
8827 | equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2); |
8828 | isl_multi_union_pw_aff_free(mupa2); |
8829 | isl_multi_union_pw_aff_free(mupa); |
8830 | isl_schedule_node_free(node); |
8831 | |
8832 | if (equal < 0) |
8833 | return -1; |
8834 | if (!equal) |
8835 | isl_die(ctx, isl_error_unknown, "unexpected prefix schedule",do { isl_handle_error(ctx, isl_error_unknown, "unexpected prefix schedule" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8836); return -1; } while (0) |
8836 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected prefix schedule" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8836); return -1; } while (0); |
8837 | |
8838 | return 0; |
8839 | } |
8840 | |
8841 | /* Check that the reaching domain elements and the prefix schedule |
8842 | * at a leaf node are the same before and after grouping. |
8843 | */ |
8844 | static int test_schedule_tree_group_1(isl_ctx *ctx) |
8845 | { |
8846 | int equal; |
8847 | const char *str; |
8848 | isl_id *id; |
8849 | isl_union_set *uset; |
8850 | isl_multi_union_pw_aff *mupa; |
8851 | isl_union_pw_multi_aff *upma1, *upma2; |
8852 | isl_union_set *domain1, *domain2; |
8853 | isl_union_map *umap1, *umap2; |
8854 | isl_schedule_node *node; |
8855 | |
8856 | str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }"; |
8857 | uset = isl_union_set_read_from_str(ctx, str); |
8858 | node = isl_schedule_node_from_domain(uset); |
8859 | node = isl_schedule_node_child(node, 0); |
8860 | str = "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]"; |
8861 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
8862 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
8863 | node = isl_schedule_node_child(node, 0); |
8864 | str = "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]"; |
8865 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
8866 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
8867 | node = isl_schedule_node_child(node, 0); |
8868 | umap1 = isl_schedule_node_get_prefix_schedule_union_map(node); |
8869 | upma1 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node); |
8870 | domain1 = isl_schedule_node_get_domain(node); |
8871 | id = isl_id_alloc(ctx, "group", NULL((void*)0)); |
8872 | node = isl_schedule_node_parent(node); |
8873 | node = isl_schedule_node_group(node, id); |
8874 | node = isl_schedule_node_child(node, 0); |
8875 | umap2 = isl_schedule_node_get_prefix_schedule_union_map(node); |
8876 | upma2 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node); |
8877 | domain2 = isl_schedule_node_get_domain(node); |
8878 | equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2); |
8879 | if (equal >= 0 && equal) |
8880 | equal = isl_union_set_is_equal(domain1, domain2); |
8881 | if (equal >= 0 && equal) |
8882 | equal = isl_union_map_is_equal(umap1, umap2); |
8883 | isl_union_map_free(umap1); |
8884 | isl_union_map_free(umap2); |
8885 | isl_union_set_free(domain1); |
8886 | isl_union_set_free(domain2); |
8887 | isl_union_pw_multi_aff_free(upma1); |
8888 | isl_union_pw_multi_aff_free(upma2); |
8889 | isl_schedule_node_free(node); |
8890 | |
8891 | if (equal < 0) |
8892 | return -1; |
8893 | if (!equal) |
8894 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8895); return -1; } while (0) |
8895 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8895); return -1; } while (0); |
8896 | |
8897 | return 0; |
8898 | } |
8899 | |
8900 | /* Check that we can have nested groupings and that the union map |
8901 | * schedule representation is the same before and after the grouping. |
8902 | * Note that after the grouping, the union map representation contains |
8903 | * the domain constraints from the ranges of the expansion nodes, |
8904 | * while they are missing from the union map representation of |
8905 | * the tree without expansion nodes. |
8906 | * |
8907 | * Also check that the global expansion is as expected. |
8908 | */ |
8909 | static int test_schedule_tree_group_2(isl_ctx *ctx) |
8910 | { |
8911 | int equal, equal_expansion; |
8912 | const char *str; |
8913 | isl_id *id; |
8914 | isl_union_set *uset; |
8915 | isl_union_map *umap1, *umap2; |
8916 | isl_union_map *expansion1, *expansion2; |
8917 | isl_union_set_list *filters; |
8918 | isl_multi_union_pw_aff *mupa; |
8919 | isl_schedule *schedule; |
8920 | isl_schedule_node *node; |
8921 | |
8922 | str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; " |
8923 | "S3[i,j] : 0 <= i,j < 10 }"; |
8924 | uset = isl_union_set_read_from_str(ctx, str); |
8925 | node = isl_schedule_node_from_domain(uset); |
8926 | node = isl_schedule_node_child(node, 0); |
8927 | str = "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]"; |
8928 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
8929 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
8930 | node = isl_schedule_node_child(node, 0); |
8931 | str = "{ S1[i,j] }"; |
8932 | uset = isl_union_set_read_from_str(ctx, str); |
8933 | filters = isl_union_set_list_from_union_set(uset); |
8934 | str = "{ S2[i,j]; S3[i,j] }"; |
8935 | uset = isl_union_set_read_from_str(ctx, str); |
8936 | filters = isl_union_set_list_add(filters, uset); |
8937 | node = isl_schedule_node_insert_sequence(node, filters); |
8938 | node = isl_schedule_node_child(node, 1); |
8939 | node = isl_schedule_node_child(node, 0); |
8940 | str = "{ S2[i,j] }"; |
8941 | uset = isl_union_set_read_from_str(ctx, str); |
8942 | filters = isl_union_set_list_from_union_set(uset); |
8943 | str = "{ S3[i,j] }"; |
8944 | uset = isl_union_set_read_from_str(ctx, str); |
8945 | filters = isl_union_set_list_add(filters, uset); |
8946 | node = isl_schedule_node_insert_sequence(node, filters); |
8947 | |
8948 | schedule = isl_schedule_node_get_schedule(node); |
8949 | umap1 = isl_schedule_get_map(schedule); |
8950 | uset = isl_schedule_get_domain(schedule); |
8951 | umap1 = isl_union_map_intersect_domain(umap1, uset); |
8952 | isl_schedule_free(schedule); |
8953 | |
8954 | node = isl_schedule_node_parent(node); |
8955 | node = isl_schedule_node_parent(node); |
8956 | id = isl_id_alloc(ctx, "group1", NULL((void*)0)); |
8957 | node = isl_schedule_node_group(node, id); |
8958 | node = isl_schedule_node_child(node, 1); |
8959 | node = isl_schedule_node_child(node, 0); |
8960 | id = isl_id_alloc(ctx, "group2", NULL((void*)0)); |
8961 | node = isl_schedule_node_group(node, id); |
8962 | |
8963 | schedule = isl_schedule_node_get_schedule(node); |
8964 | umap2 = isl_schedule_get_map(schedule); |
8965 | isl_schedule_free(schedule); |
8966 | |
8967 | node = isl_schedule_node_root(node); |
8968 | node = isl_schedule_node_child(node, 0); |
8969 | expansion1 = isl_schedule_node_get_subtree_expansion(node); |
8970 | isl_schedule_node_free(node); |
8971 | |
8972 | str = "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; " |
8973 | "group1[i] -> S2[i,j] : 0 <= i,j < 10; " |
8974 | "group1[i] -> S3[i,j] : 0 <= i,j < 10 }"; |
8975 | |
8976 | expansion2 = isl_union_map_read_from_str(ctx, str); |
8977 | |
8978 | equal = isl_union_map_is_equal(umap1, umap2); |
8979 | equal_expansion = isl_union_map_is_equal(expansion1, expansion2); |
8980 | |
8981 | isl_union_map_free(umap1); |
8982 | isl_union_map_free(umap2); |
8983 | isl_union_map_free(expansion1); |
8984 | isl_union_map_free(expansion2); |
8985 | |
8986 | if (equal < 0 || equal_expansion < 0) |
8987 | return -1; |
8988 | if (!equal) |
8989 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8990); return -1; } while (0) |
8990 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8990); return -1; } while (0); |
8991 | if (!equal_expansion) |
8992 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected expansion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8993); return -1; } while (0) |
8993 | "unexpected expansion", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected expansion" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 8993); return -1; } while (0); |
8994 | |
8995 | return 0; |
8996 | } |
8997 | |
8998 | /* Some tests for the isl_schedule_node_group function. |
8999 | */ |
9000 | static int test_schedule_tree_group(isl_ctx *ctx) |
9001 | { |
9002 | if (test_schedule_tree_group_1(ctx) < 0) |
9003 | return -1; |
9004 | if (test_schedule_tree_group_2(ctx) < 0) |
9005 | return -1; |
9006 | return 0; |
9007 | } |
9008 | |
9009 | struct { |
9010 | const char *set; |
9011 | const char *dual; |
9012 | } coef_tests[] = { |
9013 | { "{ rat: [i] : 0 <= i <= 10 }", |
9014 | "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" }, |
9015 | { "{ rat: [i] : FALSE }", |
9016 | "{ rat: coefficients[[cst] -> [a]] }" }, |
9017 | { "{ rat: [i] : }", |
9018 | "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" }, |
9019 | }; |
9020 | |
9021 | struct { |
9022 | const char *set; |
9023 | const char *dual; |
9024 | } sol_tests[] = { |
9025 | { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }", |
9026 | "{ rat: [i] : 0 <= i <= 10 }" }, |
9027 | { "{ rat: coefficients[[cst] -> [a]] : FALSE }", |
9028 | "{ rat: [i] }" }, |
9029 | { "{ rat: coefficients[[cst] -> [a]] }", |
9030 | "{ rat: [i] : FALSE }" }, |
9031 | }; |
9032 | |
9033 | /* Test the basic functionality of isl_basic_set_coefficients and |
9034 | * isl_basic_set_solutions. |
9035 | */ |
9036 | static int test_dual(isl_ctx *ctx) |
9037 | { |
9038 | int i; |
9039 | |
9040 | for (i = 0; i < ARRAY_SIZE(coef_tests)(sizeof(coef_tests)/sizeof(*coef_tests)); ++i) { |
9041 | int equal; |
9042 | isl_basic_setisl_basic_map *bset1, *bset2; |
9043 | |
9044 | bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set); |
9045 | bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual); |
9046 | bset1 = isl_basic_set_coefficients(bset1); |
9047 | equal = isl_basic_set_is_equal(bset1, bset2); |
9048 | isl_basic_set_free(bset1); |
9049 | isl_basic_set_free(bset2); |
9050 | if (equal < 0) |
9051 | return -1; |
9052 | if (!equal) |
9053 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9054); return -1; } while (0) |
9054 | "incorrect dual", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9054); return -1; } while (0); |
9055 | } |
9056 | |
9057 | for (i = 0; i < ARRAY_SIZE(sol_tests)(sizeof(sol_tests)/sizeof(*sol_tests)); ++i) { |
9058 | int equal; |
9059 | isl_basic_setisl_basic_map *bset1, *bset2; |
9060 | |
9061 | bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set); |
9062 | bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual); |
9063 | bset1 = isl_basic_set_solutions(bset1); |
9064 | equal = isl_basic_set_is_equal(bset1, bset2); |
9065 | isl_basic_set_free(bset1); |
9066 | isl_basic_set_free(bset2); |
9067 | if (equal < 0) |
9068 | return -1; |
9069 | if (!equal) |
9070 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9071); return -1; } while (0) |
9071 | "incorrect dual", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9071); return -1; } while (0); |
9072 | } |
9073 | |
9074 | return 0; |
9075 | } |
9076 | |
9077 | struct { |
9078 | int scale_tile; |
9079 | int shift_point; |
9080 | const char *domain; |
9081 | const char *schedule; |
9082 | const char *sizes; |
9083 | const char *tile; |
9084 | const char *point; |
9085 | } tile_tests[] = { |
9086 | { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }", |
9087 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
9088 | "{ [32,32] }", |
9089 | "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]", |
9090 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
9091 | }, |
9092 | { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }", |
9093 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
9094 | "{ [32,32] }", |
9095 | "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]", |
9096 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
9097 | }, |
9098 | { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }", |
9099 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
9100 | "{ [32,32] }", |
9101 | "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]", |
9102 | "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]", |
9103 | }, |
9104 | { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }", |
9105 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
9106 | "{ [32,32] }", |
9107 | "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]", |
9108 | "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]", |
9109 | }, |
9110 | }; |
9111 | |
9112 | /* Basic tiling tests. Create a schedule tree with a domain and a band node, |
9113 | * tile the band and then check if the tile and point bands have the |
9114 | * expected partial schedule. |
9115 | */ |
9116 | static int test_tile(isl_ctx *ctx) |
9117 | { |
9118 | int i; |
9119 | int scale; |
9120 | int shift; |
9121 | |
9122 | scale = isl_options_get_tile_scale_tile_loops(ctx); |
9123 | shift = isl_options_get_tile_shift_point_loops(ctx); |
9124 | |
9125 | for (i = 0; i < ARRAY_SIZE(tile_tests)(sizeof(tile_tests)/sizeof(*tile_tests)); ++i) { |
9126 | int opt; |
9127 | int equal; |
9128 | const char *str; |
9129 | isl_union_set *domain; |
9130 | isl_multi_union_pw_aff *mupa, *mupa2; |
9131 | isl_schedule_node *node; |
9132 | isl_multi_val *sizes; |
9133 | |
9134 | opt = tile_tests[i].scale_tile; |
9135 | isl_options_set_tile_scale_tile_loops(ctx, opt); |
9136 | opt = tile_tests[i].shift_point; |
9137 | isl_options_set_tile_shift_point_loops(ctx, opt); |
9138 | |
9139 | str = tile_tests[i].domain; |
9140 | domain = isl_union_set_read_from_str(ctx, str); |
9141 | node = isl_schedule_node_from_domain(domain); |
9142 | node = isl_schedule_node_child(node, 0); |
9143 | str = tile_tests[i].schedule; |
9144 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
9145 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
9146 | str = tile_tests[i].sizes; |
9147 | sizes = isl_multi_val_read_from_str(ctx, str); |
9148 | node = isl_schedule_node_band_tile(node, sizes); |
9149 | |
9150 | str = tile_tests[i].tile; |
9151 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
9152 | mupa2 = isl_schedule_node_band_get_partial_schedule(node); |
9153 | equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2); |
9154 | isl_multi_union_pw_aff_free(mupa); |
9155 | isl_multi_union_pw_aff_free(mupa2); |
9156 | |
9157 | node = isl_schedule_node_child(node, 0); |
9158 | |
9159 | str = tile_tests[i].point; |
9160 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
9161 | mupa2 = isl_schedule_node_band_get_partial_schedule(node); |
9162 | if (equal >= 0 && equal) |
9163 | equal = isl_multi_union_pw_aff_plain_is_equal(mupa, |
9164 | mupa2); |
9165 | isl_multi_union_pw_aff_free(mupa); |
9166 | isl_multi_union_pw_aff_free(mupa2); |
9167 | |
9168 | isl_schedule_node_free(node); |
9169 | |
9170 | if (equal < 0) |
9171 | return -1; |
9172 | if (!equal) |
9173 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9174); return -1; } while (0) |
9174 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9174); return -1; } while (0); |
9175 | } |
9176 | |
9177 | isl_options_set_tile_scale_tile_loops(ctx, scale); |
9178 | isl_options_set_tile_shift_point_loops(ctx, shift); |
9179 | |
9180 | return 0; |
9181 | } |
9182 | |
9183 | /* Check that the domain hash of a space is equal to the hash |
9184 | * of the domain of the space. |
9185 | */ |
9186 | static int test_domain_hash(isl_ctx *ctx) |
9187 | { |
9188 | isl_map *map; |
9189 | isl_space *space; |
9190 | uint32_t hash1, hash2; |
9191 | |
9192 | map = isl_map_read_from_str(ctx, "[n] -> { A[B[x] -> C[]] -> D[] }"); |
9193 | space = isl_map_get_space(map); |
9194 | isl_map_free(map); |
9195 | hash1 = isl_space_get_domain_hash(space); |
9196 | space = isl_space_domain(space); |
9197 | hash2 = isl_space_get_hash(space); |
9198 | isl_space_free(space); |
9199 | |
9200 | if (!space) |
9201 | return -1; |
9202 | if (hash1 != hash2) |
9203 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "domain hash not equal to hash of domain" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9204); return -1; } while (0) |
9204 | "domain hash not equal to hash of domain", return -1)do { isl_handle_error(ctx, isl_error_unknown, "domain hash not equal to hash of domain" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9204); return -1; } while (0); |
9205 | |
9206 | return 0; |
9207 | } |
9208 | |
9209 | /* Check that a universe basic set that is not obviously equal to the universe |
9210 | * is still recognized as being equal to the universe. |
9211 | */ |
9212 | static int test_universe(isl_ctx *ctx) |
9213 | { |
9214 | const char *s; |
9215 | isl_basic_setisl_basic_map *bset; |
9216 | isl_bool is_univ; |
9217 | |
9218 | s = "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }"; |
9219 | bset = isl_basic_set_read_from_str(ctx, s); |
9220 | is_univ = isl_basic_set_is_universe(bset); |
9221 | isl_basic_set_free(bset); |
9222 | |
9223 | if (is_univ < 0) |
9224 | return -1; |
9225 | if (!is_univ) |
9226 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "not recognized as universe set" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9227); return -1; } while (0) |
9227 | "not recognized as universe set", return -1)do { isl_handle_error(ctx, isl_error_unknown, "not recognized as universe set" , "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9227); return -1; } while (0); |
9228 | |
9229 | return 0; |
9230 | } |
9231 | |
9232 | /* Sets for which chambers are computed and checked. |
9233 | */ |
9234 | const char *chambers_tests[] = { |
9235 | "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and " |
9236 | "z >= 0 and z <= C - y and z <= B - x - y }", |
9237 | }; |
9238 | |
9239 | /* Add the domain of "cell" to "cells". |
9240 | */ |
9241 | static isl_stat add_cell(__isl_take isl_cell *cell, void *user) |
9242 | { |
9243 | isl_basic_set_listisl_basic_map_list **cells = user; |
9244 | isl_basic_setisl_basic_map *dom; |
9245 | |
9246 | dom = isl_cell_get_domain(cell); |
9247 | isl_cell_free(cell); |
9248 | *cells = isl_basic_set_list_add(*cells, dom); |
9249 | |
9250 | return *cells ? isl_stat_ok : isl_stat_error; |
9251 | } |
9252 | |
9253 | /* Check that the elements of "list" are pairwise disjoint. |
9254 | */ |
9255 | static isl_stat check_pairwise_disjoint(__isl_keep isl_basic_set_listisl_basic_map_list *list) |
9256 | { |
9257 | int i, j, n; |
9258 | |
9259 | if (!list) |
9260 | return isl_stat_error; |
9261 | |
9262 | n = isl_basic_set_list_n_basic_set(list); |
9263 | for (i = 0; i < n; ++i) { |
9264 | isl_basic_setisl_basic_map *bset_i; |
9265 | |
9266 | bset_i = isl_basic_set_list_get_basic_set(list, i); |
9267 | for (j = i + 1; j < n; ++j) { |
9268 | isl_basic_setisl_basic_map *bset_j; |
9269 | isl_bool disjoint; |
9270 | |
9271 | bset_j = isl_basic_set_list_get_basic_set(list, j); |
9272 | disjoint = isl_basic_set_is_disjoint(bset_i, bset_j); |
9273 | isl_basic_set_free(bset_j); |
9274 | if (!disjoint) |
9275 | isl_die(isl_basic_set_list_get_ctx(list),do { isl_handle_error(isl_basic_set_list_get_ctx(list), isl_error_unknown , "not disjoint", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9277); break; } while (0) |
9276 | isl_error_unknown, "not disjoint",do { isl_handle_error(isl_basic_set_list_get_ctx(list), isl_error_unknown , "not disjoint", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9277); break; } while (0) |
9277 | break)do { isl_handle_error(isl_basic_set_list_get_ctx(list), isl_error_unknown , "not disjoint", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9277); break; } while (0); |
9278 | if (disjoint < 0 || !disjoint) |
9279 | break; |
9280 | } |
9281 | isl_basic_set_free(bset_i); |
9282 | if (j < n) |
9283 | return isl_stat_error; |
9284 | } |
9285 | |
9286 | return isl_stat_ok; |
9287 | } |
9288 | |
9289 | /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell |
9290 | * are pairwise disjoint. |
9291 | */ |
9292 | static int test_chambers(isl_ctx *ctx) |
9293 | { |
9294 | int i; |
9295 | |
9296 | for (i = 0; i < ARRAY_SIZE(chambers_tests)(sizeof(chambers_tests)/sizeof(*chambers_tests)); ++i) { |
9297 | isl_basic_setisl_basic_map *bset; |
9298 | isl_vertices *vertices; |
9299 | isl_basic_set_listisl_basic_map_list *cells; |
9300 | isl_stat ok; |
9301 | |
9302 | bset = isl_basic_set_read_from_str(ctx, chambers_tests[i]); |
9303 | vertices = isl_basic_set_compute_vertices(bset); |
9304 | cells = isl_basic_set_list_alloc(ctx, 0); |
9305 | if (isl_vertices_foreach_disjoint_cell(vertices, &add_cell, |
9306 | &cells) < 0) |
9307 | cells = isl_basic_set_list_free(cells); |
9308 | ok = check_pairwise_disjoint(cells); |
9309 | isl_basic_set_list_free(cells); |
9310 | isl_vertices_free(vertices); |
9311 | isl_basic_set_free(bset); |
9312 | |
9313 | if (ok < 0) |
9314 | return -1; |
9315 | } |
9316 | |
9317 | return 0; |
9318 | } |
9319 | |
9320 | struct { |
9321 | const char *name; |
9322 | int (*fn)(isl_ctx *ctx); |
9323 | } tests [] = { |
9324 | { "universe", &test_universe }, |
9325 | { "domain hash", &test_domain_hash }, |
9326 | { "dual", &test_dual }, |
9327 | { "dependence analysis", &test_flow }, |
9328 | { "val", &test_val }, |
9329 | { "compute divs", &test_compute_divs }, |
9330 | { "partial lexmin", &test_partial_lexmin }, |
9331 | { "simplify", &test_simplify }, |
9332 | { "curry", &test_curry }, |
9333 | { "piecewise multi affine expressions", &test_pw_multi_aff }, |
9334 | { "multi piecewise affine expressions", &test_multi_pw_aff }, |
9335 | { "conversion", &test_conversion }, |
9336 | { "list", &test_list }, |
9337 | { "align parameters", &test_align_parameters }, |
9338 | { "drop unused parameters", &test_drop_unused_parameters }, |
9339 | { "preimage", &test_preimage }, |
9340 | { "pullback", &test_pullback }, |
9341 | { "AST", &test_ast }, |
9342 | { "AST build", &test_ast_build }, |
9343 | { "AST generation", &test_ast_gen }, |
9344 | { "eliminate", &test_eliminate }, |
9345 | { "residue class", &test_residue_class }, |
9346 | { "div", &test_div }, |
9347 | { "slice", &test_slice }, |
9348 | { "fixed power", &test_fixed_power }, |
9349 | { "sample", &test_sample }, |
9350 | { "output", &test_output }, |
9351 | { "vertices", &test_vertices }, |
9352 | { "chambers", &test_chambers }, |
9353 | { "fixed", &test_fixed }, |
9354 | { "equal", &test_equal }, |
9355 | { "disjoint", &test_disjoint }, |
9356 | { "product", &test_product }, |
9357 | { "dim_max", &test_dim_max }, |
9358 | { "affine", &test_aff }, |
9359 | { "injective", &test_injective }, |
9360 | { "schedule (whole component)", &test_schedule_whole }, |
9361 | { "schedule (incremental)", &test_schedule_incremental }, |
9362 | { "schedule tree", &test_schedule_tree }, |
9363 | { "schedule tree prefix", &test_schedule_tree_prefix }, |
9364 | { "schedule tree grouping", &test_schedule_tree_group }, |
9365 | { "tile", &test_tile }, |
9366 | { "union_pw", &test_union_pw }, |
9367 | { "locus", &test_locus }, |
9368 | { "eval", &test_eval }, |
9369 | { "parse", &test_parse }, |
9370 | { "single-valued", &test_sv }, |
9371 | { "affine hull", &test_affine_hull }, |
9372 | { "simple_hull", &test_simple_hull }, |
9373 | { "coalesce", &test_coalesce }, |
9374 | { "factorize", &test_factorize }, |
9375 | { "subset", &test_subset }, |
9376 | { "subtract", &test_subtract }, |
9377 | { "intersect", &test_intersect }, |
9378 | { "lexmin", &test_lexmin }, |
9379 | { "min", &test_min }, |
9380 | { "gist", &test_gist }, |
9381 | { "piecewise quasi-polynomials", &test_pwqp }, |
9382 | { "lift", &test_lift }, |
9383 | { "bound", &test_bound }, |
9384 | { "get lists", &test_get_list }, |
9385 | { "union", &test_union }, |
9386 | { "split periods", &test_split_periods }, |
9387 | { "lexicographic order", &test_lex }, |
9388 | { "bijectivity", &test_bijective }, |
9389 | { "dataflow analysis", &test_dep }, |
9390 | { "reading", &test_read }, |
9391 | { "bounded", &test_bounded }, |
9392 | { "construction", &test_construction }, |
9393 | { "dimension manipulation", &test_dim }, |
9394 | { "map application", &test_application }, |
9395 | { "convex hull", &test_convex_hull }, |
9396 | { "transitive closure", &test_closure }, |
9397 | }; |
9398 | |
9399 | int main(int argc, char **argv) |
9400 | { |
9401 | int i; |
9402 | struct isl_ctx *ctx; |
9403 | struct isl_options *options; |
9404 | |
9405 | options = isl_options_new_with_defaults(); |
9406 | assert(options)((options) ? (void) (0) : __assert_fail ("options", "/build/llvm-toolchain-snapshot-8~svn345461/tools/polly/lib/External/isl/isl_test.c" , 9406, __PRETTY_FUNCTION__)); |
9407 | argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL(1 << 0)); |
Value stored to 'argc' is never read | |
9408 | |
9409 | ctx = isl_ctx_alloc_with_options(&isl_options_args, options); |
9410 | for (i = 0; i < ARRAY_SIZE(tests)(sizeof(tests)/sizeof(*tests)); ++i) { |
9411 | printf("%s\n", tests[i].name); |
9412 | if (tests[i].fn(ctx) < 0) |
9413 | goto error; |
9414 | } |
9415 | isl_ctx_free(ctx); |
9416 | return 0; |
9417 | error: |
9418 | isl_ctx_free(ctx); |
9419 | return -1; |
9420 | } |