File: | tools/polly/lib/External/isl/isl_test.c |
Warning: | line 6704, column 2 Value stored to 'argc' is never read |
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/set.h> |
26 | #include <isl/flow.h> |
27 | #include <isl_constraint_private.h> |
28 | #include <isl/polynomial.h> |
29 | #include <isl/union_set.h> |
30 | #include <isl/union_map.h> |
31 | #include <isl_factorization.h> |
32 | #include <isl/schedule.h> |
33 | #include <isl/schedule_node.h> |
34 | #include <isl_options_private.h> |
35 | #include <isl/vertices.h> |
36 | #include <isl/ast_build.h> |
37 | #include <isl/val.h> |
38 | #include <isl/ilp.h> |
39 | #include <isl_ast_build_expr.h> |
40 | #include <isl/options.h> |
41 | |
42 | #define ARRAY_SIZE(array)(sizeof(array)/sizeof(*array)) (sizeof(array)/sizeof(*array)) |
43 | |
44 | static char *srcdir; |
45 | |
46 | static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) { |
47 | char *filename; |
48 | int length; |
49 | char *pattern = "%s/test_inputs/%s.%s"; |
50 | |
51 | length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name) |
52 | + strlen(suffix) + 1; |
53 | filename = isl_alloc_array(ctx, char, length)((char *)isl_malloc_or_die(ctx, (length)*sizeof(char))); |
54 | |
55 | if (!filename) |
56 | return NULL((void*)0); |
57 | |
58 | sprintf(filename, pattern, srcdir, name, suffix); |
59 | |
60 | return filename; |
61 | } |
62 | |
63 | void test_parse_map(isl_ctx *ctx, const char *str) |
64 | { |
65 | isl_map *map; |
66 | |
67 | map = isl_map_read_from_str(ctx, str); |
68 | assert(map)((map) ? (void) (0) : __assert_fail ("map", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 68, __PRETTY_FUNCTION__)); |
69 | isl_map_free(map); |
70 | } |
71 | |
72 | int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2) |
73 | { |
74 | isl_map *map, *map2; |
75 | int equal; |
76 | |
77 | map = isl_map_read_from_str(ctx, str); |
78 | map2 = isl_map_read_from_str(ctx, str2); |
79 | equal = isl_map_is_equal(map, map2); |
80 | isl_map_free(map); |
81 | isl_map_free(map2); |
82 | |
83 | if (equal < 0) |
84 | return -1; |
85 | if (!equal) |
86 | isl_die(ctx, isl_error_unknown, "maps not equal",do { isl_handle_error(ctx, isl_error_unknown, "maps not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 87); return -1; } while (0) |
87 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "maps not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 87); return -1; } while (0); |
88 | |
89 | return 0; |
90 | } |
91 | |
92 | void test_parse_pwqp(isl_ctx *ctx, const char *str) |
93 | { |
94 | isl_pw_qpolynomial *pwqp; |
95 | |
96 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
97 | assert(pwqp)((pwqp) ? (void) (0) : __assert_fail ("pwqp", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 97, __PRETTY_FUNCTION__)); |
98 | isl_pw_qpolynomial_free(pwqp); |
99 | } |
100 | |
101 | static void test_parse_pwaff(isl_ctx *ctx, const char *str) |
102 | { |
103 | isl_pw_aff *pwaff; |
104 | |
105 | pwaff = isl_pw_aff_read_from_str(ctx, str); |
106 | assert(pwaff)((pwaff) ? (void) (0) : __assert_fail ("pwaff", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 106, __PRETTY_FUNCTION__)); |
107 | isl_pw_aff_free(pwaff); |
108 | } |
109 | |
110 | /* Check that we can read an isl_multi_val from "str" without errors. |
111 | */ |
112 | static int test_parse_multi_val(isl_ctx *ctx, const char *str) |
113 | { |
114 | isl_multi_val *mv; |
115 | |
116 | mv = isl_multi_val_read_from_str(ctx, str); |
117 | isl_multi_val_free(mv); |
118 | |
119 | return mv ? 0 : -1; |
120 | } |
121 | |
122 | /* Pairs of binary relation representations that should represent |
123 | * the same binary relations. |
124 | */ |
125 | struct { |
126 | const char *map1; |
127 | const char *map2; |
128 | } parse_map_equal_tests[] = { |
129 | { "{ [x,y] : [([x/2]+y)/3] >= 1 }", |
130 | "{ [x, y] : 2y >= 6 - x }" }, |
131 | { "{ [x,y] : x <= min(y, 2*y+3) }", |
132 | "{ [x,y] : x <= y, 2*y + 3 }" }, |
133 | { "{ [x,y] : x >= min(y, 2*y+3) }", |
134 | "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" }, |
135 | { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }", |
136 | "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" }, |
137 | { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }", |
138 | "{ [i,j] -> [min(i,j)] }" }, |
139 | { "{ [i,j] : i != j }", |
140 | "{ [i,j] : i < j or i > j }" }, |
141 | { "{ [i,j] : (i+1)*2 >= j }", |
142 | "{ [i, j] : j <= 2 + 2i }" }, |
143 | { "{ [i] -> [i > 0 ? 4 : 5] }", |
144 | "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" }, |
145 | { "[N=2,M] -> { [i=[(M+N)/4]] }", |
146 | "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" }, |
147 | { "{ [x] : x >= 0 }", |
148 | "{ [x] : x-0 >= 0 }" }, |
149 | { "{ [i] : ((i > 10)) }", |
150 | "{ [i] : i >= 11 }" }, |
151 | { "{ [i] -> [0] }", |
152 | "{ [i] -> [0 * i] }" }, |
153 | { "{ [a] -> [b] : (not false) }", |
154 | "{ [a] -> [b] : true }" }, |
155 | { "{ [i] : i/2 <= 5 }", |
156 | "{ [i] : i <= 10 }" }, |
157 | { "{Sym=[n] [i] : i <= n }", |
158 | "[n] -> { [i] : i <= n }" }, |
159 | { "{ [*] }", |
160 | "{ [a] }" }, |
161 | { "{ [i] : 2*floor(i/2) = i }", |
162 | "{ [i] : exists a : i = 2 a }" }, |
163 | { "{ [a] -> [b] : a = 5 implies b = 5 }", |
164 | "{ [a] -> [b] : a != 5 or b = 5 }" }, |
165 | { "{ [a] -> [a - 1 : a > 0] }", |
166 | "{ [a] -> [a - 1] : a > 0 }" }, |
167 | { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }", |
168 | "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" }, |
169 | { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }", |
170 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
171 | { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }", |
172 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
173 | { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }", |
174 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
175 | { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }", |
176 | "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" }, |
177 | { "{ [a,b] -> [i,j] : a,b << i,j }", |
178 | "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" }, |
179 | { "{ [a,b] -> [i,j] : a,b <<= i,j }", |
180 | "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" }, |
181 | { "{ [a,b] -> [i,j] : a,b >> i,j }", |
182 | "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" }, |
183 | { "{ [a,b] -> [i,j] : a,b >>= i,j }", |
184 | "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" }, |
185 | { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and " |
186 | "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and " |
187 | "8c < n - 32a and i < n and c >= 0 and " |
188 | "c <= 3 and c >= -4a) }", |
189 | "{ [n] -> [i] : 0 <= i < n }" }, |
190 | { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and " |
191 | "2b <= x - 8a and 2b >= -1 + x - 8a) }", |
192 | "{ [x] -> [] : 0 <= x <= 15 }" }, |
193 | }; |
194 | |
195 | int test_parse(struct isl_ctx *ctx) |
196 | { |
197 | int i; |
198 | isl_map *map, *map2; |
199 | const char *str, *str2; |
200 | |
201 | if (test_parse_multi_val(ctx, "{ A[B[2] -> C[5, 7]] }") < 0) |
202 | return -1; |
203 | if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0) |
204 | return -1; |
205 | if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0) |
206 | return -1; |
207 | |
208 | str = "{ [i] -> [-i] }"; |
209 | map = isl_map_read_from_str(ctx, str); |
210 | assert(map)((map) ? (void) (0) : __assert_fail ("map", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 210, __PRETTY_FUNCTION__)); |
211 | isl_map_free(map); |
212 | |
213 | str = "{ A[i] -> L[([i/3])] }"; |
214 | map = isl_map_read_from_str(ctx, str); |
215 | assert(map)((map) ? (void) (0) : __assert_fail ("map", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 215, __PRETTY_FUNCTION__)); |
216 | isl_map_free(map); |
217 | |
218 | test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}"); |
219 | test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : " |
220 | "p1 = 1 && (y1 <= y2 || y2 = 0) }"); |
221 | |
222 | for (i = 0; i < ARRAY_SIZE(parse_map_equal_tests)(sizeof(parse_map_equal_tests)/sizeof(*parse_map_equal_tests) ); ++i) { |
223 | str = parse_map_equal_tests[i].map1; |
224 | str2 = parse_map_equal_tests[i].map2; |
225 | if (test_parse_map_equal(ctx, str, str2) < 0) |
226 | return -1; |
227 | } |
228 | |
229 | str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}"; |
230 | map = isl_map_read_from_str(ctx, str); |
231 | str = "{ [new, old] -> [o0, o1] : " |
232 | "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: " |
233 | "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and " |
234 | "o0 <= 1 and o1 >= 0 and o1 <= 1) }"; |
235 | map2 = isl_map_read_from_str(ctx, str); |
236 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 236, __PRETTY_FUNCTION__)); |
237 | isl_map_free(map); |
238 | isl_map_free(map2); |
239 | |
240 | str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}"; |
241 | map = isl_map_read_from_str(ctx, str); |
242 | str = "{[new,old] -> [(new+1)%2,(old+1)%2]}"; |
243 | map2 = isl_map_read_from_str(ctx, str); |
244 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 244, __PRETTY_FUNCTION__)); |
245 | isl_map_free(map); |
246 | isl_map_free(map2); |
247 | |
248 | test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }"); |
249 | test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }"); |
250 | test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }"); |
251 | test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }"); |
252 | test_parse_pwaff(ctx, "{ [] -> [(100)] }"); |
253 | |
254 | return 0; |
255 | } |
256 | |
257 | static int test_read(isl_ctx *ctx) |
258 | { |
259 | char *filename; |
260 | FILE *input; |
261 | isl_basic_setisl_basic_map *bset1, *bset2; |
262 | const char *str = "{[y]: Exists ( alpha : 2alpha = y)}"; |
263 | int equal; |
264 | |
265 | filename = get_filename(ctx, "set", "omega"); |
266 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 266, __PRETTY_FUNCTION__)); |
267 | input = fopen(filename, "r"); |
268 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 268, __PRETTY_FUNCTION__)); |
269 | |
270 | bset1 = isl_basic_set_read_from_file(ctx, input); |
271 | bset2 = isl_basic_set_read_from_str(ctx, str); |
272 | |
273 | equal = isl_basic_set_is_equal(bset1, bset2); |
274 | |
275 | isl_basic_set_free(bset1); |
276 | isl_basic_set_free(bset2); |
277 | free(filename); |
278 | |
279 | fclose(input); |
280 | |
281 | if (equal < 0) |
282 | return -1; |
283 | if (!equal) |
284 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "read sets not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 285); return -1; } while (0) |
285 | "read sets not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "read sets not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 285); return -1; } while (0); |
286 | |
287 | return 0; |
288 | } |
289 | |
290 | static int test_bounded(isl_ctx *ctx) |
291 | { |
292 | isl_setisl_map *set; |
293 | int bounded; |
294 | |
295 | set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }"); |
296 | bounded = isl_set_is_bounded(set); |
297 | isl_set_free(set); |
298 | |
299 | if (bounded < 0) |
300 | return -1; |
301 | if (!bounded) |
302 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set not considered bounded" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 303); return -1; } while (0) |
303 | "set not considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set not considered bounded" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 303); return -1; } while (0); |
304 | |
305 | set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }"); |
306 | bounded = isl_set_is_bounded(set); |
307 | assert(!bounded)((!bounded) ? (void) (0) : __assert_fail ("!bounded", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 307, __PRETTY_FUNCTION__)); |
308 | isl_set_free(set); |
309 | |
310 | if (bounded < 0) |
311 | return -1; |
312 | if (bounded) |
313 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 314); return -1; } while (0) |
314 | "set considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 314); return -1; } while (0); |
315 | |
316 | set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }"); |
317 | bounded = isl_set_is_bounded(set); |
318 | isl_set_free(set); |
319 | |
320 | if (bounded < 0) |
321 | return -1; |
322 | if (bounded) |
323 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 324); return -1; } while (0) |
324 | "set considered bounded", return -1)do { isl_handle_error(ctx, isl_error_unknown, "set considered bounded" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 324); return -1; } while (0); |
325 | |
326 | return 0; |
327 | } |
328 | |
329 | /* Construct the basic set { [i] : 5 <= i <= N } */ |
330 | static int test_construction(isl_ctx *ctx) |
331 | { |
332 | isl_int v; |
333 | isl_space *dim; |
334 | isl_local_space *ls; |
335 | isl_basic_setisl_basic_map *bset; |
336 | isl_constraint *c; |
337 | |
338 | isl_int_init(v)isl_sioimath_init((v)); |
339 | |
340 | dim = isl_space_set_alloc(ctx, 1, 1); |
341 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
342 | ls = isl_local_space_from_space(dim); |
343 | |
344 | c = isl_constraint_alloc_inequality(isl_local_space_copy(ls)); |
345 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
346 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
347 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
348 | isl_constraint_set_coefficient(c, isl_dim_param, 0, v); |
349 | bset = isl_basic_set_add_constraint(bset, c); |
350 | |
351 | c = isl_constraint_alloc_inequality(isl_local_space_copy(ls)); |
352 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
353 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
354 | isl_int_set_si(v, -5)isl_sioimath_set_si((v), -5); |
355 | isl_constraint_set_constant(c, v); |
356 | bset = isl_basic_set_add_constraint(bset, c); |
357 | |
358 | isl_local_space_free(ls); |
359 | isl_basic_set_free(bset); |
360 | |
361 | isl_int_clear(v)isl_sioimath_clear((v)); |
362 | |
363 | return 0; |
364 | } |
365 | |
366 | static int test_dim(isl_ctx *ctx) |
367 | { |
368 | const char *str; |
369 | isl_map *map1, *map2; |
370 | int equal; |
371 | |
372 | map1 = isl_map_read_from_str(ctx, |
373 | "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }"); |
374 | map1 = isl_map_add_dims(map1, isl_dim_in, 1); |
375 | map2 = isl_map_read_from_str(ctx, |
376 | "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }"); |
377 | equal = isl_map_is_equal(map1, map2); |
378 | isl_map_free(map2); |
379 | |
380 | map1 = isl_map_project_out(map1, isl_dim_in, 0, 1); |
381 | map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }"); |
382 | if (equal >= 0 && equal) |
383 | equal = isl_map_is_equal(map1, map2); |
384 | |
385 | isl_map_free(map1); |
386 | isl_map_free(map2); |
387 | |
388 | if (equal < 0) |
389 | return -1; |
390 | if (!equal) |
391 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 392); return -1; } while (0) |
392 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 392); return -1; } while (0); |
393 | |
394 | str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }"; |
395 | map1 = isl_map_read_from_str(ctx, str); |
396 | str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }"; |
397 | map2 = isl_map_read_from_str(ctx, str); |
398 | map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1); |
399 | equal = isl_map_is_equal(map1, map2); |
400 | isl_map_free(map1); |
401 | isl_map_free(map2); |
402 | |
403 | if (equal < 0) |
404 | return -1; |
405 | if (!equal) |
406 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 407); return -1; } while (0) |
407 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 407); return -1; } while (0); |
408 | |
409 | return 0; |
410 | } |
411 | |
412 | struct { |
413 | __isl_give isl_val *(*op)(__isl_take isl_val *v); |
414 | const char *arg; |
415 | const char *res; |
416 | } val_un_tests[] = { |
417 | { &isl_val_neg, "0", "0" }, |
418 | { &isl_val_abs, "0", "0" }, |
419 | { &isl_val_2exp, "0", "1" }, |
420 | { &isl_val_floor, "0", "0" }, |
421 | { &isl_val_ceil, "0", "0" }, |
422 | { &isl_val_neg, "1", "-1" }, |
423 | { &isl_val_neg, "-1", "1" }, |
424 | { &isl_val_neg, "1/2", "-1/2" }, |
425 | { &isl_val_neg, "-1/2", "1/2" }, |
426 | { &isl_val_neg, "infty", "-infty" }, |
427 | { &isl_val_neg, "-infty", "infty" }, |
428 | { &isl_val_neg, "NaN", "NaN" }, |
429 | { &isl_val_abs, "1", "1" }, |
430 | { &isl_val_abs, "-1", "1" }, |
431 | { &isl_val_abs, "1/2", "1/2" }, |
432 | { &isl_val_abs, "-1/2", "1/2" }, |
433 | { &isl_val_abs, "infty", "infty" }, |
434 | { &isl_val_abs, "-infty", "infty" }, |
435 | { &isl_val_abs, "NaN", "NaN" }, |
436 | { &isl_val_floor, "1", "1" }, |
437 | { &isl_val_floor, "-1", "-1" }, |
438 | { &isl_val_floor, "1/2", "0" }, |
439 | { &isl_val_floor, "-1/2", "-1" }, |
440 | { &isl_val_floor, "infty", "infty" }, |
441 | { &isl_val_floor, "-infty", "-infty" }, |
442 | { &isl_val_floor, "NaN", "NaN" }, |
443 | { &isl_val_ceil, "1", "1" }, |
444 | { &isl_val_ceil, "-1", "-1" }, |
445 | { &isl_val_ceil, "1/2", "1" }, |
446 | { &isl_val_ceil, "-1/2", "0" }, |
447 | { &isl_val_ceil, "infty", "infty" }, |
448 | { &isl_val_ceil, "-infty", "-infty" }, |
449 | { &isl_val_ceil, "NaN", "NaN" }, |
450 | { &isl_val_2exp, "-3", "1/8" }, |
451 | { &isl_val_2exp, "-1", "1/2" }, |
452 | { &isl_val_2exp, "1", "2" }, |
453 | { &isl_val_2exp, "2", "4" }, |
454 | { &isl_val_2exp, "3", "8" }, |
455 | { &isl_val_inv, "1", "1" }, |
456 | { &isl_val_inv, "2", "1/2" }, |
457 | { &isl_val_inv, "1/2", "2" }, |
458 | { &isl_val_inv, "-2", "-1/2" }, |
459 | { &isl_val_inv, "-1/2", "-2" }, |
460 | { &isl_val_inv, "0", "NaN" }, |
461 | { &isl_val_inv, "NaN", "NaN" }, |
462 | { &isl_val_inv, "infty", "0" }, |
463 | { &isl_val_inv, "-infty", "0" }, |
464 | }; |
465 | |
466 | /* Perform some basic tests of unary operations on isl_val objects. |
467 | */ |
468 | static int test_un_val(isl_ctx *ctx) |
469 | { |
470 | int i; |
471 | isl_val *v, *res; |
472 | __isl_give isl_val *(*fn)(__isl_take isl_val *v); |
473 | int ok; |
474 | |
475 | for (i = 0; i < ARRAY_SIZE(val_un_tests)(sizeof(val_un_tests)/sizeof(*val_un_tests)); ++i) { |
476 | v = isl_val_read_from_str(ctx, val_un_tests[i].arg); |
477 | res = isl_val_read_from_str(ctx, val_un_tests[i].res); |
478 | fn = val_un_tests[i].op; |
479 | v = fn(v); |
480 | if (isl_val_is_nan(res)) |
481 | ok = isl_val_is_nan(v); |
482 | else |
483 | ok = isl_val_eq(v, res); |
484 | isl_val_free(v); |
485 | isl_val_free(res); |
486 | if (ok < 0) |
487 | return -1; |
488 | if (!ok) |
489 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 490); return -1; } while (0) |
490 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 490); return -1; } while (0); |
491 | } |
492 | |
493 | return 0; |
494 | } |
495 | |
496 | struct { |
497 | __isl_give isl_val *(*fn)(__isl_take isl_val *v1, |
498 | __isl_take isl_val *v2); |
499 | } val_bin_op[] = { |
500 | ['+'] = { &isl_val_add }, |
501 | ['-'] = { &isl_val_sub }, |
502 | ['*'] = { &isl_val_mul }, |
503 | ['/'] = { &isl_val_div }, |
504 | ['g'] = { &isl_val_gcd }, |
505 | ['m'] = { &isl_val_min }, |
506 | ['M'] = { &isl_val_max }, |
507 | }; |
508 | |
509 | struct { |
510 | const char *arg1; |
511 | unsigned char op; |
512 | const char *arg2; |
513 | const char *res; |
514 | } val_bin_tests[] = { |
515 | { "0", '+', "0", "0" }, |
516 | { "1", '+', "0", "1" }, |
517 | { "1", '+', "1", "2" }, |
518 | { "1", '-', "1", "0" }, |
519 | { "1", '*', "1", "1" }, |
520 | { "1", '/', "1", "1" }, |
521 | { "2", '*', "3", "6" }, |
522 | { "2", '*', "1/2", "1" }, |
523 | { "2", '*', "1/3", "2/3" }, |
524 | { "2/3", '*', "3/5", "2/5" }, |
525 | { "2/3", '*', "7/5", "14/15" }, |
526 | { "2", '/', "1/2", "4" }, |
527 | { "-2", '/', "-1/2", "4" }, |
528 | { "-2", '/', "1/2", "-4" }, |
529 | { "2", '/', "-1/2", "-4" }, |
530 | { "2", '/', "2", "1" }, |
531 | { "2", '/', "3", "2/3" }, |
532 | { "2/3", '/', "5/3", "2/5" }, |
533 | { "2/3", '/', "5/7", "14/15" }, |
534 | { "0", '/', "0", "NaN" }, |
535 | { "42", '/', "0", "NaN" }, |
536 | { "-42", '/', "0", "NaN" }, |
537 | { "infty", '/', "0", "NaN" }, |
538 | { "-infty", '/', "0", "NaN" }, |
539 | { "NaN", '/', "0", "NaN" }, |
540 | { "0", '/', "NaN", "NaN" }, |
541 | { "42", '/', "NaN", "NaN" }, |
542 | { "-42", '/', "NaN", "NaN" }, |
543 | { "infty", '/', "NaN", "NaN" }, |
544 | { "-infty", '/', "NaN", "NaN" }, |
545 | { "NaN", '/', "NaN", "NaN" }, |
546 | { "0", '/', "infty", "0" }, |
547 | { "42", '/', "infty", "0" }, |
548 | { "-42", '/', "infty", "0" }, |
549 | { "infty", '/', "infty", "NaN" }, |
550 | { "-infty", '/', "infty", "NaN" }, |
551 | { "NaN", '/', "infty", "NaN" }, |
552 | { "0", '/', "-infty", "0" }, |
553 | { "42", '/', "-infty", "0" }, |
554 | { "-42", '/', "-infty", "0" }, |
555 | { "infty", '/', "-infty", "NaN" }, |
556 | { "-infty", '/', "-infty", "NaN" }, |
557 | { "NaN", '/', "-infty", "NaN" }, |
558 | { "1", '-', "1/3", "2/3" }, |
559 | { "1/3", '+', "1/2", "5/6" }, |
560 | { "1/2", '+', "1/2", "1" }, |
561 | { "3/4", '-', "1/4", "1/2" }, |
562 | { "1/2", '-', "1/3", "1/6" }, |
563 | { "infty", '+', "42", "infty" }, |
564 | { "infty", '+', "infty", "infty" }, |
565 | { "42", '+', "infty", "infty" }, |
566 | { "infty", '-', "infty", "NaN" }, |
567 | { "infty", '*', "infty", "infty" }, |
568 | { "infty", '*', "-infty", "-infty" }, |
569 | { "-infty", '*', "infty", "-infty" }, |
570 | { "-infty", '*', "-infty", "infty" }, |
571 | { "0", '*', "infty", "NaN" }, |
572 | { "1", '*', "infty", "infty" }, |
573 | { "infty", '*', "0", "NaN" }, |
574 | { "infty", '*', "42", "infty" }, |
575 | { "42", '-', "infty", "-infty" }, |
576 | { "infty", '+', "-infty", "NaN" }, |
577 | { "4", 'g', "6", "2" }, |
578 | { "5", 'g', "6", "1" }, |
579 | { "42", 'm', "3", "3" }, |
580 | { "42", 'M', "3", "42" }, |
581 | { "3", 'm', "42", "3" }, |
582 | { "3", 'M', "42", "42" }, |
583 | { "42", 'm', "infty", "42" }, |
584 | { "42", 'M', "infty", "infty" }, |
585 | { "42", 'm', "-infty", "-infty" }, |
586 | { "42", 'M', "-infty", "42" }, |
587 | { "42", 'm', "NaN", "NaN" }, |
588 | { "42", 'M', "NaN", "NaN" }, |
589 | { "infty", 'm', "-infty", "-infty" }, |
590 | { "infty", 'M', "-infty", "infty" }, |
591 | }; |
592 | |
593 | /* Perform some basic tests of binary operations on isl_val objects. |
594 | */ |
595 | static int test_bin_val(isl_ctx *ctx) |
596 | { |
597 | int i; |
598 | isl_val *v1, *v2, *res; |
599 | __isl_give isl_val *(*fn)(__isl_take isl_val *v1, |
600 | __isl_take isl_val *v2); |
601 | int ok; |
602 | |
603 | for (i = 0; i < ARRAY_SIZE(val_bin_tests)(sizeof(val_bin_tests)/sizeof(*val_bin_tests)); ++i) { |
604 | v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1); |
605 | v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2); |
606 | res = isl_val_read_from_str(ctx, val_bin_tests[i].res); |
607 | fn = val_bin_op[val_bin_tests[i].op].fn; |
608 | v1 = fn(v1, v2); |
609 | if (isl_val_is_nan(res)) |
610 | ok = isl_val_is_nan(v1); |
611 | else |
612 | ok = isl_val_eq(v1, res); |
613 | isl_val_free(v1); |
614 | isl_val_free(res); |
615 | if (ok < 0) |
616 | return -1; |
617 | if (!ok) |
618 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 619); return -1; } while (0) |
619 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 619); return -1; } while (0); |
620 | } |
621 | |
622 | return 0; |
623 | } |
624 | |
625 | /* Perform some basic tests on isl_val objects. |
626 | */ |
627 | static int test_val(isl_ctx *ctx) |
628 | { |
629 | if (test_un_val(ctx) < 0) |
630 | return -1; |
631 | if (test_bin_val(ctx) < 0) |
632 | return -1; |
633 | return 0; |
634 | } |
635 | |
636 | /* Sets described using existentially quantified variables that |
637 | * can also be described without. |
638 | */ |
639 | static const char *elimination_tests[] = { |
640 | "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }", |
641 | "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }", |
642 | "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }", |
643 | }; |
644 | |
645 | /* Check that redundant existentially quantified variables are |
646 | * getting removed. |
647 | */ |
648 | static int test_elimination(isl_ctx *ctx) |
649 | { |
650 | int i; |
651 | unsigned n; |
652 | isl_basic_setisl_basic_map *bset; |
653 | |
654 | for (i = 0; i < ARRAY_SIZE(elimination_tests)(sizeof(elimination_tests)/sizeof(*elimination_tests)); ++i) { |
655 | bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]); |
656 | n = isl_basic_set_dim(bset, isl_dim_div); |
657 | isl_basic_set_free(bset); |
658 | if (!bset) |
659 | return -1; |
660 | if (n != 0) |
661 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting no existentials" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 662); return -1; } while (0) |
662 | "expecting no existentials", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting no existentials" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 662); return -1; } while (0); |
663 | } |
664 | |
665 | return 0; |
666 | } |
667 | |
668 | static int test_div(isl_ctx *ctx) |
669 | { |
670 | const char *str; |
671 | int empty; |
672 | isl_int v; |
673 | isl_space *dim; |
674 | isl_setisl_map *set; |
675 | isl_local_space *ls; |
676 | struct isl_basic_setisl_basic_map *bset; |
677 | struct isl_constraint *c; |
678 | |
679 | isl_int_init(v)isl_sioimath_init((v)); |
680 | |
681 | /* test 1 */ |
682 | dim = isl_space_set_alloc(ctx, 0, 3); |
683 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
684 | ls = isl_local_space_from_space(dim); |
685 | |
686 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
687 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
688 | isl_constraint_set_constant(c, v); |
689 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
690 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
691 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
692 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
693 | bset = isl_basic_set_add_constraint(bset, c); |
694 | |
695 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
696 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
697 | isl_constraint_set_constant(c, v); |
698 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
699 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
700 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
701 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
702 | bset = isl_basic_set_add_constraint(bset, c); |
703 | |
704 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
705 | |
706 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 706, __PRETTY_FUNCTION__)); |
707 | isl_local_space_free(ls); |
708 | isl_basic_set_free(bset); |
709 | |
710 | /* test 2 */ |
711 | dim = isl_space_set_alloc(ctx, 0, 3); |
712 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
713 | ls = isl_local_space_from_space(dim); |
714 | |
715 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
716 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
717 | isl_constraint_set_constant(c, v); |
718 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
719 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
720 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
721 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
722 | bset = isl_basic_set_add_constraint(bset, c); |
723 | |
724 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
725 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
726 | isl_constraint_set_constant(c, v); |
727 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
728 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
729 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
730 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
731 | bset = isl_basic_set_add_constraint(bset, c); |
732 | |
733 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
734 | |
735 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 735, __PRETTY_FUNCTION__)); |
736 | isl_local_space_free(ls); |
737 | isl_basic_set_free(bset); |
738 | |
739 | /* test 3 */ |
740 | dim = isl_space_set_alloc(ctx, 0, 3); |
741 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
742 | ls = isl_local_space_from_space(dim); |
743 | |
744 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
745 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
746 | isl_constraint_set_constant(c, v); |
747 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
748 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
749 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
750 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
751 | bset = isl_basic_set_add_constraint(bset, c); |
752 | |
753 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
754 | isl_int_set_si(v, -3)isl_sioimath_set_si((v), -3); |
755 | isl_constraint_set_constant(c, v); |
756 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
757 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
758 | isl_int_set_si(v, 4)isl_sioimath_set_si((v), 4); |
759 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
760 | bset = isl_basic_set_add_constraint(bset, c); |
761 | |
762 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
763 | |
764 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 764, __PRETTY_FUNCTION__)); |
765 | isl_local_space_free(ls); |
766 | isl_basic_set_free(bset); |
767 | |
768 | /* test 4 */ |
769 | dim = isl_space_set_alloc(ctx, 0, 3); |
770 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
771 | ls = isl_local_space_from_space(dim); |
772 | |
773 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
774 | isl_int_set_si(v, 2)isl_sioimath_set_si((v), 2); |
775 | isl_constraint_set_constant(c, v); |
776 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
777 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
778 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
779 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
780 | bset = isl_basic_set_add_constraint(bset, c); |
781 | |
782 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
783 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
784 | isl_constraint_set_constant(c, v); |
785 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
786 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
787 | isl_int_set_si(v, 6)isl_sioimath_set_si((v), 6); |
788 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
789 | bset = isl_basic_set_add_constraint(bset, c); |
790 | |
791 | bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2); |
792 | |
793 | assert(isl_basic_set_is_empty(bset))((isl_basic_set_is_empty(bset)) ? (void) (0) : __assert_fail ( "isl_basic_set_is_empty(bset)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 793, __PRETTY_FUNCTION__)); |
794 | isl_local_space_free(ls); |
795 | isl_basic_set_free(bset); |
796 | |
797 | /* test 5 */ |
798 | dim = isl_space_set_alloc(ctx, 0, 3); |
799 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
800 | ls = isl_local_space_from_space(dim); |
801 | |
802 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
803 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
804 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
805 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
806 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
807 | bset = isl_basic_set_add_constraint(bset, c); |
808 | |
809 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
810 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
811 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
812 | isl_int_set_si(v, -3)isl_sioimath_set_si((v), -3); |
813 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
814 | bset = isl_basic_set_add_constraint(bset, c); |
815 | |
816 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
817 | |
818 | assert(bset && bset->n_div == 0)((bset && bset->n_div == 0) ? (void) (0) : __assert_fail ("bset && bset->n_div == 0", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 818, __PRETTY_FUNCTION__)); |
819 | isl_basic_set_free(bset); |
820 | isl_local_space_free(ls); |
821 | |
822 | /* test 6 */ |
823 | dim = isl_space_set_alloc(ctx, 0, 3); |
824 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
825 | ls = isl_local_space_from_space(dim); |
826 | |
827 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
828 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
829 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
830 | isl_int_set_si(v, 6)isl_sioimath_set_si((v), 6); |
831 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
832 | bset = isl_basic_set_add_constraint(bset, c); |
833 | |
834 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
835 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
836 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
837 | isl_int_set_si(v, -3)isl_sioimath_set_si((v), -3); |
838 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
839 | bset = isl_basic_set_add_constraint(bset, c); |
840 | |
841 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
842 | |
843 | assert(bset && bset->n_div == 1)((bset && bset->n_div == 1) ? (void) (0) : __assert_fail ("bset && bset->n_div == 1", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 843, __PRETTY_FUNCTION__)); |
844 | isl_basic_set_free(bset); |
845 | isl_local_space_free(ls); |
846 | |
847 | /* test 7 */ |
848 | /* This test is a bit tricky. We set up an equality |
849 | * a + 3b + 3c = 6 e0 |
850 | * Normalization of divs creates _two_ divs |
851 | * a = 3 e0 |
852 | * c - b - e0 = 2 e1 |
853 | * Afterwards e0 is removed again because it has coefficient -1 |
854 | * and we end up with the original equality and div again. |
855 | * Perhaps we can avoid the introduction of this temporary div. |
856 | */ |
857 | dim = isl_space_set_alloc(ctx, 0, 4); |
858 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
859 | ls = isl_local_space_from_space(dim); |
860 | |
861 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
862 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
863 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
864 | isl_int_set_si(v, -3)isl_sioimath_set_si((v), -3); |
865 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
866 | isl_int_set_si(v, -3)isl_sioimath_set_si((v), -3); |
867 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
868 | isl_int_set_si(v, 6)isl_sioimath_set_si((v), 6); |
869 | isl_constraint_set_coefficient(c, isl_dim_set, 3, v); |
870 | bset = isl_basic_set_add_constraint(bset, c); |
871 | |
872 | bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1); |
873 | |
874 | /* Test disabled for now */ |
875 | /* |
876 | assert(bset && bset->n_div == 1); |
877 | */ |
878 | isl_local_space_free(ls); |
879 | isl_basic_set_free(bset); |
880 | |
881 | /* test 8 */ |
882 | dim = isl_space_set_alloc(ctx, 0, 5); |
883 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
884 | ls = isl_local_space_from_space(dim); |
885 | |
886 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
887 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
888 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
889 | isl_int_set_si(v, -3)isl_sioimath_set_si((v), -3); |
890 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
891 | isl_int_set_si(v, -3)isl_sioimath_set_si((v), -3); |
892 | isl_constraint_set_coefficient(c, isl_dim_set, 3, v); |
893 | isl_int_set_si(v, 6)isl_sioimath_set_si((v), 6); |
894 | isl_constraint_set_coefficient(c, isl_dim_set, 4, v); |
895 | bset = isl_basic_set_add_constraint(bset, c); |
896 | |
897 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
898 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
899 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
900 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
901 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
902 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
903 | isl_constraint_set_constant(c, v); |
904 | bset = isl_basic_set_add_constraint(bset, c); |
905 | |
906 | bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1); |
907 | |
908 | /* Test disabled for now */ |
909 | /* |
910 | assert(bset && bset->n_div == 1); |
911 | */ |
912 | isl_local_space_free(ls); |
913 | isl_basic_set_free(bset); |
914 | |
915 | /* test 9 */ |
916 | dim = isl_space_set_alloc(ctx, 0, 4); |
917 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
918 | ls = isl_local_space_from_space(dim); |
919 | |
920 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
921 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
922 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
923 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
924 | isl_constraint_set_coefficient(c, isl_dim_set, 1, v); |
925 | isl_int_set_si(v, -2)isl_sioimath_set_si((v), -2); |
926 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
927 | bset = isl_basic_set_add_constraint(bset, c); |
928 | |
929 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
930 | isl_int_set_si(v, -1)isl_sioimath_set_si((v), -1); |
931 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
932 | isl_int_set_si(v, 3)isl_sioimath_set_si((v), 3); |
933 | isl_constraint_set_coefficient(c, isl_dim_set, 3, v); |
934 | isl_int_set_si(v, 2)isl_sioimath_set_si((v), 2); |
935 | isl_constraint_set_constant(c, v); |
936 | bset = isl_basic_set_add_constraint(bset, c); |
937 | |
938 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2); |
939 | |
940 | bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2); |
941 | |
942 | assert(!isl_basic_set_is_empty(bset))((!isl_basic_set_is_empty(bset)) ? (void) (0) : __assert_fail ("!isl_basic_set_is_empty(bset)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 942, __PRETTY_FUNCTION__)); |
943 | |
944 | isl_local_space_free(ls); |
945 | isl_basic_set_free(bset); |
946 | |
947 | /* test 10 */ |
948 | dim = isl_space_set_alloc(ctx, 0, 3); |
949 | bset = isl_basic_set_universe(isl_space_copy(dim)); |
950 | ls = isl_local_space_from_space(dim); |
951 | |
952 | c = isl_constraint_alloc_equality(isl_local_space_copy(ls)); |
953 | isl_int_set_si(v, 1)isl_sioimath_set_si((v), 1); |
954 | isl_constraint_set_coefficient(c, isl_dim_set, 0, v); |
955 | isl_int_set_si(v, -2)isl_sioimath_set_si((v), -2); |
956 | isl_constraint_set_coefficient(c, isl_dim_set, 2, v); |
957 | bset = isl_basic_set_add_constraint(bset, c); |
958 | |
959 | bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1); |
960 | |
961 | bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2); |
962 | |
963 | isl_local_space_free(ls); |
964 | isl_basic_set_free(bset); |
965 | |
966 | isl_int_clear(v)isl_sioimath_clear((v)); |
967 | |
968 | str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and " |
969 | "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }"; |
970 | set = isl_set_read_from_str(ctx, str); |
971 | set = isl_set_compute_divs(set); |
972 | isl_set_free(set); |
973 | if (!set) |
974 | return -1; |
975 | |
976 | if (test_elimination(ctx) < 0) |
977 | return -1; |
978 | |
979 | str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }"; |
980 | set = isl_set_read_from_str(ctx, str); |
981 | set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2); |
982 | set = isl_set_fix_si(set, isl_dim_set, 2, -3); |
983 | empty = isl_set_is_empty(set); |
984 | isl_set_free(set); |
985 | if (empty < 0) |
986 | return -1; |
987 | if (!empty) |
988 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as accurate as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 989); return -1; } while (0) |
989 | "result not as accurate as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as accurate as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 989); return -1; } while (0); |
990 | |
991 | return 0; |
992 | } |
993 | |
994 | void test_application_case(struct isl_ctx *ctx, const char *name) |
995 | { |
996 | char *filename; |
997 | FILE *input; |
998 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
999 | struct isl_basic_map *bmap; |
1000 | |
1001 | filename = get_filename(ctx, name, "omega"); |
1002 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1002, __PRETTY_FUNCTION__)); |
1003 | input = fopen(filename, "r"); |
1004 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1004, __PRETTY_FUNCTION__)); |
1005 | |
1006 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1007 | bmap = isl_basic_map_read_from_file(ctx, input); |
1008 | |
1009 | bset1 = isl_basic_set_apply(bset1, bmap); |
1010 | |
1011 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1012 | |
1013 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1013, __PRETTY_FUNCTION__)); |
1014 | |
1015 | isl_basic_set_free(bset1); |
1016 | isl_basic_set_free(bset2); |
1017 | free(filename); |
1018 | |
1019 | fclose(input); |
1020 | } |
1021 | |
1022 | static int test_application(isl_ctx *ctx) |
1023 | { |
1024 | test_application_case(ctx, "application"); |
1025 | test_application_case(ctx, "application2"); |
1026 | |
1027 | return 0; |
1028 | } |
1029 | |
1030 | void test_affine_hull_case(struct isl_ctx *ctx, const char *name) |
1031 | { |
1032 | char *filename; |
1033 | FILE *input; |
1034 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1035 | |
1036 | filename = get_filename(ctx, name, "polylib"); |
1037 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1037, __PRETTY_FUNCTION__)); |
1038 | input = fopen(filename, "r"); |
1039 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1039, __PRETTY_FUNCTION__)); |
1040 | |
1041 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1042 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1043 | |
1044 | bset1 = isl_basic_set_affine_hull(bset1); |
1045 | |
1046 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1046, __PRETTY_FUNCTION__)); |
1047 | |
1048 | isl_basic_set_free(bset1); |
1049 | isl_basic_set_free(bset2); |
1050 | free(filename); |
1051 | |
1052 | fclose(input); |
1053 | } |
1054 | |
1055 | int test_affine_hull(struct isl_ctx *ctx) |
1056 | { |
1057 | const char *str; |
1058 | isl_setisl_map *set; |
1059 | isl_basic_setisl_basic_map *bset, *bset2; |
1060 | int n; |
1061 | int subset; |
1062 | |
1063 | test_affine_hull_case(ctx, "affine2"); |
1064 | test_affine_hull_case(ctx, "affine"); |
1065 | test_affine_hull_case(ctx, "affine3"); |
1066 | |
1067 | str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and " |
1068 | "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and " |
1069 | "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and " |
1070 | "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }"; |
1071 | set = isl_set_read_from_str(ctx, str); |
1072 | bset = isl_set_affine_hull(set); |
1073 | n = isl_basic_set_dim(bset, isl_dim_div); |
1074 | isl_basic_set_free(bset); |
1075 | if (n != 0) |
1076 | isl_die(ctx, isl_error_unknown, "not expecting any divs",do { isl_handle_error(ctx, isl_error_unknown, "not expecting any divs" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1077); return -1; } while (0) |
1077 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "not expecting any divs" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1077); return -1; } while (0); |
1078 | |
1079 | /* Check that isl_map_affine_hull is not confused by |
1080 | * the reordering of divs in isl_map_align_divs. |
1081 | */ |
1082 | str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: " |
1083 | "32e0 = b and 32e1 = c); " |
1084 | "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }"; |
1085 | set = isl_set_read_from_str(ctx, str); |
1086 | bset = isl_set_affine_hull(set); |
1087 | isl_basic_set_free(bset); |
1088 | if (!bset) |
1089 | return -1; |
1090 | |
1091 | str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and " |
1092 | "32e2 = 31 + 31e0 }"; |
1093 | set = isl_set_read_from_str(ctx, str); |
1094 | bset = isl_set_affine_hull(set); |
1095 | str = "{ [a] : exists e : a = 32 e }"; |
1096 | bset2 = isl_basic_set_read_from_str(ctx, str); |
1097 | subset = isl_basic_set_is_subset(bset, bset2); |
1098 | isl_basic_set_free(bset); |
1099 | isl_basic_set_free(bset2); |
1100 | if (subset < 0) |
1101 | return -1; |
1102 | if (!subset) |
1103 | isl_die(ctx, isl_error_unknown, "not as accurate as expected",do { isl_handle_error(ctx, isl_error_unknown, "not as accurate as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1104); return -1; } while (0) |
1104 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "not as accurate as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1104); return -1; } while (0); |
1105 | |
1106 | return 0; |
1107 | } |
1108 | |
1109 | /* Pairs of maps and the corresponding expected results of |
1110 | * isl_map_plain_unshifted_simple_hull. |
1111 | */ |
1112 | struct { |
1113 | const char *map; |
1114 | const char *hull; |
1115 | } plain_unshifted_simple_hull_tests[] = { |
1116 | { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }", |
1117 | "{ [i] -> [j] : i >= 1 }" }, |
1118 | { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or " |
1119 | "(j mod 4 = 2 and k mod 6 = n) }", |
1120 | "{ [n] -> [i,j,k] : j mod 4 = 2 }" }, |
1121 | }; |
1122 | |
1123 | /* Basic tests for isl_map_plain_unshifted_simple_hull. |
1124 | */ |
1125 | static int test_plain_unshifted_simple_hull(isl_ctx *ctx) |
1126 | { |
1127 | int i; |
1128 | isl_map *map; |
1129 | isl_basic_map *hull, *expected; |
1130 | isl_bool equal; |
1131 | |
1132 | for (i = 0; i < ARRAY_SIZE(plain_unshifted_simple_hull_tests)(sizeof(plain_unshifted_simple_hull_tests)/sizeof(*plain_unshifted_simple_hull_tests )); ++i) { |
1133 | const char *str; |
1134 | str = plain_unshifted_simple_hull_tests[i].map; |
1135 | map = isl_map_read_from_str(ctx, str); |
1136 | str = plain_unshifted_simple_hull_tests[i].hull; |
1137 | expected = isl_basic_map_read_from_str(ctx, str); |
1138 | hull = isl_map_plain_unshifted_simple_hull(map); |
1139 | equal = isl_basic_map_is_equal(hull, expected); |
1140 | isl_basic_map_free(hull); |
1141 | isl_basic_map_free(expected); |
1142 | if (equal < 0) |
1143 | return -1; |
1144 | if (!equal) |
1145 | isl_die(ctx, isl_error_unknown, "unexpected hull",do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1146); return -1; } while (0) |
1146 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1146); return -1; } while (0); |
1147 | } |
1148 | |
1149 | return 0; |
1150 | } |
1151 | |
1152 | /* Pairs of sets and the corresponding expected results of |
1153 | * isl_set_unshifted_simple_hull. |
1154 | */ |
1155 | struct { |
1156 | const char *set; |
1157 | const char *hull; |
1158 | } unshifted_simple_hull_tests[] = { |
1159 | { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }", |
1160 | "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" }, |
1161 | }; |
1162 | |
1163 | /* Basic tests for isl_set_unshifted_simple_hull. |
1164 | */ |
1165 | static int test_unshifted_simple_hull(isl_ctx *ctx) |
1166 | { |
1167 | int i; |
1168 | isl_setisl_map *set; |
1169 | isl_basic_setisl_basic_map *hull, *expected; |
1170 | isl_bool equal; |
1171 | |
1172 | for (i = 0; i < ARRAY_SIZE(unshifted_simple_hull_tests)(sizeof(unshifted_simple_hull_tests)/sizeof(*unshifted_simple_hull_tests )); ++i) { |
1173 | const char *str; |
1174 | str = unshifted_simple_hull_tests[i].set; |
1175 | set = isl_set_read_from_str(ctx, str); |
1176 | str = unshifted_simple_hull_tests[i].hull; |
1177 | expected = isl_basic_set_read_from_str(ctx, str); |
1178 | hull = isl_set_unshifted_simple_hull(set); |
1179 | equal = isl_basic_set_is_equal(hull, expected); |
1180 | isl_basic_set_free(hull); |
1181 | isl_basic_set_free(expected); |
1182 | if (equal < 0) |
1183 | return -1; |
1184 | if (!equal) |
1185 | isl_die(ctx, isl_error_unknown, "unexpected hull",do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1186); return -1; } while (0) |
1186 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected hull" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1186); return -1; } while (0); |
1187 | } |
1188 | |
1189 | return 0; |
1190 | } |
1191 | |
1192 | static int test_simple_hull(struct isl_ctx *ctx) |
1193 | { |
1194 | const char *str; |
1195 | isl_setisl_map *set; |
1196 | isl_basic_setisl_basic_map *bset; |
1197 | isl_bool is_empty; |
1198 | |
1199 | str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;" |
1200 | "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }"; |
1201 | set = isl_set_read_from_str(ctx, str); |
1202 | bset = isl_set_simple_hull(set); |
1203 | is_empty = isl_basic_set_is_empty(bset); |
1204 | isl_basic_set_free(bset); |
1205 | |
1206 | if (is_empty == isl_bool_error) |
1207 | return -1; |
1208 | |
1209 | if (is_empty == isl_bool_false) |
1210 | isl_die(ctx, isl_error_unknown, "Empty set should be detected",do { isl_handle_error(ctx, isl_error_unknown, "Empty set should be detected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1211); return -1; } while (0) |
1211 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "Empty set should be detected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1211); return -1; } while (0); |
1212 | |
1213 | if (test_plain_unshifted_simple_hull(ctx) < 0) |
1214 | return -1; |
1215 | if (test_unshifted_simple_hull(ctx) < 0) |
1216 | return -1; |
1217 | |
1218 | return 0; |
1219 | } |
1220 | |
1221 | void test_convex_hull_case(struct isl_ctx *ctx, const char *name) |
1222 | { |
1223 | char *filename; |
1224 | FILE *input; |
1225 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1226 | struct isl_setisl_map *set; |
1227 | |
1228 | filename = get_filename(ctx, name, "polylib"); |
1229 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1229, __PRETTY_FUNCTION__)); |
1230 | input = fopen(filename, "r"); |
1231 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1231, __PRETTY_FUNCTION__)); |
1232 | |
1233 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1234 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1235 | |
1236 | set = isl_basic_set_union(bset1, bset2); |
1237 | bset1 = isl_set_convex_hull(set); |
1238 | |
1239 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1240 | |
1241 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1241, __PRETTY_FUNCTION__)); |
1242 | |
1243 | isl_basic_set_free(bset1); |
1244 | isl_basic_set_free(bset2); |
1245 | free(filename); |
1246 | |
1247 | fclose(input); |
1248 | } |
1249 | |
1250 | struct { |
1251 | const char *set; |
1252 | const char *hull; |
1253 | } convex_hull_tests[] = { |
1254 | { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or " |
1255 | "(i0 = 1 and i1 = 0 and i2 = 1) or " |
1256 | "(i0 = 0 and i1 = 0 and i2 = 0) }", |
1257 | "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" }, |
1258 | { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; " |
1259 | "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and " |
1260 | "i2 <= 5 and i2 >= 4; " |
1261 | "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }", |
1262 | "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and " |
1263 | "i2 <= 5 + i0 and i2 >= i0 }" }, |
1264 | { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }", |
1265 | "{ [x, y] : 1 = 0 }" }, |
1266 | }; |
1267 | |
1268 | static int test_convex_hull_algo(isl_ctx *ctx, int convex) |
1269 | { |
1270 | int i; |
1271 | int orig_convex = ctx->opt->convex; |
1272 | ctx->opt->convex = convex; |
1273 | |
1274 | test_convex_hull_case(ctx, "convex0"); |
1275 | test_convex_hull_case(ctx, "convex1"); |
1276 | test_convex_hull_case(ctx, "convex2"); |
1277 | test_convex_hull_case(ctx, "convex3"); |
1278 | test_convex_hull_case(ctx, "convex4"); |
1279 | test_convex_hull_case(ctx, "convex5"); |
1280 | test_convex_hull_case(ctx, "convex6"); |
1281 | test_convex_hull_case(ctx, "convex7"); |
1282 | test_convex_hull_case(ctx, "convex8"); |
1283 | test_convex_hull_case(ctx, "convex9"); |
1284 | test_convex_hull_case(ctx, "convex10"); |
1285 | test_convex_hull_case(ctx, "convex11"); |
1286 | test_convex_hull_case(ctx, "convex12"); |
1287 | test_convex_hull_case(ctx, "convex13"); |
1288 | test_convex_hull_case(ctx, "convex14"); |
1289 | test_convex_hull_case(ctx, "convex15"); |
1290 | |
1291 | for (i = 0; i < ARRAY_SIZE(convex_hull_tests)(sizeof(convex_hull_tests)/sizeof(*convex_hull_tests)); ++i) { |
1292 | isl_setisl_map *set1, *set2; |
1293 | int equal; |
1294 | |
1295 | set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set); |
1296 | set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull); |
1297 | set1 = isl_set_from_basic_set(isl_set_convex_hull(set1)); |
1298 | equal = isl_set_is_equal(set1, set2); |
1299 | isl_set_free(set1); |
1300 | isl_set_free(set2); |
1301 | |
1302 | if (equal < 0) |
1303 | return -1; |
1304 | if (!equal) |
1305 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected convex hull" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1306); return -1; } while (0) |
1306 | "unexpected convex hull", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected convex hull" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1306); return -1; } while (0); |
1307 | } |
1308 | |
1309 | ctx->opt->convex = orig_convex; |
1310 | |
1311 | return 0; |
1312 | } |
1313 | |
1314 | static int test_convex_hull(isl_ctx *ctx) |
1315 | { |
1316 | if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM1) < 0) |
1317 | return -1; |
1318 | if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP0) < 0) |
1319 | return -1; |
1320 | return 0; |
1321 | } |
1322 | |
1323 | void test_gist_case(struct isl_ctx *ctx, const char *name) |
1324 | { |
1325 | char *filename; |
1326 | FILE *input; |
1327 | struct isl_basic_setisl_basic_map *bset1, *bset2; |
1328 | |
1329 | filename = get_filename(ctx, name, "polylib"); |
1330 | assert(filename)((filename) ? (void) (0) : __assert_fail ("filename", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1330, __PRETTY_FUNCTION__)); |
1331 | input = fopen(filename, "r"); |
1332 | assert(input)((input) ? (void) (0) : __assert_fail ("input", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1332, __PRETTY_FUNCTION__)); |
1333 | |
1334 | bset1 = isl_basic_set_read_from_file(ctx, input); |
1335 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1336 | |
1337 | bset1 = isl_basic_set_gist(bset1, bset2); |
1338 | |
1339 | bset2 = isl_basic_set_read_from_file(ctx, input); |
1340 | |
1341 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1341, __PRETTY_FUNCTION__)); |
1342 | |
1343 | isl_basic_set_free(bset1); |
1344 | isl_basic_set_free(bset2); |
1345 | free(filename); |
1346 | |
1347 | fclose(input); |
1348 | } |
1349 | |
1350 | /* Inputs to isl_map_plain_gist_basic_map, along with the expected output. |
1351 | */ |
1352 | struct { |
1353 | const char *map; |
1354 | const char *context; |
1355 | const char *gist; |
1356 | } plain_gist_tests[] = { |
1357 | { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }", |
1358 | "{ [i] -> [j] : i >= 1 }", |
1359 | "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" }, |
1360 | { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or " |
1361 | "(j mod 4 = 2 and k mod 6 = n) }", |
1362 | "{ [n] -> [i,j,k] : j mod 4 = 2 }", |
1363 | "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" }, |
1364 | { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }", |
1365 | "{ [i] -> [j] : i > j }", |
1366 | "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" }, |
1367 | }; |
1368 | |
1369 | /* Basic tests for isl_map_plain_gist_basic_map. |
1370 | */ |
1371 | static int test_plain_gist(isl_ctx *ctx) |
1372 | { |
1373 | int i; |
1374 | |
1375 | for (i = 0; i < ARRAY_SIZE(plain_gist_tests)(sizeof(plain_gist_tests)/sizeof(*plain_gist_tests)); ++i) { |
1376 | const char *str; |
1377 | int equal; |
1378 | isl_map *map, *gist; |
1379 | isl_basic_map *context; |
1380 | |
1381 | map = isl_map_read_from_str(ctx, plain_gist_tests[i].map); |
1382 | str = plain_gist_tests[i].context; |
1383 | context = isl_basic_map_read_from_str(ctx, str); |
1384 | map = isl_map_plain_gist_basic_map(map, context); |
1385 | gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist); |
1386 | equal = isl_map_is_equal(map, gist); |
1387 | isl_map_free(map); |
1388 | isl_map_free(gist); |
1389 | if (equal < 0) |
1390 | return -1; |
1391 | if (!equal) |
1392 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1393); return -1; } while (0) |
1393 | "incorrect gist result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1393); return -1; } while (0); |
1394 | } |
1395 | |
1396 | return 0; |
1397 | } |
1398 | |
1399 | struct { |
1400 | const char *set; |
1401 | const char *context; |
1402 | const char *gist; |
1403 | } gist_tests[] = { |
1404 | { "{ [a, b, c] : a <= 15 and a >= 1 }", |
1405 | "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and " |
1406 | "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }", |
1407 | "{ [a, b, c] : a <= 15 }" }, |
1408 | { "{ : }", "{ : 1 = 0 }", "{ : }" }, |
1409 | { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" }, |
1410 | { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }", |
1411 | "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" }, |
1412 | { "{ [m, n, a, b] : a <= 2147 + n }", |
1413 | "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and " |
1414 | "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or " |
1415 | "(n >= 1 and a >= 0 and b <= 2148 - n - a and " |
1416 | "b >= 0) }", |
1417 | "{ [m, n, ku, kl] }" }, |
1418 | { "{ [a, a, b] : a >= 10 }", |
1419 | "{ [a, b, c] : c >= a and c <= b and c >= 2 }", |
1420 | "{ [a, a, b] : a >= 10 }" }, |
1421 | { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }", |
1422 | "{ [0, j] : j >= 0 }" }, |
1423 | /* Check that no constraints on i6 are introduced in the gist */ |
1424 | { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): " |
1425 | "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and " |
1426 | "5e0 <= 381 - t1 and i4 <= 1) }", |
1427 | "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): " |
1428 | "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }", |
1429 | "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): " |
1430 | "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and " |
1431 | "20e0 >= 1511 - 4t1 - 5i4) }" }, |
1432 | /* Check that no constraints on i6 are introduced in the gist */ |
1433 | { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), " |
1434 | "e1 = floor((1530 - 4t1 - 5i4)/20), " |
1435 | "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), " |
1436 | "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and " |
1437 | "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and " |
1438 | "2e0 <= 1 + i4 and 2e0 >= i4 and " |
1439 | "20e1 <= 1530 - 4t1 - 5i4 and " |
1440 | "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and " |
1441 | "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }", |
1442 | "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), " |
1443 | "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and " |
1444 | "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and " |
1445 | "10e0 <= -91 + 5i4 + 4i6 and " |
1446 | "10e0 >= -105 + 5i4 + 4i6) }", |
1447 | "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), " |
1448 | "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and " |
1449 | "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" }, |
1450 | { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }", |
1451 | "{ [a, b, q, p] : b >= 1 + a }", |
1452 | "{ [a, b, q, p] : false }" }, |
1453 | { "[n] -> { [x] : x = n && x mod 32 = 0 }", |
1454 | "[n] -> { [x] : x mod 32 = 0 }", |
1455 | "[n] -> { [x = n] }" }, |
1456 | { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }", |
1457 | "{ [x] : x mod 2 = 0 }" }, |
1458 | { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }", |
1459 | "{ [x] : x mod 128 = 0 }" }, |
1460 | { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }", |
1461 | "{ [x] : x mod 3200 = 0 }" }, |
1462 | { "{ [a, b, c] : a mod 2 = 0 and a = c }", |
1463 | "{ [a, b, c] : b mod 2 = 0 and b = c }", |
1464 | "{ [a, b, c = a] }" }, |
1465 | { "{ [a, b, c] : a mod 6 = 0 and a = c }", |
1466 | "{ [a, b, c] : b mod 2 = 0 and b = c }", |
1467 | "{ [a, b, c = a] : a mod 3 = 0 }" }, |
1468 | { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }", |
1469 | "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }", |
1470 | "{ [x] }" }, |
1471 | { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }", |
1472 | "{ [x,y] : 1 <= y <= 3 }", |
1473 | "{ [x,y] }" }, |
1474 | }; |
1475 | |
1476 | /* Check that isl_set_gist behaves as expected. |
1477 | * |
1478 | * For the test cases in gist_tests, besides checking that the result |
1479 | * is as expected, also check that applying the gist operation does |
1480 | * not modify the input set (an earlier version of isl would do that) and |
1481 | * that the test case is consistent, i.e., that the gist has the same |
1482 | * intersection with the context as the input set. |
1483 | */ |
1484 | static int test_gist(struct isl_ctx *ctx) |
1485 | { |
1486 | int i; |
1487 | const char *str; |
1488 | isl_basic_setisl_basic_map *bset1, *bset2; |
1489 | isl_map *map1, *map2; |
1490 | int equal; |
1491 | |
1492 | for (i = 0; i < ARRAY_SIZE(gist_tests)(sizeof(gist_tests)/sizeof(*gist_tests)); ++i) { |
1493 | int equal_input, equal_intersection; |
1494 | isl_setisl_map *set1, *set2, *copy, *context; |
1495 | |
1496 | set1 = isl_set_read_from_str(ctx, gist_tests[i].set); |
1497 | context = isl_set_read_from_str(ctx, gist_tests[i].context); |
1498 | copy = isl_set_copy(set1); |
1499 | set1 = isl_set_gist(set1, isl_set_copy(context)); |
1500 | set2 = isl_set_read_from_str(ctx, gist_tests[i].gist); |
1501 | equal = isl_set_is_equal(set1, set2); |
1502 | isl_set_free(set1); |
1503 | set1 = isl_set_read_from_str(ctx, gist_tests[i].set); |
1504 | equal_input = isl_set_is_equal(set1, copy); |
1505 | isl_set_free(copy); |
1506 | set1 = isl_set_intersect(set1, isl_set_copy(context)); |
1507 | set2 = isl_set_intersect(set2, context); |
1508 | equal_intersection = isl_set_is_equal(set1, set2); |
1509 | isl_set_free(set2); |
1510 | isl_set_free(set1); |
1511 | if (equal < 0 || equal_input < 0 || equal_intersection < 0) |
1512 | return -1; |
1513 | if (!equal) |
1514 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1515); return -1; } while (0) |
1515 | "incorrect gist result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1515); return -1; } while (0); |
1516 | if (!equal_input) |
1517 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "gist modified input" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1518); return -1; } while (0) |
1518 | "gist modified input", return -1)do { isl_handle_error(ctx, isl_error_unknown, "gist modified input" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1518); return -1; } while (0); |
1519 | if (!equal_input) |
1520 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1521); return -1; } while (0) |
1521 | "inconsistent gist test case", return -1)do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1521); return -1; } while (0); |
1522 | } |
1523 | |
1524 | test_gist_case(ctx, "gist1"); |
1525 | |
1526 | str = "[p0, p2, p3, p5, p6, p10] -> { [] : " |
1527 | "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], " |
1528 | "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], " |
1529 | "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and " |
1530 | "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and " |
1531 | "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and " |
1532 | "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and " |
1533 | "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and " |
1534 | "p10 <= 15 and p10 <= -1 + p0 - p6) }"; |
1535 | bset1 = isl_basic_set_read_from_str(ctx, str); |
1536 | str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], " |
1537 | "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], " |
1538 | "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and " |
1539 | "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and " |
1540 | "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and " |
1541 | "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and " |
1542 | "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and " |
1543 | "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }"; |
1544 | bset2 = isl_basic_set_read_from_str(ctx, str); |
1545 | bset1 = isl_basic_set_gist(bset1, bset2); |
1546 | assert(bset1 && bset1->n_div == 0)((bset1 && bset1->n_div == 0) ? (void) (0) : __assert_fail ("bset1 && bset1->n_div == 0", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1546, __PRETTY_FUNCTION__)); |
1547 | isl_basic_set_free(bset1); |
1548 | |
1549 | /* Check that the integer divisions of the second disjunct |
1550 | * do not spread to the first disjunct. |
1551 | */ |
1552 | str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: " |
1553 | "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or " |
1554 | "(exists (e0 = [(-1 + t1)/16], " |
1555 | "e1 = [(-16 + t1 - 16e0)/4294967296]: " |
1556 | "4294967296e1 = -16 + t1 - o0 - 16e0 and " |
1557 | "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and " |
1558 | "o0 <= 4294967295 and t1 <= -1)) }"; |
1559 | map1 = isl_map_read_from_str(ctx, str); |
1560 | str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }"; |
1561 | map2 = isl_map_read_from_str(ctx, str); |
1562 | map1 = isl_map_gist(map1, map2); |
1563 | if (!map1) |
1564 | return -1; |
1565 | if (map1->n != 1) |
1566 | isl_die(ctx, isl_error_unknown, "expecting single disjunct",do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1567); isl_map_free(map1); return -1; } while (0) |
1567 | isl_map_free(map1); return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1567); isl_map_free(map1); return -1; } while (0); |
1568 | if (isl_basic_map_dim(map1->p[0], isl_dim_div) != 1) |
1569 | isl_die(ctx, isl_error_unknown, "expecting single div",do { isl_handle_error(ctx, isl_error_unknown, "expecting single div" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1570); isl_map_free(map1); return -1; } while (0) |
1570 | isl_map_free(map1); return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single div" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1570); isl_map_free(map1); return -1; } while (0); |
1571 | isl_map_free(map1); |
1572 | |
1573 | if (test_plain_gist(ctx) < 0) |
1574 | return -1; |
1575 | |
1576 | return 0; |
1577 | } |
1578 | |
1579 | int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one) |
1580 | { |
1581 | isl_setisl_map *set, *set2; |
1582 | int equal; |
1583 | int one; |
1584 | |
1585 | set = isl_set_read_from_str(ctx, str); |
1586 | set = isl_set_coalesce(set); |
1587 | set2 = isl_set_read_from_str(ctx, str); |
1588 | equal = isl_set_is_equal(set, set2); |
1589 | one = set && set->n == 1; |
1590 | isl_set_free(set); |
1591 | isl_set_free(set2); |
1592 | |
1593 | if (equal < 0) |
1594 | return -1; |
1595 | if (!equal) |
1596 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "coalesced set not equal to input" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1597); return -1; } while (0) |
1597 | "coalesced set not equal to input", return -1)do { isl_handle_error(ctx, isl_error_unknown, "coalesced set not equal to input" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1597); return -1; } while (0); |
1598 | if (check_one && !one) |
1599 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "coalesced set should not be a union" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1600); return -1; } while (0) |
1600 | "coalesced set should not be a union", return -1)do { isl_handle_error(ctx, isl_error_unknown, "coalesced set should not be a union" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 1600); return -1; } while (0); |
1601 | |
1602 | return 0; |
1603 | } |
1604 | |
1605 | /* Inputs for coalescing tests with unbounded wrapping. |
1606 | * "str" is a string representation of the input set. |
1607 | * "single_disjunct" is set if we expect the result to consist of |
1608 | * a single disjunct. |
1609 | */ |
1610 | struct { |
1611 | int single_disjunct; |
1612 | const char *str; |
1613 | } coalesce_unbounded_tests[] = { |
1614 | { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and " |
1615 | "-x - y + 1 >= 0 and -3 <= z <= 3;" |
1616 | "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and " |
1617 | "x-z + 20 >= 0 and x+z + 20 >= 0 and " |
1618 | "-10 <= y <= 0}" }, |
1619 | { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" }, |
1620 | { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" }, |
1621 | { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" }, |
1622 | { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" }, |
1623 | }; |
1624 | |
1625 | /* Test the functionality of isl_set_coalesce with the bounded wrapping |
1626 | * option turned off. |
1627 | */ |
1628 | int test_coalesce_unbounded_wrapping(isl_ctx *ctx) |
1629 | { |
1630 | int i; |
1631 | int r = 0; |
1632 | int bounded; |
1633 | |
1634 | bounded = isl_options_get_coalesce_bounded_wrapping(ctx); |
1635 | isl_options_set_coalesce_bounded_wrapping(ctx, 0); |
1636 | |
1637 | for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests)(sizeof(coalesce_unbounded_tests)/sizeof(*coalesce_unbounded_tests )); ++i) { |
1638 | const char *str = coalesce_unbounded_tests[i].str; |
1639 | int check_one = coalesce_unbounded_tests[i].single_disjunct; |
1640 | if (test_coalesce_set(ctx, str, check_one) >= 0) |
1641 | continue; |
1642 | r = -1; |
1643 | break; |
1644 | } |
1645 | |
1646 | isl_options_set_coalesce_bounded_wrapping(ctx, bounded); |
1647 | |
1648 | return r; |
1649 | } |
1650 | |
1651 | /* Inputs for coalescing tests. |
1652 | * "str" is a string representation of the input set. |
1653 | * "single_disjunct" is set if we expect the result to consist of |
1654 | * a single disjunct. |
1655 | */ |
1656 | struct { |
1657 | int single_disjunct; |
1658 | const char *str; |
1659 | } coalesce_tests[] = { |
1660 | { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or " |
1661 | "y >= x & x >= 2 & 5 >= y }" }, |
1662 | { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or " |
1663 | "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" }, |
1664 | { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or " |
1665 | "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" }, |
1666 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
1667 | "y >= 0 & x >= 6 & x <= 10 & y <= x}" }, |
1668 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
1669 | "y >= 0 & x >= 7 & x <= 10 & y <= x}" }, |
1670 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or " |
1671 | "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" }, |
1672 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" }, |
1673 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" }, |
1674 | { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" }, |
1675 | { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" }, |
1676 | { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" }, |
1677 | { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" }, |
1678 | { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" }, |
1679 | { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], " |
1680 | "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], " |
1681 | "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and " |
1682 | "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and " |
1683 | "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and " |
1684 | "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and " |
1685 | "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and " |
1686 | "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);" |
1687 | "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], " |
1688 | "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], " |
1689 | "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and " |
1690 | "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and " |
1691 | "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and " |
1692 | "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and " |
1693 | "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and " |
1694 | "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and " |
1695 | "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and " |
1696 | "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" }, |
1697 | { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and " |
1698 | "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or " |
1699 | "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and " |
1700 | "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" }, |
1701 | { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> " |
1702 | "[o0, o1, o2, o3, o4, o5, o6]] : " |
1703 | "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and " |
1704 | "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and " |
1705 | "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and " |
1706 | "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 " |
1707 | "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and " |
1708 | "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 " |
1709 | "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and " |
1710 | "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 " |
1711 | "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or " |
1712 | "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and " |
1713 | "o6 >= i3 + i6 - o3 and M >= 0 and " |
1714 | "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and " |
1715 | "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" }, |
1716 | { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or " |
1717 | "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or " |
1718 | "(o0 = 0 and M >= 2 and N >= 3) or " |
1719 | "(M = 0 and o0 = 0 and N >= 3) }" }, |
1720 | { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and " |
1721 | "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or " |
1722 | "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and " |
1723 | "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" }, |
1724 | { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" }, |
1725 | { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" }, |
1726 | { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or " |
1727 | "(y = 3 and x = 1) }" }, |
1728 | { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and " |
1729 | "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and " |
1730 | "i1 <= M and i3 <= M and i4 <= M) or " |
1731 | "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and " |
1732 | "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and " |
1733 | "i4 <= -1 + M) }" }, |
1734 | { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or " |
1735 | "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" }, |
1736 | { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" }, |
1737 | { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" }, |
1738 | { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" }, |
1739 | { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" }, |
1740 | { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" }, |
1741 | { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" }, |
1742 | { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" }, |
1743 | { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" }, |
1744 | { 0, "{ [a, b] : exists e : 2e = a and " |
1745 | "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" }, |
1746 | { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and " |
1747 | "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and " |
1748 | "j >= 1 and j' <= i + j - i' and i >= 1; " |
1749 | "[1, 1, 1, 1] }" }, |
1750 | { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; " |
1751 | "[i,j] : exists a : j = 3a }" }, |
1752 | { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and " |
1753 | "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and " |
1754 | "a >= 3) or " |
1755 | "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and " |
1756 | "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" }, |
1757 | { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and " |
1758 | "c <= 6 + 8a and a >= 3; " |
1759 | "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and " |
1760 | "c <= 7 + 8a and a >= 3 and a <= 4 }" }, |
1761 | { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; " |
1762 | "[x,0] : 3 <= x <= 4 }" }, |
1763 | { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; " |
1764 | "[x,0] : 4 <= x <= 5 }" }, |
1765 | { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; " |
1766 | "[x,0] : 3 <= x <= 5 }" }, |
1767 | { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; " |
1768 | "[x,0] : 3 <= x <= 4 }" }, |
1769 | { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and " |
1770 | "i1 <= 0; " |
1771 | "[i0, 0] : i0 >= 123 and i0 <= 124 }" }, |
1772 | { 1, "{ [0,0]; [1,1] }" }, |
1773 | { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" }, |
1774 | { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and " |
1775 | "ii <= k;" |
1776 | "[k, 0, k] : k <= 6 and k >= 1 }" }, |
1777 | { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;" |
1778 | "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" }, |
1779 | { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" }, |
1780 | { 1, "[n] -> { [1] : n >= 0;" |
1781 | "[x] : exists (e0 = floor((x)/2): x >= 2 and " |
1782 | "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" }, |
1783 | { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): " |
1784 | "3e1 = y and x >= 2 and 2e0 >= -1 + x and " |
1785 | "2e0 <= x and 2e0 <= n);" |
1786 | "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and " |
1787 | "n >= 0) }" }, |
1788 | { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): " |
1789 | "128e0 >= -134 + 127t1 and t1 >= 2 and " |
1790 | "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or " |
1791 | "t1 = 1 }" }, |
1792 | { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and " |
1793 | "3e0 >= -1 + 2i and i <= 9 and i >= 1);" |
1794 | "[0, 0] }" }, |
1795 | { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and " |
1796 | "t1 >= 13 and t1 <= 16);" |
1797 | "[t1] : t1 <= 15 and t1 >= 12 }" }, |
1798 | { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" }, |
1799 | { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" }, |
1800 | { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" }, |
1801 | { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" }, |
1802 | { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;" |
1803 | "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and " |
1804 | "i <= 4j + 2 }" }, |
1805 | { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or " |
1806 | "(exists (e0 : 3e0 = -2 + c0)) }" }, |
1807 | { 0, "[n, b0, t0] -> " |
1808 | "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : " |
1809 | "(exists (e0 = floor((-32b0 + i4)/1048576), " |
1810 | "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and " |
1811 | "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and " |
1812 | "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and " |
1813 | "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and " |
1814 | "i8 >= -157 + i0 - 4i4 and i8 >= 0 and " |
1815 | "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or " |
1816 | "(exists (e0 = floor((-32b0 + i4)/1048576), " |
1817 | "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and " |
1818 | "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and " |
1819 | "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and " |
1820 | "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and " |
1821 | "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and " |
1822 | "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));" |
1823 | "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : " |
1824 | "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and " |
1825 | "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and " |
1826 | "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and " |
1827 | "i8 >= -40 + i0 and i8 <= -10 + i0)) }" }, |
1828 | { 0, "{ [i0, i1, i2] : " |
1829 | "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): " |
1830 | "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and " |
1831 | "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and " |
1832 | "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and " |
1833 | "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and " |
1834 | "32e0 <= 31 + i0)) or " |
1835 | "i0 >= 0 }" }, |
1836 | { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" }, |
1837 | { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and " |
1838 | "2*floor((c)/2) = c and 0 <= a <= 192;" |
1839 | "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }" |
1840 | }, |
1841 | { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or " |
1842 | "(0 <= a <= b <= n) }" }, |
1843 | { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and " |
1844 | "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" }, |
1845 | { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" }, |
1846 | { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and " |
1847 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
1848 | "(exists (e0 = floor((-16 + 2c)/9): a = 4 and " |
1849 | "b = 3 and 9e0 <= -19 + 2c)) }" }, |
1850 | { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or " |
1851 | "(b = -1 + a and 0 < a <= 3 and " |
1852 | "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or " |
1853 | "(exists (e0 = floor((-16 + 2c)/9): a = 4 and " |
1854 | "b = 3 and 9e0 <= -19 + 2c)) }" }, |
1855 | { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;" |
1856 | "[1, 0] }" }, |
1857 | { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;" |
1858 | "[0, 1] }" }, |
1859 | { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" }, |
1860 | { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" }, |
1861 | { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; " |
1862 | "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; " |
1863 | "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; " |
1864 | "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" }, |
1865 | { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; " |
1866 | "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; " |
1867 | "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" }, |
1868 | { 1, "{ [a] : a <= 8 and " |
1869 | "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" }, |
1870 | }; |
1871 | |
1872 | /* A specialized coalescing test case that would result |
1873 | * in a segmentation fault or a failed assertion in earlier versions of isl. |
1874 | */ |
1875 | static int test_coalesce_special(struct isl_ctx *ctx) |
1876 | { |
1877 | const char *str; |
1878 | isl_map *map1, *map2; |
1879 | |
1880 | str = "[y] -> { [S_L220_OUT[] -> T7[]] -> " |
1881 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : " |
1882 | "(y = 201 and o1 <= 239 and o1 >= 212) or " |
1883 | "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and " |
1884 | "o1 <= 239 and o1 >= 212)) or " |
1885 | "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and " |
1886 | "o1 <= 241 and o1 >= 240));" |
1887 | "[S_L220_OUT[] -> T7[]] -> " |
1888 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : " |
1889 | "(y = 2 and o1 <= 241 and o1 >= 212) or " |
1890 | "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and " |
1891 | "y >= 5 and o1 <= 241 and o1 >= 212)) }"; |
1892 | map1 = isl_map_read_from_str(ctx, str); |
1893 | map1 = isl_map_align_divs(map1); |
1894 | map1 = isl_map_coalesce(map1); |
1895 | str = "[y] -> { [S_L220_OUT[] -> T7[]] -> " |
1896 | "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : " |
1897 | "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and " |
1898 | "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and " |
1899 | "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }"; |
1900 | map2 = isl_map_read_from_str(ctx, str); |
1901 | map2 = isl_map_union(map2, map1); |
1902 | map2 = isl_map_align_divs(map2); |
1903 | map2 = isl_map_coalesce(map2); |
1904 | isl_map_free(map2); |
1905 | if (!map2) |
1906 | return -1; |
1907 | |
1908 | return 0; |
1909 | } |
1910 | |
1911 | /* A specialized coalescing test case that would result in an assertion |
1912 | * in an earlier version of isl. |
1913 | * The explicit call to isl_basic_set_union prevents the implicit |
1914 | * equality constraints in the first basic map from being detected prior |
1915 | * to the call to isl_set_coalesce, at least at the point |
1916 | * where this test case was introduced. |
1917 | */ |
1918 | static int test_coalesce_special2(struct isl_ctx *ctx) |
1919 | { |
1920 | const char *str; |
1921 | isl_basic_setisl_basic_map *bset1, *bset2; |
1922 | isl_setisl_map *set; |
1923 | |
1924 | str = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }"; |
1925 | bset1 = isl_basic_set_read_from_str(ctx, str); |
1926 | str = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ; |
1927 | bset2 = isl_basic_set_read_from_str(ctx, str); |
1928 | set = isl_basic_set_union(bset1, bset2); |
1929 | set = isl_set_coalesce(set); |
1930 | isl_set_free(set); |
1931 | |
1932 | if (!set) |
1933 | return -1; |
1934 | return 0; |
1935 | } |
1936 | |
1937 | /* Test the functionality of isl_set_coalesce. |
1938 | * That is, check that the output is always equal to the input |
1939 | * and in some cases that the result consists of a single disjunct. |
1940 | */ |
1941 | static int test_coalesce(struct isl_ctx *ctx) |
1942 | { |
1943 | int i; |
1944 | |
1945 | for (i = 0; i < ARRAY_SIZE(coalesce_tests)(sizeof(coalesce_tests)/sizeof(*coalesce_tests)); ++i) { |
1946 | const char *str = coalesce_tests[i].str; |
1947 | int check_one = coalesce_tests[i].single_disjunct; |
1948 | if (test_coalesce_set(ctx, str, check_one) < 0) |
1949 | return -1; |
1950 | } |
1951 | |
1952 | if (test_coalesce_unbounded_wrapping(ctx) < 0) |
1953 | return -1; |
1954 | if (test_coalesce_special(ctx) < 0) |
1955 | return -1; |
1956 | if (test_coalesce_special2(ctx) < 0) |
1957 | return -1; |
1958 | |
1959 | return 0; |
1960 | } |
1961 | |
1962 | /* Construct a representation of the graph on the right of Figure 1 |
1963 | * in "Computing the Transitive Closure of a Union of |
1964 | * Affine Integer Tuple Relations". |
1965 | */ |
1966 | static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx) |
1967 | { |
1968 | isl_setisl_map *dom; |
1969 | isl_map *up, *right; |
1970 | |
1971 | dom = isl_set_read_from_str(ctx, |
1972 | "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and " |
1973 | "2 x - 3 y + 3 >= 0 }"); |
1974 | right = isl_map_read_from_str(ctx, |
1975 | "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }"); |
1976 | up = isl_map_read_from_str(ctx, |
1977 | "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }"); |
1978 | right = isl_map_intersect_domain(right, isl_set_copy(dom)); |
1979 | right = isl_map_intersect_range(right, isl_set_copy(dom)); |
1980 | up = isl_map_intersect_domain(up, isl_set_copy(dom)); |
1981 | up = isl_map_intersect_range(up, dom); |
1982 | return isl_map_union(up, right); |
1983 | } |
1984 | |
1985 | /* Construct a representation of the power of the graph |
1986 | * on the right of Figure 1 in "Computing the Transitive Closure of |
1987 | * a Union of Affine Integer Tuple Relations". |
1988 | */ |
1989 | static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx) |
1990 | { |
1991 | return isl_map_read_from_str(ctx, |
1992 | "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; " |
1993 | " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; " |
1994 | " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }"); |
1995 | } |
1996 | |
1997 | /* Construct a representation of the transitive closure of the graph |
1998 | * on the right of Figure 1 in "Computing the Transitive Closure of |
1999 | * a Union of Affine Integer Tuple Relations". |
2000 | */ |
2001 | static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx) |
2002 | { |
2003 | return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx))); |
2004 | } |
2005 | |
2006 | static int test_closure(isl_ctx *ctx) |
2007 | { |
2008 | const char *str; |
2009 | isl_map *map, *map2; |
2010 | int exact, equal; |
2011 | |
2012 | /* COCOA example 1 */ |
2013 | map = isl_map_read_from_str(ctx, |
2014 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and " |
2015 | "1 <= i and i < n and 1 <= j and j < n or " |
2016 | "i2 = i + 1 and j2 = j - 1 and " |
2017 | "1 <= i and i < n and 2 <= j and j <= n }"); |
2018 | map = isl_map_power(map, &exact); |
2019 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2019, __PRETTY_FUNCTION__)); |
2020 | isl_map_free(map); |
2021 | |
2022 | /* COCOA example 1 */ |
2023 | map = isl_map_read_from_str(ctx, |
2024 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and " |
2025 | "1 <= i and i < n and 1 <= j and j < n or " |
2026 | "i2 = i + 1 and j2 = j - 1 and " |
2027 | "1 <= i and i < n and 2 <= j and j <= n }"); |
2028 | map = isl_map_transitive_closure(map, &exact); |
2029 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2029, __PRETTY_FUNCTION__)); |
2030 | map2 = isl_map_read_from_str(ctx, |
2031 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : " |
2032 | "1 <= i and i < n and 1 <= j and j <= n and " |
2033 | "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and " |
2034 | "i2 = i + k1 + k2 and j2 = j + k1 - k2 and " |
2035 | "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}"); |
2036 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2036, __PRETTY_FUNCTION__)); |
2037 | isl_map_free(map2); |
2038 | isl_map_free(map); |
2039 | |
2040 | map = isl_map_read_from_str(ctx, |
2041 | "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and " |
2042 | " 0 <= y and y <= n }"); |
2043 | map = isl_map_transitive_closure(map, &exact); |
2044 | map2 = isl_map_read_from_str(ctx, |
2045 | "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and " |
2046 | " 0 <= y and y <= n }"); |
2047 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2047, __PRETTY_FUNCTION__)); |
2048 | isl_map_free(map2); |
2049 | isl_map_free(map); |
2050 | |
2051 | /* COCOA example 2 */ |
2052 | map = isl_map_read_from_str(ctx, |
2053 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and " |
2054 | "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or " |
2055 | "i2 = i + 2 and j2 = j - 2 and " |
2056 | "1 <= i and i < n - 1 and 3 <= j and j <= n }"); |
2057 | map = isl_map_transitive_closure(map, &exact); |
2058 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2058, __PRETTY_FUNCTION__)); |
2059 | map2 = isl_map_read_from_str(ctx, |
2060 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : " |
2061 | "1 <= i and i < n - 1 and 1 <= j and j <= n and " |
2062 | "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and " |
2063 | "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and " |
2064 | "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }"); |
2065 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2065, __PRETTY_FUNCTION__)); |
2066 | isl_map_free(map); |
2067 | isl_map_free(map2); |
2068 | |
2069 | /* COCOA Fig.2 left */ |
2070 | map = isl_map_read_from_str(ctx, |
2071 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and " |
2072 | "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and " |
2073 | "j <= n or " |
2074 | "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and " |
2075 | "j <= 2 i - 3 and j <= n - 2 or " |
2076 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2077 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2078 | map = isl_map_transitive_closure(map, &exact); |
2079 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2079, __PRETTY_FUNCTION__)); |
2080 | isl_map_free(map); |
2081 | |
2082 | /* COCOA Fig.2 right */ |
2083 | map = isl_map_read_from_str(ctx, |
2084 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and " |
2085 | "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and " |
2086 | "j <= n or " |
2087 | "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and " |
2088 | "j <= 2 i - 4 and j <= n - 3 or " |
2089 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2090 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2091 | map = isl_map_power(map, &exact); |
2092 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2092, __PRETTY_FUNCTION__)); |
2093 | isl_map_free(map); |
2094 | |
2095 | /* COCOA Fig.2 right */ |
2096 | map = isl_map_read_from_str(ctx, |
2097 | "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and " |
2098 | "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and " |
2099 | "j <= n or " |
2100 | "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and " |
2101 | "j <= 2 i - 4 and j <= n - 3 or " |
2102 | "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and " |
2103 | "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }"); |
2104 | map = isl_map_transitive_closure(map, &exact); |
2105 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2105, __PRETTY_FUNCTION__)); |
2106 | map2 = isl_map_read_from_str(ctx, |
2107 | "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : " |
2108 | "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and " |
2109 | "j <= n and 3 + i + 2 j <= 3 n and " |
2110 | "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and " |
2111 | "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and " |
2112 | "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and " |
2113 | "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and " |
2114 | "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }"); |
2115 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2115, __PRETTY_FUNCTION__)); |
2116 | isl_map_free(map2); |
2117 | isl_map_free(map); |
2118 | |
2119 | map = cocoa_fig_1_right_graph(ctx); |
2120 | map = isl_map_transitive_closure(map, &exact); |
2121 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2121, __PRETTY_FUNCTION__)); |
2122 | map2 = cocoa_fig_1_right_tc(ctx); |
2123 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2123, __PRETTY_FUNCTION__)); |
2124 | isl_map_free(map2); |
2125 | isl_map_free(map); |
2126 | |
2127 | map = cocoa_fig_1_right_graph(ctx); |
2128 | map = isl_map_power(map, &exact); |
2129 | map2 = cocoa_fig_1_right_power(ctx); |
2130 | equal = isl_map_is_equal(map, map2); |
2131 | isl_map_free(map2); |
2132 | isl_map_free(map); |
2133 | if (equal < 0) |
2134 | return -1; |
2135 | if (!exact) |
2136 | isl_die(ctx, isl_error_unknown, "power not exact", return -1)do { isl_handle_error(ctx, isl_error_unknown, "power not exact" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2136); return -1; } while (0); |
2137 | if (!equal) |
2138 | isl_die(ctx, isl_error_unknown, "unexpected power", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected power" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2138); return -1; } while (0); |
2139 | |
2140 | /* COCOA Theorem 1 counter example */ |
2141 | map = isl_map_read_from_str(ctx, |
2142 | "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and " |
2143 | "i2 = 1 and j2 = j or " |
2144 | "i = 0 and j = 0 and i2 = 0 and j2 = 1 }"); |
2145 | map = isl_map_transitive_closure(map, &exact); |
2146 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2146, __PRETTY_FUNCTION__)); |
2147 | isl_map_free(map); |
2148 | |
2149 | map = isl_map_read_from_str(ctx, |
2150 | "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and " |
2151 | "1 <= i,i2 <= n and 1 <= j,j2 <= m or " |
2152 | "i2 = i + 1 and 3 <= j2 - j <= 4 and " |
2153 | "1 <= i,i2 <= n and 1 <= j,j2 <= m }"); |
2154 | map = isl_map_transitive_closure(map, &exact); |
2155 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2155, __PRETTY_FUNCTION__)); |
2156 | isl_map_free(map); |
2157 | |
2158 | /* Kelly et al 1996, fig 12 */ |
2159 | map = isl_map_read_from_str(ctx, |
2160 | "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and " |
2161 | "1 <= i,j,j+1 <= n or " |
2162 | "j = n and j2 = 1 and i2 = i + 1 and " |
2163 | "1 <= i,i+1 <= n }"); |
2164 | map = isl_map_transitive_closure(map, &exact); |
2165 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2165, __PRETTY_FUNCTION__)); |
2166 | map2 = isl_map_read_from_str(ctx, |
2167 | "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and " |
2168 | "1 <= i <= n and i = i2 or " |
2169 | "1 <= i < i2 <= n and 1 <= j <= n and " |
2170 | "1 <= j2 <= n }"); |
2171 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2171, __PRETTY_FUNCTION__)); |
2172 | isl_map_free(map2); |
2173 | isl_map_free(map); |
2174 | |
2175 | /* Omega's closure4 */ |
2176 | map = isl_map_read_from_str(ctx, |
2177 | "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and " |
2178 | "1 <= x,y <= 10 or " |
2179 | "x2 = x + 1 and y2 = y and " |
2180 | "1 <= x <= 20 && 5 <= y <= 15 }"); |
2181 | map = isl_map_transitive_closure(map, &exact); |
2182 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2182, __PRETTY_FUNCTION__)); |
2183 | isl_map_free(map); |
2184 | |
2185 | map = isl_map_read_from_str(ctx, |
2186 | "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }"); |
2187 | map = isl_map_transitive_closure(map, &exact); |
2188 | assert(!exact)((!exact) ? (void) (0) : __assert_fail ("!exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2188, __PRETTY_FUNCTION__)); |
2189 | map2 = isl_map_read_from_str(ctx, |
2190 | "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }"); |
2191 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2191, __PRETTY_FUNCTION__)); |
2192 | isl_map_free(map); |
2193 | isl_map_free(map2); |
2194 | |
2195 | str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : " |
2196 | "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and " |
2197 | "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and " |
2198 | "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }"; |
2199 | map = isl_map_read_from_str(ctx, str); |
2200 | map = isl_map_transitive_closure(map, &exact); |
2201 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2201, __PRETTY_FUNCTION__)); |
2202 | map2 = isl_map_read_from_str(ctx, str); |
2203 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2203, __PRETTY_FUNCTION__)); |
2204 | isl_map_free(map); |
2205 | isl_map_free(map2); |
2206 | |
2207 | str = "{[0] -> [1]; [2] -> [3]}"; |
2208 | map = isl_map_read_from_str(ctx, str); |
2209 | map = isl_map_transitive_closure(map, &exact); |
2210 | assert(exact)((exact) ? (void) (0) : __assert_fail ("exact", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2210, __PRETTY_FUNCTION__)); |
2211 | map2 = isl_map_read_from_str(ctx, str); |
2212 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2212, __PRETTY_FUNCTION__)); |
2213 | isl_map_free(map); |
2214 | isl_map_free(map2); |
2215 | |
2216 | str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> " |
2217 | "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : " |
2218 | "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and " |
2219 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2220 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2221 | "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> " |
2222 | "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : " |
2223 | "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and " |
2224 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2225 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2226 | "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> " |
2227 | "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : " |
2228 | "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and " |
2229 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2230 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); " |
2231 | "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> " |
2232 | "[[i0, i1, 1, 0, i0] -> [i5, 1]] : " |
2233 | "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and " |
2234 | "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and " |
2235 | "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }"; |
2236 | map = isl_map_read_from_str(ctx, str); |
2237 | map = isl_map_transitive_closure(map, NULL((void*)0)); |
2238 | assert(map)((map) ? (void) (0) : __assert_fail ("map", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2238, __PRETTY_FUNCTION__)); |
2239 | isl_map_free(map); |
2240 | |
2241 | return 0; |
2242 | } |
2243 | |
2244 | static int test_lex(struct isl_ctx *ctx) |
2245 | { |
2246 | isl_space *dim; |
2247 | isl_map *map; |
2248 | int empty; |
2249 | |
2250 | dim = isl_space_set_alloc(ctx, 0, 0); |
2251 | map = isl_map_lex_le(dim); |
2252 | empty = isl_map_is_empty(map); |
2253 | isl_map_free(map); |
2254 | |
2255 | if (empty < 0) |
2256 | return -1; |
2257 | if (empty) |
2258 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2259); return -1; } while (0) |
2259 | "expecting non-empty result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2259); return -1; } while (0); |
2260 | |
2261 | return 0; |
2262 | } |
2263 | |
2264 | /* Inputs for isl_map_lexmin tests. |
2265 | * "map" is the input and "lexmin" is the expected result. |
2266 | */ |
2267 | struct { |
2268 | const char *map; |
2269 | const char *lexmin; |
2270 | } lexmin_tests [] = { |
2271 | { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }", |
2272 | "{ [x] -> [5] : 6 <= x <= 8; " |
2273 | "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" }, |
2274 | { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }", |
2275 | "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" }, |
2276 | { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }", |
2277 | "{ [x] -> [y] : (4y = x and x >= 0) or " |
2278 | "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and " |
2279 | "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or " |
2280 | "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" }, |
2281 | { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }", |
2282 | "{ T[a] -> S[b, c] : 2b = a and 2c = a }" }, |
2283 | /* Check that empty pieces are properly combined. */ |
2284 | { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and " |
2285 | "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and " |
2286 | "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }", |
2287 | "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and " |
2288 | "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and " |
2289 | "x >= 4 }" }, |
2290 | { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and " |
2291 | "a <= 255 and c <= 255 and d <= 255 - j and " |
2292 | "255 - j <= 7d <= 7 - i and 240d <= 239 + a and " |
2293 | "247d <= 247 + k - j and 247d <= 247 + k - b and " |
2294 | "247d <= 247 + i and 248 - b <= 248d <= c and " |
2295 | "254d >= i - a + b and 254d >= -a + b and " |
2296 | "255d >= -i + a - b and 1792d >= -63736 + 257b }", |
2297 | "{ [i, k, j] -> " |
2298 | "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : " |
2299 | "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and " |
2300 | "247j >= 62738 - i and 509j <= 129795 + i and " |
2301 | "742j >= 188724 - i; " |
2302 | "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" }, |
2303 | { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and " |
2304 | "16*floor((8 + b)/16) <= 7 + b; " |
2305 | "[a] -> [1] }", |
2306 | "{ [a] -> [b = 1] : a >= 510 or a <= 0; " |
2307 | "[a] -> [b = 0] : 0 < a <= 509 }" }, |
2308 | { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" }, |
2309 | { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" }, |
2310 | }; |
2311 | |
2312 | static int test_lexmin(struct isl_ctx *ctx) |
2313 | { |
2314 | int i; |
2315 | int equal; |
2316 | const char *str; |
2317 | isl_basic_map *bmap; |
2318 | isl_map *map, *map2; |
2319 | isl_setisl_map *set; |
2320 | isl_setisl_map *set2; |
2321 | isl_pw_multi_aff *pma; |
2322 | |
2323 | str = "[p0, p1] -> { [] -> [] : " |
2324 | "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], " |
2325 | "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: " |
2326 | "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and " |
2327 | "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and " |
2328 | "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and " |
2329 | "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and " |
2330 | "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and " |
2331 | "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and " |
2332 | "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and " |
2333 | "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and " |
2334 | "e2 <= e1 and e3 >= 1 and e4 <= e2) }"; |
2335 | map = isl_map_read_from_str(ctx, str); |
2336 | map = isl_map_lexmin(map); |
2337 | isl_map_free(map); |
2338 | |
2339 | str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and " |
2340 | "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }"; |
2341 | set = isl_set_read_from_str(ctx, str); |
2342 | set = isl_set_lexmax(set); |
2343 | str = "[C] -> { [obj,a,b,c] : C = 8 }"; |
2344 | set2 = isl_set_read_from_str(ctx, str); |
2345 | set = isl_set_intersect(set, set2); |
2346 | assert(!isl_set_is_empty(set))((!isl_set_is_empty(set)) ? (void) (0) : __assert_fail ("!isl_set_is_empty(set)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2346, __PRETTY_FUNCTION__)); |
2347 | isl_set_free(set); |
2348 | |
2349 | for (i = 0; i < ARRAY_SIZE(lexmin_tests)(sizeof(lexmin_tests)/sizeof(*lexmin_tests)); ++i) { |
2350 | map = isl_map_read_from_str(ctx, lexmin_tests[i].map); |
2351 | map = isl_map_lexmin(map); |
2352 | map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin); |
2353 | equal = isl_map_is_equal(map, map2); |
2354 | isl_map_free(map); |
2355 | isl_map_free(map2); |
2356 | |
2357 | if (equal < 0) |
2358 | return -1; |
2359 | if (!equal) |
2360 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2361); return -1; } while (0) |
2361 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2361); return -1; } while (0); |
2362 | } |
2363 | |
2364 | str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and " |
2365 | " 8i' <= i and 8i' >= -7 + i }"; |
2366 | bmap = isl_basic_map_read_from_str(ctx, str); |
2367 | pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap)); |
2368 | map2 = isl_map_from_pw_multi_aff(pma); |
2369 | map = isl_map_from_basic_map(bmap); |
2370 | assert(isl_map_is_equal(map, map2))((isl_map_is_equal(map, map2)) ? (void) (0) : __assert_fail ( "isl_map_is_equal(map, map2)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2370, __PRETTY_FUNCTION__)); |
2371 | isl_map_free(map); |
2372 | isl_map_free(map2); |
2373 | |
2374 | str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and " |
2375 | " 8i' <= i and 8i' >= -7 + i }"; |
2376 | set = isl_set_read_from_str(ctx, str); |
2377 | pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set)); |
2378 | set2 = isl_set_from_pw_multi_aff(pma); |
2379 | equal = isl_set_is_equal(set, set2); |
2380 | isl_set_free(set); |
2381 | isl_set_free(set2); |
2382 | if (equal < 0) |
2383 | return -1; |
2384 | if (!equal) |
2385 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2387); return -1; } while (0) |
2386 | "unexpected difference between set and "do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2387); return -1; } while (0) |
2387 | "piecewise affine expression", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected difference between set and " "piecewise affine expression", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2387); return -1; } while (0); |
2388 | |
2389 | return 0; |
2390 | } |
2391 | |
2392 | /* A specialized isl_set_min_val test case that would return the wrong result |
2393 | * in earlier versions of isl. |
2394 | * The explicit call to isl_basic_set_union prevents the second basic set |
2395 | * from being determined to be empty prior to the call to isl_set_min_val, |
2396 | * at least at the point where this test case was introduced. |
2397 | */ |
2398 | static int test_min_special(isl_ctx *ctx) |
2399 | { |
2400 | const char *str; |
2401 | isl_basic_setisl_basic_map *bset1, *bset2; |
2402 | isl_setisl_map *set; |
2403 | isl_aff *obj; |
2404 | isl_val *res; |
2405 | int ok; |
2406 | |
2407 | str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }"; |
2408 | bset1 = isl_basic_set_read_from_str(ctx, str); |
2409 | str = "{ [a, b] : 1 <= a, b and a + b <= 1 }"; |
2410 | bset2 = isl_basic_set_read_from_str(ctx, str); |
2411 | set = isl_basic_set_union(bset1, bset2); |
2412 | obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }"); |
2413 | |
2414 | res = isl_set_min_val(set, obj); |
2415 | ok = isl_val_cmp_si(res, 5) == 0; |
2416 | |
2417 | isl_aff_free(obj); |
2418 | isl_set_free(set); |
2419 | isl_val_free(res); |
2420 | |
2421 | if (!res) |
2422 | return -1; |
2423 | if (!ok) |
2424 | isl_die(ctx, isl_error_unknown, "unexpected minimum",do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2425); return -1; } while (0) |
2425 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2425); return -1; } while (0); |
2426 | |
2427 | return 0; |
2428 | } |
2429 | |
2430 | struct { |
2431 | const char *set; |
2432 | const char *obj; |
2433 | __isl_give isl_val *(*fn)(__isl_keep isl_setisl_map *set, |
2434 | __isl_keep isl_aff *obj); |
2435 | const char *res; |
2436 | } opt_tests[] = { |
2437 | { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" }, |
2438 | { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" }, |
2439 | { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}", |
2440 | "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }", |
2441 | &isl_set_max_val, "30" }, |
2442 | |
2443 | }; |
2444 | |
2445 | /* Perform basic isl_set_min_val and isl_set_max_val tests. |
2446 | * In particular, check the results on non-convex inputs. |
2447 | */ |
2448 | static int test_min(struct isl_ctx *ctx) |
2449 | { |
2450 | int i; |
2451 | isl_setisl_map *set; |
2452 | isl_aff *obj; |
2453 | isl_val *val, *res; |
2454 | isl_bool ok; |
2455 | |
2456 | for (i = 0; i < ARRAY_SIZE(opt_tests)(sizeof(opt_tests)/sizeof(*opt_tests)); ++i) { |
2457 | set = isl_set_read_from_str(ctx, opt_tests[i].set); |
2458 | obj = isl_aff_read_from_str(ctx, opt_tests[i].obj); |
2459 | res = isl_val_read_from_str(ctx, opt_tests[i].res); |
2460 | val = opt_tests[i].fn(set, obj); |
2461 | ok = isl_val_eq(res, val); |
2462 | isl_val_free(res); |
2463 | isl_val_free(val); |
2464 | isl_aff_free(obj); |
2465 | isl_set_free(set); |
2466 | |
2467 | if (ok < 0) |
2468 | return -1; |
2469 | if (!ok) |
2470 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2471); return -1; } while (0) |
2471 | "unexpected optimum", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2471); return -1; } while (0); |
2472 | } |
2473 | |
2474 | if (test_min_special(ctx) < 0) |
2475 | return -1; |
2476 | |
2477 | return 0; |
2478 | } |
2479 | |
2480 | struct must_may { |
2481 | isl_map *must; |
2482 | isl_map *may; |
2483 | }; |
2484 | |
2485 | static isl_stat collect_must_may(__isl_take isl_map *dep, int must, |
2486 | void *dep_user, void *user) |
2487 | { |
2488 | struct must_may *mm = (struct must_may *)user; |
2489 | |
2490 | if (must) |
2491 | mm->must = isl_map_union(mm->must, dep); |
2492 | else |
2493 | mm->may = isl_map_union(mm->may, dep); |
2494 | |
2495 | return isl_stat_ok; |
2496 | } |
2497 | |
2498 | static int common_space(void *first, void *second) |
2499 | { |
2500 | int depth = *(int *)first; |
2501 | return 2 * depth; |
2502 | } |
2503 | |
2504 | static int map_is_equal(__isl_keep isl_map *map, const char *str) |
2505 | { |
2506 | isl_map *map2; |
2507 | int equal; |
2508 | |
2509 | if (!map) |
2510 | return -1; |
2511 | |
2512 | map2 = isl_map_read_from_str(map->ctx, str); |
2513 | equal = isl_map_is_equal(map, map2); |
2514 | isl_map_free(map2); |
2515 | |
2516 | return equal; |
2517 | } |
2518 | |
2519 | static int map_check_equal(__isl_keep isl_map *map, const char *str) |
2520 | { |
2521 | int equal; |
2522 | |
2523 | equal = map_is_equal(map, str); |
2524 | if (equal < 0) |
2525 | return -1; |
2526 | if (!equal) |
2527 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2528); return -1; } while (0) |
2528 | "result not as expected", return -1)do { isl_handle_error(isl_map_get_ctx(map), isl_error_unknown , "result not as expected", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2528); return -1; } while (0); |
2529 | return 0; |
2530 | } |
2531 | |
2532 | static int test_dep(struct isl_ctx *ctx) |
2533 | { |
2534 | const char *str; |
2535 | isl_space *dim; |
2536 | isl_map *map; |
2537 | isl_access_info *ai; |
2538 | isl_flow *flow; |
2539 | int depth; |
2540 | struct must_may mm; |
2541 | |
2542 | depth = 3; |
2543 | |
2544 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
2545 | map = isl_map_read_from_str(ctx, str); |
2546 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2547 | |
2548 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2549 | map = isl_map_read_from_str(ctx, str); |
2550 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
2551 | |
2552 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
2553 | map = isl_map_read_from_str(ctx, str); |
2554 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
2555 | |
2556 | flow = isl_access_info_compute_flow(ai); |
2557 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2558 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2559 | mm.may = isl_map_empty(dim); |
2560 | |
2561 | isl_flow_foreach(flow, collect_must_may, &mm); |
2562 | |
2563 | str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); " |
2564 | " [1,10,0] -> [2,5,0] }"; |
2565 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2565, __PRETTY_FUNCTION__)); |
2566 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
2567 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2567, __PRETTY_FUNCTION__)); |
2568 | |
2569 | isl_map_free(mm.must); |
2570 | isl_map_free(mm.may); |
2571 | isl_flow_free(flow); |
2572 | |
2573 | |
2574 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
2575 | map = isl_map_read_from_str(ctx, str); |
2576 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2577 | |
2578 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2579 | map = isl_map_read_from_str(ctx, str); |
2580 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
2581 | |
2582 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
2583 | map = isl_map_read_from_str(ctx, str); |
2584 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2585 | |
2586 | flow = isl_access_info_compute_flow(ai); |
2587 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2588 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2589 | mm.may = isl_map_empty(dim); |
2590 | |
2591 | isl_flow_foreach(flow, collect_must_may, &mm); |
2592 | |
2593 | str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }"; |
2594 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2594, __PRETTY_FUNCTION__)); |
2595 | str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }"; |
2596 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2596, __PRETTY_FUNCTION__)); |
2597 | |
2598 | isl_map_free(mm.must); |
2599 | isl_map_free(mm.may); |
2600 | isl_flow_free(flow); |
2601 | |
2602 | |
2603 | str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; |
2604 | map = isl_map_read_from_str(ctx, str); |
2605 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2606 | |
2607 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2608 | map = isl_map_read_from_str(ctx, str); |
2609 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2610 | |
2611 | str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; |
2612 | map = isl_map_read_from_str(ctx, str); |
2613 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2614 | |
2615 | flow = isl_access_info_compute_flow(ai); |
2616 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2617 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2618 | mm.may = isl_map_empty(dim); |
2619 | |
2620 | isl_flow_foreach(flow, collect_must_may, &mm); |
2621 | |
2622 | str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; " |
2623 | " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }"; |
2624 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2624, __PRETTY_FUNCTION__)); |
2625 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
2626 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2626, __PRETTY_FUNCTION__)); |
2627 | |
2628 | isl_map_free(mm.must); |
2629 | isl_map_free(mm.may); |
2630 | isl_flow_free(flow); |
2631 | |
2632 | |
2633 | str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }"; |
2634 | map = isl_map_read_from_str(ctx, str); |
2635 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2636 | |
2637 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2638 | map = isl_map_read_from_str(ctx, str); |
2639 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2640 | |
2641 | str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }"; |
2642 | map = isl_map_read_from_str(ctx, str); |
2643 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2644 | |
2645 | flow = isl_access_info_compute_flow(ai); |
2646 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2647 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2648 | mm.may = isl_map_empty(dim); |
2649 | |
2650 | isl_flow_foreach(flow, collect_must_may, &mm); |
2651 | |
2652 | str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; " |
2653 | " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }"; |
2654 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2654, __PRETTY_FUNCTION__)); |
2655 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
2656 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2656, __PRETTY_FUNCTION__)); |
2657 | |
2658 | isl_map_free(mm.must); |
2659 | isl_map_free(mm.may); |
2660 | isl_flow_free(flow); |
2661 | |
2662 | |
2663 | str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }"; |
2664 | map = isl_map_read_from_str(ctx, str); |
2665 | ai = isl_access_info_alloc(map, &depth, &common_space, 2); |
2666 | |
2667 | str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; |
2668 | map = isl_map_read_from_str(ctx, str); |
2669 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2670 | |
2671 | str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }"; |
2672 | map = isl_map_read_from_str(ctx, str); |
2673 | ai = isl_access_info_add_source(ai, map, 0, &depth); |
2674 | |
2675 | flow = isl_access_info_compute_flow(ai); |
2676 | dim = isl_space_alloc(ctx, 0, 3, 3); |
2677 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2678 | mm.may = isl_map_empty(dim); |
2679 | |
2680 | isl_flow_foreach(flow, collect_must_may, &mm); |
2681 | |
2682 | str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; " |
2683 | " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }"; |
2684 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2684, __PRETTY_FUNCTION__)); |
2685 | str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }"; |
2686 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2686, __PRETTY_FUNCTION__)); |
2687 | |
2688 | isl_map_free(mm.must); |
2689 | isl_map_free(mm.may); |
2690 | isl_flow_free(flow); |
2691 | |
2692 | |
2693 | depth = 5; |
2694 | |
2695 | str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }"; |
2696 | map = isl_map_read_from_str(ctx, str); |
2697 | ai = isl_access_info_alloc(map, &depth, &common_space, 1); |
2698 | |
2699 | str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }"; |
2700 | map = isl_map_read_from_str(ctx, str); |
2701 | ai = isl_access_info_add_source(ai, map, 1, &depth); |
2702 | |
2703 | flow = isl_access_info_compute_flow(ai); |
2704 | dim = isl_space_alloc(ctx, 0, 5, 5); |
2705 | mm.must = isl_map_empty(isl_space_copy(dim)); |
2706 | mm.may = isl_map_empty(dim); |
2707 | |
2708 | isl_flow_foreach(flow, collect_must_may, &mm); |
2709 | |
2710 | str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }"; |
2711 | assert(map_is_equal(mm.must, str))((map_is_equal(mm.must, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.must, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2711, __PRETTY_FUNCTION__)); |
2712 | str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }"; |
2713 | assert(map_is_equal(mm.may, str))((map_is_equal(mm.may, str)) ? (void) (0) : __assert_fail ("map_is_equal(mm.may, str)" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2713, __PRETTY_FUNCTION__)); |
2714 | |
2715 | isl_map_free(mm.must); |
2716 | isl_map_free(mm.may); |
2717 | isl_flow_free(flow); |
2718 | |
2719 | return 0; |
2720 | } |
2721 | |
2722 | /* Check that the dependence analysis proceeds without errors. |
2723 | * Earlier versions of isl would break down during the analysis |
2724 | * due to the use of the wrong spaces. |
2725 | */ |
2726 | static int test_flow(isl_ctx *ctx) |
2727 | { |
2728 | const char *str; |
2729 | isl_union_map *access, *schedule; |
2730 | isl_union_map *must_dep, *may_dep; |
2731 | int r; |
2732 | |
2733 | str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }"; |
2734 | access = isl_union_map_read_from_str(ctx, str); |
2735 | str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; " |
2736 | "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; " |
2737 | "S2[] -> [1,0,0,0]; " |
2738 | "S3[] -> [-1,0,0,0] }"; |
2739 | schedule = isl_union_map_read_from_str(ctx, str); |
2740 | r = isl_union_map_compute_flow(access, isl_union_map_copy(access), |
2741 | isl_union_map_copy(access), schedule, |
2742 | &must_dep, &may_dep, NULL((void*)0), NULL((void*)0)); |
2743 | isl_union_map_free(may_dep); |
2744 | isl_union_map_free(must_dep); |
2745 | |
2746 | return r; |
2747 | } |
2748 | |
2749 | struct { |
2750 | const char *map; |
2751 | int sv; |
2752 | } sv_tests[] = { |
2753 | { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 }, |
2754 | { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 }, |
2755 | { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 }, |
2756 | { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 }, |
2757 | { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 }, |
2758 | { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 }, |
2759 | { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 }, |
2760 | { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 }, |
2761 | { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 }, |
2762 | }; |
2763 | |
2764 | int test_sv(isl_ctx *ctx) |
2765 | { |
2766 | isl_union_map *umap; |
2767 | int i; |
2768 | int sv; |
2769 | |
2770 | for (i = 0; i < ARRAY_SIZE(sv_tests)(sizeof(sv_tests)/sizeof(*sv_tests)); ++i) { |
2771 | umap = isl_union_map_read_from_str(ctx, sv_tests[i].map); |
2772 | sv = isl_union_map_is_single_valued(umap); |
2773 | isl_union_map_free(umap); |
2774 | if (sv < 0) |
2775 | return -1; |
2776 | if (sv_tests[i].sv && !sv) |
2777 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as single valued" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2778); return -1; } while (0) |
2778 | "map not detected as single valued", return -1)do { isl_handle_error(ctx, isl_error_internal, "map not detected as single valued" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2778); return -1; } while (0); |
2779 | if (!sv_tests[i].sv && sv) |
2780 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2781); return -1; } while (0) |
2781 | "map detected as single valued", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2781); return -1; } while (0); |
2782 | } |
2783 | |
2784 | return 0; |
2785 | } |
2786 | |
2787 | struct { |
2788 | const char *str; |
2789 | int bijective; |
2790 | } bijective_tests[] = { |
2791 | { "[N,M]->{[i,j] -> [i]}", 0 }, |
2792 | { "[N,M]->{[i,j] -> [i] : j=i}", 1 }, |
2793 | { "[N,M]->{[i,j] -> [i] : j=0}", 1 }, |
2794 | { "[N,M]->{[i,j] -> [i] : j=N}", 1 }, |
2795 | { "[N,M]->{[i,j] -> [j,i]}", 1 }, |
2796 | { "[N,M]->{[i,j] -> [i+j]}", 0 }, |
2797 | { "[N,M]->{[i,j] -> []}", 0 }, |
2798 | { "[N,M]->{[i,j] -> [i,j,N]}", 1 }, |
2799 | { "[N,M]->{[i,j] -> [2i]}", 0 }, |
2800 | { "[N,M]->{[i,j] -> [i,i]}", 0 }, |
2801 | { "[N,M]->{[i,j] -> [2i,i]}", 0 }, |
2802 | { "[N,M]->{[i,j] -> [2i,j]}", 1 }, |
2803 | { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 }, |
2804 | }; |
2805 | |
2806 | static int test_bijective(struct isl_ctx *ctx) |
2807 | { |
2808 | isl_map *map; |
2809 | int i; |
2810 | int bijective; |
2811 | |
2812 | for (i = 0; i < ARRAY_SIZE(bijective_tests)(sizeof(bijective_tests)/sizeof(*bijective_tests)); ++i) { |
2813 | map = isl_map_read_from_str(ctx, bijective_tests[i].str); |
2814 | bijective = isl_map_is_bijective(map); |
2815 | isl_map_free(map); |
2816 | if (bijective < 0) |
2817 | return -1; |
2818 | if (bijective_tests[i].bijective && !bijective) |
2819 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2820); return -1; } while (0) |
2820 | "map not detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2820); return -1; } while (0); |
2821 | if (!bijective_tests[i].bijective && bijective) |
2822 | isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2823); return -1; } while (0) |
2823 | "map detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2823); return -1; } while (0); |
2824 | } |
2825 | |
2826 | return 0; |
2827 | } |
2828 | |
2829 | /* Inputs for isl_pw_qpolynomial_gist tests. |
2830 | * "pwqp" is the input, "set" is the context and "gist" is the expected result. |
2831 | */ |
2832 | struct { |
2833 | const char *pwqp; |
2834 | const char *set; |
2835 | const char *gist; |
2836 | } pwqp_gist_tests[] = { |
2837 | { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" }, |
2838 | { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" }, |
2839 | { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }", |
2840 | "{ [i] -> -1/2 + 1/2 * i }" }, |
2841 | { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" }, |
2842 | }; |
2843 | |
2844 | static int test_pwqp(struct isl_ctx *ctx) |
2845 | { |
2846 | int i; |
2847 | const char *str; |
2848 | isl_setisl_map *set; |
2849 | isl_pw_qpolynomial *pwqp1, *pwqp2; |
2850 | int equal; |
2851 | |
2852 | str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }"; |
2853 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2854 | |
2855 | pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0, |
2856 | isl_dim_in, 1, 1); |
2857 | |
2858 | str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }"; |
2859 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2860 | |
2861 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
2862 | |
2863 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2863, __PRETTY_FUNCTION__)); |
2864 | |
2865 | isl_pw_qpolynomial_free(pwqp1); |
2866 | |
2867 | for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests)(sizeof(pwqp_gist_tests)/sizeof(*pwqp_gist_tests)); ++i) { |
2868 | str = pwqp_gist_tests[i].pwqp; |
2869 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2870 | str = pwqp_gist_tests[i].set; |
2871 | set = isl_set_read_from_str(ctx, str); |
2872 | pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set); |
2873 | str = pwqp_gist_tests[i].gist; |
2874 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2875 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
2876 | equal = isl_pw_qpolynomial_is_zero(pwqp1); |
2877 | isl_pw_qpolynomial_free(pwqp1); |
2878 | |
2879 | if (equal < 0) |
2880 | return -1; |
2881 | if (!equal) |
2882 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2883); return -1; } while (0) |
2883 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2883); return -1; } while (0); |
2884 | } |
2885 | |
2886 | str = "{ [i] -> ([([i/2] + [i/2])/5]) }"; |
2887 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2888 | str = "{ [i] -> ([(2 * [i/2])/5]) }"; |
2889 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2890 | |
2891 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
2892 | |
2893 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2893, __PRETTY_FUNCTION__)); |
2894 | |
2895 | isl_pw_qpolynomial_free(pwqp1); |
2896 | |
2897 | str = "{ [x] -> ([x/2] + [(x+1)/2]) }"; |
2898 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2899 | str = "{ [x] -> x }"; |
2900 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2901 | |
2902 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
2903 | |
2904 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2904, __PRETTY_FUNCTION__)); |
2905 | |
2906 | isl_pw_qpolynomial_free(pwqp1); |
2907 | |
2908 | str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }"; |
2909 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2910 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2911 | pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1); |
2912 | pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2); |
2913 | assert(isl_pw_qpolynomial_is_zero(pwqp1))((isl_pw_qpolynomial_is_zero(pwqp1)) ? (void) (0) : __assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2913, __PRETTY_FUNCTION__)); |
2914 | isl_pw_qpolynomial_free(pwqp1); |
2915 | |
2916 | str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }"; |
2917 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2918 | str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }"; |
2919 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2920 | set = isl_set_read_from_str(ctx, "{ [a,b,a] }"); |
2921 | pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set); |
2922 | equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2); |
2923 | isl_pw_qpolynomial_free(pwqp1); |
2924 | isl_pw_qpolynomial_free(pwqp2); |
2925 | if (equal < 0) |
2926 | return -1; |
2927 | if (!equal) |
2928 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2928); return -1; } while (0); |
2929 | |
2930 | str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }"; |
2931 | pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2932 | str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }"; |
2933 | pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); |
2934 | pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1, |
2935 | isl_val_one(ctx)); |
2936 | equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2); |
2937 | isl_pw_qpolynomial_free(pwqp1); |
2938 | isl_pw_qpolynomial_free(pwqp2); |
2939 | if (equal < 0) |
2940 | return -1; |
2941 | if (!equal) |
2942 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2942); return -1; } while (0); |
2943 | |
2944 | return 0; |
2945 | } |
2946 | |
2947 | static int test_split_periods(isl_ctx *ctx) |
2948 | { |
2949 | const char *str; |
2950 | isl_pw_qpolynomial *pwqp; |
2951 | |
2952 | str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : " |
2953 | "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and " |
2954 | "U >= 0; [U,V] -> U^2 : U >= 100 }"; |
2955 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
2956 | |
2957 | pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2); |
2958 | |
2959 | isl_pw_qpolynomial_free(pwqp); |
2960 | |
2961 | if (!pwqp) |
2962 | return -1; |
2963 | |
2964 | return 0; |
2965 | } |
2966 | |
2967 | static int test_union(isl_ctx *ctx) |
2968 | { |
2969 | const char *str; |
2970 | isl_union_set *uset1, *uset2; |
2971 | isl_union_map *umap1, *umap2; |
2972 | int equal; |
2973 | |
2974 | str = "{ [i] : 0 <= i <= 1 }"; |
2975 | uset1 = isl_union_set_read_from_str(ctx, str); |
2976 | str = "{ [1] -> [0] }"; |
2977 | umap1 = isl_union_map_read_from_str(ctx, str); |
2978 | |
2979 | umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1); |
2980 | equal = isl_union_map_is_equal(umap1, umap2); |
2981 | |
2982 | isl_union_map_free(umap1); |
2983 | isl_union_map_free(umap2); |
2984 | |
2985 | if (equal < 0) |
2986 | return -1; |
2987 | if (!equal) |
2988 | isl_die(ctx, isl_error_unknown, "union maps not equal",do { isl_handle_error(ctx, isl_error_unknown, "union maps not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2989); return -1; } while (0) |
2989 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "union maps not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 2989); return -1; } while (0); |
2990 | |
2991 | str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }"; |
2992 | umap1 = isl_union_map_read_from_str(ctx, str); |
2993 | str = "{ A[i]; B[i] }"; |
2994 | uset1 = isl_union_set_read_from_str(ctx, str); |
2995 | |
2996 | uset2 = isl_union_map_domain(umap1); |
2997 | |
2998 | equal = isl_union_set_is_equal(uset1, uset2); |
2999 | |
3000 | isl_union_set_free(uset1); |
3001 | isl_union_set_free(uset2); |
3002 | |
3003 | if (equal < 0) |
3004 | return -1; |
3005 | if (!equal) |
3006 | isl_die(ctx, isl_error_unknown, "union sets not equal",do { isl_handle_error(ctx, isl_error_unknown, "union sets not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3007); return -1; } while (0) |
3007 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "union sets not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3007); return -1; } while (0); |
3008 | |
3009 | return 0; |
3010 | } |
3011 | |
3012 | /* Check that computing a bound of a non-zero polynomial over an unbounded |
3013 | * domain does not produce a rational value. |
3014 | * In particular, check that the upper bound is infinity. |
3015 | */ |
3016 | static int test_bound_unbounded_domain(isl_ctx *ctx) |
3017 | { |
3018 | const char *str; |
3019 | isl_pw_qpolynomial *pwqp; |
3020 | isl_pw_qpolynomial_fold *pwf, *pwf2; |
3021 | isl_bool equal; |
3022 | |
3023 | str = "{ [m,n] -> -m * n }"; |
3024 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3025 | pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3026 | str = "{ infty }"; |
3027 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3028 | pwf2 = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3029 | equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf, pwf2); |
3030 | isl_pw_qpolynomial_fold_free(pwf); |
3031 | isl_pw_qpolynomial_fold_free(pwf2); |
3032 | |
3033 | if (equal < 0) |
3034 | return -1; |
3035 | if (!equal) |
3036 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting infinite polynomial bound" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3037); return -1; } while (0) |
3037 | "expecting infinite polynomial bound", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting infinite polynomial bound" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3037); return -1; } while (0); |
3038 | |
3039 | return 0; |
3040 | } |
3041 | |
3042 | static int test_bound(isl_ctx *ctx) |
3043 | { |
3044 | const char *str; |
3045 | unsigned dim; |
3046 | isl_pw_qpolynomial *pwqp; |
3047 | isl_pw_qpolynomial_fold *pwf; |
3048 | |
3049 | if (test_bound_unbounded_domain(ctx) < 0) |
3050 | return -1; |
3051 | |
3052 | str = "{ [[a, b, c, d] -> [e]] -> 0 }"; |
3053 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3054 | pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3055 | dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in); |
3056 | isl_pw_qpolynomial_fold_free(pwf); |
3057 | if (dim != 4) |
3058 | isl_die(ctx, isl_error_unknown, "unexpected input dimension",do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3059); return -1; } while (0) |
3059 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3059); return -1; } while (0); |
3060 | |
3061 | str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }"; |
3062 | pwqp = isl_pw_qpolynomial_read_from_str(ctx, str); |
3063 | pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0)); |
3064 | dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in); |
3065 | isl_pw_qpolynomial_fold_free(pwf); |
3066 | if (dim != 1) |
3067 | isl_die(ctx, isl_error_unknown, "unexpected input dimension",do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3068); return -1; } while (0) |
3068 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3068); return -1; } while (0); |
3069 | |
3070 | return 0; |
3071 | } |
3072 | |
3073 | static int test_lift(isl_ctx *ctx) |
3074 | { |
3075 | const char *str; |
3076 | isl_basic_map *bmap; |
3077 | isl_basic_setisl_basic_map *bset; |
3078 | |
3079 | str = "{ [i0] : exists e0 : i0 = 4e0 }"; |
3080 | bset = isl_basic_set_read_from_str(ctx, str); |
3081 | bset = isl_basic_set_lift(bset); |
3082 | bmap = isl_basic_map_from_range(bset); |
3083 | bset = isl_basic_map_domain(bmap); |
3084 | isl_basic_set_free(bset); |
3085 | |
3086 | return 0; |
3087 | } |
3088 | |
3089 | struct { |
3090 | const char *set1; |
3091 | const char *set2; |
3092 | int subset; |
3093 | } subset_tests[] = { |
3094 | { "{ [112, 0] }", |
3095 | "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: " |
3096 | "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and " |
3097 | "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 }, |
3098 | { "{ [65] }", |
3099 | "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], " |
3100 | "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], " |
3101 | "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: " |
3102 | "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and " |
3103 | "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and " |
3104 | "256e0 <= 255i and 256e0 >= -255 + 255i and " |
3105 | "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and " |
3106 | "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and " |
3107 | "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 }, |
3108 | { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 }, |
3109 | { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 }, |
3110 | { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 }, |
3111 | { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 }, |
3112 | { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and " |
3113 | "4e0 >= -1 + t and i >= 57 and i <= 62 and " |
3114 | "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and " |
3115 | "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and " |
3116 | "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }", |
3117 | "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and " |
3118 | "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and " |
3119 | "4e0 <= -57 + i0 + i1)) or " |
3120 | "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and " |
3121 | "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and " |
3122 | "4e0 >= -61 + i0 + i1)) or " |
3123 | "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 }, |
3124 | { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 }, |
3125 | }; |
3126 | |
3127 | static int test_subset(isl_ctx *ctx) |
3128 | { |
3129 | int i; |
3130 | isl_setisl_map *set1, *set2; |
3131 | int subset; |
3132 | |
3133 | for (i = 0; i < ARRAY_SIZE(subset_tests)(sizeof(subset_tests)/sizeof(*subset_tests)); ++i) { |
3134 | set1 = isl_set_read_from_str(ctx, subset_tests[i].set1); |
3135 | set2 = isl_set_read_from_str(ctx, subset_tests[i].set2); |
3136 | subset = isl_set_is_subset(set1, set2); |
3137 | isl_set_free(set1); |
3138 | isl_set_free(set2); |
3139 | if (subset < 0) |
3140 | return -1; |
3141 | if (subset != subset_tests[i].subset) |
3142 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3143); return -1; } while (0) |
3143 | "incorrect subset result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3143); return -1; } while (0); |
3144 | } |
3145 | |
3146 | return 0; |
3147 | } |
3148 | |
3149 | struct { |
3150 | const char *minuend; |
3151 | const char *subtrahend; |
3152 | const char *difference; |
3153 | } subtract_domain_tests[] = { |
3154 | { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" }, |
3155 | { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" }, |
3156 | { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" }, |
3157 | }; |
3158 | |
3159 | static int test_subtract(isl_ctx *ctx) |
3160 | { |
3161 | int i; |
3162 | isl_union_map *umap1, *umap2; |
3163 | isl_union_pw_multi_aff *upma1, *upma2; |
3164 | isl_union_set *uset; |
3165 | int equal; |
3166 | |
3167 | for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests) ); ++i) { |
3168 | umap1 = isl_union_map_read_from_str(ctx, |
3169 | subtract_domain_tests[i].minuend); |
3170 | uset = isl_union_set_read_from_str(ctx, |
3171 | subtract_domain_tests[i].subtrahend); |
3172 | umap2 = isl_union_map_read_from_str(ctx, |
3173 | subtract_domain_tests[i].difference); |
3174 | umap1 = isl_union_map_subtract_domain(umap1, uset); |
3175 | equal = isl_union_map_is_equal(umap1, umap2); |
3176 | isl_union_map_free(umap1); |
3177 | isl_union_map_free(umap2); |
3178 | if (equal < 0) |
3179 | return -1; |
3180 | if (!equal) |
3181 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3182); return -1; } while (0) |
3182 | "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3182); return -1; } while (0); |
3183 | } |
3184 | |
3185 | for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests) ); ++i) { |
3186 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
3187 | subtract_domain_tests[i].minuend); |
3188 | uset = isl_union_set_read_from_str(ctx, |
3189 | subtract_domain_tests[i].subtrahend); |
3190 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
3191 | subtract_domain_tests[i].difference); |
3192 | upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset); |
3193 | equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2); |
3194 | isl_union_pw_multi_aff_free(upma1); |
3195 | isl_union_pw_multi_aff_free(upma2); |
3196 | if (equal < 0) |
3197 | return -1; |
3198 | if (!equal) |
3199 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3200); return -1; } while (0) |
3200 | "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3200); return -1; } while (0); |
3201 | } |
3202 | |
3203 | return 0; |
3204 | } |
3205 | |
3206 | /* Check that intersecting the empty basic set with another basic set |
3207 | * does not increase the number of constraints. In particular, |
3208 | * the empty basic set should maintain its canonical representation. |
3209 | */ |
3210 | static int test_intersect(isl_ctx *ctx) |
3211 | { |
3212 | int n1, n2; |
3213 | isl_basic_setisl_basic_map *bset1, *bset2; |
3214 | |
3215 | bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }"); |
3216 | bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }"); |
3217 | n1 = isl_basic_set_n_constraint(bset1); |
3218 | bset1 = isl_basic_set_intersect(bset1, bset2); |
3219 | n2 = isl_basic_set_n_constraint(bset1); |
3220 | isl_basic_set_free(bset1); |
3221 | if (!bset1) |
3222 | return -1; |
3223 | if (n1 != n2) |
3224 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3226); return -1; } while (0) |
3225 | "number of constraints of empty set changed",do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3226); return -1; } while (0) |
3226 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3226); return -1; } while (0); |
3227 | |
3228 | return 0; |
3229 | } |
3230 | |
3231 | int test_factorize(isl_ctx *ctx) |
3232 | { |
3233 | const char *str; |
3234 | isl_basic_setisl_basic_map *bset; |
3235 | isl_factorizer *f; |
3236 | |
3237 | str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and " |
3238 | "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and " |
3239 | "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and " |
3240 | "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and " |
3241 | "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and " |
3242 | "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and " |
3243 | "3i5 >= -2i0 - i2 + 3i4 }"; |
3244 | bset = isl_basic_set_read_from_str(ctx, str); |
3245 | f = isl_basic_set_factorizer(bset); |
3246 | isl_basic_set_free(bset); |
3247 | isl_factorizer_free(f); |
3248 | if (!f) |
3249 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3250); return -1; } while (0) |
3250 | "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3250); return -1; } while (0); |
3251 | |
3252 | str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : " |
3253 | "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and " |
3254 | "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and " |
3255 | "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and " |
3256 | "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and " |
3257 | "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and " |
3258 | "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and " |
3259 | "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and " |
3260 | "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and " |
3261 | "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }"; |
3262 | bset = isl_basic_set_read_from_str(ctx, str); |
3263 | f = isl_basic_set_factorizer(bset); |
3264 | isl_basic_set_free(bset); |
3265 | isl_factorizer_free(f); |
3266 | if (!f) |
3267 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3268); return -1; } while (0) |
3268 | "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3268); return -1; } while (0); |
3269 | |
3270 | return 0; |
3271 | } |
3272 | |
3273 | static isl_stat check_injective(__isl_take isl_map *map, void *user) |
3274 | { |
3275 | int *injective = user; |
3276 | |
3277 | *injective = isl_map_is_injective(map); |
3278 | isl_map_free(map); |
3279 | |
3280 | if (*injective < 0 || !*injective) |
3281 | return isl_stat_error; |
3282 | |
3283 | return isl_stat_ok; |
3284 | } |
3285 | |
3286 | int test_one_schedule(isl_ctx *ctx, const char *d, const char *w, |
3287 | const char *r, const char *s, int tilable, int parallel) |
3288 | { |
3289 | int i; |
3290 | isl_union_set *D; |
3291 | isl_union_map *W, *R, *S; |
3292 | isl_union_map *empty; |
3293 | isl_union_map *dep_raw, *dep_war, *dep_waw, *dep; |
3294 | isl_union_map *validity, *proximity, *coincidence; |
3295 | isl_union_map *schedule; |
3296 | isl_union_map *test; |
3297 | isl_union_set *delta; |
3298 | isl_union_set *domain; |
3299 | isl_setisl_map *delta_set; |
3300 | isl_setisl_map *slice; |
3301 | isl_setisl_map *origin; |
3302 | isl_schedule_constraints *sc; |
3303 | isl_schedule *sched; |
3304 | int is_nonneg, is_parallel, is_tilable, is_injection, is_complete; |
3305 | |
3306 | D = isl_union_set_read_from_str(ctx, d); |
3307 | W = isl_union_map_read_from_str(ctx, w); |
3308 | R = isl_union_map_read_from_str(ctx, r); |
3309 | S = isl_union_map_read_from_str(ctx, s); |
3310 | |
3311 | W = isl_union_map_intersect_domain(W, isl_union_set_copy(D)); |
3312 | R = isl_union_map_intersect_domain(R, isl_union_set_copy(D)); |
3313 | |
3314 | empty = isl_union_map_empty(isl_union_map_get_space(S)); |
3315 | isl_union_map_compute_flow(isl_union_map_copy(R), |
3316 | isl_union_map_copy(W), empty, |
3317 | isl_union_map_copy(S), |
3318 | &dep_raw, NULL((void*)0), NULL((void*)0), NULL((void*)0)); |
3319 | isl_union_map_compute_flow(isl_union_map_copy(W), |
3320 | isl_union_map_copy(W), |
3321 | isl_union_map_copy(R), |
3322 | isl_union_map_copy(S), |
3323 | &dep_waw, &dep_war, NULL((void*)0), NULL((void*)0)); |
3324 | |
3325 | dep = isl_union_map_union(dep_waw, dep_war); |
3326 | dep = isl_union_map_union(dep, dep_raw); |
3327 | validity = isl_union_map_copy(dep); |
3328 | coincidence = isl_union_map_copy(dep); |
3329 | proximity = isl_union_map_copy(dep); |
3330 | |
3331 | sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D)); |
3332 | sc = isl_schedule_constraints_set_validity(sc, validity); |
3333 | sc = isl_schedule_constraints_set_coincidence(sc, coincidence); |
3334 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
3335 | sched = isl_schedule_constraints_compute_schedule(sc); |
3336 | schedule = isl_schedule_get_map(sched); |
3337 | isl_schedule_free(sched); |
3338 | isl_union_map_free(W); |
3339 | isl_union_map_free(R); |
3340 | isl_union_map_free(S); |
3341 | |
3342 | is_injection = 1; |
3343 | isl_union_map_foreach_map(schedule, &check_injective, &is_injection); |
3344 | |
3345 | domain = isl_union_map_domain(isl_union_map_copy(schedule)); |
3346 | is_complete = isl_union_set_is_subset(D, domain); |
3347 | isl_union_set_free(D); |
3348 | isl_union_set_free(domain); |
3349 | |
3350 | test = isl_union_map_reverse(isl_union_map_copy(schedule)); |
3351 | test = isl_union_map_apply_range(test, dep); |
3352 | test = isl_union_map_apply_range(test, schedule); |
3353 | |
3354 | delta = isl_union_map_deltas(test); |
3355 | if (isl_union_set_n_set(delta) == 0) { |
3356 | is_tilable = 1; |
3357 | is_parallel = 1; |
3358 | is_nonneg = 1; |
3359 | isl_union_set_free(delta); |
3360 | } else { |
3361 | delta_set = isl_set_from_union_set(delta); |
3362 | |
3363 | slice = isl_set_universe(isl_set_get_space(delta_set)); |
3364 | for (i = 0; i < tilable; ++i) |
3365 | slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0); |
3366 | is_tilable = isl_set_is_subset(delta_set, slice); |
3367 | isl_set_free(slice); |
3368 | |
3369 | slice = isl_set_universe(isl_set_get_space(delta_set)); |
3370 | for (i = 0; i < parallel; ++i) |
3371 | slice = isl_set_fix_si(slice, isl_dim_set, i, 0); |
3372 | is_parallel = isl_set_is_subset(delta_set, slice); |
3373 | isl_set_free(slice); |
3374 | |
3375 | origin = isl_set_universe(isl_set_get_space(delta_set)); |
3376 | for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i) |
3377 | origin = isl_set_fix_si(origin, isl_dim_set, i, 0); |
3378 | |
3379 | delta_set = isl_set_union(delta_set, isl_set_copy(origin)); |
3380 | delta_set = isl_set_lexmin(delta_set); |
3381 | |
3382 | is_nonneg = isl_set_is_equal(delta_set, origin); |
3383 | |
3384 | isl_set_free(origin); |
3385 | isl_set_free(delta_set); |
3386 | } |
3387 | |
3388 | if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 || |
3389 | is_injection < 0 || is_complete < 0) |
3390 | return -1; |
3391 | if (!is_complete) |
3392 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3393); return -1; } while (0) |
3393 | "generated schedule incomplete", return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3393); return -1; } while (0); |
3394 | if (!is_injection) |
3395 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3397); return -1; } while (0) |
3396 | "generated schedule not injective on each statement",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3397); return -1; } while (0) |
3397 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3397); return -1; } while (0); |
3398 | if (!is_nonneg) |
3399 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3401); return -1; } while (0) |
3400 | "negative dependences in generated schedule",do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3401); return -1; } while (0) |
3401 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3401); return -1; } while (0); |
3402 | if (!is_tilable) |
3403 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3405); return -1; } while (0) |
3404 | "generated schedule not as tilable as expected",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3405); return -1; } while (0) |
3405 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3405); return -1; } while (0); |
3406 | if (!is_parallel) |
3407 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3409); return -1; } while (0) |
3408 | "generated schedule not as parallel as expected",do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3409); return -1; } while (0) |
3409 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3409); return -1; } while (0); |
3410 | |
3411 | return 0; |
3412 | } |
3413 | |
3414 | /* Compute a schedule for the given instance set, validity constraints, |
3415 | * proximity constraints and context and return a corresponding union map |
3416 | * representation. |
3417 | */ |
3418 | static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx, |
3419 | const char *domain, const char *validity, const char *proximity, |
3420 | const char *context) |
3421 | { |
3422 | isl_setisl_map *con; |
3423 | isl_union_set *dom; |
3424 | isl_union_map *dep; |
3425 | isl_union_map *prox; |
3426 | isl_schedule_constraints *sc; |
3427 | isl_schedule *schedule; |
3428 | isl_union_map *sched; |
3429 | |
3430 | con = isl_set_read_from_str(ctx, context); |
3431 | dom = isl_union_set_read_from_str(ctx, domain); |
3432 | dep = isl_union_map_read_from_str(ctx, validity); |
3433 | prox = isl_union_map_read_from_str(ctx, proximity); |
3434 | sc = isl_schedule_constraints_on_domain(dom); |
3435 | sc = isl_schedule_constraints_set_context(sc, con); |
3436 | sc = isl_schedule_constraints_set_validity(sc, dep); |
3437 | sc = isl_schedule_constraints_set_proximity(sc, prox); |
3438 | schedule = isl_schedule_constraints_compute_schedule(sc); |
3439 | sched = isl_schedule_get_map(schedule); |
3440 | isl_schedule_free(schedule); |
3441 | |
3442 | return sched; |
3443 | } |
3444 | |
3445 | /* Compute a schedule for the given instance set, validity constraints and |
3446 | * proximity constraints and return a corresponding union map representation. |
3447 | */ |
3448 | static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx, |
3449 | const char *domain, const char *validity, const char *proximity) |
3450 | { |
3451 | return compute_schedule_with_context(ctx, domain, validity, proximity, |
3452 | "{ : }"); |
3453 | } |
3454 | |
3455 | /* Check that a schedule can be constructed on the given domain |
3456 | * with the given validity and proximity constraints. |
3457 | */ |
3458 | static int test_has_schedule(isl_ctx *ctx, const char *domain, |
3459 | const char *validity, const char *proximity) |
3460 | { |
3461 | isl_union_map *sched; |
3462 | |
3463 | sched = compute_schedule(ctx, domain, validity, proximity); |
3464 | if (!sched) |
3465 | return -1; |
3466 | |
3467 | isl_union_map_free(sched); |
3468 | return 0; |
3469 | } |
3470 | |
3471 | int test_special_schedule(isl_ctx *ctx, const char *domain, |
3472 | const char *validity, const char *proximity, const char *expected_sched) |
3473 | { |
3474 | isl_union_map *sched1, *sched2; |
3475 | int equal; |
3476 | |
3477 | sched1 = compute_schedule(ctx, domain, validity, proximity); |
3478 | sched2 = isl_union_map_read_from_str(ctx, expected_sched); |
3479 | |
3480 | equal = isl_union_map_is_equal(sched1, sched2); |
3481 | isl_union_map_free(sched1); |
3482 | isl_union_map_free(sched2); |
3483 | |
3484 | if (equal < 0) |
3485 | return -1; |
3486 | if (!equal) |
3487 | isl_die(ctx, isl_error_unknown, "unexpected schedule",do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3488); return -1; } while (0) |
3488 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3488); return -1; } while (0); |
3489 | |
3490 | return 0; |
3491 | } |
3492 | |
3493 | /* Check that the schedule map is properly padded, even after being |
3494 | * reconstructed from the band forest. |
3495 | */ |
3496 | static int test_padded_schedule(isl_ctx *ctx) |
3497 | { |
3498 | const char *str; |
3499 | isl_union_set *D; |
3500 | isl_union_map *validity, *proximity; |
3501 | isl_schedule_constraints *sc; |
3502 | isl_schedule *sched; |
3503 | isl_union_map *map1, *map2; |
3504 | isl_band_list *list; |
3505 | int equal; |
3506 | |
3507 | str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }"; |
3508 | D = isl_union_set_read_from_str(ctx, str); |
3509 | validity = isl_union_map_empty(isl_union_set_get_space(D)); |
3510 | proximity = isl_union_map_copy(validity); |
3511 | sc = isl_schedule_constraints_on_domain(D); |
3512 | sc = isl_schedule_constraints_set_validity(sc, validity); |
3513 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
3514 | sched = isl_schedule_constraints_compute_schedule(sc); |
3515 | map1 = isl_schedule_get_map(sched); |
3516 | list = isl_schedule_get_band_forest(sched); |
3517 | isl_band_list_free(list); |
3518 | map2 = isl_schedule_get_map(sched); |
3519 | isl_schedule_free(sched); |
3520 | equal = isl_union_map_is_equal(map1, map2); |
3521 | isl_union_map_free(map1); |
3522 | isl_union_map_free(map2); |
3523 | |
3524 | if (equal < 0) |
3525 | return -1; |
3526 | if (!equal) |
3527 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "reconstructed schedule map not the same as original" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3529); return -1; } while (0) |
3528 | "reconstructed schedule map not the same as original",do { isl_handle_error(ctx, isl_error_unknown, "reconstructed schedule map not the same as original" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3529); return -1; } while (0) |
3529 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "reconstructed schedule map not the same as original" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3529); return -1; } while (0); |
3530 | |
3531 | return 0; |
3532 | } |
3533 | |
3534 | /* Check that conditional validity constraints are also taken into |
3535 | * account across bands. |
3536 | * In particular, try to make sure that live ranges D[1,0]->C[2,1] and |
3537 | * D[2,0]->C[3,0] are not local in the outer band of the generated schedule |
3538 | * and then check that the adjacent order constraint C[2,1]->D[2,0] |
3539 | * is enforced by the rest of the schedule. |
3540 | */ |
3541 | static int test_special_conditional_schedule_constraints(isl_ctx *ctx) |
3542 | { |
3543 | const char *str; |
3544 | isl_union_set *domain; |
3545 | isl_union_map *validity, *proximity, *condition; |
3546 | isl_union_map *sink, *source, *dep; |
3547 | isl_schedule_constraints *sc; |
3548 | isl_schedule *schedule; |
3549 | isl_union_access_info *access; |
3550 | isl_union_flow *flow; |
3551 | int empty; |
3552 | |
3553 | str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; " |
3554 | "A[k] : k >= 1 and k <= -1 + n; " |
3555 | "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; " |
3556 | "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }"; |
3557 | domain = isl_union_set_read_from_str(ctx, str); |
3558 | sc = isl_schedule_constraints_on_domain(domain); |
3559 | str = "[n] -> { D[k, i] -> C[1 + k, k - i] : " |
3560 | "k <= -2 + n and i >= 1 and i <= -1 + k; " |
3561 | "D[k, i] -> C[1 + k, i] : " |
3562 | "k <= -2 + n and i >= 1 and i <= -1 + k; " |
3563 | "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; " |
3564 | "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }"; |
3565 | validity = isl_union_map_read_from_str(ctx, str); |
3566 | sc = isl_schedule_constraints_set_validity(sc, validity); |
3567 | str = "[n] -> { C[k, i] -> D[k, i] : " |
3568 | "0 <= i <= -1 + k and k <= -1 + n }"; |
3569 | proximity = isl_union_map_read_from_str(ctx, str); |
3570 | sc = isl_schedule_constraints_set_proximity(sc, proximity); |
3571 | str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : " |
3572 | "i <= -1 + k and i >= 1 and k <= -2 + n; " |
3573 | "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : " |
3574 | "k <= -1 + n and i >= 0 and i <= -2 + k }"; |
3575 | condition = isl_union_map_read_from_str(ctx, str); |
3576 | str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : " |
3577 | "i >= 0 and i <= -1 + k and k <= -1 + n; " |
3578 | "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : " |
3579 | "i >= 0 and i <= -1 + k and k <= -1 + n and " |
3580 | "k' <= -1 + n and k' >= k - i and k' >= 1 + k; " |
3581 | "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : " |
3582 | "i >= 0 and i <= -1 + k and k <= -1 + n; " |
3583 | "[B[k, i] -> c[]] -> [A[k'] -> d[]] : " |
3584 | "k <= -1 + n and i >= 0 and i <= -1 + k and " |
3585 | "k' >= 1 and k' <= -1 + n and k' >= 1 + k }"; |
3586 | validity = isl_union_map_read_from_str(ctx, str); |
3587 | sc = isl_schedule_constraints_set_conditional_validity(sc, condition, |
3588 | validity); |
3589 | schedule = isl_schedule_constraints_compute_schedule(sc); |
3590 | str = "{ D[2,0] -> [] }"; |
3591 | sink = isl_union_map_read_from_str(ctx, str); |
3592 | access = isl_union_access_info_from_sink(sink); |
3593 | str = "{ C[2,1] -> [] }"; |
3594 | source = isl_union_map_read_from_str(ctx, str); |
3595 | access = isl_union_access_info_set_must_source(access, source); |
3596 | access = isl_union_access_info_set_schedule(access, schedule); |
3597 | flow = isl_union_access_info_compute_flow(access); |
3598 | dep = isl_union_flow_get_must_dependence(flow); |
3599 | isl_union_flow_free(flow); |
3600 | empty = isl_union_map_is_empty(dep); |
3601 | isl_union_map_free(dep); |
3602 | |
3603 | if (empty < 0) |
3604 | return -1; |
3605 | if (empty) |
3606 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3607); return -1; } while (0) |
3607 | "conditional validity not respected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3607); return -1; } while (0); |
3608 | |
3609 | return 0; |
3610 | } |
3611 | |
3612 | /* Input for testing of schedule construction based on |
3613 | * conditional constraints. |
3614 | * |
3615 | * domain is the iteration domain |
3616 | * flow are the flow dependences, which determine the validity and |
3617 | * proximity constraints |
3618 | * condition are the conditions on the conditional validity constraints |
3619 | * conditional_validity are the conditional validity constraints |
3620 | * outer_band_n is the expected number of members in the outer band |
3621 | */ |
3622 | struct { |
3623 | const char *domain; |
3624 | const char *flow; |
3625 | const char *condition; |
3626 | const char *conditional_validity; |
3627 | int outer_band_n; |
3628 | } live_range_tests[] = { |
3629 | /* Contrived example that illustrates that we need to keep |
3630 | * track of tagged condition dependences and |
3631 | * tagged conditional validity dependences |
3632 | * in isl_sched_edge separately. |
3633 | * In particular, the conditional validity constraints on A |
3634 | * cannot be satisfied, |
3635 | * but they can be ignored because there are no corresponding |
3636 | * condition constraints. However, we do have an additional |
3637 | * conditional validity constraint that maps to the same |
3638 | * dependence relation |
3639 | * as the condition constraint on B. If we did not make a distinction |
3640 | * between tagged condition and tagged conditional validity |
3641 | * dependences, then we |
3642 | * could end up treating this shared dependence as an condition |
3643 | * constraint on A, forcing a localization of the conditions, |
3644 | * which is impossible. |
3645 | */ |
3646 | { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }", |
3647 | "{ S[i] -> S[i+1] : 0 <= i < 99 }", |
3648 | "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }", |
3649 | "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';" |
3650 | "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';" |
3651 | "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }", |
3652 | 1 |
3653 | }, |
3654 | /* TACO 2013 Fig. 7 */ |
3655 | { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }", |
3656 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
3657 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
3658 | "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;" |
3659 | "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : " |
3660 | "0 <= i < n and 0 <= j < n - 1 }", |
3661 | "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : " |
3662 | "0 <= i < n and 0 <= j < j' < n;" |
3663 | "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : " |
3664 | "0 <= i < i' < n and 0 <= j,j' < n;" |
3665 | "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : " |
3666 | "0 <= i,j,j' < n and j < j' }", |
3667 | 2 |
3668 | }, |
3669 | /* TACO 2013 Fig. 7, without tags */ |
3670 | { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }", |
3671 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
3672 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
3673 | "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;" |
3674 | "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }", |
3675 | "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;" |
3676 | "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;" |
3677 | "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }", |
3678 | 1 |
3679 | }, |
3680 | /* TACO 2013 Fig. 12 */ |
3681 | { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;" |
3682 | "S3[i,3] : 0 <= i <= 1 }", |
3683 | "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;" |
3684 | "S2[i,1] -> S2[i,2] : 0 <= i <= 1;" |
3685 | "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }", |
3686 | "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;" |
3687 | "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;" |
3688 | "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }", |
3689 | "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;" |
3690 | "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;" |
3691 | "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;" |
3692 | "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;" |
3693 | "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }", |
3694 | 1 |
3695 | } |
3696 | }; |
3697 | |
3698 | /* Test schedule construction based on conditional constraints. |
3699 | * In particular, check the number of members in the outer band node |
3700 | * as an indication of whether tiling is possible or not. |
3701 | */ |
3702 | static int test_conditional_schedule_constraints(isl_ctx *ctx) |
3703 | { |
3704 | int i; |
3705 | isl_union_set *domain; |
3706 | isl_union_map *condition; |
3707 | isl_union_map *flow; |
3708 | isl_union_map *validity; |
3709 | isl_schedule_constraints *sc; |
3710 | isl_schedule *schedule; |
3711 | isl_schedule_node *node; |
3712 | int n_member; |
3713 | |
3714 | if (test_special_conditional_schedule_constraints(ctx) < 0) |
3715 | return -1; |
3716 | |
3717 | for (i = 0; i < ARRAY_SIZE(live_range_tests)(sizeof(live_range_tests)/sizeof(*live_range_tests)); ++i) { |
3718 | domain = isl_union_set_read_from_str(ctx, |
3719 | live_range_tests[i].domain); |
3720 | flow = isl_union_map_read_from_str(ctx, |
3721 | live_range_tests[i].flow); |
3722 | condition = isl_union_map_read_from_str(ctx, |
3723 | live_range_tests[i].condition); |
3724 | validity = isl_union_map_read_from_str(ctx, |
3725 | live_range_tests[i].conditional_validity); |
3726 | sc = isl_schedule_constraints_on_domain(domain); |
3727 | sc = isl_schedule_constraints_set_validity(sc, |
3728 | isl_union_map_copy(flow)); |
3729 | sc = isl_schedule_constraints_set_proximity(sc, flow); |
3730 | sc = isl_schedule_constraints_set_conditional_validity(sc, |
3731 | condition, validity); |
3732 | schedule = isl_schedule_constraints_compute_schedule(sc); |
3733 | node = isl_schedule_get_root(schedule); |
3734 | while (node && |
3735 | isl_schedule_node_get_type(node) != isl_schedule_node_band) |
3736 | node = isl_schedule_node_first_child(node); |
3737 | n_member = isl_schedule_node_band_n_member(node); |
3738 | isl_schedule_node_free(node); |
3739 | isl_schedule_free(schedule); |
3740 | |
3741 | if (!schedule) |
3742 | return -1; |
3743 | if (n_member != live_range_tests[i].outer_band_n) |
3744 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3746); return -1; } while (0) |
3745 | "unexpected number of members in outer band",do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3746); return -1; } while (0) |
3746 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3746); return -1; } while (0); |
3747 | } |
3748 | return 0; |
3749 | } |
3750 | |
3751 | /* Check that the schedule computed for the given instance set and |
3752 | * dependence relation strongly satisfies the dependences. |
3753 | * In particular, check that no instance is scheduled before |
3754 | * or together with an instance on which it depends. |
3755 | * Earlier versions of isl would produce a schedule that |
3756 | * only weakly satisfies the dependences. |
3757 | */ |
3758 | static int test_strongly_satisfying_schedule(isl_ctx *ctx) |
3759 | { |
3760 | const char *domain, *dep; |
3761 | isl_union_map *D, *schedule; |
3762 | isl_map *map, *ge; |
3763 | int empty; |
3764 | |
3765 | domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; " |
3766 | "A[i0] : 0 <= i0 <= 1 }"; |
3767 | dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; " |
3768 | "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }"; |
3769 | schedule = compute_schedule(ctx, domain, dep, dep); |
3770 | D = isl_union_map_read_from_str(ctx, dep); |
3771 | D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule)); |
3772 | D = isl_union_map_apply_range(D, schedule); |
3773 | map = isl_map_from_union_map(D); |
3774 | ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map))); |
3775 | map = isl_map_intersect(map, ge); |
3776 | empty = isl_map_is_empty(map); |
3777 | isl_map_free(map); |
3778 | |
3779 | if (empty < 0) |
3780 | return -1; |
3781 | if (!empty) |
3782 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3783); return -1; } while (0) |
3783 | "dependences not strongly satisfied", return -1)do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3783); return -1; } while (0); |
3784 | |
3785 | return 0; |
3786 | } |
3787 | |
3788 | /* Compute a schedule for input where the instance set constraints |
3789 | * conflict with the context constraints. |
3790 | * Earlier versions of isl did not properly handle this situation. |
3791 | */ |
3792 | static int test_conflicting_context_schedule(isl_ctx *ctx) |
3793 | { |
3794 | isl_union_map *schedule; |
3795 | const char *domain, *context; |
3796 | |
3797 | domain = "[n] -> { A[] : n >= 0 }"; |
3798 | context = "[n] -> { : n < 0 }"; |
3799 | schedule = compute_schedule_with_context(ctx, |
3800 | domain, "{}", "{}", context); |
3801 | isl_union_map_free(schedule); |
3802 | |
3803 | if (!schedule) |
3804 | return -1; |
3805 | |
3806 | return 0; |
3807 | } |
3808 | |
3809 | /* Check that the dependence carrying step is not confused by |
3810 | * a bound on the coefficient size. |
3811 | * In particular, force the scheduler to move to a dependence carrying |
3812 | * step by demanding outer coincidence and bound the size of |
3813 | * the coefficients. Earlier versions of isl would take this |
3814 | * bound into account while carrying dependences, breaking |
3815 | * fundamental assumptions. |
3816 | * On the other hand, the dependence carrying step now tries |
3817 | * to prevent loop coalescing by default, so check that indeed |
3818 | * no loop coalescing occurs by comparing the computed schedule |
3819 | * to the expected non-coalescing schedule. |
3820 | */ |
3821 | static int test_bounded_coefficients_schedule(isl_ctx *ctx) |
3822 | { |
3823 | const char *domain, *dep; |
3824 | isl_union_set *I; |
3825 | isl_union_map *D; |
3826 | isl_schedule_constraints *sc; |
3827 | isl_schedule *schedule; |
3828 | isl_union_map *sched1, *sched2; |
3829 | isl_bool equal; |
3830 | |
3831 | domain = "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }"; |
3832 | dep = "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and " |
3833 | "i1 <= -2 + i0; " |
3834 | "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }"; |
3835 | I = isl_union_set_read_from_str(ctx, domain); |
3836 | D = isl_union_map_read_from_str(ctx, dep); |
3837 | sc = isl_schedule_constraints_on_domain(I); |
3838 | sc = isl_schedule_constraints_set_validity(sc, isl_union_map_copy(D)); |
3839 | sc = isl_schedule_constraints_set_coincidence(sc, D); |
3840 | isl_options_set_schedule_outer_coincidence(ctx, 1); |
3841 | isl_options_set_schedule_max_coefficient(ctx, 20); |
3842 | schedule = isl_schedule_constraints_compute_schedule(sc); |
3843 | isl_options_set_schedule_max_coefficient(ctx, -1); |
3844 | isl_options_set_schedule_outer_coincidence(ctx, 0); |
3845 | sched1 = isl_schedule_get_map(schedule); |
3846 | isl_schedule_free(schedule); |
3847 | |
3848 | sched2 = isl_union_map_read_from_str(ctx, "{ C[x,y] -> [x,y] }"); |
3849 | equal = isl_union_map_is_equal(sched1, sched2); |
3850 | isl_union_map_free(sched1); |
3851 | isl_union_map_free(sched2); |
3852 | |
3853 | if (equal < 0) |
3854 | return -1; |
3855 | if (!equal) |
3856 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3857); return -1; } while (0) |
3857 | "unexpected schedule", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 3857); return -1; } while (0); |
3858 | |
3859 | return 0; |
3860 | } |
3861 | |
3862 | /* Check that a set of schedule constraints that only allow for |
3863 | * a coalescing schedule still produces a schedule even if the user |
3864 | * request a non-coalescing schedule. Earlier versions of isl |
3865 | * would not handle this case correctly. |
3866 | */ |
3867 | static int test_coalescing_schedule(isl_ctx *ctx) |
3868 | { |
3869 | const char *domain, *dep; |
3870 | isl_union_set *I; |
3871 | isl_union_map *D; |
3872 | isl_schedule_constraints *sc; |
3873 | isl_schedule *schedule; |
3874 | int treat_coalescing; |
3875 | |
3876 | domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }"; |
3877 | dep = "{ S[a, b] -> S[a + b, 1 - b] }"; |
3878 | I = isl_union_set_read_from_str(ctx, domain); |
3879 | D = isl_union_map_read_from_str(ctx, dep); |
3880 | sc = isl_schedule_constraints_on_domain(I); |
3881 | sc = isl_schedule_constraints_set_validity(sc, D); |
3882 | treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx); |
3883 | isl_options_set_schedule_treat_coalescing(ctx, 1); |
3884 | schedule = isl_schedule_constraints_compute_schedule(sc); |
3885 | isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing); |
3886 | isl_schedule_free(schedule); |
3887 | if (!schedule) |
3888 | return -1; |
3889 | return 0; |
3890 | } |
3891 | |
3892 | int test_schedule(isl_ctx *ctx) |
3893 | { |
3894 | const char *D, *W, *R, *V, *P, *S; |
3895 | int max_coincidence; |
3896 | int treat_coalescing; |
3897 | |
3898 | /* Handle resulting schedule with zero bands. */ |
3899 | if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0) |
3900 | return -1; |
3901 | |
3902 | /* Jacobi */ |
3903 | D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }"; |
3904 | W = "{ S1[t,i] -> a[t,i] }"; |
3905 | R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; " |
3906 | "S1[t,i] -> a[t-1,i+1] }"; |
3907 | S = "{ S1[t,i] -> [t,i] }"; |
3908 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
3909 | return -1; |
3910 | |
3911 | /* Fig. 5 of CC2008 */ |
3912 | D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and " |
3913 | "j <= -1 + N }"; |
3914 | W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and " |
3915 | "j >= 2 and j <= -1 + N }"; |
3916 | R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and " |
3917 | "j >= 2 and j <= -1 + N; " |
3918 | "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and " |
3919 | "j >= 2 and j <= -1 + N }"; |
3920 | S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }"; |
3921 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
3922 | return -1; |
3923 | |
3924 | D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }"; |
3925 | W = "{ S1[i] -> a[i] }"; |
3926 | R = "{ S2[i] -> a[i+1] }"; |
3927 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
3928 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
3929 | return -1; |
3930 | |
3931 | D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }"; |
3932 | W = "{ S1[i] -> a[i] }"; |
3933 | R = "{ S2[i] -> a[9-i] }"; |
3934 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
3935 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
3936 | return -1; |
3937 | |
3938 | D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }"; |
3939 | W = "{ S1[i] -> a[i] }"; |
3940 | R = "[N] -> { S2[i] -> a[N-1-i] }"; |
3941 | S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }"; |
3942 | if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0) |
3943 | return -1; |
3944 | |
3945 | D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }"; |
3946 | W = "{ S1[i] -> a[i]; S2[i] -> b[i] }"; |
3947 | R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }"; |
3948 | S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }"; |
3949 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
3950 | return -1; |
3951 | |
3952 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }"; |
3953 | W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }"; |
3954 | R = "{ S2[i,j] -> a[i-1,j] }"; |
3955 | S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }"; |
3956 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
3957 | return -1; |
3958 | |
3959 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }"; |
3960 | W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }"; |
3961 | R = "{ S2[i,j] -> a[i,j-1] }"; |
3962 | S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }"; |
3963 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
3964 | return -1; |
3965 | |
3966 | D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }"; |
3967 | W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; " |
3968 | "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }"; |
3969 | R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }"; |
3970 | S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; " |
3971 | "S_0[] -> [0, 0, 0] }"; |
3972 | if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0) |
3973 | return -1; |
3974 | ctx->opt->schedule_parametric = 0; |
3975 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
3976 | return -1; |
3977 | ctx->opt->schedule_parametric = 1; |
3978 | |
3979 | D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; " |
3980 | "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }"; |
3981 | W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }"; |
3982 | R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; " |
3983 | "S4[i] -> a[i,N] }"; |
3984 | S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; " |
3985 | "S4[i] -> [4,i,0] }"; |
3986 | max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx); |
3987 | isl_options_set_schedule_maximize_coincidence(ctx, 0); |
3988 | if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0) |
3989 | return -1; |
3990 | isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence); |
3991 | |
3992 | D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }"; |
3993 | W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and " |
3994 | "j <= N }"; |
3995 | R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and " |
3996 | "j <= N; " |
3997 | "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and " |
3998 | "j <= N }"; |
3999 | S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }"; |
4000 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4001 | return -1; |
4002 | |
4003 | D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; " |
4004 | " S_2[t] : t >= 0 and t <= -1 + N; " |
4005 | " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and " |
4006 | "i <= -1 + N }"; |
4007 | W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; " |
4008 | " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; " |
4009 | " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and " |
4010 | "i >= 0 and i <= -1 + N }"; |
4011 | R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and " |
4012 | "i >= 0 and i <= -1 + N; " |
4013 | " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }"; |
4014 | S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; " |
4015 | " S_0[t] -> [0, t, 0] }"; |
4016 | |
4017 | if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0) |
4018 | return -1; |
4019 | ctx->opt->schedule_parametric = 0; |
4020 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4021 | return -1; |
4022 | ctx->opt->schedule_parametric = 1; |
4023 | |
4024 | D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }"; |
4025 | S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }"; |
4026 | if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0) |
4027 | return -1; |
4028 | |
4029 | D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; " |
4030 | "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }"; |
4031 | W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and " |
4032 | "j >= 0 and j <= -1 + N; " |
4033 | "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }"; |
4034 | R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and " |
4035 | "j >= 0 and j <= -1 + N; " |
4036 | "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }"; |
4037 | S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }"; |
4038 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4039 | return -1; |
4040 | |
4041 | D = "{ S_0[i] : i >= 0 }"; |
4042 | W = "{ S_0[i] -> a[i] : i >= 0 }"; |
4043 | R = "{ S_0[i] -> a[0] : i >= 0 }"; |
4044 | S = "{ S_0[i] -> [0, i, 0] }"; |
4045 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4046 | return -1; |
4047 | |
4048 | D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }"; |
4049 | W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }"; |
4050 | R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }"; |
4051 | S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }"; |
4052 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4053 | return -1; |
4054 | |
4055 | D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and " |
4056 | "k <= -1 + n and k >= 0 }"; |
4057 | W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }"; |
4058 | R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " |
4059 | "k <= -1 + n and k >= 0; " |
4060 | "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and " |
4061 | "k <= -1 + n and k >= 0; " |
4062 | "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and " |
4063 | "k <= -1 + n and k >= 0 }"; |
4064 | S = "[n] -> { S_0[j, k] -> [2, j, k] }"; |
4065 | ctx->opt->schedule_outer_coincidence = 1; |
4066 | if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0) |
4067 | return -1; |
4068 | ctx->opt->schedule_outer_coincidence = 0; |
4069 | |
4070 | D = "{Stmt_for_body24[i0, i1, i2, i3]:" |
4071 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and " |
4072 | "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;" |
4073 | "Stmt_for_body24[i0, i1, 1, 0]:" |
4074 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;" |
4075 | "Stmt_for_body7[i0, i1, i2]:" |
4076 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and " |
4077 | "i2 <= 7 }"; |
4078 | |
4079 | V = "{Stmt_for_body24[0, i1, i2, i3] -> " |
4080 | "Stmt_for_body24[1, i1, i2, i3]:" |
4081 | "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and " |
4082 | "i2 >= 1;" |
4083 | "Stmt_for_body24[0, i1, i2, i3] -> " |
4084 | "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:" |
4085 | "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and " |
4086 | "i3 >= 0;" |
4087 | "Stmt_for_body24[0, i1, i2, i3] ->" |
4088 | "Stmt_for_body7[1, i1, 1 + i1 + i3]:" |
4089 | "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;" |
4090 | "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:" |
4091 | "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or " |
4092 | "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or " |
4093 | "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);" |
4094 | "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:" |
4095 | "i1 <= 6 and i1 >= 0;" |
4096 | "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];" |
4097 | "Stmt_for_body7[i0, i1, i2] -> " |
4098 | "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:" |
4099 | "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and " |
4100 | "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;" |
4101 | "Stmt_for_body7[i0, i1, i2] -> " |
4102 | "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:" |
4103 | "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and " |
4104 | "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }"; |
4105 | P = V; |
4106 | S = "{ Stmt_for_body24[i0, i1, i2, i3] -> " |
4107 | "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];" |
4108 | "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }"; |
4109 | |
4110 | treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx); |
4111 | isl_options_set_schedule_treat_coalescing(ctx, 0); |
4112 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4113 | return -1; |
4114 | isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing); |
4115 | |
4116 | D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }"; |
4117 | V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and " |
4118 | "j >= 1 and j <= 7;" |
4119 | "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and " |
4120 | "j >= 1 and j <= 8 }"; |
4121 | P = "{ }"; |
4122 | S = "{ S_0[i, j] -> [i + j, j] }"; |
4123 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4124 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4125 | return -1; |
4126 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4127 | |
4128 | /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */ |
4129 | D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and " |
4130 | "j >= 0 and j <= -1 + i }"; |
4131 | V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and " |
4132 | "i <= -1 + N and j >= 0;" |
4133 | "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and " |
4134 | "i <= -2 + N }"; |
4135 | P = "{ }"; |
4136 | S = "{ S_0[i, j] -> [i, j] }"; |
4137 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4138 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4139 | return -1; |
4140 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4141 | |
4142 | /* Test both algorithms on a case with only proximity dependences. */ |
4143 | D = "{ S[i,j] : 0 <= i <= 10 }"; |
4144 | V = "{ }"; |
4145 | P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }"; |
4146 | S = "{ S[i, j] -> [j, i] }"; |
4147 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4148 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4149 | return -1; |
4150 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4151 | if (test_special_schedule(ctx, D, V, P, S) < 0) |
4152 | return -1; |
4153 | |
4154 | D = "{ A[a]; B[] }"; |
4155 | V = "{}"; |
4156 | P = "{ A[a] -> B[] }"; |
4157 | if (test_has_schedule(ctx, D, V, P) < 0) |
4158 | return -1; |
4159 | |
4160 | if (test_padded_schedule(ctx) < 0) |
4161 | return -1; |
4162 | |
4163 | /* Check that check for progress is not confused by rational |
4164 | * solution. |
4165 | */ |
4166 | D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }"; |
4167 | V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and " |
4168 | "i0 <= -2 + N; " |
4169 | "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and " |
4170 | "i0 <= N and i1 >= 0 and i1 <= -1 + N }"; |
4171 | P = "{}"; |
4172 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4173 | if (test_has_schedule(ctx, D, V, P) < 0) |
4174 | return -1; |
4175 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4176 | |
4177 | /* Check that we allow schedule rows that are only non-trivial |
4178 | * on some full-dimensional domains. |
4179 | */ |
4180 | D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }"; |
4181 | V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];" |
4182 | "S1[j] -> S2[1] : 0 <= j <= 1 }"; |
4183 | P = "{}"; |
4184 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1; |
4185 | if (test_has_schedule(ctx, D, V, P) < 0) |
4186 | return -1; |
4187 | ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0; |
4188 | |
4189 | if (test_conditional_schedule_constraints(ctx) < 0) |
4190 | return -1; |
4191 | |
4192 | if (test_strongly_satisfying_schedule(ctx) < 0) |
4193 | return -1; |
4194 | |
4195 | if (test_conflicting_context_schedule(ctx) < 0) |
4196 | return -1; |
4197 | |
4198 | if (test_bounded_coefficients_schedule(ctx) < 0) |
4199 | return -1; |
4200 | if (test_coalescing_schedule(ctx) < 0) |
4201 | return -1; |
4202 | |
4203 | return 0; |
4204 | } |
4205 | |
4206 | /* Perform scheduling tests using the whole component scheduler. |
4207 | */ |
4208 | static int test_schedule_whole(isl_ctx *ctx) |
4209 | { |
4210 | int whole; |
4211 | int r; |
4212 | |
4213 | whole = isl_options_get_schedule_whole_component(ctx); |
4214 | isl_options_set_schedule_whole_component(ctx, 1); |
4215 | r = test_schedule(ctx); |
4216 | isl_options_set_schedule_whole_component(ctx, whole); |
4217 | |
4218 | return r; |
4219 | } |
4220 | |
4221 | /* Perform scheduling tests using the incremental scheduler. |
4222 | */ |
4223 | static int test_schedule_incremental(isl_ctx *ctx) |
4224 | { |
4225 | int whole; |
4226 | int r; |
4227 | |
4228 | whole = isl_options_get_schedule_whole_component(ctx); |
4229 | isl_options_set_schedule_whole_component(ctx, 0); |
4230 | r = test_schedule(ctx); |
4231 | isl_options_set_schedule_whole_component(ctx, whole); |
4232 | |
4233 | return r; |
4234 | } |
4235 | |
4236 | int test_plain_injective(isl_ctx *ctx, const char *str, int injective) |
4237 | { |
4238 | isl_union_map *umap; |
4239 | int test; |
4240 | |
4241 | umap = isl_union_map_read_from_str(ctx, str); |
4242 | test = isl_union_map_plain_is_injective(umap); |
4243 | isl_union_map_free(umap); |
4244 | if (test < 0) |
4245 | return -1; |
4246 | if (test == injective) |
4247 | return 0; |
4248 | if (injective) |
4249 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4250); return -1; } while (0) |
4250 | "map not detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4250); return -1; } while (0); |
4251 | else |
4252 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4253); return -1; } while (0) |
4253 | "map detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4253); return -1; } while (0); |
4254 | } |
4255 | |
4256 | int test_injective(isl_ctx *ctx) |
4257 | { |
4258 | const char *str; |
4259 | |
4260 | if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0)) |
4261 | return -1; |
4262 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1)) |
4263 | return -1; |
4264 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1)) |
4265 | return -1; |
4266 | if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0)) |
4267 | return -1; |
4268 | if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1)) |
4269 | return -1; |
4270 | if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0)) |
4271 | return -1; |
4272 | if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1)) |
4273 | return -1; |
4274 | if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1)) |
4275 | return -1; |
4276 | |
4277 | str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}"; |
4278 | if (test_plain_injective(ctx, str, 1)) |
4279 | return -1; |
4280 | str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}"; |
4281 | if (test_plain_injective(ctx, str, 0)) |
4282 | return -1; |
4283 | |
4284 | return 0; |
4285 | } |
4286 | |
4287 | static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str) |
4288 | { |
4289 | isl_aff *aff2; |
4290 | int equal; |
4291 | |
4292 | if (!aff) |
4293 | return -1; |
4294 | |
4295 | aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str); |
4296 | equal = isl_aff_plain_is_equal(aff, aff2); |
4297 | isl_aff_free(aff2); |
4298 | |
4299 | return equal; |
4300 | } |
4301 | |
4302 | static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str) |
4303 | { |
4304 | int equal; |
4305 | |
4306 | equal = aff_plain_is_equal(aff, str); |
4307 | if (equal < 0) |
4308 | return -1; |
4309 | if (!equal) |
4310 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4311); return -1; } while (0) |
4311 | "result not as expected", return -1)do { isl_handle_error(isl_aff_get_ctx(aff), isl_error_unknown , "result not as expected", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4311); return -1; } while (0); |
4312 | return 0; |
4313 | } |
4314 | |
4315 | struct { |
4316 | __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1, |
4317 | __isl_take isl_aff *aff2); |
4318 | } aff_bin_op[] = { |
4319 | ['+'] = { &isl_aff_add }, |
4320 | ['-'] = { &isl_aff_sub }, |
4321 | ['*'] = { &isl_aff_mul }, |
4322 | ['/'] = { &isl_aff_div }, |
4323 | }; |
4324 | |
4325 | struct { |
4326 | const char *arg1; |
4327 | unsigned char op; |
4328 | const char *arg2; |
4329 | const char *res; |
4330 | } aff_bin_tests[] = { |
4331 | { "{ [i] -> [i] }", '+', "{ [i] -> [i] }", |
4332 | "{ [i] -> [2i] }" }, |
4333 | { "{ [i] -> [i] }", '-', "{ [i] -> [i] }", |
4334 | "{ [i] -> [0] }" }, |
4335 | { "{ [i] -> [i] }", '*', "{ [i] -> [2] }", |
4336 | "{ [i] -> [2i] }" }, |
4337 | { "{ [i] -> [2] }", '*', "{ [i] -> [i] }", |
4338 | "{ [i] -> [2i] }" }, |
4339 | { "{ [i] -> [i] }", '/', "{ [i] -> [2] }", |
4340 | "{ [i] -> [i/2] }" }, |
4341 | { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }", |
4342 | "{ [i] -> [i] }" }, |
4343 | { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }", |
4344 | "{ [i] -> [NaN] }" }, |
4345 | { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }", |
4346 | "{ [i] -> [NaN] }" }, |
4347 | { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }", |
4348 | "{ [i] -> [NaN] }" }, |
4349 | { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }", |
4350 | "{ [i] -> [NaN] }" }, |
4351 | { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }", |
4352 | "{ [i] -> [NaN] }" }, |
4353 | { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }", |
4354 | "{ [i] -> [NaN] }" }, |
4355 | { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }", |
4356 | "{ [i] -> [NaN] }" }, |
4357 | { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }", |
4358 | "{ [i] -> [NaN] }" }, |
4359 | { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }", |
4360 | "{ [i] -> [NaN] }" }, |
4361 | { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }", |
4362 | "{ [i] -> [NaN] }" }, |
4363 | { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }", |
4364 | "{ [i] -> [NaN] }" }, |
4365 | { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }", |
4366 | "{ [i] -> [NaN] }" }, |
4367 | }; |
4368 | |
4369 | /* Perform some basic tests of binary operations on isl_aff objects. |
4370 | */ |
4371 | static int test_bin_aff(isl_ctx *ctx) |
4372 | { |
4373 | int i; |
4374 | isl_aff *aff1, *aff2, *res; |
4375 | __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1, |
4376 | __isl_take isl_aff *aff2); |
4377 | int ok; |
4378 | |
4379 | for (i = 0; i < ARRAY_SIZE(aff_bin_tests)(sizeof(aff_bin_tests)/sizeof(*aff_bin_tests)); ++i) { |
4380 | aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1); |
4381 | aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2); |
4382 | res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res); |
4383 | fn = aff_bin_op[aff_bin_tests[i].op].fn; |
4384 | aff1 = fn(aff1, aff2); |
4385 | if (isl_aff_is_nan(res)) |
4386 | ok = isl_aff_is_nan(aff1); |
4387 | else |
4388 | ok = isl_aff_plain_is_equal(aff1, res); |
4389 | isl_aff_free(aff1); |
4390 | isl_aff_free(res); |
4391 | if (ok < 0) |
4392 | return -1; |
4393 | if (!ok) |
4394 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4395); return -1; } while (0) |
4395 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4395); return -1; } while (0); |
4396 | } |
4397 | |
4398 | return 0; |
4399 | } |
4400 | |
4401 | struct { |
4402 | __isl_give isl_union_pw_multi_aff *(*fn)( |
4403 | __isl_take isl_union_pw_multi_aff *upma1, |
4404 | __isl_take isl_union_pw_multi_aff *upma2); |
4405 | const char *arg1; |
4406 | const char *arg2; |
4407 | const char *res; |
4408 | } upma_bin_tests[] = { |
4409 | { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }", |
4410 | "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" }, |
4411 | { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }", |
4412 | "{ B[x] -> [2] : x >= 0 }", |
4413 | "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" }, |
4414 | { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff, |
4415 | "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }", |
4416 | "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }", |
4417 | "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; " |
4418 | "D[i] -> B[2] : i >= 5 }" }, |
4419 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
4420 | "{ B[x] -> C[2] : x > 0 }", |
4421 | "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" }, |
4422 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
4423 | "{ B[x] -> A[2] : x >= 0 }", |
4424 | "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" }, |
4425 | }; |
4426 | |
4427 | /* Perform some basic tests of binary operations on |
4428 | * isl_union_pw_multi_aff objects. |
4429 | */ |
4430 | static int test_bin_upma(isl_ctx *ctx) |
4431 | { |
4432 | int i; |
4433 | isl_union_pw_multi_aff *upma1, *upma2, *res; |
4434 | int ok; |
4435 | |
4436 | for (i = 0; i < ARRAY_SIZE(upma_bin_tests)(sizeof(upma_bin_tests)/sizeof(*upma_bin_tests)); ++i) { |
4437 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
4438 | upma_bin_tests[i].arg1); |
4439 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
4440 | upma_bin_tests[i].arg2); |
4441 | res = isl_union_pw_multi_aff_read_from_str(ctx, |
4442 | upma_bin_tests[i].res); |
4443 | upma1 = upma_bin_tests[i].fn(upma1, upma2); |
4444 | ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res); |
4445 | isl_union_pw_multi_aff_free(upma1); |
4446 | isl_union_pw_multi_aff_free(res); |
4447 | if (ok < 0) |
4448 | return -1; |
4449 | if (!ok) |
4450 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4451); return -1; } while (0) |
4451 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4451); return -1; } while (0); |
4452 | } |
4453 | |
4454 | return 0; |
4455 | } |
4456 | |
4457 | struct { |
4458 | __isl_give isl_union_pw_multi_aff *(*fn)( |
4459 | __isl_take isl_union_pw_multi_aff *upma1, |
4460 | __isl_take isl_union_pw_multi_aff *upma2); |
4461 | const char *arg1; |
4462 | const char *arg2; |
4463 | } upma_bin_fail_tests[] = { |
4464 | { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }", |
4465 | "{ B[x] -> C[2] : x >= 0 }" }, |
4466 | }; |
4467 | |
4468 | /* Perform some basic tests of binary operations on |
4469 | * isl_union_pw_multi_aff objects that are expected to fail. |
4470 | */ |
4471 | static int test_bin_upma_fail(isl_ctx *ctx) |
4472 | { |
4473 | int i, n; |
4474 | isl_union_pw_multi_aff *upma1, *upma2; |
4475 | int on_error; |
4476 | |
4477 | on_error = isl_options_get_on_error(ctx); |
4478 | isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE1); |
4479 | n = ARRAY_SIZE(upma_bin_fail_tests)(sizeof(upma_bin_fail_tests)/sizeof(*upma_bin_fail_tests)); |
4480 | for (i = 0; i < n; ++i) { |
4481 | upma1 = isl_union_pw_multi_aff_read_from_str(ctx, |
4482 | upma_bin_fail_tests[i].arg1); |
4483 | upma2 = isl_union_pw_multi_aff_read_from_str(ctx, |
4484 | upma_bin_fail_tests[i].arg2); |
4485 | upma1 = upma_bin_fail_tests[i].fn(upma1, upma2); |
4486 | isl_union_pw_multi_aff_free(upma1); |
4487 | if (upma1) |
4488 | break; |
4489 | } |
4490 | isl_options_set_on_error(ctx, on_error); |
4491 | if (i < n) |
4492 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4493); return -1; } while (0) |
4493 | "operation not expected to succeed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4493); return -1; } while (0); |
4494 | |
4495 | return 0; |
4496 | } |
4497 | |
4498 | int test_aff(isl_ctx *ctx) |
4499 | { |
4500 | const char *str; |
4501 | isl_setisl_map *set; |
4502 | isl_space *space; |
4503 | isl_local_space *ls; |
4504 | isl_aff *aff; |
4505 | int zero, equal; |
4506 | |
4507 | if (test_bin_aff(ctx) < 0) |
4508 | return -1; |
4509 | if (test_bin_upma(ctx) < 0) |
4510 | return -1; |
4511 | if (test_bin_upma_fail(ctx) < 0) |
4512 | return -1; |
4513 | |
4514 | space = isl_space_set_alloc(ctx, 0, 1); |
4515 | ls = isl_local_space_from_space(space); |
4516 | aff = isl_aff_zero_on_domain(ls); |
4517 | |
4518 | aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); |
4519 | aff = isl_aff_scale_down_ui(aff, 3); |
4520 | aff = isl_aff_floor(aff); |
4521 | aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); |
4522 | aff = isl_aff_scale_down_ui(aff, 2); |
4523 | aff = isl_aff_floor(aff); |
4524 | aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); |
4525 | |
4526 | str = "{ [10] }"; |
4527 | set = isl_set_read_from_str(ctx, str); |
4528 | aff = isl_aff_gist(aff, set); |
4529 | |
4530 | aff = isl_aff_add_constant_si(aff, -16); |
4531 | zero = isl_aff_plain_is_zero(aff); |
4532 | isl_aff_free(aff); |
4533 | |
4534 | if (zero < 0) |
4535 | return -1; |
4536 | if (!zero) |
4537 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4537); return -1; } while (0); |
4538 | |
4539 | aff = isl_aff_read_from_str(ctx, "{ [-1] }"); |
4540 | aff = isl_aff_scale_down_ui(aff, 64); |
4541 | aff = isl_aff_floor(aff); |
4542 | equal = aff_check_plain_equal(aff, "{ [-1] }"); |
4543 | isl_aff_free(aff); |
4544 | if (equal < 0) |
4545 | return -1; |
4546 | |
4547 | return 0; |
4548 | } |
4549 | |
4550 | int test_dim_max(isl_ctx *ctx) |
4551 | { |
4552 | int equal; |
4553 | const char *str; |
4554 | isl_setisl_map *set1, *set2; |
4555 | isl_setisl_map *set; |
4556 | isl_map *map; |
4557 | isl_pw_aff *pwaff; |
4558 | |
4559 | str = "[N] -> { [i] : 0 <= i <= min(N,10) }"; |
4560 | set = isl_set_read_from_str(ctx, str); |
4561 | pwaff = isl_set_dim_max(set, 0); |
4562 | set1 = isl_set_from_pw_aff(pwaff); |
4563 | str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }"; |
4564 | set2 = isl_set_read_from_str(ctx, str); |
4565 | equal = isl_set_is_equal(set1, set2); |
4566 | isl_set_free(set1); |
4567 | isl_set_free(set2); |
4568 | if (equal < 0) |
4569 | return -1; |
4570 | if (!equal) |
4571 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4571); return -1; } while (0); |
4572 | |
4573 | str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }"; |
4574 | set = isl_set_read_from_str(ctx, str); |
4575 | pwaff = isl_set_dim_max(set, 0); |
4576 | set1 = isl_set_from_pw_aff(pwaff); |
4577 | str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }"; |
4578 | set2 = isl_set_read_from_str(ctx, str); |
4579 | equal = isl_set_is_equal(set1, set2); |
4580 | isl_set_free(set1); |
4581 | isl_set_free(set2); |
4582 | if (equal < 0) |
4583 | return -1; |
4584 | if (!equal) |
4585 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4585); return -1; } while (0); |
4586 | |
4587 | str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }"; |
4588 | set = isl_set_read_from_str(ctx, str); |
4589 | pwaff = isl_set_dim_max(set, 0); |
4590 | set1 = isl_set_from_pw_aff(pwaff); |
4591 | str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }"; |
4592 | set2 = isl_set_read_from_str(ctx, str); |
4593 | equal = isl_set_is_equal(set1, set2); |
4594 | isl_set_free(set1); |
4595 | isl_set_free(set2); |
4596 | if (equal < 0) |
4597 | return -1; |
4598 | if (!equal) |
4599 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4599); return -1; } while (0); |
4600 | |
4601 | str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : " |
4602 | "0 <= i < N and 0 <= j < M }"; |
4603 | map = isl_map_read_from_str(ctx, str); |
4604 | set = isl_map_range(map); |
4605 | |
4606 | pwaff = isl_set_dim_max(isl_set_copy(set), 0); |
4607 | set1 = isl_set_from_pw_aff(pwaff); |
4608 | str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }"; |
4609 | set2 = isl_set_read_from_str(ctx, str); |
4610 | equal = isl_set_is_equal(set1, set2); |
4611 | isl_set_free(set1); |
4612 | isl_set_free(set2); |
4613 | |
4614 | pwaff = isl_set_dim_max(isl_set_copy(set), 3); |
4615 | set1 = isl_set_from_pw_aff(pwaff); |
4616 | str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }"; |
4617 | set2 = isl_set_read_from_str(ctx, str); |
4618 | if (equal >= 0 && equal) |
4619 | equal = isl_set_is_equal(set1, set2); |
4620 | isl_set_free(set1); |
4621 | isl_set_free(set2); |
4622 | |
4623 | isl_set_free(set); |
4624 | |
4625 | if (equal < 0) |
4626 | return -1; |
4627 | if (!equal) |
4628 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4628); return -1; } while (0); |
4629 | |
4630 | /* Check that solutions are properly merged. */ |
4631 | str = "[n] -> { [a, b, c] : c >= -4a - 2b and " |
4632 | "c <= -1 + n - 4a - 2b and c >= -2b and " |
4633 | "4a >= -4 + n and c >= 0 }"; |
4634 | set = isl_set_read_from_str(ctx, str); |
4635 | pwaff = isl_set_dim_min(set, 2); |
4636 | set1 = isl_set_from_pw_aff(pwaff); |
4637 | str = "[n] -> { [(0)] : n >= 1 }"; |
4638 | set2 = isl_set_read_from_str(ctx, str); |
4639 | equal = isl_set_is_equal(set1, set2); |
4640 | isl_set_free(set1); |
4641 | isl_set_free(set2); |
4642 | |
4643 | if (equal < 0) |
4644 | return -1; |
4645 | if (!equal) |
4646 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4646); return -1; } while (0); |
4647 | |
4648 | /* Check that empty solution lie in the right space. */ |
4649 | str = "[n] -> { [t,a] : 1 = 0 }"; |
4650 | set = isl_set_read_from_str(ctx, str); |
4651 | pwaff = isl_set_dim_max(set, 0); |
4652 | set1 = isl_set_from_pw_aff(pwaff); |
4653 | str = "[n] -> { [t] : 1 = 0 }"; |
4654 | set2 = isl_set_read_from_str(ctx, str); |
4655 | equal = isl_set_is_equal(set1, set2); |
4656 | isl_set_free(set1); |
4657 | isl_set_free(set2); |
4658 | |
4659 | if (equal < 0) |
4660 | return -1; |
4661 | if (!equal) |
4662 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4662); return -1; } while (0); |
4663 | |
4664 | return 0; |
4665 | } |
4666 | |
4667 | /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"? |
4668 | */ |
4669 | static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff *pma, |
4670 | const char *str) |
4671 | { |
4672 | isl_ctx *ctx; |
4673 | isl_pw_multi_aff *pma2; |
4674 | int equal; |
4675 | |
4676 | if (!pma) |
4677 | return -1; |
4678 | |
4679 | ctx = isl_pw_multi_aff_get_ctx(pma); |
4680 | pma2 = isl_pw_multi_aff_read_from_str(ctx, str); |
4681 | equal = isl_pw_multi_aff_plain_is_equal(pma, pma2); |
4682 | isl_pw_multi_aff_free(pma2); |
4683 | |
4684 | return equal; |
4685 | } |
4686 | |
4687 | /* Check that "pma" is obviously equal to the isl_pw_multi_aff |
4688 | * represented by "str". |
4689 | */ |
4690 | static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff *pma, |
4691 | const char *str) |
4692 | { |
4693 | int equal; |
4694 | |
4695 | equal = pw_multi_aff_plain_is_equal(pma, str); |
4696 | if (equal < 0) |
4697 | return -1; |
4698 | if (!equal) |
4699 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4700); return -1; } while (0) |
4700 | "result not as expected", return -1)do { isl_handle_error(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown , "result not as expected", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4700); return -1; } while (0); |
4701 | return 0; |
4702 | } |
4703 | |
4704 | /* Basic test for isl_pw_multi_aff_product. |
4705 | * |
4706 | * Check that multiple pieces are properly handled. |
4707 | */ |
4708 | static int test_product_pma(isl_ctx *ctx) |
4709 | { |
4710 | int equal; |
4711 | const char *str; |
4712 | isl_pw_multi_aff *pma1, *pma2; |
4713 | |
4714 | str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }"; |
4715 | pma1 = isl_pw_multi_aff_read_from_str(ctx, str); |
4716 | str = "{ C[] -> D[] }"; |
4717 | pma2 = isl_pw_multi_aff_read_from_str(ctx, str); |
4718 | pma1 = isl_pw_multi_aff_product(pma1, pma2); |
4719 | str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;" |
4720 | "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }"; |
4721 | equal = pw_multi_aff_check_plain_equal(pma1, str); |
4722 | isl_pw_multi_aff_free(pma1); |
4723 | if (equal < 0) |
4724 | return -1; |
4725 | |
4726 | return 0; |
4727 | } |
4728 | |
4729 | int test_product(isl_ctx *ctx) |
4730 | { |
4731 | const char *str; |
4732 | isl_setisl_map *set; |
4733 | isl_union_set *uset1, *uset2; |
4734 | int ok; |
4735 | |
4736 | str = "{ A[i] }"; |
4737 | set = isl_set_read_from_str(ctx, str); |
4738 | set = isl_set_product(set, isl_set_copy(set)); |
4739 | ok = isl_set_is_wrapping(set); |
4740 | isl_set_free(set); |
4741 | if (ok < 0) |
4742 | return -1; |
4743 | if (!ok) |
4744 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4744); return -1; } while (0); |
4745 | |
4746 | str = "{ [] }"; |
4747 | uset1 = isl_union_set_read_from_str(ctx, str); |
4748 | uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1)); |
4749 | str = "{ [[] -> []] }"; |
4750 | uset2 = isl_union_set_read_from_str(ctx, str); |
4751 | ok = isl_union_set_is_equal(uset1, uset2); |
4752 | isl_union_set_free(uset1); |
4753 | isl_union_set_free(uset2); |
4754 | if (ok < 0) |
4755 | return -1; |
4756 | if (!ok) |
4757 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4757); return -1; } while (0); |
4758 | |
4759 | if (test_product_pma(ctx) < 0) |
4760 | return -1; |
4761 | |
4762 | return 0; |
4763 | } |
4764 | |
4765 | /* Check that two sets are not considered disjoint just because |
4766 | * they have a different set of (named) parameters. |
4767 | */ |
4768 | static int test_disjoint(isl_ctx *ctx) |
4769 | { |
4770 | const char *str; |
4771 | isl_setisl_map *set, *set2; |
4772 | int disjoint; |
4773 | |
4774 | str = "[n] -> { [[]->[]] }"; |
4775 | set = isl_set_read_from_str(ctx, str); |
4776 | str = "{ [[]->[]] }"; |
4777 | set2 = isl_set_read_from_str(ctx, str); |
4778 | disjoint = isl_set_is_disjoint(set, set2); |
4779 | isl_set_free(set); |
4780 | isl_set_free(set2); |
4781 | if (disjoint < 0) |
4782 | return -1; |
4783 | if (disjoint) |
4784 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4784); return -1; } while (0); |
4785 | |
4786 | return 0; |
4787 | } |
4788 | |
4789 | int test_equal(isl_ctx *ctx) |
4790 | { |
4791 | const char *str; |
4792 | isl_setisl_map *set, *set2; |
4793 | int equal; |
4794 | |
4795 | str = "{ S_6[i] }"; |
4796 | set = isl_set_read_from_str(ctx, str); |
4797 | str = "{ S_7[i] }"; |
4798 | set2 = isl_set_read_from_str(ctx, str); |
4799 | equal = isl_set_is_equal(set, set2); |
4800 | isl_set_free(set); |
4801 | isl_set_free(set2); |
4802 | if (equal < 0) |
4803 | return -1; |
4804 | if (equal) |
4805 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4805); return -1; } while (0); |
4806 | |
4807 | return 0; |
4808 | } |
4809 | |
4810 | static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map, |
4811 | enum isl_dim_type type, unsigned pos, int fixed) |
4812 | { |
4813 | int test; |
4814 | |
4815 | test = isl_map_plain_is_fixed(map, type, pos, NULL((void*)0)); |
4816 | isl_map_free(map); |
4817 | if (test < 0) |
4818 | return -1; |
4819 | if (test == fixed) |
4820 | return 0; |
4821 | if (fixed) |
4822 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map not detected as fixed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4823); return -1; } while (0) |
4823 | "map not detected as fixed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map not detected as fixed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4823); return -1; } while (0); |
4824 | else |
4825 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map detected as fixed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4826); return -1; } while (0) |
4826 | "map detected as fixed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map detected as fixed" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4826); return -1; } while (0); |
4827 | } |
4828 | |
4829 | int test_fixed(isl_ctx *ctx) |
4830 | { |
4831 | const char *str; |
4832 | isl_map *map; |
4833 | |
4834 | str = "{ [i] -> [i] }"; |
4835 | map = isl_map_read_from_str(ctx, str); |
4836 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0)) |
4837 | return -1; |
4838 | str = "{ [i] -> [1] }"; |
4839 | map = isl_map_read_from_str(ctx, str); |
4840 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1)) |
4841 | return -1; |
4842 | str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }"; |
4843 | map = isl_map_read_from_str(ctx, str); |
4844 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1)) |
4845 | return -1; |
4846 | map = isl_map_read_from_str(ctx, str); |
4847 | map = isl_map_neg(map); |
4848 | if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1)) |
4849 | return -1; |
4850 | |
4851 | return 0; |
4852 | } |
4853 | |
4854 | struct isl_vertices_test_data { |
4855 | const char *set; |
4856 | int n; |
4857 | const char *vertex[2]; |
4858 | } vertices_tests[] = { |
4859 | { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }", |
4860 | 2, { "{ A[12, 4] }", "{ A[12, 12] }" } }, |
4861 | { "{ A[t, i] : t = 14 and i = 1 }", |
4862 | 1, { "{ A[14, 1] }" } }, |
4863 | }; |
4864 | |
4865 | /* Check that "vertex" corresponds to one of the vertices in data->vertex. |
4866 | */ |
4867 | static isl_stat find_vertex(__isl_take isl_vertex *vertex, void *user) |
4868 | { |
4869 | struct isl_vertices_test_data *data = user; |
4870 | isl_ctx *ctx; |
4871 | isl_multi_aff *ma; |
4872 | isl_basic_setisl_basic_map *bset; |
4873 | isl_pw_multi_aff *pma; |
4874 | int i; |
4875 | isl_bool equal; |
4876 | |
4877 | ctx = isl_vertex_get_ctx(vertex); |
4878 | bset = isl_vertex_get_domain(vertex); |
4879 | ma = isl_vertex_get_expr(vertex); |
4880 | pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma); |
4881 | |
4882 | for (i = 0; i < data->n; ++i) { |
4883 | isl_pw_multi_aff *pma_i; |
4884 | |
4885 | pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]); |
4886 | equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i); |
4887 | isl_pw_multi_aff_free(pma_i); |
4888 | |
4889 | if (equal < 0 || equal) |
4890 | break; |
4891 | } |
4892 | |
4893 | isl_pw_multi_aff_free(pma); |
4894 | isl_vertex_free(vertex); |
4895 | |
4896 | if (equal < 0) |
4897 | return isl_stat_error; |
4898 | |
4899 | return equal ? isl_stat_ok : isl_stat_error; |
4900 | } |
4901 | |
4902 | int test_vertices(isl_ctx *ctx) |
4903 | { |
4904 | int i; |
4905 | |
4906 | for (i = 0; i < ARRAY_SIZE(vertices_tests)(sizeof(vertices_tests)/sizeof(*vertices_tests)); ++i) { |
4907 | isl_basic_setisl_basic_map *bset; |
4908 | isl_vertices *vertices; |
4909 | int ok = 1; |
4910 | int n; |
4911 | |
4912 | bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set); |
4913 | vertices = isl_basic_set_compute_vertices(bset); |
4914 | n = isl_vertices_get_n_vertices(vertices); |
4915 | if (vertices_tests[i].n != n) |
4916 | ok = 0; |
4917 | if (isl_vertices_foreach_vertex(vertices, &find_vertex, |
4918 | &vertices_tests[i]) < 0) |
4919 | ok = 0; |
4920 | isl_vertices_free(vertices); |
4921 | isl_basic_set_free(bset); |
4922 | |
4923 | if (!vertices) |
4924 | return -1; |
4925 | if (!ok) |
4926 | isl_die(ctx, isl_error_unknown, "unexpected vertices",do { isl_handle_error(ctx, isl_error_unknown, "unexpected vertices" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4927); return -1; } while (0) |
4927 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected vertices" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4927); return -1; } while (0); |
4928 | } |
4929 | |
4930 | return 0; |
4931 | } |
4932 | |
4933 | int test_union_pw(isl_ctx *ctx) |
4934 | { |
4935 | int equal; |
4936 | const char *str; |
4937 | isl_union_set *uset; |
4938 | isl_union_pw_qpolynomial *upwqp1, *upwqp2; |
4939 | |
4940 | str = "{ [x] -> x^2 }"; |
4941 | upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str); |
4942 | upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1); |
4943 | uset = isl_union_pw_qpolynomial_domain(upwqp1); |
4944 | upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2); |
4945 | upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset); |
4946 | equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2); |
4947 | isl_union_pw_qpolynomial_free(upwqp1); |
4948 | isl_union_pw_qpolynomial_free(upwqp2); |
4949 | if (equal < 0) |
4950 | return -1; |
4951 | if (!equal) |
4952 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4952); return -1; } while (0); |
4953 | |
4954 | return 0; |
4955 | } |
4956 | |
4957 | /* Test that isl_union_pw_qpolynomial_eval picks up the function |
4958 | * defined over the correct domain space. |
4959 | */ |
4960 | static int test_eval(isl_ctx *ctx) |
4961 | { |
4962 | const char *str; |
4963 | isl_point *pnt; |
4964 | isl_setisl_map *set; |
4965 | isl_union_pw_qpolynomial *upwqp; |
4966 | isl_val *v; |
4967 | int cmp; |
4968 | |
4969 | str = "{ A[x] -> x^2; B[x] -> -x^2 }"; |
4970 | upwqp = isl_union_pw_qpolynomial_read_from_str(ctx, str); |
4971 | str = "{ A[6] }"; |
4972 | set = isl_set_read_from_str(ctx, str); |
4973 | pnt = isl_set_sample_point(set); |
4974 | v = isl_union_pw_qpolynomial_eval(upwqp, pnt); |
4975 | cmp = isl_val_cmp_si(v, 36); |
4976 | isl_val_free(v); |
4977 | |
4978 | if (!v) |
4979 | return -1; |
4980 | if (cmp != 0) |
4981 | isl_die(ctx, isl_error_unknown, "unexpected value", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected value" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 4981); return -1; } while (0); |
4982 | |
4983 | return 0; |
4984 | } |
4985 | |
4986 | /* Descriptions of sets that are tested for reparsing after printing. |
4987 | */ |
4988 | const char *output_tests[] = { |
4989 | "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }", |
4990 | }; |
4991 | |
4992 | /* Check that printing a set and reparsing a set from the printed output |
4993 | * results in the same set. |
4994 | */ |
4995 | static int test_output_set(isl_ctx *ctx) |
4996 | { |
4997 | int i; |
4998 | char *str; |
4999 | isl_setisl_map *set1, *set2; |
5000 | isl_bool equal; |
5001 | |
5002 | for (i = 0; i < ARRAY_SIZE(output_tests)(sizeof(output_tests)/sizeof(*output_tests)); ++i) { |
5003 | set1 = isl_set_read_from_str(ctx, output_tests[i]); |
5004 | str = isl_set_to_str(set1); |
5005 | set2 = isl_set_read_from_str(ctx, str); |
5006 | free(str); |
5007 | equal = isl_set_is_equal(set1, set2); |
5008 | isl_set_free(set1); |
5009 | isl_set_free(set2); |
5010 | if (equal < 0) |
5011 | return -1; |
5012 | if (!equal) |
5013 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "parsed output not the same" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5014); return -1; } while (0) |
5014 | "parsed output not the same", return -1)do { isl_handle_error(ctx, isl_error_unknown, "parsed output not the same" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5014); return -1; } while (0); |
5015 | } |
5016 | |
5017 | return 0; |
5018 | } |
5019 | |
5020 | int test_output(isl_ctx *ctx) |
5021 | { |
5022 | char *s; |
5023 | const char *str; |
5024 | isl_pw_aff *pa; |
5025 | isl_printer *p; |
5026 | int equal; |
5027 | |
5028 | if (test_output_set(ctx) < 0) |
5029 | return -1; |
5030 | |
5031 | str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }"; |
5032 | pa = isl_pw_aff_read_from_str(ctx, str); |
5033 | |
5034 | p = isl_printer_to_str(ctx); |
5035 | p = isl_printer_set_output_format(p, ISL_FORMAT_C4); |
5036 | p = isl_printer_print_pw_aff(p, pa); |
5037 | s = isl_printer_get_str(p); |
5038 | isl_printer_free(p); |
5039 | isl_pw_aff_free(pa); |
5040 | if (!s) |
5041 | equal = -1; |
5042 | else |
5043 | 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" )))); }); |
5044 | free(s); |
5045 | if (equal < 0) |
5046 | return -1; |
5047 | if (!equal) |
5048 | isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5048); return -1; } while (0); |
5049 | |
5050 | return 0; |
5051 | } |
5052 | |
5053 | int test_sample(isl_ctx *ctx) |
5054 | { |
5055 | const char *str; |
5056 | isl_basic_setisl_basic_map *bset1, *bset2; |
5057 | int empty, subset; |
5058 | |
5059 | str = "{ [a, b, c, d, e, f, g, h, i, j, k] : " |
5060 | "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and " |
5061 | "3i >= -1 + 3221225466b + c + d - 3221225466e - f and " |
5062 | "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and " |
5063 | "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and " |
5064 | "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and " |
5065 | "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and " |
5066 | "3h >= a + 2147483646b + 2c - 2147483646e - 2f and " |
5067 | "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and " |
5068 | "f >= 1 - a + 1073741822b + c + d - 1073741822e and " |
5069 | "3i >= 1 + 2b - 2c + e + 2f + 3g and " |
5070 | "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +" |
5071 | "d - 1073741821e and " |
5072 | "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and " |
5073 | "3j >= 1 - a + b + 2e and " |
5074 | "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and " |
5075 | "3i <= 4 - a + 4b - e and " |
5076 | "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and " |
5077 | "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and " |
5078 | "c <= -1 + a and 3i >= -2 - a + 3e and " |
5079 | "1073741822e <= 1073741823 - a + 1073741822b + c and " |
5080 | "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and " |
5081 | "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and " |
5082 | "1073741823e >= 1 + 1073741823b - d and " |
5083 | "3i >= 1073741823b + c - 1073741823e - f and " |
5084 | "3i >= 1 + 2b + e + 3g }"; |
5085 | bset1 = isl_basic_set_read_from_str(ctx, str); |
5086 | bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1)); |
5087 | empty = isl_basic_set_is_empty(bset2); |
5088 | subset = isl_basic_set_is_subset(bset2, bset1); |
5089 | isl_basic_set_free(bset1); |
5090 | isl_basic_set_free(bset2); |
5091 | if (empty < 0 || subset < 0) |
5092 | return -1; |
5093 | if (empty) |
5094 | isl_die(ctx, isl_error_unknown, "point not found", return -1)do { isl_handle_error(ctx, isl_error_unknown, "point not found" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5094); return -1; } while (0); |
5095 | if (!subset) |
5096 | isl_die(ctx, isl_error_unknown, "bad point found", return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad point found" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5096); return -1; } while (0); |
5097 | |
5098 | return 0; |
5099 | } |
5100 | |
5101 | int test_fixed_power(isl_ctx *ctx) |
5102 | { |
5103 | const char *str; |
5104 | isl_map *map; |
5105 | isl_int exp; |
5106 | int equal; |
5107 | |
5108 | isl_int_init(exp)isl_sioimath_init((exp)); |
5109 | str = "{ [i] -> [i + 1] }"; |
5110 | map = isl_map_read_from_str(ctx, str); |
5111 | isl_int_set_si(exp, 23)isl_sioimath_set_si((exp), 23); |
5112 | map = isl_map_fixed_power(map, exp); |
5113 | equal = map_check_equal(map, "{ [i] -> [i + 23] }"); |
5114 | isl_int_clear(exp)isl_sioimath_clear((exp)); |
5115 | isl_map_free(map); |
5116 | if (equal < 0) |
5117 | return -1; |
5118 | |
5119 | return 0; |
5120 | } |
5121 | |
5122 | int test_slice(isl_ctx *ctx) |
5123 | { |
5124 | const char *str; |
5125 | isl_map *map; |
5126 | int equal; |
5127 | |
5128 | str = "{ [i] -> [j] }"; |
5129 | map = isl_map_read_from_str(ctx, str); |
5130 | map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0); |
5131 | equal = map_check_equal(map, "{ [i] -> [i] }"); |
5132 | isl_map_free(map); |
5133 | if (equal < 0) |
5134 | return -1; |
5135 | |
5136 | str = "{ [i] -> [j] }"; |
5137 | map = isl_map_read_from_str(ctx, str); |
5138 | map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0); |
5139 | equal = map_check_equal(map, "{ [i] -> [j] }"); |
5140 | isl_map_free(map); |
5141 | if (equal < 0) |
5142 | return -1; |
5143 | |
5144 | str = "{ [i] -> [j] }"; |
5145 | map = isl_map_read_from_str(ctx, str); |
5146 | map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0); |
5147 | equal = map_check_equal(map, "{ [i] -> [-i] }"); |
5148 | isl_map_free(map); |
5149 | if (equal < 0) |
5150 | return -1; |
5151 | |
5152 | str = "{ [i] -> [j] }"; |
5153 | map = isl_map_read_from_str(ctx, str); |
5154 | map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0); |
5155 | equal = map_check_equal(map, "{ [0] -> [j] }"); |
5156 | isl_map_free(map); |
5157 | if (equal < 0) |
5158 | return -1; |
5159 | |
5160 | str = "{ [i] -> [j] }"; |
5161 | map = isl_map_read_from_str(ctx, str); |
5162 | map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0); |
5163 | equal = map_check_equal(map, "{ [i] -> [j] : i > j }"); |
5164 | isl_map_free(map); |
5165 | if (equal < 0) |
5166 | return -1; |
5167 | |
5168 | str = "{ [i] -> [j] }"; |
5169 | map = isl_map_read_from_str(ctx, str); |
5170 | map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0); |
5171 | equal = map_check_equal(map, "{ [i] -> [j] : false }"); |
5172 | isl_map_free(map); |
5173 | if (equal < 0) |
5174 | return -1; |
5175 | |
5176 | return 0; |
5177 | } |
5178 | |
5179 | int test_eliminate(isl_ctx *ctx) |
5180 | { |
5181 | const char *str; |
5182 | isl_map *map; |
5183 | int equal; |
5184 | |
5185 | str = "{ [i] -> [j] : i = 2j }"; |
5186 | map = isl_map_read_from_str(ctx, str); |
5187 | map = isl_map_eliminate(map, isl_dim_out, 0, 1); |
5188 | equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }"); |
5189 | isl_map_free(map); |
5190 | if (equal < 0) |
5191 | return -1; |
5192 | |
5193 | return 0; |
5194 | } |
5195 | |
5196 | /* Check that isl_set_dim_residue_class detects that the values of j |
5197 | * in the set below are all odd and that it does not detect any spurious |
5198 | * strides. |
5199 | */ |
5200 | static int test_residue_class(isl_ctx *ctx) |
5201 | { |
5202 | const char *str; |
5203 | isl_setisl_map *set; |
5204 | isl_int m, r; |
5205 | int res; |
5206 | |
5207 | str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; " |
5208 | "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }"; |
5209 | set = isl_set_read_from_str(ctx, str); |
5210 | isl_int_init(m)isl_sioimath_init((m)); |
5211 | isl_int_init(r)isl_sioimath_init((r)); |
5212 | res = isl_set_dim_residue_class(set, 1, &m, &r); |
5213 | if (res >= 0 && |
5214 | (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)) |
5215 | isl_die(ctx, isl_error_unknown, "incorrect residue class",do { isl_handle_error(ctx, isl_error_unknown, "incorrect residue class" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5216); res = -1; } while (0) |
5216 | res = -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect residue class" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5216); res = -1; } while (0); |
5217 | isl_int_clear(r)isl_sioimath_clear((r)); |
5218 | isl_int_clear(m)isl_sioimath_clear((m)); |
5219 | isl_set_free(set); |
5220 | |
5221 | return res; |
5222 | } |
5223 | |
5224 | int test_align_parameters(isl_ctx *ctx) |
5225 | { |
5226 | const char *str; |
5227 | isl_space *space; |
5228 | isl_multi_aff *ma1, *ma2; |
5229 | int equal; |
5230 | |
5231 | str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }"; |
5232 | ma1 = isl_multi_aff_read_from_str(ctx, str); |
5233 | |
5234 | space = isl_space_params_alloc(ctx, 1); |
5235 | space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); |
5236 | ma1 = isl_multi_aff_align_params(ma1, space); |
5237 | |
5238 | str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }"; |
5239 | ma2 = isl_multi_aff_read_from_str(ctx, str); |
5240 | |
5241 | equal = isl_multi_aff_plain_is_equal(ma1, ma2); |
5242 | |
5243 | isl_multi_aff_free(ma1); |
5244 | isl_multi_aff_free(ma2); |
5245 | |
5246 | if (equal < 0) |
5247 | return -1; |
5248 | if (!equal) |
5249 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5250); return -1; } while (0) |
5250 | "result not as expected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "result not as expected" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5250); return -1; } while (0); |
5251 | |
5252 | return 0; |
5253 | } |
5254 | |
5255 | static int test_list(isl_ctx *ctx) |
5256 | { |
5257 | isl_id *a, *b, *c, *d, *id; |
5258 | isl_id_list *list; |
5259 | int ok; |
5260 | |
5261 | a = isl_id_alloc(ctx, "a", NULL((void*)0)); |
5262 | b = isl_id_alloc(ctx, "b", NULL((void*)0)); |
5263 | c = isl_id_alloc(ctx, "c", NULL((void*)0)); |
5264 | d = isl_id_alloc(ctx, "d", NULL((void*)0)); |
5265 | |
5266 | list = isl_id_list_alloc(ctx, 4); |
5267 | list = isl_id_list_add(list, a); |
5268 | list = isl_id_list_add(list, b); |
5269 | list = isl_id_list_add(list, c); |
5270 | list = isl_id_list_add(list, d); |
5271 | list = isl_id_list_drop(list, 1, 1); |
5272 | |
5273 | if (isl_id_list_n_id(list) != 3) { |
5274 | isl_id_list_free(list); |
5275 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of elements in list" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5276); return -1; } while (0) |
5276 | "unexpected number of elements in list", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of elements in list" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5276); return -1; } while (0); |
5277 | } |
5278 | |
5279 | id = isl_id_list_get_id(list, 0); |
5280 | ok = id == a; |
5281 | isl_id_free(id); |
5282 | id = isl_id_list_get_id(list, 1); |
5283 | ok = ok && id == c; |
5284 | isl_id_free(id); |
5285 | id = isl_id_list_get_id(list, 2); |
5286 | ok = ok && id == d; |
5287 | isl_id_free(id); |
5288 | |
5289 | isl_id_list_free(list); |
5290 | |
5291 | if (!ok) |
5292 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected elements in list" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5293); return -1; } while (0) |
5293 | "unexpected elements in list", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected elements in list" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5293); return -1; } while (0); |
5294 | |
5295 | return 0; |
5296 | } |
5297 | |
5298 | const char *set_conversion_tests[] = { |
5299 | "[N] -> { [i] : N - 1 <= 2 i <= N }", |
5300 | "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }", |
5301 | "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }", |
5302 | "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }", |
5303 | "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }", |
5304 | "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and " |
5305 | "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and " |
5306 | "-3 + c <= d <= 28 + c) }", |
5307 | }; |
5308 | |
5309 | /* Check that converting from isl_set to isl_pw_multi_aff and back |
5310 | * to isl_set produces the original isl_set. |
5311 | */ |
5312 | static int test_set_conversion(isl_ctx *ctx) |
5313 | { |
5314 | int i; |
5315 | const char *str; |
5316 | isl_setisl_map *set1, *set2; |
5317 | isl_pw_multi_aff *pma; |
5318 | int equal; |
5319 | |
5320 | for (i = 0; i < ARRAY_SIZE(set_conversion_tests)(sizeof(set_conversion_tests)/sizeof(*set_conversion_tests)); ++i) { |
5321 | str = set_conversion_tests[i]; |
5322 | set1 = isl_set_read_from_str(ctx, str); |
5323 | pma = isl_pw_multi_aff_from_set(isl_set_copy(set1)); |
5324 | set2 = isl_set_from_pw_multi_aff(pma); |
5325 | equal = isl_set_is_equal(set1, set2); |
5326 | isl_set_free(set1); |
5327 | isl_set_free(set2); |
5328 | |
5329 | if (equal < 0) |
5330 | return -1; |
5331 | if (!equal) |
5332 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5333); return -1; } while (0) |
5333 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5333); return -1; } while (0); |
5334 | } |
5335 | |
5336 | return 0; |
5337 | } |
5338 | |
5339 | const char *conversion_tests[] = { |
5340 | "{ [a, b, c, d] -> s0[a, b, e, f] : " |
5341 | "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], " |
5342 | "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and " |
5343 | "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and " |
5344 | "9e <= -2 - 2a) }", |
5345 | "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): " |
5346 | "5e0 = -a - b + c and c >= -a and c <= 4 - a) }", |
5347 | "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }", |
5348 | }; |
5349 | |
5350 | /* Check that converting from isl_map to isl_pw_multi_aff and back |
5351 | * to isl_map produces the original isl_map. |
5352 | */ |
5353 | static int test_map_conversion(isl_ctx *ctx) |
5354 | { |
5355 | int i; |
5356 | isl_map *map1, *map2; |
5357 | isl_pw_multi_aff *pma; |
5358 | int equal; |
5359 | |
5360 | for (i = 0; i < ARRAY_SIZE(conversion_tests)(sizeof(conversion_tests)/sizeof(*conversion_tests)); ++i) { |
5361 | map1 = isl_map_read_from_str(ctx, conversion_tests[i]); |
5362 | pma = isl_pw_multi_aff_from_map(isl_map_copy(map1)); |
5363 | map2 = isl_map_from_pw_multi_aff(pma); |
5364 | equal = isl_map_is_equal(map1, map2); |
5365 | isl_map_free(map1); |
5366 | isl_map_free(map2); |
5367 | |
5368 | if (equal < 0) |
5369 | return -1; |
5370 | if (!equal) |
5371 | isl_die(ctx, isl_error_unknown, "bad conversion",do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5372); return -1; } while (0) |
5372 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad conversion" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5372); return -1; } while (0); |
5373 | } |
5374 | |
5375 | return 0; |
5376 | } |
5377 | |
5378 | static int test_conversion(isl_ctx *ctx) |
5379 | { |
5380 | if (test_set_conversion(ctx) < 0) |
5381 | return -1; |
5382 | if (test_map_conversion(ctx) < 0) |
5383 | return -1; |
5384 | return 0; |
5385 | } |
5386 | |
5387 | /* Check that isl_basic_map_curry does not modify input. |
5388 | */ |
5389 | static int test_curry(isl_ctx *ctx) |
5390 | { |
5391 | const char *str; |
5392 | isl_basic_map *bmap1, *bmap2; |
5393 | int equal; |
5394 | |
5395 | str = "{ [A[] -> B[]] -> C[] }"; |
5396 | bmap1 = isl_basic_map_read_from_str(ctx, str); |
5397 | bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1)); |
5398 | equal = isl_basic_map_is_equal(bmap1, bmap2); |
5399 | isl_basic_map_free(bmap1); |
5400 | isl_basic_map_free(bmap2); |
5401 | |
5402 | if (equal < 0) |
5403 | return -1; |
5404 | if (equal) |
5405 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "curried map should not be equal to original" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5407); return -1; } while (0) |
5406 | "curried map should not be equal to original",do { isl_handle_error(ctx, isl_error_unknown, "curried map should not be equal to original" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5407); return -1; } while (0) |
5407 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "curried map should not be equal to original" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5407); return -1; } while (0); |
5408 | |
5409 | return 0; |
5410 | } |
5411 | |
5412 | struct { |
5413 | const char *set; |
5414 | const char *ma; |
5415 | const char *res; |
5416 | } preimage_tests[] = { |
5417 | { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }", |
5418 | "{ A[j,i] -> B[i,j] }", |
5419 | "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" }, |
5420 | { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }", |
5421 | "{ A[a,b] -> B[a/2,b/6] }", |
5422 | "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" }, |
5423 | { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }", |
5424 | "{ A[a,b] -> B[a/2,b/6] }", |
5425 | "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and " |
5426 | "exists i,j : a = 2 i and b = 6 j }" }, |
5427 | { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }", |
5428 | "[n] -> { : 0 <= n <= 100 }" }, |
5429 | { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }", |
5430 | "{ A[a] -> B[2a] }", |
5431 | "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" }, |
5432 | { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }", |
5433 | "{ A[a] -> B[([a/2])] }", |
5434 | "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" }, |
5435 | { "{ B[i,j,k] : 0 <= i,j,k <= 100 }", |
5436 | "{ A[a] -> B[a,a,a/3] }", |
5437 | "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" }, |
5438 | { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }", |
5439 | "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" }, |
5440 | }; |
5441 | |
5442 | static int test_preimage_basic_set(isl_ctx *ctx) |
5443 | { |
5444 | int i; |
5445 | isl_basic_setisl_basic_map *bset1, *bset2; |
5446 | isl_multi_aff *ma; |
5447 | int equal; |
5448 | |
5449 | for (i = 0; i < ARRAY_SIZE(preimage_tests)(sizeof(preimage_tests)/sizeof(*preimage_tests)); ++i) { |
5450 | bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set); |
5451 | ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma); |
5452 | bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res); |
5453 | bset1 = isl_basic_set_preimage_multi_aff(bset1, ma); |
5454 | equal = isl_basic_set_is_equal(bset1, bset2); |
5455 | isl_basic_set_free(bset1); |
5456 | isl_basic_set_free(bset2); |
5457 | if (equal < 0) |
5458 | return -1; |
5459 | if (!equal) |
5460 | isl_die(ctx, isl_error_unknown, "bad preimage",do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5461); return -1; } while (0) |
5461 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5461); return -1; } while (0); |
5462 | } |
5463 | |
5464 | return 0; |
5465 | } |
5466 | |
5467 | struct { |
5468 | const char *map; |
5469 | const char *ma; |
5470 | const char *res; |
5471 | } preimage_domain_tests[] = { |
5472 | { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }", |
5473 | "{ A[j,i] -> B[i,j] }", |
5474 | "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" }, |
5475 | { "{ B[i] -> C[i]; D[i] -> E[i] }", |
5476 | "{ A[i] -> B[i + 1] }", |
5477 | "{ A[i] -> C[i + 1] }" }, |
5478 | { "{ B[i] -> C[i]; B[i] -> E[i] }", |
5479 | "{ A[i] -> B[i + 1] }", |
5480 | "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" }, |
5481 | { "{ B[i] -> C[([i/2])] }", |
5482 | "{ A[i] -> B[2i] }", |
5483 | "{ A[i] -> C[i] }" }, |
5484 | { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }", |
5485 | "{ A[i] -> B[([i/5]), ([i/7])] }", |
5486 | "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" }, |
5487 | { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }", |
5488 | "[N] -> { A[] -> B[([N/5])] }", |
5489 | "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" }, |
5490 | { "{ B[i] -> C[i] : exists a : i = 5 a }", |
5491 | "{ A[i] -> B[2i] }", |
5492 | "{ A[i] -> C[2i] : exists a : 2i = 5 a }" }, |
5493 | { "{ B[i] -> C[i] : exists a : i = 2 a; " |
5494 | "B[i] -> D[i] : exists a : i = 2 a + 1 }", |
5495 | "{ A[i] -> B[2i] }", |
5496 | "{ A[i] -> C[2i] }" }, |
5497 | { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }", |
5498 | "{ C[i] -> B[j] : 2j = i + floor(i/3) }" }, |
5499 | }; |
5500 | |
5501 | static int test_preimage_union_map(isl_ctx *ctx) |
5502 | { |
5503 | int i; |
5504 | isl_union_map *umap1, *umap2; |
5505 | isl_multi_aff *ma; |
5506 | int equal; |
5507 | |
5508 | for (i = 0; i < ARRAY_SIZE(preimage_domain_tests)(sizeof(preimage_domain_tests)/sizeof(*preimage_domain_tests) ); ++i) { |
5509 | umap1 = isl_union_map_read_from_str(ctx, |
5510 | preimage_domain_tests[i].map); |
5511 | ma = isl_multi_aff_read_from_str(ctx, |
5512 | preimage_domain_tests[i].ma); |
5513 | umap2 = isl_union_map_read_from_str(ctx, |
5514 | preimage_domain_tests[i].res); |
5515 | umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma); |
5516 | equal = isl_union_map_is_equal(umap1, umap2); |
5517 | isl_union_map_free(umap1); |
5518 | isl_union_map_free(umap2); |
5519 | if (equal < 0) |
5520 | return -1; |
5521 | if (!equal) |
5522 | isl_die(ctx, isl_error_unknown, "bad preimage",do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5523); return -1; } while (0) |
5523 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad preimage", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5523); return -1; } while (0); |
5524 | } |
5525 | |
5526 | return 0; |
5527 | } |
5528 | |
5529 | static int test_preimage(isl_ctx *ctx) |
5530 | { |
5531 | if (test_preimage_basic_set(ctx) < 0) |
5532 | return -1; |
5533 | if (test_preimage_union_map(ctx) < 0) |
5534 | return -1; |
5535 | |
5536 | return 0; |
5537 | } |
5538 | |
5539 | struct { |
5540 | const char *ma1; |
5541 | const char *ma; |
5542 | const char *res; |
5543 | } pullback_tests[] = { |
5544 | { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }", |
5545 | "{ A[a,b] -> C[b + 2a] }" }, |
5546 | { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" }, |
5547 | { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" }, |
5548 | { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }", |
5549 | "{ A[a] -> C[(a)/6] }" }, |
5550 | { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" }, |
5551 | { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }", |
5552 | "{ A[a] -> C[(2a)/3] }" }, |
5553 | { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"}, |
5554 | { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }", |
5555 | "{ A[i,j] -> C[i + j, i + j] }"}, |
5556 | { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" }, |
5557 | { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }", |
5558 | "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", }, |
5559 | { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }", |
5560 | "{ [i, j] -> [floor((i)/3), j] }", |
5561 | "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" }, |
5562 | }; |
5563 | |
5564 | static int test_pullback(isl_ctx *ctx) |
5565 | { |
5566 | int i; |
5567 | isl_multi_aff *ma1, *ma2; |
5568 | isl_multi_aff *ma; |
5569 | int equal; |
5570 | |
5571 | for (i = 0; i < ARRAY_SIZE(pullback_tests)(sizeof(pullback_tests)/sizeof(*pullback_tests)); ++i) { |
5572 | ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1); |
5573 | ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma); |
5574 | ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res); |
5575 | ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma); |
5576 | equal = isl_multi_aff_plain_is_equal(ma1, ma2); |
5577 | isl_multi_aff_free(ma1); |
5578 | isl_multi_aff_free(ma2); |
5579 | if (equal < 0) |
5580 | return -1; |
5581 | if (!equal) |
5582 | isl_die(ctx, isl_error_unknown, "bad pullback",do { isl_handle_error(ctx, isl_error_unknown, "bad pullback", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5583); return -1; } while (0) |
5583 | return -1)do { isl_handle_error(ctx, isl_error_unknown, "bad pullback", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5583); return -1; } while (0); |
5584 | } |
5585 | |
5586 | return 0; |
5587 | } |
5588 | |
5589 | /* Check that negation is printed correctly and that equal expressions |
5590 | * are correctly identified. |
5591 | */ |
5592 | static int test_ast(isl_ctx *ctx) |
5593 | { |
5594 | isl_ast_expr *expr, *expr1, *expr2, *expr3; |
5595 | char *str; |
5596 | int ok, equal; |
5597 | |
5598 | expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL((void*)0))); |
5599 | expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL((void*)0))); |
5600 | expr = isl_ast_expr_add(expr1, expr2); |
5601 | expr2 = isl_ast_expr_copy(expr); |
5602 | expr = isl_ast_expr_neg(expr); |
5603 | expr2 = isl_ast_expr_neg(expr2); |
5604 | equal = isl_ast_expr_is_equal(expr, expr2); |
5605 | str = isl_ast_expr_to_C_str(expr); |
5606 | 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; |
5607 | free(str); |
5608 | isl_ast_expr_free(expr); |
5609 | isl_ast_expr_free(expr2); |
5610 | |
5611 | if (ok < 0 || equal < 0) |
5612 | return -1; |
5613 | if (!equal) |
5614 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "equal expressions not considered equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5615); return -1; } while (0) |
5615 | "equal expressions not considered equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "equal expressions not considered equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5615); return -1; } while (0); |
5616 | if (!ok) |
5617 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5618); return -1; } while (0) |
5618 | "isl_ast_expr printed incorrectly", return -1)do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5618); return -1; } while (0); |
5619 | |
5620 | expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL((void*)0))); |
5621 | expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL((void*)0))); |
5622 | expr = isl_ast_expr_add(expr1, expr2); |
5623 | expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL((void*)0))); |
5624 | expr = isl_ast_expr_sub(expr3, expr); |
5625 | str = isl_ast_expr_to_C_str(expr); |
5626 | 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; |
5627 | free(str); |
5628 | isl_ast_expr_free(expr); |
5629 | |
5630 | if (ok < 0) |
5631 | return -1; |
5632 | if (!ok) |
5633 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5634); return -1; } while (0) |
5634 | "isl_ast_expr printed incorrectly", return -1)do { isl_handle_error(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5634); return -1; } while (0); |
5635 | |
5636 | return 0; |
5637 | } |
5638 | |
5639 | /* Check that isl_ast_build_expr_from_set returns a valid expression |
5640 | * for an empty set. Note that isl_ast_build_expr_from_set getting |
5641 | * called on an empty set probably indicates a bug in the caller. |
5642 | */ |
5643 | static int test_ast_build(isl_ctx *ctx) |
5644 | { |
5645 | isl_setisl_map *set; |
5646 | isl_ast_build *build; |
5647 | isl_ast_expr *expr; |
5648 | |
5649 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
5650 | build = isl_ast_build_from_context(set); |
5651 | |
5652 | set = isl_set_empty(isl_space_params_alloc(ctx, 0)); |
5653 | expr = isl_ast_build_expr_from_set(build, set); |
5654 | |
5655 | isl_ast_expr_free(expr); |
5656 | isl_ast_build_free(build); |
5657 | |
5658 | if (!expr) |
5659 | return -1; |
5660 | |
5661 | return 0; |
5662 | } |
5663 | |
5664 | /* Internal data structure for before_for and after_for callbacks. |
5665 | * |
5666 | * depth is the current depth |
5667 | * before is the number of times before_for has been called |
5668 | * after is the number of times after_for has been called |
5669 | */ |
5670 | struct isl_test_codegen_data { |
5671 | int depth; |
5672 | int before; |
5673 | int after; |
5674 | }; |
5675 | |
5676 | /* This function is called before each for loop in the AST generated |
5677 | * from test_ast_gen1. |
5678 | * |
5679 | * Increment the number of calls and the depth. |
5680 | * Check that the space returned by isl_ast_build_get_schedule_space |
5681 | * matches the target space of the schedule returned by |
5682 | * isl_ast_build_get_schedule. |
5683 | * Return an isl_id that is checked by the corresponding call |
5684 | * to after_for. |
5685 | */ |
5686 | static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build, |
5687 | void *user) |
5688 | { |
5689 | struct isl_test_codegen_data *data = user; |
5690 | isl_ctx *ctx; |
5691 | isl_space *space; |
5692 | isl_union_map *schedule; |
5693 | isl_union_set *uset; |
5694 | isl_setisl_map *set; |
5695 | int empty; |
5696 | char name[] = "d0"; |
5697 | |
5698 | ctx = isl_ast_build_get_ctx(build); |
5699 | |
5700 | if (data->before >= 3) |
5701 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5702); return ((void*)0); } while (0) |
5702 | "unexpected number of for nodes", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5702); return ((void*)0); } while (0); |
5703 | if (data->depth >= 2) |
5704 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected depth" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5705); return ((void*)0); } while (0) |
5705 | "unexpected depth", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "unexpected depth" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5705); return ((void*)0); } while (0); |
5706 | |
5707 | snprintf(name, sizeof(name), "d%d", data->depth); |
5708 | data->before++; |
5709 | data->depth++; |
5710 | |
5711 | schedule = isl_ast_build_get_schedule(build); |
5712 | uset = isl_union_map_range(schedule); |
5713 | if (!uset) |
5714 | return NULL((void*)0); |
5715 | if (isl_union_set_n_set(uset) != 1) { |
5716 | isl_union_set_free(uset); |
5717 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting single range space" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5718); return ((void*)0); } while (0) |
5718 | "expecting single range space", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "expecting single range space" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5718); return ((void*)0); } while (0); |
5719 | } |
5720 | |
5721 | space = isl_ast_build_get_schedule_space(build); |
5722 | set = isl_union_set_extract_set(uset, space); |
5723 | isl_union_set_free(uset); |
5724 | empty = isl_set_is_empty(set); |
5725 | isl_set_free(set); |
5726 | |
5727 | if (empty < 0) |
5728 | return NULL((void*)0); |
5729 | if (empty) |
5730 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "spaces don't match" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5731); return ((void*)0); } while (0) |
5731 | "spaces don't match", return NULL)do { isl_handle_error(ctx, isl_error_unknown, "spaces don't match" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5731); return ((void*)0); } while (0); |
5732 | |
5733 | return isl_id_alloc(ctx, name, NULL((void*)0)); |
5734 | } |
5735 | |
5736 | /* This function is called after each for loop in the AST generated |
5737 | * from test_ast_gen1. |
5738 | * |
5739 | * Increment the number of calls and decrement the depth. |
5740 | * Check that the annotation attached to the node matches |
5741 | * the isl_id returned by the corresponding call to before_for. |
5742 | */ |
5743 | static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node, |
5744 | __isl_keep isl_ast_build *build, void *user) |
5745 | { |
5746 | struct isl_test_codegen_data *data = user; |
5747 | isl_id *id; |
5748 | const char *name; |
5749 | int valid; |
5750 | |
5751 | data->after++; |
5752 | data->depth--; |
5753 | |
5754 | if (data->after > data->before) |
5755 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5757); return isl_ast_node_free(node); } while (0) |
5756 | "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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5757); return isl_ast_node_free(node); } while (0) |
5757 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5757); return isl_ast_node_free(node); } while (0); |
5758 | |
5759 | id = isl_ast_node_get_annotation(node); |
5760 | if (!id) |
5761 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5762); return isl_ast_node_free(node); } while (0) |
5762 | "missing annotation", return isl_ast_node_free(node))do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "missing annotation", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5762); return isl_ast_node_free(node); } while (0); |
5763 | |
5764 | name = isl_id_get_name(id); |
5765 | valid = name && atoi(name + 1) == data->depth; |
5766 | isl_id_free(id); |
5767 | |
5768 | if (!valid) |
5769 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5770); return isl_ast_node_free(node); } while (0) |
5770 | "wrong annotation", return isl_ast_node_free(node))do { isl_handle_error(isl_ast_node_get_ctx(node), isl_error_unknown , "wrong annotation", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5770); return isl_ast_node_free(node); } while (0); |
5771 | |
5772 | return node; |
5773 | } |
5774 | |
5775 | /* Check that the before_each_for and after_each_for callbacks |
5776 | * are called for each for loop in the generated code, |
5777 | * that they are called in the right order and that the isl_id |
5778 | * returned from the before_each_for callback is attached to |
5779 | * the isl_ast_node passed to the corresponding after_each_for call. |
5780 | */ |
5781 | static int test_ast_gen1(isl_ctx *ctx) |
5782 | { |
5783 | const char *str; |
5784 | isl_setisl_map *set; |
5785 | isl_union_map *schedule; |
5786 | isl_ast_build *build; |
5787 | isl_ast_node *tree; |
5788 | struct isl_test_codegen_data data; |
5789 | |
5790 | str = "[N] -> { : N >= 10 }"; |
5791 | set = isl_set_read_from_str(ctx, str); |
5792 | str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; " |
5793 | "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }"; |
5794 | schedule = isl_union_map_read_from_str(ctx, str); |
5795 | |
5796 | data.before = 0; |
5797 | data.after = 0; |
5798 | data.depth = 0; |
5799 | build = isl_ast_build_from_context(set); |
5800 | build = isl_ast_build_set_before_each_for(build, |
5801 | &before_for, &data); |
5802 | build = isl_ast_build_set_after_each_for(build, |
5803 | &after_for, &data); |
5804 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
5805 | isl_ast_build_free(build); |
5806 | if (!tree) |
5807 | return -1; |
5808 | |
5809 | isl_ast_node_free(tree); |
5810 | |
5811 | if (data.before != 3 || data.after != 3) |
5812 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5813); return -1; } while (0) |
5813 | "unexpected number of for nodes", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5813); return -1; } while (0); |
5814 | |
5815 | return 0; |
5816 | } |
5817 | |
5818 | /* Check that the AST generator handles domains that are integrally disjoint |
5819 | * but not rationally disjoint. |
5820 | */ |
5821 | static int test_ast_gen2(isl_ctx *ctx) |
5822 | { |
5823 | const char *str; |
5824 | isl_setisl_map *set; |
5825 | isl_union_map *schedule; |
5826 | isl_union_map *options; |
5827 | isl_ast_build *build; |
5828 | isl_ast_node *tree; |
5829 | |
5830 | str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }"; |
5831 | schedule = isl_union_map_read_from_str(ctx, str); |
5832 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
5833 | build = isl_ast_build_from_context(set); |
5834 | |
5835 | str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }"; |
5836 | options = isl_union_map_read_from_str(ctx, str); |
5837 | build = isl_ast_build_set_options(build, options); |
5838 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
5839 | isl_ast_build_free(build); |
5840 | if (!tree) |
5841 | return -1; |
5842 | isl_ast_node_free(tree); |
5843 | |
5844 | return 0; |
5845 | } |
5846 | |
5847 | /* Increment *user on each call. |
5848 | */ |
5849 | static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node, |
5850 | __isl_keep isl_ast_build *build, void *user) |
5851 | { |
5852 | int *n = user; |
5853 | |
5854 | (*n)++; |
5855 | |
5856 | return node; |
5857 | } |
5858 | |
5859 | /* Test that unrolling tries to minimize the number of instances. |
5860 | * In particular, for the schedule given below, make sure it generates |
5861 | * 3 nodes (rather than 101). |
5862 | */ |
5863 | static int test_ast_gen3(isl_ctx *ctx) |
5864 | { |
5865 | const char *str; |
5866 | isl_setisl_map *set; |
5867 | isl_union_map *schedule; |
5868 | isl_union_map *options; |
5869 | isl_ast_build *build; |
5870 | isl_ast_node *tree; |
5871 | int n_domain = 0; |
5872 | |
5873 | str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }"; |
5874 | schedule = isl_union_map_read_from_str(ctx, str); |
5875 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
5876 | |
5877 | str = "{ [i] -> unroll[0] }"; |
5878 | options = isl_union_map_read_from_str(ctx, str); |
5879 | |
5880 | build = isl_ast_build_from_context(set); |
5881 | build = isl_ast_build_set_options(build, options); |
5882 | build = isl_ast_build_set_at_each_domain(build, |
5883 | &count_domains, &n_domain); |
5884 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
5885 | isl_ast_build_free(build); |
5886 | if (!tree) |
5887 | return -1; |
5888 | |
5889 | isl_ast_node_free(tree); |
5890 | |
5891 | if (n_domain != 3) |
5892 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5893); return -1; } while (0) |
5893 | "unexpected number of for nodes", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of for nodes" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5893); return -1; } while (0); |
5894 | |
5895 | return 0; |
5896 | } |
5897 | |
5898 | /* Check that if the ast_build_exploit_nested_bounds options is set, |
5899 | * we do not get an outer if node in the generated AST, |
5900 | * while we do get such an outer if node if the options is not set. |
5901 | */ |
5902 | static int test_ast_gen4(isl_ctx *ctx) |
5903 | { |
5904 | const char *str; |
5905 | isl_setisl_map *set; |
5906 | isl_union_map *schedule; |
5907 | isl_ast_build *build; |
5908 | isl_ast_node *tree; |
5909 | enum isl_ast_node_type type; |
5910 | int enb; |
5911 | |
5912 | enb = isl_options_get_ast_build_exploit_nested_bounds(ctx); |
5913 | str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }"; |
5914 | |
5915 | isl_options_set_ast_build_exploit_nested_bounds(ctx, 1); |
5916 | |
5917 | schedule = isl_union_map_read_from_str(ctx, str); |
5918 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
5919 | build = isl_ast_build_from_context(set); |
5920 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
5921 | isl_ast_build_free(build); |
5922 | if (!tree) |
5923 | return -1; |
5924 | |
5925 | type = isl_ast_node_get_type(tree); |
5926 | isl_ast_node_free(tree); |
5927 | |
5928 | if (type == isl_ast_node_if) |
5929 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "not expecting if node" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5930); return -1; } while (0) |
5930 | "not expecting if node", return -1)do { isl_handle_error(ctx, isl_error_unknown, "not expecting if node" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5930); return -1; } while (0); |
5931 | |
5932 | isl_options_set_ast_build_exploit_nested_bounds(ctx, 0); |
5933 | |
5934 | schedule = isl_union_map_read_from_str(ctx, str); |
5935 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
5936 | build = isl_ast_build_from_context(set); |
5937 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
5938 | isl_ast_build_free(build); |
5939 | if (!tree) |
5940 | return -1; |
5941 | |
5942 | type = isl_ast_node_get_type(tree); |
5943 | isl_ast_node_free(tree); |
5944 | |
5945 | if (type != isl_ast_node_if) |
5946 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting if node" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5947); return -1; } while (0) |
5947 | "expecting if node", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting if node" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5947); return -1; } while (0); |
5948 | |
5949 | isl_options_set_ast_build_exploit_nested_bounds(ctx, enb); |
5950 | |
5951 | return 0; |
5952 | } |
5953 | |
5954 | /* This function is called for each leaf in the AST generated |
5955 | * from test_ast_gen5. |
5956 | * |
5957 | * We finalize the AST generation by extending the outer schedule |
5958 | * with a zero-dimensional schedule. If this results in any for loops, |
5959 | * then this means that we did not pass along enough information |
5960 | * about the outer schedule to the inner AST generation. |
5961 | */ |
5962 | static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build, |
5963 | void *user) |
5964 | { |
5965 | isl_union_map *schedule, *extra; |
5966 | isl_ast_node *tree; |
5967 | |
5968 | schedule = isl_ast_build_get_schedule(build); |
5969 | extra = isl_union_map_copy(schedule); |
5970 | extra = isl_union_map_from_domain(isl_union_map_domain(extra)); |
5971 | schedule = isl_union_map_range_product(schedule, extra); |
5972 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
5973 | isl_ast_build_free(build); |
5974 | |
5975 | if (!tree) |
5976 | return NULL((void*)0); |
5977 | |
5978 | if (isl_ast_node_get_type(tree) == isl_ast_node_for) |
5979 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5981); return isl_ast_node_free(tree); } while (0) |
5980 | "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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5981); return isl_ast_node_free(tree); } while (0) |
5981 | 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", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 5981); return isl_ast_node_free(tree); } while (0); |
5982 | |
5983 | return tree; |
5984 | } |
5985 | |
5986 | /* Check that we do not lose any information when going back and |
5987 | * forth between internal and external schedule. |
5988 | * |
5989 | * In particular, we create an AST where we unroll the only |
5990 | * non-constant dimension in the schedule. We therefore do |
5991 | * not expect any for loops in the AST. However, older versions |
5992 | * of isl would not pass along enough information about the outer |
5993 | * schedule when performing an inner code generation from a create_leaf |
5994 | * callback, resulting in the inner code generation producing a for loop. |
5995 | */ |
5996 | static int test_ast_gen5(isl_ctx *ctx) |
5997 | { |
5998 | const char *str; |
5999 | isl_setisl_map *set; |
6000 | isl_union_map *schedule, *options; |
6001 | isl_ast_build *build; |
6002 | isl_ast_node *tree; |
6003 | |
6004 | str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }"; |
6005 | schedule = isl_union_map_read_from_str(ctx, str); |
6006 | |
6007 | str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: " |
6008 | "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }"; |
6009 | options = isl_union_map_read_from_str(ctx, str); |
6010 | |
6011 | set = isl_set_universe(isl_space_params_alloc(ctx, 0)); |
6012 | build = isl_ast_build_from_context(set); |
6013 | build = isl_ast_build_set_options(build, options); |
6014 | build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL((void*)0)); |
6015 | tree = isl_ast_build_node_from_schedule_map(build, schedule); |
6016 | isl_ast_build_free(build); |
6017 | isl_ast_node_free(tree); |
6018 | if (!tree) |
6019 | return -1; |
6020 | |
6021 | return 0; |
6022 | } |
6023 | |
6024 | static int test_ast_gen(isl_ctx *ctx) |
6025 | { |
6026 | if (test_ast_gen1(ctx) < 0) |
6027 | return -1; |
6028 | if (test_ast_gen2(ctx) < 0) |
6029 | return -1; |
6030 | if (test_ast_gen3(ctx) < 0) |
6031 | return -1; |
6032 | if (test_ast_gen4(ctx) < 0) |
6033 | return -1; |
6034 | if (test_ast_gen5(ctx) < 0) |
6035 | return -1; |
6036 | return 0; |
6037 | } |
6038 | |
6039 | /* Check if dropping output dimensions from an isl_pw_multi_aff |
6040 | * works properly. |
6041 | */ |
6042 | static int test_pw_multi_aff(isl_ctx *ctx) |
6043 | { |
6044 | const char *str; |
6045 | isl_pw_multi_aff *pma1, *pma2; |
6046 | int equal; |
6047 | |
6048 | str = "{ [i,j] -> [i+j, 4i-j] }"; |
6049 | pma1 = isl_pw_multi_aff_read_from_str(ctx, str); |
6050 | str = "{ [i,j] -> [4i-j] }"; |
6051 | pma2 = isl_pw_multi_aff_read_from_str(ctx, str); |
6052 | |
6053 | pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1); |
6054 | |
6055 | equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2); |
6056 | |
6057 | isl_pw_multi_aff_free(pma1); |
6058 | isl_pw_multi_aff_free(pma2); |
6059 | if (equal < 0) |
6060 | return -1; |
6061 | if (!equal) |
6062 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6063); return -1; } while (0) |
6063 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6063); return -1; } while (0); |
6064 | |
6065 | return 0; |
6066 | } |
6067 | |
6068 | /* Check that we can properly parse multi piecewise affine expressions |
6069 | * where the piecewise affine expressions have different domains. |
6070 | */ |
6071 | static int test_multi_pw_aff(isl_ctx *ctx) |
6072 | { |
6073 | const char *str; |
6074 | isl_setisl_map *dom, *dom2; |
6075 | isl_multi_pw_aff *mpa1, *mpa2; |
6076 | isl_pw_aff *pa; |
6077 | int equal; |
6078 | int equal_domain; |
6079 | |
6080 | mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }"); |
6081 | dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }"); |
6082 | mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom); |
6083 | mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }"); |
6084 | mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2); |
6085 | str = "{ [i] -> [(i : i > 0), 2i] }"; |
6086 | mpa1 = isl_multi_pw_aff_read_from_str(ctx, str); |
6087 | |
6088 | equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2); |
6089 | |
6090 | pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0); |
6091 | dom = isl_pw_aff_domain(pa); |
6092 | pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1); |
6093 | dom2 = isl_pw_aff_domain(pa); |
6094 | equal_domain = isl_set_is_equal(dom, dom2); |
6095 | |
6096 | isl_set_free(dom); |
6097 | isl_set_free(dom2); |
6098 | isl_multi_pw_aff_free(mpa1); |
6099 | isl_multi_pw_aff_free(mpa2); |
6100 | |
6101 | if (equal < 0) |
6102 | return -1; |
6103 | if (!equal) |
6104 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6105); return -1; } while (0) |
6105 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6105); return -1; } while (0); |
6106 | |
6107 | if (equal_domain < 0) |
6108 | return -1; |
6109 | if (equal_domain) |
6110 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "domains unexpectedly equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6111); return -1; } while (0) |
6111 | "domains unexpectedly equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "domains unexpectedly equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6111); return -1; } while (0); |
6112 | |
6113 | return 0; |
6114 | } |
6115 | |
6116 | /* This is a regression test for a bug where isl_basic_map_simplify |
6117 | * would end up in an infinite loop. In particular, we construct |
6118 | * an empty basic set that is not obviously empty. |
6119 | * isl_basic_set_is_empty marks the basic set as empty. |
6120 | * After projecting out i3, the variable can be dropped completely, |
6121 | * but isl_basic_map_simplify refrains from doing so if the basic set |
6122 | * is empty and would end up in an infinite loop if it didn't test |
6123 | * explicitly for empty basic maps in the outer loop. |
6124 | */ |
6125 | static int test_simplify_1(isl_ctx *ctx) |
6126 | { |
6127 | const char *str; |
6128 | isl_basic_setisl_basic_map *bset; |
6129 | int empty; |
6130 | |
6131 | str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and " |
6132 | "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and " |
6133 | "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and " |
6134 | "i3 >= i2 }"; |
6135 | bset = isl_basic_set_read_from_str(ctx, str); |
6136 | empty = isl_basic_set_is_empty(bset); |
6137 | bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1); |
6138 | isl_basic_set_free(bset); |
6139 | if (!bset) |
6140 | return -1; |
6141 | if (!empty) |
6142 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "basic set should be empty" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6143); return -1; } while (0) |
6143 | "basic set should be empty", return -1)do { isl_handle_error(ctx, isl_error_unknown, "basic set should be empty" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6143); return -1; } while (0); |
6144 | |
6145 | return 0; |
6146 | } |
6147 | |
6148 | /* Check that the equality in the set description below |
6149 | * is simplified away. |
6150 | */ |
6151 | static int test_simplify_2(isl_ctx *ctx) |
6152 | { |
6153 | const char *str; |
6154 | isl_basic_setisl_basic_map *bset; |
6155 | isl_bool universe; |
6156 | |
6157 | str = "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }"; |
6158 | bset = isl_basic_set_read_from_str(ctx, str); |
6159 | universe = isl_basic_set_plain_is_universe(bset); |
6160 | isl_basic_set_free(bset); |
6161 | |
6162 | if (universe < 0) |
6163 | return -1; |
6164 | if (!universe) |
6165 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "equality not simplified away" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6166); return -1; } while (0) |
6166 | "equality not simplified away", return -1)do { isl_handle_error(ctx, isl_error_unknown, "equality not simplified away" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6166); return -1; } while (0); |
6167 | return 0; |
6168 | } |
6169 | |
6170 | /* Some simplification tests. |
6171 | */ |
6172 | static int test_simplify(isl_ctx *ctx) |
6173 | { |
6174 | if (test_simplify_1(ctx) < 0) |
6175 | return -1; |
6176 | if (test_simplify_2(ctx) < 0) |
6177 | return -1; |
6178 | return 0; |
6179 | } |
6180 | |
6181 | /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt |
6182 | * with gbr context would fail to disable the use of the shifted tableau |
6183 | * when transferring equalities for the input to the context, resulting |
6184 | * in invalid sample values. |
6185 | */ |
6186 | static int test_partial_lexmin(isl_ctx *ctx) |
6187 | { |
6188 | const char *str; |
6189 | isl_basic_setisl_basic_map *bset; |
6190 | isl_basic_map *bmap; |
6191 | isl_map *map; |
6192 | |
6193 | str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }"; |
6194 | bmap = isl_basic_map_read_from_str(ctx, str); |
6195 | str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }"; |
6196 | bset = isl_basic_set_read_from_str(ctx, str); |
6197 | map = isl_basic_map_partial_lexmin(bmap, bset, NULL((void*)0)); |
6198 | isl_map_free(map); |
6199 | |
6200 | if (!map) |
6201 | return -1; |
6202 | |
6203 | return 0; |
6204 | } |
6205 | |
6206 | /* Check that the variable compression performed on the existentially |
6207 | * quantified variables inside isl_basic_set_compute_divs is not confused |
6208 | * by the implicit equalities among the parameters. |
6209 | */ |
6210 | static int test_compute_divs(isl_ctx *ctx) |
6211 | { |
6212 | const char *str; |
6213 | isl_basic_setisl_basic_map *bset; |
6214 | isl_setisl_map *set; |
6215 | |
6216 | str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and " |
6217 | "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and " |
6218 | "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and " |
6219 | "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }"; |
6220 | bset = isl_basic_set_read_from_str(ctx, str); |
6221 | set = isl_basic_set_compute_divs(bset); |
6222 | isl_set_free(set); |
6223 | if (!set) |
6224 | return -1; |
6225 | |
6226 | return 0; |
6227 | } |
6228 | |
6229 | /* Check that the reaching domain elements and the prefix schedule |
6230 | * at a leaf node are the same before and after grouping. |
6231 | */ |
6232 | static int test_schedule_tree_group_1(isl_ctx *ctx) |
6233 | { |
6234 | int equal; |
6235 | const char *str; |
6236 | isl_id *id; |
6237 | isl_union_set *uset; |
6238 | isl_multi_union_pw_aff *mupa; |
6239 | isl_union_pw_multi_aff *upma1, *upma2; |
6240 | isl_union_set *domain1, *domain2; |
6241 | isl_union_map *umap1, *umap2; |
6242 | isl_schedule_node *node; |
6243 | |
6244 | str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }"; |
6245 | uset = isl_union_set_read_from_str(ctx, str); |
6246 | node = isl_schedule_node_from_domain(uset); |
6247 | node = isl_schedule_node_child(node, 0); |
6248 | str = "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]"; |
6249 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
6250 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
6251 | node = isl_schedule_node_child(node, 0); |
6252 | str = "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]"; |
6253 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
6254 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
6255 | node = isl_schedule_node_child(node, 0); |
6256 | umap1 = isl_schedule_node_get_prefix_schedule_union_map(node); |
6257 | upma1 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node); |
6258 | domain1 = isl_schedule_node_get_domain(node); |
6259 | id = isl_id_alloc(ctx, "group", NULL((void*)0)); |
6260 | node = isl_schedule_node_parent(node); |
6261 | node = isl_schedule_node_group(node, id); |
6262 | node = isl_schedule_node_child(node, 0); |
6263 | umap2 = isl_schedule_node_get_prefix_schedule_union_map(node); |
6264 | upma2 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node); |
6265 | domain2 = isl_schedule_node_get_domain(node); |
6266 | equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2); |
6267 | if (equal >= 0 && equal) |
6268 | equal = isl_union_set_is_equal(domain1, domain2); |
6269 | if (equal >= 0 && equal) |
6270 | equal = isl_union_map_is_equal(umap1, umap2); |
6271 | isl_union_map_free(umap1); |
6272 | isl_union_map_free(umap2); |
6273 | isl_union_set_free(domain1); |
6274 | isl_union_set_free(domain2); |
6275 | isl_union_pw_multi_aff_free(upma1); |
6276 | isl_union_pw_multi_aff_free(upma2); |
6277 | isl_schedule_node_free(node); |
6278 | |
6279 | if (equal < 0) |
6280 | return -1; |
6281 | if (!equal) |
6282 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6283); return -1; } while (0) |
6283 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6283); return -1; } while (0); |
6284 | |
6285 | return 0; |
6286 | } |
6287 | |
6288 | /* Check that we can have nested groupings and that the union map |
6289 | * schedule representation is the same before and after the grouping. |
6290 | * Note that after the grouping, the union map representation contains |
6291 | * the domain constraints from the ranges of the expansion nodes, |
6292 | * while they are missing from the union map representation of |
6293 | * the tree without expansion nodes. |
6294 | * |
6295 | * Also check that the global expansion is as expected. |
6296 | */ |
6297 | static int test_schedule_tree_group_2(isl_ctx *ctx) |
6298 | { |
6299 | int equal, equal_expansion; |
6300 | const char *str; |
6301 | isl_id *id; |
6302 | isl_union_set *uset; |
6303 | isl_union_map *umap1, *umap2; |
6304 | isl_union_map *expansion1, *expansion2; |
6305 | isl_union_set_list *filters; |
6306 | isl_multi_union_pw_aff *mupa; |
6307 | isl_schedule *schedule; |
6308 | isl_schedule_node *node; |
6309 | |
6310 | str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; " |
6311 | "S3[i,j] : 0 <= i,j < 10 }"; |
6312 | uset = isl_union_set_read_from_str(ctx, str); |
6313 | node = isl_schedule_node_from_domain(uset); |
6314 | node = isl_schedule_node_child(node, 0); |
6315 | str = "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]"; |
6316 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
6317 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
6318 | node = isl_schedule_node_child(node, 0); |
6319 | str = "{ S1[i,j] }"; |
6320 | uset = isl_union_set_read_from_str(ctx, str); |
6321 | filters = isl_union_set_list_from_union_set(uset); |
6322 | str = "{ S2[i,j]; S3[i,j] }"; |
6323 | uset = isl_union_set_read_from_str(ctx, str); |
6324 | filters = isl_union_set_list_add(filters, uset); |
6325 | node = isl_schedule_node_insert_sequence(node, filters); |
6326 | node = isl_schedule_node_child(node, 1); |
6327 | node = isl_schedule_node_child(node, 0); |
6328 | str = "{ S2[i,j] }"; |
6329 | uset = isl_union_set_read_from_str(ctx, str); |
6330 | filters = isl_union_set_list_from_union_set(uset); |
6331 | str = "{ S3[i,j] }"; |
6332 | uset = isl_union_set_read_from_str(ctx, str); |
6333 | filters = isl_union_set_list_add(filters, uset); |
6334 | node = isl_schedule_node_insert_sequence(node, filters); |
6335 | |
6336 | schedule = isl_schedule_node_get_schedule(node); |
6337 | umap1 = isl_schedule_get_map(schedule); |
6338 | uset = isl_schedule_get_domain(schedule); |
6339 | umap1 = isl_union_map_intersect_domain(umap1, uset); |
6340 | isl_schedule_free(schedule); |
6341 | |
6342 | node = isl_schedule_node_parent(node); |
6343 | node = isl_schedule_node_parent(node); |
6344 | id = isl_id_alloc(ctx, "group1", NULL((void*)0)); |
6345 | node = isl_schedule_node_group(node, id); |
6346 | node = isl_schedule_node_child(node, 1); |
6347 | node = isl_schedule_node_child(node, 0); |
6348 | id = isl_id_alloc(ctx, "group2", NULL((void*)0)); |
6349 | node = isl_schedule_node_group(node, id); |
6350 | |
6351 | schedule = isl_schedule_node_get_schedule(node); |
6352 | umap2 = isl_schedule_get_map(schedule); |
6353 | isl_schedule_free(schedule); |
6354 | |
6355 | node = isl_schedule_node_root(node); |
6356 | node = isl_schedule_node_child(node, 0); |
6357 | expansion1 = isl_schedule_node_get_subtree_expansion(node); |
6358 | isl_schedule_node_free(node); |
6359 | |
6360 | str = "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; " |
6361 | "group1[i] -> S2[i,j] : 0 <= i,j < 10; " |
6362 | "group1[i] -> S3[i,j] : 0 <= i,j < 10 }"; |
6363 | |
6364 | expansion2 = isl_union_map_read_from_str(ctx, str); |
6365 | |
6366 | equal = isl_union_map_is_equal(umap1, umap2); |
6367 | equal_expansion = isl_union_map_is_equal(expansion1, expansion2); |
6368 | |
6369 | isl_union_map_free(umap1); |
6370 | isl_union_map_free(umap2); |
6371 | isl_union_map_free(expansion1); |
6372 | isl_union_map_free(expansion2); |
6373 | |
6374 | if (equal < 0 || equal_expansion < 0) |
6375 | return -1; |
6376 | if (!equal) |
6377 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6378); return -1; } while (0) |
6378 | "expressions not equal", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expressions not equal" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6378); return -1; } while (0); |
6379 | if (!equal_expansion) |
6380 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected expansion" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6381); return -1; } while (0) |
6381 | "unexpected expansion", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected expansion" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6381); return -1; } while (0); |
6382 | |
6383 | return 0; |
6384 | } |
6385 | |
6386 | /* Some tests for the isl_schedule_node_group function. |
6387 | */ |
6388 | static int test_schedule_tree_group(isl_ctx *ctx) |
6389 | { |
6390 | if (test_schedule_tree_group_1(ctx) < 0) |
6391 | return -1; |
6392 | if (test_schedule_tree_group_2(ctx) < 0) |
6393 | return -1; |
6394 | return 0; |
6395 | } |
6396 | |
6397 | struct { |
6398 | const char *set; |
6399 | const char *dual; |
6400 | } coef_tests[] = { |
6401 | { "{ rat: [i] : 0 <= i <= 10 }", |
6402 | "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" }, |
6403 | { "{ rat: [i] : FALSE }", |
6404 | "{ rat: coefficients[[cst] -> [a]] }" }, |
6405 | { "{ rat: [i] : }", |
6406 | "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" }, |
6407 | }; |
6408 | |
6409 | struct { |
6410 | const char *set; |
6411 | const char *dual; |
6412 | } sol_tests[] = { |
6413 | { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }", |
6414 | "{ rat: [i] : 0 <= i <= 10 }" }, |
6415 | { "{ rat: coefficients[[cst] -> [a]] : FALSE }", |
6416 | "{ rat: [i] }" }, |
6417 | { "{ rat: coefficients[[cst] -> [a]] }", |
6418 | "{ rat: [i] : FALSE }" }, |
6419 | }; |
6420 | |
6421 | /* Test the basic functionality of isl_basic_set_coefficients and |
6422 | * isl_basic_set_solutions. |
6423 | */ |
6424 | static int test_dual(isl_ctx *ctx) |
6425 | { |
6426 | int i; |
6427 | |
6428 | for (i = 0; i < ARRAY_SIZE(coef_tests)(sizeof(coef_tests)/sizeof(*coef_tests)); ++i) { |
6429 | int equal; |
6430 | isl_basic_setisl_basic_map *bset1, *bset2; |
6431 | |
6432 | bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set); |
6433 | bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual); |
6434 | bset1 = isl_basic_set_coefficients(bset1); |
6435 | equal = isl_basic_set_is_equal(bset1, bset2); |
6436 | isl_basic_set_free(bset1); |
6437 | isl_basic_set_free(bset2); |
6438 | if (equal < 0) |
6439 | return -1; |
6440 | if (!equal) |
6441 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6442); return -1; } while (0) |
6442 | "incorrect dual", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6442); return -1; } while (0); |
6443 | } |
6444 | |
6445 | for (i = 0; i < ARRAY_SIZE(sol_tests)(sizeof(sol_tests)/sizeof(*sol_tests)); ++i) { |
6446 | int equal; |
6447 | isl_basic_setisl_basic_map *bset1, *bset2; |
6448 | |
6449 | bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set); |
6450 | bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual); |
6451 | bset1 = isl_basic_set_solutions(bset1); |
6452 | equal = isl_basic_set_is_equal(bset1, bset2); |
6453 | isl_basic_set_free(bset1); |
6454 | isl_basic_set_free(bset2); |
6455 | if (equal < 0) |
6456 | return -1; |
6457 | if (!equal) |
6458 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6459); return -1; } while (0) |
6459 | "incorrect dual", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect dual" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6459); return -1; } while (0); |
6460 | } |
6461 | |
6462 | return 0; |
6463 | } |
6464 | |
6465 | struct { |
6466 | int scale_tile; |
6467 | int shift_point; |
6468 | const char *domain; |
6469 | const char *schedule; |
6470 | const char *sizes; |
6471 | const char *tile; |
6472 | const char *point; |
6473 | } tile_tests[] = { |
6474 | { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }", |
6475 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
6476 | "{ [32,32] }", |
6477 | "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]", |
6478 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
6479 | }, |
6480 | { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }", |
6481 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
6482 | "{ [32,32] }", |
6483 | "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]", |
6484 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
6485 | }, |
6486 | { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }", |
6487 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
6488 | "{ [32,32] }", |
6489 | "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]", |
6490 | "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]", |
6491 | }, |
6492 | { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }", |
6493 | "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]", |
6494 | "{ [32,32] }", |
6495 | "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]", |
6496 | "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]", |
6497 | }, |
6498 | }; |
6499 | |
6500 | /* Basic tiling tests. Create a schedule tree with a domain and a band node, |
6501 | * tile the band and then check if the tile and point bands have the |
6502 | * expected partial schedule. |
6503 | */ |
6504 | static int test_tile(isl_ctx *ctx) |
6505 | { |
6506 | int i; |
6507 | int scale; |
6508 | int shift; |
6509 | |
6510 | scale = isl_options_get_tile_scale_tile_loops(ctx); |
6511 | shift = isl_options_get_tile_shift_point_loops(ctx); |
6512 | |
6513 | for (i = 0; i < ARRAY_SIZE(tile_tests)(sizeof(tile_tests)/sizeof(*tile_tests)); ++i) { |
6514 | int opt; |
6515 | int equal; |
6516 | const char *str; |
6517 | isl_union_set *domain; |
6518 | isl_multi_union_pw_aff *mupa, *mupa2; |
6519 | isl_schedule_node *node; |
6520 | isl_multi_val *sizes; |
6521 | |
6522 | opt = tile_tests[i].scale_tile; |
6523 | isl_options_set_tile_scale_tile_loops(ctx, opt); |
6524 | opt = tile_tests[i].shift_point; |
6525 | isl_options_set_tile_shift_point_loops(ctx, opt); |
6526 | |
6527 | str = tile_tests[i].domain; |
6528 | domain = isl_union_set_read_from_str(ctx, str); |
6529 | node = isl_schedule_node_from_domain(domain); |
6530 | node = isl_schedule_node_child(node, 0); |
6531 | str = tile_tests[i].schedule; |
6532 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
6533 | node = isl_schedule_node_insert_partial_schedule(node, mupa); |
6534 | str = tile_tests[i].sizes; |
6535 | sizes = isl_multi_val_read_from_str(ctx, str); |
6536 | node = isl_schedule_node_band_tile(node, sizes); |
6537 | |
6538 | str = tile_tests[i].tile; |
6539 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
6540 | mupa2 = isl_schedule_node_band_get_partial_schedule(node); |
6541 | equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2); |
6542 | isl_multi_union_pw_aff_free(mupa); |
6543 | isl_multi_union_pw_aff_free(mupa2); |
6544 | |
6545 | node = isl_schedule_node_child(node, 0); |
6546 | |
6547 | str = tile_tests[i].point; |
6548 | mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); |
6549 | mupa2 = isl_schedule_node_band_get_partial_schedule(node); |
6550 | if (equal >= 0 && equal) |
6551 | equal = isl_multi_union_pw_aff_plain_is_equal(mupa, |
6552 | mupa2); |
6553 | isl_multi_union_pw_aff_free(mupa); |
6554 | isl_multi_union_pw_aff_free(mupa2); |
6555 | |
6556 | isl_schedule_node_free(node); |
6557 | |
6558 | if (equal < 0) |
6559 | return -1; |
6560 | if (!equal) |
6561 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6562); return -1; } while (0) |
6562 | "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6562); return -1; } while (0); |
6563 | } |
6564 | |
6565 | isl_options_set_tile_scale_tile_loops(ctx, scale); |
6566 | isl_options_set_tile_shift_point_loops(ctx, shift); |
6567 | |
6568 | return 0; |
6569 | } |
6570 | |
6571 | /* Check that the domain hash of a space is equal to the hash |
6572 | * of the domain of the space. |
6573 | */ |
6574 | static int test_domain_hash(isl_ctx *ctx) |
6575 | { |
6576 | isl_map *map; |
6577 | isl_space *space; |
6578 | uint32_t hash1, hash2; |
6579 | |
6580 | map = isl_map_read_from_str(ctx, "[n] -> { A[B[x] -> C[]] -> D[] }"); |
6581 | space = isl_map_get_space(map); |
6582 | isl_map_free(map); |
6583 | hash1 = isl_space_get_domain_hash(space); |
6584 | space = isl_space_domain(space); |
6585 | hash2 = isl_space_get_hash(space); |
6586 | isl_space_free(space); |
6587 | |
6588 | if (!space) |
6589 | return -1; |
6590 | if (hash1 != hash2) |
6591 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "domain hash not equal to hash of domain" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6592); return -1; } while (0) |
6592 | "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" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6592); return -1; } while (0); |
6593 | |
6594 | return 0; |
6595 | } |
6596 | |
6597 | /* Check that a universe basic set that is not obviously equal to the universe |
6598 | * is still recognized as being equal to the universe. |
6599 | */ |
6600 | static int test_universe(isl_ctx *ctx) |
6601 | { |
6602 | const char *s; |
6603 | isl_basic_setisl_basic_map *bset; |
6604 | isl_bool is_univ; |
6605 | |
6606 | s = "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }"; |
6607 | bset = isl_basic_set_read_from_str(ctx, s); |
6608 | is_univ = isl_basic_set_is_universe(bset); |
6609 | isl_basic_set_free(bset); |
6610 | |
6611 | if (is_univ < 0) |
6612 | return -1; |
6613 | if (!is_univ) |
6614 | isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "not recognized as universe set" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6615); return -1; } while (0) |
6615 | "not recognized as universe set", return -1)do { isl_handle_error(ctx, isl_error_unknown, "not recognized as universe set" , "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6615); return -1; } while (0); |
6616 | |
6617 | return 0; |
6618 | } |
6619 | |
6620 | struct { |
6621 | const char *name; |
6622 | int (*fn)(isl_ctx *ctx); |
6623 | } tests [] = { |
6624 | { "universe", &test_universe }, |
6625 | { "domain hash", &test_domain_hash }, |
6626 | { "dual", &test_dual }, |
6627 | { "dependence analysis", &test_flow }, |
6628 | { "val", &test_val }, |
6629 | { "compute divs", &test_compute_divs }, |
6630 | { "partial lexmin", &test_partial_lexmin }, |
6631 | { "simplify", &test_simplify }, |
6632 | { "curry", &test_curry }, |
6633 | { "piecewise multi affine expressions", &test_pw_multi_aff }, |
6634 | { "multi piecewise affine expressions", &test_multi_pw_aff }, |
6635 | { "conversion", &test_conversion }, |
6636 | { "list", &test_list }, |
6637 | { "align parameters", &test_align_parameters }, |
6638 | { "preimage", &test_preimage }, |
6639 | { "pullback", &test_pullback }, |
6640 | { "AST", &test_ast }, |
6641 | { "AST build", &test_ast_build }, |
6642 | { "AST generation", &test_ast_gen }, |
6643 | { "eliminate", &test_eliminate }, |
6644 | { "residue class", &test_residue_class }, |
6645 | { "div", &test_div }, |
6646 | { "slice", &test_slice }, |
6647 | { "fixed power", &test_fixed_power }, |
6648 | { "sample", &test_sample }, |
6649 | { "output", &test_output }, |
6650 | { "vertices", &test_vertices }, |
6651 | { "fixed", &test_fixed }, |
6652 | { "equal", &test_equal }, |
6653 | { "disjoint", &test_disjoint }, |
6654 | { "product", &test_product }, |
6655 | { "dim_max", &test_dim_max }, |
6656 | { "affine", &test_aff }, |
6657 | { "injective", &test_injective }, |
6658 | { "schedule (whole component)", &test_schedule_whole }, |
6659 | { "schedule (incremental)", &test_schedule_incremental }, |
6660 | { "schedule tree grouping", &test_schedule_tree_group }, |
6661 | { "tile", &test_tile }, |
6662 | { "union_pw", &test_union_pw }, |
6663 | { "eval", &test_eval }, |
6664 | { "parse", &test_parse }, |
6665 | { "single-valued", &test_sv }, |
6666 | { "affine hull", &test_affine_hull }, |
6667 | { "simple_hull", &test_simple_hull }, |
6668 | { "coalesce", &test_coalesce }, |
6669 | { "factorize", &test_factorize }, |
6670 | { "subset", &test_subset }, |
6671 | { "subtract", &test_subtract }, |
6672 | { "intersect", &test_intersect }, |
6673 | { "lexmin", &test_lexmin }, |
6674 | { "min", &test_min }, |
6675 | { "gist", &test_gist }, |
6676 | { "piecewise quasi-polynomials", &test_pwqp }, |
6677 | { "lift", &test_lift }, |
6678 | { "bound", &test_bound }, |
6679 | { "union", &test_union }, |
6680 | { "split periods", &test_split_periods }, |
6681 | { "lexicographic order", &test_lex }, |
6682 | { "bijectivity", &test_bijective }, |
6683 | { "dataflow analysis", &test_dep }, |
6684 | { "reading", &test_read }, |
6685 | { "bounded", &test_bounded }, |
6686 | { "construction", &test_construction }, |
6687 | { "dimension manipulation", &test_dim }, |
6688 | { "map application", &test_application }, |
6689 | { "convex hull", &test_convex_hull }, |
6690 | { "transitive closure", &test_closure }, |
6691 | }; |
6692 | |
6693 | int main(int argc, char **argv) |
6694 | { |
6695 | int i; |
6696 | struct isl_ctx *ctx; |
6697 | struct isl_options *options; |
6698 | |
6699 | srcdir = getenv("srcdir"); |
6700 | assert(srcdir)((srcdir) ? (void) (0) : __assert_fail ("srcdir", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6700, __PRETTY_FUNCTION__)); |
6701 | |
6702 | options = isl_options_new_with_defaults(); |
6703 | assert(options)((options) ? (void) (0) : __assert_fail ("options", "/tmp/buildd/llvm-toolchain-snapshot-4.0~svn285991/tools/polly/lib/External/isl/isl_test.c" , 6703, __PRETTY_FUNCTION__)); |
6704 | argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL(1 << 0)); |
Value stored to 'argc' is never read | |
6705 | |
6706 | ctx = isl_ctx_alloc_with_options(&isl_options_args, options); |
6707 | for (i = 0; i < ARRAY_SIZE(tests)(sizeof(tests)/sizeof(*tests)); ++i) { |
6708 | printf("%s\n", tests[i].name); |
6709 | if (tests[i].fn(ctx) < 0) |
6710 | goto error; |
6711 | } |
6712 | isl_ctx_free(ctx); |
6713 | return 0; |
6714 | error: |
6715 | isl_ctx_free(ctx); |
6716 | return -1; |
6717 | } |