Bug Summary

File:tools/polly/lib/External/isl/isl_test.c
Warning:line 9407, column 2
Value stored to 'argc' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

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