Bug Summary

File:tools/polly/lib/External/isl/isl_test.c
Warning:line 9467, 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-eagerly-assume -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-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn336939/build-llvm/tools/polly/lib/External -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/pet/include -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/ppcg/include -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/ppcg/imath -I /build/llvm-toolchain-snapshot-7~svn336939/build-llvm/tools/polly/lib/External/ppcg -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/imath -I /build/llvm-toolchain-snapshot-7~svn336939/build-llvm/tools/polly/lib/External/isl -I /build/llvm-toolchain-snapshot-7~svn336939/build-llvm/tools/polly/include -I /usr/include/jsoncpp -I /build/llvm-toolchain-snapshot-7~svn336939/build-llvm/tools/polly/lib/External/isl/include -I /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/include -I /build/llvm-toolchain-snapshot-7~svn336939/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn336939/include -U NDEBUG -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.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-7~svn336939/build-llvm/tools/polly/lib/External -fdebug-prefix-map=/build/llvm-toolchain-snapshot-7~svn336939=. -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-07-13-043813-3945-1 -x c /build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c
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)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else
__assert_fail ("map", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 69, __extension__ __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-7~svn336939/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-7~svn336939/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)((void) sizeof ((pwqp) ? 1 : 0), __extension__ ({ if (pwqp) ;
else __assert_fail ("pwqp", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 98, __extension__ __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)((void) sizeof ((pwaff) ? 1 : 0), __extension__ ({ if (pwaff)
; else __assert_fail ("pwaff", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 107, __extension__ __PRETTY_FUNCTION__); }))
;
108 isl_pw_aff_free(pwaff);
109}
110
111/* Check that we can read an isl_multi_val from "str" without errors.
112 */
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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else
__assert_fail ("map", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 409, __extension__ __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)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else
__assert_fail ("map", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 414, __extension__ __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))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 435, __extension__ __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))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 443, __extension__ __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)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename
) ; else __assert_fail ("filename", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 465, __extension__ __PRETTY_FUNCTION__); }))
;
466 input = fopen(filename, "r");
467 assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input)
; else __assert_fail ("input", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 467, __extension__ __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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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)((void) sizeof ((!bounded) ? 1 : 0), __extension__ ({ if (!bounded
) ; else __assert_fail ("!bounded", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 506, __extension__ __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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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_2exp, "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_2exp, "-3", "1/8" },
714 { &isl_val_2exp, "-1", "1/2" },
715 { &isl_val_2exp, "1", "2" },
716 { &isl_val_2exp, "2", "4" },
717 { &isl_val_2exp, "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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0
), __extension__ ({ if (bset && bset->n_div == 1) ;
else __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 953, __extension__ __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)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0
), __extension__ ({ if (bset && bset->n_div == 1) ;
else __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 976, __extension__ __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)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0
), __extension__ ({ if (bset && bset->n_div == 1) ;
else __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 999, __extension__ __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))((void) sizeof ((isl_basic_set_is_empty(bset)) ? 1 : 0), __extension__
({ if (isl_basic_set_is_empty(bset)) ; else __assert_fail ("isl_basic_set_is_empty(bset)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1022, __extension__ __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)((void) sizeof ((bset && bset->n_div == 0) ? 1 : 0
), __extension__ ({ if (bset && bset->n_div == 0) ;
else __assert_fail ("bset && bset->n_div == 0", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1043, __extension__ __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)((void) sizeof ((bset && bset->n_div == 1) ? 1 : 0
), __extension__ ({ if (bset && bset->n_div == 1) ;
else __assert_fail ("bset && bset->n_div == 1", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1064, __extension__ __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))((void) sizeof ((!isl_basic_set_is_empty(bset)) ? 1 : 0), __extension__
({ if (!isl_basic_set_is_empty(bset)) ; else __assert_fail (
"!isl_basic_set_is_empty(bset)", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1146, __extension__ __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-7~svn336939/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-7~svn336939/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)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename
) ; else __assert_fail ("filename", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1202, __extension__ __PRETTY_FUNCTION__); }))
;
1203 input = fopen(filename, "r");
1204 assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input)
; else __assert_fail ("input", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1204, __extension__ __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)((void) sizeof ((isl_basic_set_is_equal(bset1, bset2) == 1) ?
1 : 0), __extension__ ({ if (isl_basic_set_is_equal(bset1, bset2
) == 1) ; else __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1213, __extension__ __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)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename
) ; else __assert_fail ("filename", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1237, __extension__ __PRETTY_FUNCTION__); }))
;
1238 input = fopen(filename, "r");
1239 assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input)
; else __assert_fail ("input", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1239, __extension__ __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)((void) sizeof ((isl_basic_set_is_equal(bset1, bset2) == 1) ?
1 : 0), __extension__ ({ if (isl_basic_set_is_equal(bset1, bset2
) == 1) ; else __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1246, __extension__ __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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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-7~svn336939/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)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename
) ; else __assert_fail ("filename", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1429, __extension__ __PRETTY_FUNCTION__); }))
;
1430 input = fopen(filename, "r");
1431 assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input)
; else __assert_fail ("input", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1431, __extension__ __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)((void) sizeof ((isl_basic_set_is_equal(bset1, bset2) == 1) ?
1 : 0), __extension__ ({ if (isl_basic_set_is_equal(bset1, bset2
) == 1) ; else __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1441, __extension__ __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-7~svn336939/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-7~svn336939/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)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename
) ; else __assert_fail ("filename", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1533, __extension__ __PRETTY_FUNCTION__); }))
;
1534 input = fopen(filename, "r");
1535 assert(input)((void) sizeof ((input) ? 1 : 0), __extension__ ({ if (input)
; else __assert_fail ("input", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1535, __extension__ __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)((void) sizeof ((isl_basic_set_is_equal(bset1, bset2) == 1) ?
1 : 0), __extension__ ({ if (isl_basic_set_is_equal(bset1, bset2
) == 1) ; else __assert_fail ("isl_basic_set_is_equal(bset1, bset2) == 1"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1544, __extension__ __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-7~svn336939/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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1596); return -1; } while (0)
;
1597 }
1598
1599 return 0;
1600}
1601
1602struct {
1603 const char *set;
1604 const char *context;
1605 const char *gist;
1606} gist_tests[] = {
1607 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1608 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1609 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1610 "{ [a, b, c] : a <= 15 }" },
1611 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1612 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1613 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1614 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1615 { "{ [m, n, a, b] : a <= 2147 + n }",
1616 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1617 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1618 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1619 "b >= 0) }",
1620 "{ [m, n, ku, kl] }" },
1621 { "{ [a, a, b] : a >= 10 }",
1622 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1623 "{ [a, a, b] : a >= 10 }" },
1624 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1625 "{ [0, j] : j >= 0 }" },
1626 /* Check that no constraints on i6 are introduced in the gist */
1627 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1628 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1629 "5e0 <= 381 - t1 and i4 <= 1) }",
1630 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1631 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1632 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1633 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1634 "20e0 >= 1511 - 4t1 - 5i4) }" },
1635 /* Check that no constraints on i6 are introduced in the gist */
1636 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1637 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1638 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1639 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1640 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1641 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1642 "20e1 <= 1530 - 4t1 - 5i4 and "
1643 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1644 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1645 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1646 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1647 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1648 "10e0 <= -91 + 5i4 + 4i6 and "
1649 "10e0 >= -105 + 5i4 + 4i6) }",
1650 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1651 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1652 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1653 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1654 "{ [a, b, q, p] : b >= 1 + a }",
1655 "{ [a, b, q, p] : false }" },
1656 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1657 "[n] -> { [x] : x mod 32 = 0 }",
1658 "[n] -> { [x = n] }" },
1659 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1660 "{ [x] : x mod 2 = 0 }" },
1661 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1662 "{ [x] : x mod 128 = 0 }" },
1663 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1664 "{ [x] : x mod 3200 = 0 }" },
1665 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1666 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1667 "{ [a, b, c = a] }" },
1668 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1669 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1670 "{ [a, b, c = a] : a mod 3 = 0 }" },
1671 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1672 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1673 "{ [x] }" },
1674 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1675 "{ [x,y] : 1 <= y <= 3 }",
1676 "{ [x,y] }" },
1677};
1678
1679/* Check that isl_set_gist behaves as expected.
1680 *
1681 * For the test cases in gist_tests, besides checking that the result
1682 * is as expected, also check that applying the gist operation does
1683 * not modify the input set (an earlier version of isl would do that) and
1684 * that the test case is consistent, i.e., that the gist has the same
1685 * intersection with the context as the input set.
1686 */
1687static int test_gist(struct isl_ctx *ctx)
1688{
1689 int i;
1690 const char *str;
1691 isl_basic_setisl_basic_map *bset1, *bset2;
1692 isl_map *map1, *map2;
1693 int equal;
1694
1695 for (i = 0; i < ARRAY_SIZE(gist_tests)(sizeof(gist_tests)/sizeof(*gist_tests)); ++i) {
1696 int equal_input, equal_intersection;
1697 isl_setisl_map *set1, *set2, *copy, *context;
1698
1699 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1700 context = isl_set_read_from_str(ctx, gist_tests[i].context);
1701 copy = isl_set_copy(set1);
1702 set1 = isl_set_gist(set1, isl_set_copy(context));
1703 set2 = isl_set_read_from_str(ctx, gist_tests[i].gist);
1704 equal = isl_set_is_equal(set1, set2);
1705 isl_set_free(set1);
1706 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1707 equal_input = isl_set_is_equal(set1, copy);
1708 isl_set_free(copy);
1709 set1 = isl_set_intersect(set1, isl_set_copy(context));
1710 set2 = isl_set_intersect(set2, context);
1711 equal_intersection = isl_set_is_equal(set1, set2);
1712 isl_set_free(set2);
1713 isl_set_free(set1);
1714 if (equal < 0 || equal_input < 0 || equal_intersection < 0)
1715 return -1;
1716 if (!equal)
1717 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1718); return -1; } while (0)
1718 "incorrect gist result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect gist result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1718); return -1; } while (0)
;
1719 if (!equal_input)
1720 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "gist modified input"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1721); return -1; } while (0)
1721 "gist modified input", return -1)do { isl_handle_error(ctx, isl_error_unknown, "gist modified input"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1721); return -1; } while (0)
;
1722 if (!equal_input)
1723 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1724); return -1; } while (0)
1724 "inconsistent gist test case", return -1)do { isl_handle_error(ctx, isl_error_unknown, "inconsistent gist test case"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1724); return -1; } while (0)
;
1725 }
1726
1727 test_gist_case(ctx, "gist1");
1728
1729 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1730 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1731 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1732 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1733 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1734 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1735 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1736 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1737 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1738 bset1 = isl_basic_set_read_from_str(ctx, str);
1739 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1740 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1741 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1742 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1743 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1744 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1745 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1746 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1747 bset2 = isl_basic_set_read_from_str(ctx, str);
1748 bset1 = isl_basic_set_gist(bset1, bset2);
1749 assert(bset1 && bset1->n_div == 0)((void) sizeof ((bset1 && bset1->n_div == 0) ? 1 :
0), __extension__ ({ if (bset1 && bset1->n_div ==
0) ; else __assert_fail ("bset1 && bset1->n_div == 0"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1749, __extension__ __PRETTY_FUNCTION__); }))
;
1750 isl_basic_set_free(bset1);
1751
1752 /* Check that the integer divisions of the second disjunct
1753 * do not spread to the first disjunct.
1754 */
1755 str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1756 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1757 "(exists (e0 = [(-1 + t1)/16], "
1758 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1759 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1760 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1761 "o0 <= 4294967295 and t1 <= -1)) }";
1762 map1 = isl_map_read_from_str(ctx, str);
1763 str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1764 map2 = isl_map_read_from_str(ctx, str);
1765 map1 = isl_map_gist(map1, map2);
1766 if (!map1)
1767 return -1;
1768 if (map1->n != 1)
1769 isl_die(ctx, isl_error_unknown, "expecting single disjunct",do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1770); isl_map_free(map1); return -1; } while (0)
1770 isl_map_free(map1); return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single disjunct"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1770); isl_map_free(map1); return -1; } while (0)
;
1771 if (isl_basic_map_dim(map1->p[0], isl_dim_div) != 1)
1772 isl_die(ctx, isl_error_unknown, "expecting single div",do { isl_handle_error(ctx, isl_error_unknown, "expecting single div"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1773); isl_map_free(map1); return -1; } while (0)
1773 isl_map_free(map1); return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting single div"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1773); isl_map_free(map1); return -1; } while (0)
;
1774 isl_map_free(map1);
1775
1776 if (test_plain_gist(ctx) < 0)
1777 return -1;
1778
1779 return 0;
1780}
1781
1782int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
1783{
1784 isl_setisl_map *set, *set2;
1785 int equal;
1786 int one;
1787
1788 set = isl_set_read_from_str(ctx, str);
1789 set = isl_set_coalesce(set);
1790 set2 = isl_set_read_from_str(ctx, str);
1791 equal = isl_set_is_equal(set, set2);
1792 one = set && set->n == 1;
1793 isl_set_free(set);
1794 isl_set_free(set2);
1795
1796 if (equal < 0)
1797 return -1;
1798 if (!equal)
1799 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "coalesced set not equal to input"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1800); return -1; } while (0)
1800 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1800); return -1; } while (0)
;
1801 if (check_one && !one)
1802 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1803); return -1; } while (0)
1803 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 1803); return -1; } while (0)
;
1804
1805 return 0;
1806}
1807
1808/* Inputs for coalescing tests with unbounded wrapping.
1809 * "str" is a string representation of the input set.
1810 * "single_disjunct" is set if we expect the result to consist of
1811 * a single disjunct.
1812 */
1813struct {
1814 int single_disjunct;
1815 const char *str;
1816} coalesce_unbounded_tests[] = {
1817 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1818 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1819 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1820 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1821 "-10 <= y <= 0}" },
1822 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1823 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1824 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1825 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1826};
1827
1828/* Test the functionality of isl_set_coalesce with the bounded wrapping
1829 * option turned off.
1830 */
1831int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
1832{
1833 int i;
1834 int r = 0;
1835 int bounded;
1836
1837 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
1838 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
1839
1840 for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests)(sizeof(coalesce_unbounded_tests)/sizeof(*coalesce_unbounded_tests
))
; ++i) {
1841 const char *str = coalesce_unbounded_tests[i].str;
1842 int check_one = coalesce_unbounded_tests[i].single_disjunct;
1843 if (test_coalesce_set(ctx, str, check_one) >= 0)
1844 continue;
1845 r = -1;
1846 break;
1847 }
1848
1849 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
1850
1851 return r;
1852}
1853
1854/* Inputs for coalescing tests.
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_tests[] = {
1863 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1864 "y >= x & x >= 2 & 5 >= y }" },
1865 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1866 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1867 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1868 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1869 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1870 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1871 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1872 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1873 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1874 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1875 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1876 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1877 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1878 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1879 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1880 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1881 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1882 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1883 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1884 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1885 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1886 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1887 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1888 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1889 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1890 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1891 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1892 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1893 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1894 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1895 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1896 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1897 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1898 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1899 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1900 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1901 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1902 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1903 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1904 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1905 "[o0, o1, o2, o3, o4, o5, o6]] : "
1906 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1907 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1908 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1909 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1910 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1911 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1912 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1913 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1914 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1915 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1916 "o6 >= i3 + i6 - o3 and M >= 0 and "
1917 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1918 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1919 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1920 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1921 "(o0 = 0 and M >= 2 and N >= 3) or "
1922 "(M = 0 and o0 = 0 and N >= 3) }" },
1923 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1924 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1925 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1926 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1927 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1928 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1929 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1930 "(y = 3 and x = 1) }" },
1931 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1932 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1933 "i1 <= M and i3 <= M and i4 <= M) or "
1934 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1935 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1936 "i4 <= -1 + M) }" },
1937 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1938 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1939 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1940 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1941 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1942 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1943 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1944 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1945 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1946 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1947 { 0, "{ [a, b] : exists e : 2e = a and "
1948 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1949 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1950 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1951 "j >= 1 and j' <= i + j - i' and i >= 1; "
1952 "[1, 1, 1, 1] }" },
1953 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1954 "[i,j] : exists a : j = 3a }" },
1955 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1956 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1957 "a >= 3) or "
1958 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1959 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1960 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1961 "c <= 6 + 8a and a >= 3; "
1962 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1963 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1964 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1965 "[x,0] : 3 <= x <= 4 }" },
1966 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1967 "[x,0] : 4 <= x <= 5 }" },
1968 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1969 "[x,0] : 3 <= x <= 5 }" },
1970 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1971 "[x,0] : 3 <= x <= 4 }" },
1972 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1973 "i1 <= 0; "
1974 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1975 { 1, "{ [0,0]; [1,1] }" },
1976 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1977 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1978 "ii <= k;"
1979 "[k, 0, k] : k <= 6 and k >= 1 }" },
1980 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1981 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1982 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1983 { 1, "[n] -> { [1] : n >= 0;"
1984 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1985 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1986 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1987 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1988 "2e0 <= x and 2e0 <= n);"
1989 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1990 "n >= 0) }" },
1991 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1992 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1993 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1994 "t1 = 1 }" },
1995 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1996 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1997 "[0, 0] }" },
1998 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1999 "t1 >= 13 and t1 <= 16);"
2000 "[t1] : t1 <= 15 and t1 >= 12 }" },
2001 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2002 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2003 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2004 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2005 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2006 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2007 "i <= 4j + 2 }" },
2008 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2009 "(exists (e0 : 3e0 = -2 + c0)) }" },
2010 { 0, "[n, b0, t0] -> "
2011 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2012 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2013 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2014 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2015 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2016 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2017 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2018 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2019 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2020 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2021 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2022 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2023 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2024 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2025 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2026 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2027 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2028 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2029 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2030 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2031 { 0, "{ [i0, i1, i2] : "
2032 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2033 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2034 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2035 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2036 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2037 "32e0 <= 31 + i0)) or "
2038 "i0 >= 0 }" },
2039 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2040 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2041 "2*floor((c)/2) = c and 0 <= a <= 192;"
2042 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2043 },
2044 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2045 "(0 <= a <= b <= n) }" },
2046 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2047 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2048 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2049 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2050 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2051 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2052 "b = 3 and 9e0 <= -19 + 2c)) }" },
2053 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2054 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2055 "(a = 4 and b = 3 and "
2056 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2057 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2058 "(b = -1 + a and 0 < a <= 3 and "
2059 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2060 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2061 "b = 3 and 9e0 <= -19 + 2c)) }" },
2062 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2063 "[1, 0] }" },
2064 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2065 "[0, 1] }" },
2066 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2067 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2068 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2069 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2070 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2071 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2072 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2073 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2074 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2075 { 1, "{ [a] : a <= 8 and "
2076 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2077 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2078 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2079 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2080 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2081 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2082 "(a < 0 and 3*floor((a)/3) < a) }" },
2083 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2084 "(a < -1 and 3*floor((a)/3) < a) }" },
2085 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2086 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2087 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2088 "or (2 <= a <= 15 and b < a)) }" },
2089 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2090 "32*floor((a)/32) < a) or a <= 15) }" },
2091 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2092 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2093 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2094 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2095 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2096 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2097 "S_0[n] : n <= m <= 2 + n }" },
2098 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2099 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2100 "2e0 <= a + b); "
2101 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2102 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2103 "2e0 < -a + 2b) }" },
2104 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2105 "[i, 0, i] : 0 <= i <= 7 }" },
2106 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2107 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2108 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2109 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2110 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2111 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2112 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2113 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2114 "a > 0 and a <= 5) }" },
2115};
2116
2117/* A specialized coalescing test case that would result
2118 * in a segmentation fault or a failed assertion in earlier versions of isl.
2119 */
2120static int test_coalesce_special(struct isl_ctx *ctx)
2121{
2122 const char *str;
2123 isl_map *map1, *map2;
2124
2125 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2126 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2127 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2128 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2129 "o1 <= 239 and o1 >= 212)) or "
2130 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2131 "o1 <= 241 and o1 >= 240));"
2132 "[S_L220_OUT[] -> T7[]] -> "
2133 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2134 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2135 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2136 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2137 map1 = isl_map_read_from_str(ctx, str);
2138 map1 = isl_map_align_divs_internal(map1);
2139 map1 = isl_map_coalesce(map1);
2140 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2141 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2142 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2143 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2144 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2145 map2 = isl_map_read_from_str(ctx, str);
2146 map2 = isl_map_union(map2, map1);
2147 map2 = isl_map_align_divs_internal(map2);
2148 map2 = isl_map_coalesce(map2);
2149 isl_map_free(map2);
2150 if (!map2)
2151 return -1;
2152
2153 return 0;
2154}
2155
2156/* A specialized coalescing test case that would result in an assertion
2157 * in an earlier version of isl.
2158 * The explicit call to isl_basic_set_union prevents the implicit
2159 * equality constraints in the first basic map from being detected prior
2160 * to the call to isl_set_coalesce, at least at the point
2161 * where this test case was introduced.
2162 */
2163static int test_coalesce_special2(struct isl_ctx *ctx)
2164{
2165 const char *str;
2166 isl_basic_setisl_basic_map *bset1, *bset2;
2167 isl_setisl_map *set;
2168
2169 str = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2170 bset1 = isl_basic_set_read_from_str(ctx, str);
2171 str = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2172 bset2 = isl_basic_set_read_from_str(ctx, str);
2173 set = isl_basic_set_union(bset1, bset2);
2174 set = isl_set_coalesce(set);
2175 isl_set_free(set);
2176
2177 if (!set)
2178 return -1;
2179 return 0;
2180}
2181
2182/* Check that calling isl_set_coalesce does not leave other sets
2183 * that may share some information with the input to isl_set_coalesce
2184 * in an inconsistent state.
2185 * In particular, older versions of isl would modify all copies
2186 * of the basic sets in the isl_set_coalesce input in a way
2187 * that could leave them in an inconsistent state.
2188 * The result of printing any other set containing one of these
2189 * basic sets would then result in an invalid set description.
2190 */
2191static int test_coalesce_special3(isl_ctx *ctx)
2192{
2193 const char *str;
2194 char *s;
2195 isl_setisl_map *set1, *set2;
2196 isl_printer *p;
2197
2198 set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }");
2199 str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2200 set2 = isl_set_read_from_str(ctx, str);
2201 set1 = isl_set_union(set1, isl_set_copy(set2));
2202 set1 = isl_set_coalesce(set1);
2203 isl_set_free(set1);
2204
2205 p = isl_printer_to_str(ctx);
2206 p = isl_printer_print_set(p, set2);
2207 isl_set_free(set2);
2208 s = isl_printer_get_str(p);
2209 isl_printer_free(p);
2210 set1 = isl_set_read_from_str(ctx, s);
2211 free(s);
2212 isl_set_free(set1);
2213
2214 if (!set1)
2215 return -1;
2216
2217 return 0;
2218}
2219
2220/* Test the functionality of isl_set_coalesce.
2221 * That is, check that the output is always equal to the input
2222 * and in some cases that the result consists of a single disjunct.
2223 */
2224static int test_coalesce(struct isl_ctx *ctx)
2225{
2226 int i;
2227
2228 for (i = 0; i < ARRAY_SIZE(coalesce_tests)(sizeof(coalesce_tests)/sizeof(*coalesce_tests)); ++i) {
2229 const char *str = coalesce_tests[i].str;
2230 int check_one = coalesce_tests[i].single_disjunct;
2231 if (test_coalesce_set(ctx, str, check_one) < 0)
2232 return -1;
2233 }
2234
2235 if (test_coalesce_unbounded_wrapping(ctx) < 0)
2236 return -1;
2237 if (test_coalesce_special(ctx) < 0)
2238 return -1;
2239 if (test_coalesce_special2(ctx) < 0)
2240 return -1;
2241 if (test_coalesce_special3(ctx) < 0)
2242 return -1;
2243
2244 return 0;
2245}
2246
2247/* Construct a representation of the graph on the right of Figure 1
2248 * in "Computing the Transitive Closure of a Union of
2249 * Affine Integer Tuple Relations".
2250 */
2251static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx)
2252{
2253 isl_setisl_map *dom;
2254 isl_map *up, *right;
2255
2256 dom = isl_set_read_from_str(ctx,
2257 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2258 "2 x - 3 y + 3 >= 0 }");
2259 right = isl_map_read_from_str(ctx,
2260 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2261 up = isl_map_read_from_str(ctx,
2262 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2263 right = isl_map_intersect_domain(right, isl_set_copy(dom));
2264 right = isl_map_intersect_range(right, isl_set_copy(dom));
2265 up = isl_map_intersect_domain(up, isl_set_copy(dom));
2266 up = isl_map_intersect_range(up, dom);
2267 return isl_map_union(up, right);
2268}
2269
2270/* Construct a representation of the power of the graph
2271 * on the right of Figure 1 in "Computing the Transitive Closure of
2272 * a Union of Affine Integer Tuple Relations".
2273 */
2274static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx)
2275{
2276 return isl_map_read_from_str(ctx,
2277 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2278 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2279 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2280}
2281
2282/* Construct a representation of the transitive closure of the graph
2283 * on the right of Figure 1 in "Computing the Transitive Closure of
2284 * a Union of Affine Integer Tuple Relations".
2285 */
2286static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx)
2287{
2288 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx)));
2289}
2290
2291static int test_closure(isl_ctx *ctx)
2292{
2293 const char *str;
2294 isl_map *map, *map2;
2295 int exact, equal;
2296
2297 /* COCOA example 1 */
2298 map = isl_map_read_from_str(ctx,
2299 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2300 "1 <= i and i < n and 1 <= j and j < n or "
2301 "i2 = i + 1 and j2 = j - 1 and "
2302 "1 <= i and i < n and 2 <= j and j <= n }");
2303 map = isl_map_power(map, &exact);
2304 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2304, __extension__ __PRETTY_FUNCTION__); }))
;
2305 isl_map_free(map);
2306
2307 /* COCOA example 1 */
2308 map = isl_map_read_from_str(ctx,
2309 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2310 "1 <= i and i < n and 1 <= j and j < n or "
2311 "i2 = i + 1 and j2 = j - 1 and "
2312 "1 <= i and i < n and 2 <= j and j <= n }");
2313 map = isl_map_transitive_closure(map, &exact);
2314 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2314, __extension__ __PRETTY_FUNCTION__); }))
;
2315 map2 = isl_map_read_from_str(ctx,
2316 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2317 "1 <= i and i < n and 1 <= j and j <= n and "
2318 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2319 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2320 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2321 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2321, __extension__ __PRETTY_FUNCTION__); }))
;
2322 isl_map_free(map2);
2323 isl_map_free(map);
2324
2325 map = isl_map_read_from_str(ctx,
2326 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2327 " 0 <= y and y <= n }");
2328 map = isl_map_transitive_closure(map, &exact);
2329 map2 = isl_map_read_from_str(ctx,
2330 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2331 " 0 <= y and y <= n }");
2332 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2332, __extension__ __PRETTY_FUNCTION__); }))
;
2333 isl_map_free(map2);
2334 isl_map_free(map);
2335
2336 /* COCOA example 2 */
2337 map = isl_map_read_from_str(ctx,
2338 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2339 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2340 "i2 = i + 2 and j2 = j - 2 and "
2341 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2342 map = isl_map_transitive_closure(map, &exact);
2343 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2343, __extension__ __PRETTY_FUNCTION__); }))
;
2344 map2 = isl_map_read_from_str(ctx,
2345 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2346 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2347 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2348 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2349 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2350 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2350, __extension__ __PRETTY_FUNCTION__); }))
;
2351 isl_map_free(map);
2352 isl_map_free(map2);
2353
2354 /* COCOA Fig.2 left */
2355 map = isl_map_read_from_str(ctx,
2356 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2357 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2358 "j <= n or "
2359 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2360 "j <= 2 i - 3 and j <= n - 2 or "
2361 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2362 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2363 map = isl_map_transitive_closure(map, &exact);
2364 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2364, __extension__ __PRETTY_FUNCTION__); }))
;
2365 isl_map_free(map);
2366
2367 /* COCOA Fig.2 right */
2368 map = isl_map_read_from_str(ctx,
2369 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2370 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2371 "j <= n or "
2372 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2373 "j <= 2 i - 4 and j <= n - 3 or "
2374 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2375 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2376 map = isl_map_power(map, &exact);
2377 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2377, __extension__ __PRETTY_FUNCTION__); }))
;
2378 isl_map_free(map);
2379
2380 /* COCOA Fig.2 right */
2381 map = isl_map_read_from_str(ctx,
2382 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2383 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2384 "j <= n or "
2385 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2386 "j <= 2 i - 4 and j <= n - 3 or "
2387 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2388 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2389 map = isl_map_transitive_closure(map, &exact);
2390 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2390, __extension__ __PRETTY_FUNCTION__); }))
;
2391 map2 = isl_map_read_from_str(ctx,
2392 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2393 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2394 "j <= n and 3 + i + 2 j <= 3 n and "
2395 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2396 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2397 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2398 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2399 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2400 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2400, __extension__ __PRETTY_FUNCTION__); }))
;
2401 isl_map_free(map2);
2402 isl_map_free(map);
2403
2404 map = cocoa_fig_1_right_graph(ctx);
2405 map = isl_map_transitive_closure(map, &exact);
2406 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2406, __extension__ __PRETTY_FUNCTION__); }))
;
2407 map2 = cocoa_fig_1_right_tc(ctx);
2408 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2408, __extension__ __PRETTY_FUNCTION__); }))
;
2409 isl_map_free(map2);
2410 isl_map_free(map);
2411
2412 map = cocoa_fig_1_right_graph(ctx);
2413 map = isl_map_power(map, &exact);
2414 map2 = cocoa_fig_1_right_power(ctx);
2415 equal = isl_map_is_equal(map, map2);
2416 isl_map_free(map2);
2417 isl_map_free(map);
2418 if (equal < 0)
2419 return -1;
2420 if (!exact)
2421 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2421); return -1; } while (0)
;
2422 if (!equal)
2423 isl_die(ctx, isl_error_unknown, "unexpected power", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected power"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2423); return -1; } while (0)
;
2424
2425 /* COCOA Theorem 1 counter example */
2426 map = isl_map_read_from_str(ctx,
2427 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2428 "i2 = 1 and j2 = j or "
2429 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2430 map = isl_map_transitive_closure(map, &exact);
2431 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2431, __extension__ __PRETTY_FUNCTION__); }))
;
2432 isl_map_free(map);
2433
2434 map = isl_map_read_from_str(ctx,
2435 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2436 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2437 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2438 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2439 map = isl_map_transitive_closure(map, &exact);
2440 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2440, __extension__ __PRETTY_FUNCTION__); }))
;
2441 isl_map_free(map);
2442
2443 /* Kelly et al 1996, fig 12 */
2444 map = isl_map_read_from_str(ctx,
2445 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2446 "1 <= i,j,j+1 <= n or "
2447 "j = n and j2 = 1 and i2 = i + 1 and "
2448 "1 <= i,i+1 <= n }");
2449 map = isl_map_transitive_closure(map, &exact);
2450 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2450, __extension__ __PRETTY_FUNCTION__); }))
;
2451 map2 = isl_map_read_from_str(ctx,
2452 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2453 "1 <= i <= n and i = i2 or "
2454 "1 <= i < i2 <= n and 1 <= j <= n and "
2455 "1 <= j2 <= n }");
2456 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2456, __extension__ __PRETTY_FUNCTION__); }))
;
2457 isl_map_free(map2);
2458 isl_map_free(map);
2459
2460 /* Omega's closure4 */
2461 map = isl_map_read_from_str(ctx,
2462 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2463 "1 <= x,y <= 10 or "
2464 "x2 = x + 1 and y2 = y and "
2465 "1 <= x <= 20 && 5 <= y <= 15 }");
2466 map = isl_map_transitive_closure(map, &exact);
2467 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2467, __extension__ __PRETTY_FUNCTION__); }))
;
2468 isl_map_free(map);
2469
2470 map = isl_map_read_from_str(ctx,
2471 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2472 map = isl_map_transitive_closure(map, &exact);
2473 assert(!exact)((void) sizeof ((!exact) ? 1 : 0), __extension__ ({ if (!exact
) ; else __assert_fail ("!exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2473, __extension__ __PRETTY_FUNCTION__); }))
;
2474 map2 = isl_map_read_from_str(ctx,
2475 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2476 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2476, __extension__ __PRETTY_FUNCTION__); }))
;
2477 isl_map_free(map);
2478 isl_map_free(map2);
2479
2480 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2481 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2482 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2483 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2484 map = isl_map_read_from_str(ctx, str);
2485 map = isl_map_transitive_closure(map, &exact);
2486 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2486, __extension__ __PRETTY_FUNCTION__); }))
;
2487 map2 = isl_map_read_from_str(ctx, str);
2488 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2488, __extension__ __PRETTY_FUNCTION__); }))
;
2489 isl_map_free(map);
2490 isl_map_free(map2);
2491
2492 str = "{[0] -> [1]; [2] -> [3]}";
2493 map = isl_map_read_from_str(ctx, str);
2494 map = isl_map_transitive_closure(map, &exact);
2495 assert(exact)((void) sizeof ((exact) ? 1 : 0), __extension__ ({ if (exact)
; else __assert_fail ("exact", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2495, __extension__ __PRETTY_FUNCTION__); }))
;
2496 map2 = isl_map_read_from_str(ctx, str);
2497 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2497, __extension__ __PRETTY_FUNCTION__); }))
;
2498 isl_map_free(map);
2499 isl_map_free(map2);
2500
2501 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2502 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2503 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2504 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2505 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2506 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2507 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2508 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2509 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2510 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2511 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2512 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2513 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2514 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2515 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2516 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2517 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2518 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2519 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2520 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2521 map = isl_map_read_from_str(ctx, str);
2522 map = isl_map_transitive_closure(map, NULL((void*)0));
2523 assert(map)((void) sizeof ((map) ? 1 : 0), __extension__ ({ if (map) ; else
__assert_fail ("map", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2523, __extension__ __PRETTY_FUNCTION__); }))
;
2524 isl_map_free(map);
2525
2526 return 0;
2527}
2528
2529static int test_lex(struct isl_ctx *ctx)
2530{
2531 isl_space *dim;
2532 isl_map *map;
2533 int empty;
2534
2535 dim = isl_space_set_alloc(ctx, 0, 0);
2536 map = isl_map_lex_le(dim);
2537 empty = isl_map_is_empty(map);
2538 isl_map_free(map);
2539
2540 if (empty < 0)
2541 return -1;
2542 if (empty)
2543 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2544); return -1; } while (0)
2544 "expecting non-empty result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting non-empty result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2544); return -1; } while (0)
;
2545
2546 return 0;
2547}
2548
2549/* Inputs for isl_map_lexmin tests.
2550 * "map" is the input and "lexmin" is the expected result.
2551 */
2552struct {
2553 const char *map;
2554 const char *lexmin;
2555} lexmin_tests [] = {
2556 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2557 "{ [x] -> [5] : 6 <= x <= 8; "
2558 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2559 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2560 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2561 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2562 "{ [x] -> [y] : (4y = x and x >= 0) or "
2563 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2564 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2565 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2566 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2567 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2568 /* Check that empty pieces are properly combined. */
2569 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2570 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2571 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2572 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2573 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2574 "x >= 4 }" },
2575 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2576 "a <= 255 and c <= 255 and d <= 255 - j and "
2577 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2578 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2579 "247d <= 247 + i and 248 - b <= 248d <= c and "
2580 "254d >= i - a + b and 254d >= -a + b and "
2581 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2582 "{ [i, k, j] -> "
2583 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2584 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2585 "247j >= 62738 - i and 509j <= 129795 + i and "
2586 "742j >= 188724 - i; "
2587 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2588 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2589 "16*floor((8 + b)/16) <= 7 + b; "
2590 "[a] -> [1] }",
2591 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2592 "[a] -> [b = 0] : 0 < a <= 509 }" },
2593 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2594 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2595};
2596
2597static int test_lexmin(struct isl_ctx *ctx)
2598{
2599 int i;
2600 int equal;
2601 const char *str;
2602 isl_basic_map *bmap;
2603 isl_map *map, *map2;
2604 isl_setisl_map *set;
2605 isl_setisl_map *set2;
2606 isl_pw_multi_aff *pma;
2607
2608 str = "[p0, p1] -> { [] -> [] : "
2609 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2610 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2611 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2612 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2613 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2614 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2615 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2616 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2617 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2618 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2619 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2620 map = isl_map_read_from_str(ctx, str);
2621 map = isl_map_lexmin(map);
2622 isl_map_free(map);
2623
2624 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2625 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2626 set = isl_set_read_from_str(ctx, str);
2627 set = isl_set_lexmax(set);
2628 str = "[C] -> { [obj,a,b,c] : C = 8 }";
2629 set2 = isl_set_read_from_str(ctx, str);
2630 set = isl_set_intersect(set, set2);
2631 assert(!isl_set_is_empty(set))((void) sizeof ((!isl_set_is_empty(set)) ? 1 : 0), __extension__
({ if (!isl_set_is_empty(set)) ; else __assert_fail ("!isl_set_is_empty(set)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2631, __extension__ __PRETTY_FUNCTION__); }))
;
2632 isl_set_free(set);
2633
2634 for (i = 0; i < ARRAY_SIZE(lexmin_tests)(sizeof(lexmin_tests)/sizeof(*lexmin_tests)); ++i) {
2635 map = isl_map_read_from_str(ctx, lexmin_tests[i].map);
2636 map = isl_map_lexmin(map);
2637 map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin);
2638 equal = isl_map_is_equal(map, map2);
2639 isl_map_free(map);
2640 isl_map_free(map2);
2641
2642 if (equal < 0)
2643 return -1;
2644 if (!equal)
2645 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2646); return -1; } while (0)
2646 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2646); return -1; } while (0)
;
2647 }
2648
2649 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2650 " 8i' <= i and 8i' >= -7 + i }";
2651 bmap = isl_basic_map_read_from_str(ctx, str);
2652 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
2653 map2 = isl_map_from_pw_multi_aff(pma);
2654 map = isl_map_from_basic_map(bmap);
2655 assert(isl_map_is_equal(map, map2))((void) sizeof ((isl_map_is_equal(map, map2)) ? 1 : 0), __extension__
({ if (isl_map_is_equal(map, map2)) ; else __assert_fail ("isl_map_is_equal(map, map2)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2655, __extension__ __PRETTY_FUNCTION__); }))
;
2656 isl_map_free(map);
2657 isl_map_free(map2);
2658
2659 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2660 " 8i' <= i and 8i' >= -7 + i }";
2661 set = isl_set_read_from_str(ctx, str);
2662 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
2663 set2 = isl_set_from_pw_multi_aff(pma);
2664 equal = isl_set_is_equal(set, set2);
2665 isl_set_free(set);
2666 isl_set_free(set2);
2667 if (equal < 0)
2668 return -1;
2669 if (!equal)
2670 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2672); return -1; } while (0)
2671 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2672); return -1; } while (0)
2672 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2672); return -1; } while (0)
;
2673
2674 return 0;
2675}
2676
2677/* A specialized isl_set_min_val test case that would return the wrong result
2678 * in earlier versions of isl.
2679 * The explicit call to isl_basic_set_union prevents the second basic set
2680 * from being determined to be empty prior to the call to isl_set_min_val,
2681 * at least at the point where this test case was introduced.
2682 */
2683static int test_min_special(isl_ctx *ctx)
2684{
2685 const char *str;
2686 isl_basic_setisl_basic_map *bset1, *bset2;
2687 isl_setisl_map *set;
2688 isl_aff *obj;
2689 isl_val *res;
2690 int ok;
2691
2692 str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2693 bset1 = isl_basic_set_read_from_str(ctx, str);
2694 str = "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2695 bset2 = isl_basic_set_read_from_str(ctx, str);
2696 set = isl_basic_set_union(bset1, bset2);
2697 obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }");
2698
2699 res = isl_set_min_val(set, obj);
2700 ok = isl_val_cmp_si(res, 5) == 0;
2701
2702 isl_aff_free(obj);
2703 isl_set_free(set);
2704 isl_val_free(res);
2705
2706 if (!res)
2707 return -1;
2708 if (!ok)
2709 isl_die(ctx, isl_error_unknown, "unexpected minimum",do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2710); return -1; } while (0)
2710 return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected minimum"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2710); return -1; } while (0)
;
2711
2712 return 0;
2713}
2714
2715/* A specialized isl_set_min_val test case that would return an error
2716 * in earlier versions of isl.
2717 */
2718static int test_min_special2(isl_ctx *ctx)
2719{
2720 const char *str;
2721 isl_basic_setisl_basic_map *bset;
2722 isl_aff *obj;
2723 isl_val *res;
2724
2725 str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2726 bset = isl_basic_set_read_from_str(ctx, str);
2727
2728 obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }");
2729
2730 res = isl_basic_set_max_val(bset, obj);
2731
2732 isl_basic_set_free(bset);
2733 isl_aff_free(obj);
2734 isl_val_free(res);
2735
2736 if (!res)
2737 return -1;
2738
2739 return 0;
2740}
2741
2742struct {
2743 const char *set;
2744 const char *obj;
2745 __isl_give isl_val *(*fn)(__isl_keep isl_setisl_map *set,
2746 __isl_keep isl_aff *obj);
2747 const char *res;
2748} opt_tests[] = {
2749 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" },
2750 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" },
2751 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2752 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2753 &isl_set_max_val, "30" },
2754
2755};
2756
2757/* Perform basic isl_set_min_val and isl_set_max_val tests.
2758 * In particular, check the results on non-convex inputs.
2759 */
2760static int test_min(struct isl_ctx *ctx)
2761{
2762 int i;
2763 isl_setisl_map *set;
2764 isl_aff *obj;
2765 isl_val *val, *res;
2766 isl_bool ok;
2767
2768 for (i = 0; i < ARRAY_SIZE(opt_tests)(sizeof(opt_tests)/sizeof(*opt_tests)); ++i) {
2769 set = isl_set_read_from_str(ctx, opt_tests[i].set);
2770 obj = isl_aff_read_from_str(ctx, opt_tests[i].obj);
2771 res = isl_val_read_from_str(ctx, opt_tests[i].res);
2772 val = opt_tests[i].fn(set, obj);
2773 ok = isl_val_eq(res, val);
2774 isl_val_free(res);
2775 isl_val_free(val);
2776 isl_aff_free(obj);
2777 isl_set_free(set);
2778
2779 if (ok < 0)
2780 return -1;
2781 if (!ok)
2782 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2783); return -1; } while (0)
2783 "unexpected optimum", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected optimum"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2783); return -1; } while (0)
;
2784 }
2785
2786 if (test_min_special(ctx) < 0)
2787 return -1;
2788 if (test_min_special2(ctx) < 0)
2789 return -1;
2790
2791 return 0;
2792}
2793
2794struct must_may {
2795 isl_map *must;
2796 isl_map *may;
2797};
2798
2799static isl_stat collect_must_may(__isl_take isl_map *dep, int must,
2800 void *dep_user, void *user)
2801{
2802 struct must_may *mm = (struct must_may *)user;
2803
2804 if (must)
2805 mm->must = isl_map_union(mm->must, dep);
2806 else
2807 mm->may = isl_map_union(mm->may, dep);
2808
2809 return isl_stat_ok;
2810}
2811
2812static int common_space(void *first, void *second)
2813{
2814 int depth = *(int *)first;
2815 return 2 * depth;
2816}
2817
2818static int map_is_equal(__isl_keep isl_map *map, const char *str)
2819{
2820 isl_map *map2;
2821 int equal;
2822
2823 if (!map)
2824 return -1;
2825
2826 map2 = isl_map_read_from_str(map->ctx, str);
2827 equal = isl_map_is_equal(map, map2);
2828 isl_map_free(map2);
2829
2830 return equal;
2831}
2832
2833static int map_check_equal(__isl_keep isl_map *map, const char *str)
2834{
2835 int equal;
2836
2837 equal = map_is_equal(map, str);
2838 if (equal < 0)
2839 return -1;
2840 if (!equal)
2841 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2842); return -1; } while (0)
2842 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2842); return -1; } while (0)
;
2843 return 0;
2844}
2845
2846static int test_dep(struct isl_ctx *ctx)
2847{
2848 const char *str;
2849 isl_space *dim;
2850 isl_map *map;
2851 isl_access_info *ai;
2852 isl_flow *flow;
2853 int depth;
2854 struct must_may mm;
2855
2856 depth = 3;
2857
2858 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2859 map = isl_map_read_from_str(ctx, str);
2860 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2861
2862 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2863 map = isl_map_read_from_str(ctx, str);
2864 ai = isl_access_info_add_source(ai, map, 1, &depth);
2865
2866 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2867 map = isl_map_read_from_str(ctx, str);
2868 ai = isl_access_info_add_source(ai, map, 1, &depth);
2869
2870 flow = isl_access_info_compute_flow(ai);
2871 dim = isl_space_alloc(ctx, 0, 3, 3);
2872 mm.must = isl_map_empty(isl_space_copy(dim));
2873 mm.may = isl_map_empty(dim);
2874
2875 isl_flow_foreach(flow, collect_must_may, &mm);
2876
2877 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2878 " [1,10,0] -> [2,5,0] }";
2879 assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2879, __extension__ __PRETTY_FUNCTION__); }))
;
2880 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2881 assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2881, __extension__ __PRETTY_FUNCTION__); }))
;
2882
2883 isl_map_free(mm.must);
2884 isl_map_free(mm.may);
2885 isl_flow_free(flow);
2886
2887
2888 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2889 map = isl_map_read_from_str(ctx, str);
2890 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2891
2892 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2893 map = isl_map_read_from_str(ctx, str);
2894 ai = isl_access_info_add_source(ai, map, 1, &depth);
2895
2896 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2897 map = isl_map_read_from_str(ctx, str);
2898 ai = isl_access_info_add_source(ai, map, 0, &depth);
2899
2900 flow = isl_access_info_compute_flow(ai);
2901 dim = isl_space_alloc(ctx, 0, 3, 3);
2902 mm.must = isl_map_empty(isl_space_copy(dim));
2903 mm.may = isl_map_empty(dim);
2904
2905 isl_flow_foreach(flow, collect_must_may, &mm);
2906
2907 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2908 assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2908, __extension__ __PRETTY_FUNCTION__); }))
;
2909 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2910 assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2910, __extension__ __PRETTY_FUNCTION__); }))
;
2911
2912 isl_map_free(mm.must);
2913 isl_map_free(mm.may);
2914 isl_flow_free(flow);
2915
2916
2917 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2918 map = isl_map_read_from_str(ctx, str);
2919 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2920
2921 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2922 map = isl_map_read_from_str(ctx, str);
2923 ai = isl_access_info_add_source(ai, map, 0, &depth);
2924
2925 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2926 map = isl_map_read_from_str(ctx, str);
2927 ai = isl_access_info_add_source(ai, map, 0, &depth);
2928
2929 flow = isl_access_info_compute_flow(ai);
2930 dim = isl_space_alloc(ctx, 0, 3, 3);
2931 mm.must = isl_map_empty(isl_space_copy(dim));
2932 mm.may = isl_map_empty(dim);
2933
2934 isl_flow_foreach(flow, collect_must_may, &mm);
2935
2936 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2937 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2938 assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2938, __extension__ __PRETTY_FUNCTION__); }))
;
2939 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2940 assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2940, __extension__ __PRETTY_FUNCTION__); }))
;
2941
2942 isl_map_free(mm.must);
2943 isl_map_free(mm.may);
2944 isl_flow_free(flow);
2945
2946
2947 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2948 map = isl_map_read_from_str(ctx, str);
2949 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2950
2951 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2952 map = isl_map_read_from_str(ctx, str);
2953 ai = isl_access_info_add_source(ai, map, 0, &depth);
2954
2955 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2956 map = isl_map_read_from_str(ctx, str);
2957 ai = isl_access_info_add_source(ai, map, 0, &depth);
2958
2959 flow = isl_access_info_compute_flow(ai);
2960 dim = isl_space_alloc(ctx, 0, 3, 3);
2961 mm.must = isl_map_empty(isl_space_copy(dim));
2962 mm.may = isl_map_empty(dim);
2963
2964 isl_flow_foreach(flow, collect_must_may, &mm);
2965
2966 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2967 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2968 assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2968, __extension__ __PRETTY_FUNCTION__); }))
;
2969 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2970 assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2970, __extension__ __PRETTY_FUNCTION__); }))
;
2971
2972 isl_map_free(mm.must);
2973 isl_map_free(mm.may);
2974 isl_flow_free(flow);
2975
2976
2977 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2978 map = isl_map_read_from_str(ctx, str);
2979 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2980
2981 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2982 map = isl_map_read_from_str(ctx, str);
2983 ai = isl_access_info_add_source(ai, map, 0, &depth);
2984
2985 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2986 map = isl_map_read_from_str(ctx, str);
2987 ai = isl_access_info_add_source(ai, map, 0, &depth);
2988
2989 flow = isl_access_info_compute_flow(ai);
2990 dim = isl_space_alloc(ctx, 0, 3, 3);
2991 mm.must = isl_map_empty(isl_space_copy(dim));
2992 mm.may = isl_map_empty(dim);
2993
2994 isl_flow_foreach(flow, collect_must_may, &mm);
2995
2996 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2997 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2998 assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 2998, __extension__ __PRETTY_FUNCTION__); }))
;
2999 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3000 assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3000, __extension__ __PRETTY_FUNCTION__); }))
;
3001
3002 isl_map_free(mm.must);
3003 isl_map_free(mm.may);
3004 isl_flow_free(flow);
3005
3006
3007 depth = 5;
3008
3009 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3010 map = isl_map_read_from_str(ctx, str);
3011 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
3012
3013 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3014 map = isl_map_read_from_str(ctx, str);
3015 ai = isl_access_info_add_source(ai, map, 1, &depth);
3016
3017 flow = isl_access_info_compute_flow(ai);
3018 dim = isl_space_alloc(ctx, 0, 5, 5);
3019 mm.must = isl_map_empty(isl_space_copy(dim));
3020 mm.may = isl_map_empty(dim);
3021
3022 isl_flow_foreach(flow, collect_must_may, &mm);
3023
3024 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3025 assert(map_is_equal(mm.must, str))((void) sizeof ((map_is_equal(mm.must, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.must, str)) ; else __assert_fail ("map_is_equal(mm.must, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3025, __extension__ __PRETTY_FUNCTION__); }))
;
3026 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3027 assert(map_is_equal(mm.may, str))((void) sizeof ((map_is_equal(mm.may, str)) ? 1 : 0), __extension__
({ if (map_is_equal(mm.may, str)) ; else __assert_fail ("map_is_equal(mm.may, str)"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3027, __extension__ __PRETTY_FUNCTION__); }))
;
3028
3029 isl_map_free(mm.must);
3030 isl_map_free(mm.may);
3031 isl_flow_free(flow);
3032
3033 return 0;
3034}
3035
3036/* Check that the dependence analysis proceeds without errors.
3037 * Earlier versions of isl would break down during the analysis
3038 * due to the use of the wrong spaces.
3039 */
3040static int test_flow(isl_ctx *ctx)
3041{
3042 const char *str;
3043 isl_union_map *access, *schedule;
3044 isl_union_map *must_dep, *may_dep;
3045 int r;
3046
3047 str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3048 access = isl_union_map_read_from_str(ctx, str);
3049 str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3050 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3051 "S2[] -> [1,0,0,0]; "
3052 "S3[] -> [-1,0,0,0] }";
3053 schedule = isl_union_map_read_from_str(ctx, str);
3054 r = isl_union_map_compute_flow(access, isl_union_map_copy(access),
3055 isl_union_map_copy(access), schedule,
3056 &must_dep, &may_dep, NULL((void*)0), NULL((void*)0));
3057 isl_union_map_free(may_dep);
3058 isl_union_map_free(must_dep);
3059
3060 return r;
3061}
3062
3063struct {
3064 const char *map;
3065 int sv;
3066} sv_tests[] = {
3067 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3068 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3069 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3070 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3071 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3072 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3073 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3074 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3075 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3076};
3077
3078int test_sv(isl_ctx *ctx)
3079{
3080 isl_union_map *umap;
3081 int i;
3082 int sv;
3083
3084 for (i = 0; i < ARRAY_SIZE(sv_tests)(sizeof(sv_tests)/sizeof(*sv_tests)); ++i) {
3085 umap = isl_union_map_read_from_str(ctx, sv_tests[i].map);
3086 sv = isl_union_map_is_single_valued(umap);
3087 isl_union_map_free(umap);
3088 if (sv < 0)
3089 return -1;
3090 if (sv_tests[i].sv && !sv)
3091 isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as single valued"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3092); return -1; } while (0)
3092 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3092); return -1; } while (0)
;
3093 if (!sv_tests[i].sv && sv)
3094 isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3095); return -1; } while (0)
3095 "map detected as single valued", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as single valued"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3095); return -1; } while (0)
;
3096 }
3097
3098 return 0;
3099}
3100
3101struct {
3102 const char *str;
3103 int bijective;
3104} bijective_tests[] = {
3105 { "[N,M]->{[i,j] -> [i]}", 0 },
3106 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3107 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3108 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3109 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3110 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3111 { "[N,M]->{[i,j] -> []}", 0 },
3112 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3113 { "[N,M]->{[i,j] -> [2i]}", 0 },
3114 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3115 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3116 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3117 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3118};
3119
3120static int test_bijective(struct isl_ctx *ctx)
3121{
3122 isl_map *map;
3123 int i;
3124 int bijective;
3125
3126 for (i = 0; i < ARRAY_SIZE(bijective_tests)(sizeof(bijective_tests)/sizeof(*bijective_tests)); ++i) {
3127 map = isl_map_read_from_str(ctx, bijective_tests[i].str);
3128 bijective = isl_map_is_bijective(map);
3129 isl_map_free(map);
3130 if (bijective < 0)
3131 return -1;
3132 if (bijective_tests[i].bijective && !bijective)
3133 isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3134); return -1; } while (0)
3134 "map not detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map not detected as bijective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3134); return -1; } while (0)
;
3135 if (!bijective_tests[i].bijective && bijective)
3136 isl_die(ctx, isl_error_internal,do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3137); return -1; } while (0)
3137 "map detected as bijective", return -1)do { isl_handle_error(ctx, isl_error_internal, "map detected as bijective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3137); return -1; } while (0)
;
3138 }
3139
3140 return 0;
3141}
3142
3143/* Inputs for isl_pw_qpolynomial_gist tests.
3144 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3145 */
3146struct {
3147 const char *pwqp;
3148 const char *set;
3149 const char *gist;
3150} pwqp_gist_tests[] = {
3151 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3152 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3153 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3154 "{ [i] -> -1/2 + 1/2 * i }" },
3155 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3156};
3157
3158static int test_pwqp(struct isl_ctx *ctx)
3159{
3160 int i;
3161 const char *str;
3162 isl_setisl_map *set;
3163 isl_pw_qpolynomial *pwqp1, *pwqp2;
3164 int equal;
3165
3166 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3167 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3168
3169 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
3170 isl_dim_in, 1, 1);
3171
3172 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3173 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3174
3175 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3176
3177 assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0),
__extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else
__assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3177, __extension__ __PRETTY_FUNCTION__); }))
;
3178
3179 isl_pw_qpolynomial_free(pwqp1);
3180
3181 for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests)(sizeof(pwqp_gist_tests)/sizeof(*pwqp_gist_tests)); ++i) {
3182 str = pwqp_gist_tests[i].pwqp;
3183 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3184 str = pwqp_gist_tests[i].set;
3185 set = isl_set_read_from_str(ctx, str);
3186 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
3187 str = pwqp_gist_tests[i].gist;
3188 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3189 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3190 equal = isl_pw_qpolynomial_is_zero(pwqp1);
3191 isl_pw_qpolynomial_free(pwqp1);
3192
3193 if (equal < 0)
3194 return -1;
3195 if (!equal)
3196 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3197); return -1; } while (0)
3197 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3197); return -1; } while (0)
;
3198 }
3199
3200 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
3201 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3202 str = "{ [i] -> ([(2 * [i/2])/5]) }";
3203 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3204
3205 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3206
3207 assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0),
__extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else
__assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3207, __extension__ __PRETTY_FUNCTION__); }))
;
3208
3209 isl_pw_qpolynomial_free(pwqp1);
3210
3211 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
3212 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3213 str = "{ [x] -> x }";
3214 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3215
3216 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3217
3218 assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0),
__extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else
__assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3218, __extension__ __PRETTY_FUNCTION__); }))
;
3219
3220 isl_pw_qpolynomial_free(pwqp1);
3221
3222 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3223 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3224 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3225 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
3226 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3227 assert(isl_pw_qpolynomial_is_zero(pwqp1))((void) sizeof ((isl_pw_qpolynomial_is_zero(pwqp1)) ? 1 : 0),
__extension__ ({ if (isl_pw_qpolynomial_is_zero(pwqp1)) ; else
__assert_fail ("isl_pw_qpolynomial_is_zero(pwqp1)", "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3227, __extension__ __PRETTY_FUNCTION__); }))
;
3228 isl_pw_qpolynomial_free(pwqp1);
3229
3230 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3231 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3232 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3233 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3234 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
3235 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
3236 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3237 isl_pw_qpolynomial_free(pwqp1);
3238 isl_pw_qpolynomial_free(pwqp2);
3239 if (equal < 0)
3240 return -1;
3241 if (!equal)
3242 isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3242); return -1; } while (0)
;
3243
3244 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3245 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3246 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3247 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3248 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
3249 isl_val_one(ctx));
3250 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3251 isl_pw_qpolynomial_free(pwqp1);
3252 isl_pw_qpolynomial_free(pwqp2);
3253 if (equal < 0)
3254 return -1;
3255 if (!equal)
3256 isl_die(ctx, isl_error_unknown, "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3256); return -1; } while (0)
;
3257
3258 return 0;
3259}
3260
3261static int test_split_periods(isl_ctx *ctx)
3262{
3263 const char *str;
3264 isl_pw_qpolynomial *pwqp;
3265
3266 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3267 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3268 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3269 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3270
3271 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
3272
3273 isl_pw_qpolynomial_free(pwqp);
3274
3275 if (!pwqp)
3276 return -1;
3277
3278 return 0;
3279}
3280
3281static int test_union(isl_ctx *ctx)
3282{
3283 const char *str;
3284 isl_union_set *uset1, *uset2;
3285 isl_union_map *umap1, *umap2;
3286 int equal;
3287
3288 str = "{ [i] : 0 <= i <= 1 }";
3289 uset1 = isl_union_set_read_from_str(ctx, str);
3290 str = "{ [1] -> [0] }";
3291 umap1 = isl_union_map_read_from_str(ctx, str);
3292
3293 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
3294 equal = isl_union_map_is_equal(umap1, umap2);
3295
3296 isl_union_map_free(umap1);
3297 isl_union_map_free(umap2);
3298
3299 if (equal < 0)
3300 return -1;
3301 if (!equal)
3302 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3303); return -1; } while (0)
3303 return -1)do { isl_handle_error(ctx, isl_error_unknown, "union maps not equal"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3303); return -1; } while (0)
;
3304
3305 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3306 umap1 = isl_union_map_read_from_str(ctx, str);
3307 str = "{ A[i]; B[i] }";
3308 uset1 = isl_union_set_read_from_str(ctx, str);
3309
3310 uset2 = isl_union_map_domain(umap1);
3311
3312 equal = isl_union_set_is_equal(uset1, uset2);
3313
3314 isl_union_set_free(uset1);
3315 isl_union_set_free(uset2);
3316
3317 if (equal < 0)
3318 return -1;
3319 if (!equal)
3320 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3321); return -1; } while (0)
3321 return -1)do { isl_handle_error(ctx, isl_error_unknown, "union sets not equal"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3321); return -1; } while (0)
;
3322
3323 return 0;
3324}
3325
3326/* Check that computing a bound of a non-zero polynomial over an unbounded
3327 * domain does not produce a rational value.
3328 * In particular, check that the upper bound is infinity.
3329 */
3330static int test_bound_unbounded_domain(isl_ctx *ctx)
3331{
3332 const char *str;
3333 isl_pw_qpolynomial *pwqp;
3334 isl_pw_qpolynomial_fold *pwf, *pwf2;
3335 isl_bool equal;
3336
3337 str = "{ [m,n] -> -m * n }";
3338 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3339 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0));
3340 str = "{ infty }";
3341 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3342 pwf2 = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0));
3343 equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf, pwf2);
3344 isl_pw_qpolynomial_fold_free(pwf);
3345 isl_pw_qpolynomial_fold_free(pwf2);
3346
3347 if (equal < 0)
3348 return -1;
3349 if (!equal)
3350 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "expecting infinite polynomial bound"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3351); return -1; } while (0)
3351 "expecting infinite polynomial bound", return -1)do { isl_handle_error(ctx, isl_error_unknown, "expecting infinite polynomial bound"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3351); return -1; } while (0)
;
3352
3353 return 0;
3354}
3355
3356static int test_bound(isl_ctx *ctx)
3357{
3358 const char *str;
3359 unsigned dim;
3360 isl_pw_qpolynomial *pwqp;
3361 isl_pw_qpolynomial_fold *pwf;
3362
3363 if (test_bound_unbounded_domain(ctx) < 0)
3364 return -1;
3365
3366 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
3367 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3368 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0));
3369 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3370 isl_pw_qpolynomial_fold_free(pwf);
3371 if (dim != 4)
3372 isl_die(ctx, isl_error_unknown, "unexpected input dimension",do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3373); return -1; } while (0)
3373 return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3373); return -1; } while (0)
;
3374
3375 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3376 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3377 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL((void*)0));
3378 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3379 isl_pw_qpolynomial_fold_free(pwf);
3380 if (dim != 1)
3381 isl_die(ctx, isl_error_unknown, "unexpected input dimension",do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3382); return -1; } while (0)
3382 return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected input dimension"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3382); return -1; } while (0)
;
3383
3384 return 0;
3385}
3386
3387/* Check that the conversion from 'set' to 'basic set list' works as expected.
3388 */
3389static isl_stat test_get_list_bset_from_set(isl_ctx *ctx)
3390{
3391 int i;
3392 isl_bool equal;
3393 isl_setisl_map *set, *set2;
3394 isl_basic_set_listisl_basic_map_list *bset_list;
3395
3396 set = isl_set_read_from_str(ctx, "{ [0]; [2]; [3] }");
3397 bset_list = isl_set_get_basic_set_list(set);
3398
3399 set2 = isl_set_empty(isl_set_get_space(set));
3400
3401 for (i = 0; i < isl_basic_set_list_n_basic_set(bset_list); i++) {
3402 isl_basic_setisl_basic_map *bset;
3403 bset = isl_basic_set_list_get_basic_set(bset_list, i);
3404 set2 = isl_set_union(set2, isl_set_from_basic_set(bset));
3405 }
3406
3407 equal = isl_set_is_equal(set, set2);
3408
3409 isl_set_free(set);
3410 isl_set_free(set2);
3411 isl_basic_set_list_free(bset_list);
3412
3413 if (equal < 0)
3414 return isl_stat_error;
3415
3416 if (!equal)
3417 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3418); return isl_stat_error; } while (0)
3418 return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "sets are not equal"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3418); return isl_stat_error; } while (0)
;
3419
3420 return isl_stat_ok;
3421}
3422
3423/* Check that the conversion from 'union set' to 'basic set list' works as
3424 * expected.
3425 */
3426static isl_stat test_get_list_bset_from_uset(isl_ctx *ctx)
3427{
3428 int i;
3429 isl_bool equal;
3430 isl_union_set *uset, *uset2;
3431 isl_basic_set_listisl_basic_map_list *bset_list;
3432
3433 uset = isl_union_set_read_from_str(ctx, "{ A[0]; B[2]; B[3] }");
3434 bset_list = isl_union_set_get_basic_set_list(uset);
3435
3436 uset2 = isl_union_set_empty(isl_union_set_get_space(uset));
3437
3438 for (i = 0; i < isl_basic_set_list_n_basic_set(bset_list); i++) {
3439 isl_basic_setisl_basic_map *bset;
3440 bset = isl_basic_set_list_get_basic_set(bset_list, i);
3441 uset2 = isl_union_set_union(uset2,
3442 isl_union_set_from_basic_set(bset));
3443 }
3444
3445 equal = isl_union_set_is_equal(uset, uset2);
3446
3447 isl_union_set_free(uset);
3448 isl_union_set_free(uset2);
3449 isl_basic_set_list_free(bset_list);
3450
3451 if (equal < 0)
3452 return isl_stat_error;
3453
3454 if (!equal)
3455 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3456); return isl_stat_error; } while (0)
3456 return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "sets are not equal"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3456); return isl_stat_error; } while (0)
;
3457
3458 return isl_stat_ok;
3459}
3460
3461/* Check that the conversion from 'union set' to 'set list' works as expected.
3462 */
3463static isl_stat test_get_list_set_from_uset(isl_ctx *ctx)
3464{
3465 int i;
3466 isl_bool equal;
3467 isl_union_set *uset, *uset2;
3468 isl_set_listisl_map_list *set_list;
3469
3470 uset = isl_union_set_read_from_str(ctx, "{ A[0]; A[2]; B[3] }");
3471 set_list = isl_union_set_get_set_list(uset);
3472
3473 uset2 = isl_union_set_empty(isl_union_set_get_space(uset));
3474
3475 for (i = 0; i < isl_set_list_n_set(set_list); i++) {
3476 isl_setisl_map *set;
3477 set = isl_set_list_get_set(set_list, i);
3478 uset2 = isl_union_set_union(uset2, isl_union_set_from_set(set));
3479 }
3480
3481 equal = isl_union_set_is_equal(uset, uset2);
3482
3483 isl_union_set_free(uset);
3484 isl_union_set_free(uset2);
3485 isl_set_list_free(set_list);
3486
3487 if (equal < 0)
3488 return isl_stat_error;
3489
3490 if (!equal)
3491 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3492); return isl_stat_error; } while (0)
3492 return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "union sets are not equal"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3492); return isl_stat_error; } while (0)
;
3493
3494 return isl_stat_ok;
3495}
3496
3497/* Check that the conversion from 'map' to 'basic map list' works as expected.
3498 */
3499static isl_stat test_get_list_bmap_from_map(isl_ctx *ctx)
3500{
3501 int i;
3502 isl_bool equal;
3503 isl_map *map, *map2;
3504 isl_basic_map_list *bmap_list;
3505
3506 map = isl_map_read_from_str(ctx,
3507 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }");
3508 bmap_list = isl_map_get_basic_map_list(map);
3509
3510 map2 = isl_map_empty(isl_map_get_space(map));
3511
3512 for (i = 0; i < isl_basic_map_list_n_basic_map(bmap_list); i++) {
3513 isl_basic_map *bmap;
3514 bmap = isl_basic_map_list_get_basic_map(bmap_list, i);
3515 map2 = isl_map_union(map2, isl_map_from_basic_map(bmap));
3516 }
3517
3518 equal = isl_map_is_equal(map, map2);
3519
3520 isl_map_free(map);
3521 isl_map_free(map2);
3522 isl_basic_map_list_free(bmap_list);
3523
3524 if (equal < 0)
3525 return isl_stat_error;
3526
3527 if (!equal)
3528 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3529); return isl_stat_error; } while (0)
3529 return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "maps are not equal"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3529); return isl_stat_error; } while (0)
;
3530
3531 return isl_stat_ok;
3532}
3533
3534/* Check that the conversion from 'union map' to 'map list' works as expected.
3535 */
3536static isl_stat test_get_list_map_from_umap(isl_ctx *ctx)
3537{
3538 int i;
3539 isl_bool equal;
3540 isl_union_map *umap, *umap2;
3541 isl_map_list *map_list;
3542
3543 umap = isl_union_map_read_from_str(ctx,
3544 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }");
3545 map_list = isl_union_map_get_map_list(umap);
3546
3547 umap2 = isl_union_map_empty(isl_union_map_get_space(umap));
3548
3549 for (i = 0; i < isl_map_list_n_map(map_list); i++) {
3550 isl_map *map;
3551 map = isl_map_list_get_map(map_list, i);
3552 umap2 = isl_union_map_union(umap2, isl_union_map_from_map(map));
3553 }
3554
3555 equal = isl_union_map_is_equal(umap, umap2);
3556
3557 isl_union_map_free(umap);
3558 isl_union_map_free(umap2);
3559 isl_map_list_free(map_list);
3560
3561 if (equal < 0)
3562 return isl_stat_error;
3563
3564 if (!equal)
3565 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3566); return isl_stat_error; } while (0)
3566 return isl_stat_error)do { isl_handle_error(ctx, isl_error_unknown, "union maps are not equal"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3566); return isl_stat_error; } while (0)
;
3567
3568 return isl_stat_ok;
3569}
3570
3571/* Check that the conversion from isl objects to lists works as expected.
3572 */
3573static int test_get_list(isl_ctx *ctx)
3574{
3575 if (test_get_list_bset_from_set(ctx))
3576 return -1;
3577 if (test_get_list_bset_from_uset(ctx))
3578 return -1;
3579 if (test_get_list_set_from_uset(ctx))
3580 return -1;
3581 if (test_get_list_bmap_from_map(ctx))
3582 return -1;
3583 if (test_get_list_map_from_umap(ctx))
3584 return -1;
3585
3586 return 0;
3587}
3588
3589static int test_lift(isl_ctx *ctx)
3590{
3591 const char *str;
3592 isl_basic_map *bmap;
3593 isl_basic_setisl_basic_map *bset;
3594
3595 str = "{ [i0] : exists e0 : i0 = 4e0 }";
3596 bset = isl_basic_set_read_from_str(ctx, str);
3597 bset = isl_basic_set_lift(bset);
3598 bmap = isl_basic_map_from_range(bset);
3599 bset = isl_basic_map_domain(bmap);
3600 isl_basic_set_free(bset);
3601
3602 return 0;
3603}
3604
3605/* Check that isl_set_is_subset is not confused by identical
3606 * integer divisions.
3607 * The call to isl_set_normalize ensures that the equality constraints
3608 * a = b = 0 are discovered, turning e0 and e1 into identical
3609 * integer divisions. Any further simplification would remove
3610 * the duplicate integer divisions.
3611 */
3612static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx)
3613{
3614 const char *str;
3615 isl_bool is_subset;
3616 isl_setisl_map *set1, *set2;
3617
3618 str = "{ [a, b, c, d] : "
3619 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
3620 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
3621 "e3 = floor((-d + 4*floor((d)/4))/10): "
3622 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
3623 "b >= 0 and a <= 0 and b <= a) }";
3624 set1 = isl_set_read_from_str(ctx, str);
3625 set2 = isl_set_read_from_str(ctx, str);
3626 set2 = isl_set_normalize(set2);
3627
3628 is_subset = isl_set_is_subset(set1, set2);
3629
3630 isl_set_free(set1);
3631 isl_set_free(set2);
3632
3633 if (is_subset < 0)
3634 return isl_stat_error;
3635 if (!is_subset)
3636 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3638); return isl_stat_error; } while (0)
3637 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3638); return isl_stat_error; } while (0)
3638 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3638); return isl_stat_error; } while (0)
;
3639
3640 return isl_stat_ok;
3641}
3642
3643struct {
3644 const char *set1;
3645 const char *set2;
3646 int subset;
3647} subset_tests[] = {
3648 { "{ [112, 0] }",
3649 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3650 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3651 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3652 { "{ [65] }",
3653 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3654 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3655 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3656 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3657 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3658 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3659 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3660 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3661 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3662 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3663 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3664 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3665 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3666 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3667 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3668 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3669 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3670 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3671 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3672 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3673 "4e0 <= -57 + i0 + i1)) or "
3674 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3675 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3676 "4e0 >= -61 + i0 + i1)) or "
3677 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3678 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3679};
3680
3681static int test_subset(isl_ctx *ctx)
3682{
3683 int i;
3684 isl_setisl_map *set1, *set2;
3685 int subset;
3686
3687 if (test_subset_duplicate_integer_divisions(ctx) < 0)
3688 return -1;
3689
3690 for (i = 0; i < ARRAY_SIZE(subset_tests)(sizeof(subset_tests)/sizeof(*subset_tests)); ++i) {
3691 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
3692 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
3693 subset = isl_set_is_subset(set1, set2);
3694 isl_set_free(set1);
3695 isl_set_free(set2);
3696 if (subset < 0)
3697 return -1;
3698 if (subset != subset_tests[i].subset)
3699 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3700); return -1; } while (0)
3700 "incorrect subset result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subset result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3700); return -1; } while (0)
;
3701 }
3702
3703 return 0;
3704}
3705
3706struct {
3707 const char *minuend;
3708 const char *subtrahend;
3709 const char *difference;
3710} subtract_domain_tests[] = {
3711 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3712 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3713 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3714};
3715
3716static int test_subtract(isl_ctx *ctx)
3717{
3718 int i;
3719 isl_union_map *umap1, *umap2;
3720 isl_union_pw_multi_aff *upma1, *upma2;
3721 isl_union_set *uset;
3722 int equal;
3723
3724 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests)
)
; ++i) {
3725 umap1 = isl_union_map_read_from_str(ctx,
3726 subtract_domain_tests[i].minuend);
3727 uset = isl_union_set_read_from_str(ctx,
3728 subtract_domain_tests[i].subtrahend);
3729 umap2 = isl_union_map_read_from_str(ctx,
3730 subtract_domain_tests[i].difference);
3731 umap1 = isl_union_map_subtract_domain(umap1, uset);
3732 equal = isl_union_map_is_equal(umap1, umap2);
3733 isl_union_map_free(umap1);
3734 isl_union_map_free(umap2);
3735 if (equal < 0)
3736 return -1;
3737 if (!equal)
3738 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3739); return -1; } while (0)
3739 "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3739); return -1; } while (0)
;
3740 }
3741
3742 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests)(sizeof(subtract_domain_tests)/sizeof(*subtract_domain_tests)
)
; ++i) {
3743 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
3744 subtract_domain_tests[i].minuend);
3745 uset = isl_union_set_read_from_str(ctx,
3746 subtract_domain_tests[i].subtrahend);
3747 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
3748 subtract_domain_tests[i].difference);
3749 upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset);
3750 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
3751 isl_union_pw_multi_aff_free(upma1);
3752 isl_union_pw_multi_aff_free(upma2);
3753 if (equal < 0)
3754 return -1;
3755 if (!equal)
3756 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3757); return -1; } while (0)
3757 "incorrect subtract domain result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "incorrect subtract domain result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3757); return -1; } while (0)
;
3758 }
3759
3760 return 0;
3761}
3762
3763/* Check that intersecting the empty basic set with another basic set
3764 * does not increase the number of constraints. In particular,
3765 * the empty basic set should maintain its canonical representation.
3766 */
3767static int test_intersect_1(isl_ctx *ctx)
3768{
3769 int n1, n2;
3770 isl_basic_setisl_basic_map *bset1, *bset2;
3771
3772 bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }");
3773 bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }");
3774 n1 = isl_basic_set_n_constraint(bset1);
3775 bset1 = isl_basic_set_intersect(bset1, bset2);
3776 n2 = isl_basic_set_n_constraint(bset1);
3777 isl_basic_set_free(bset1);
3778 if (!bset1)
3779 return -1;
3780 if (n1 != n2)
3781 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3783); return -1; } while (0)
3782 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3783); return -1; } while (0)
3783 return -1)do { isl_handle_error(ctx, isl_error_unknown, "number of constraints of empty set changed"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3783); return -1; } while (0)
;
3784
3785 return 0;
3786}
3787
3788/* Check that intersecting a set with itself does not cause
3789 * an explosion in the number of disjuncts.
3790 */
3791static isl_stat test_intersect_2(isl_ctx *ctx)
3792{
3793 int i;
3794 isl_setisl_map *set;
3795
3796 set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }");
3797 for (i = 0; i < 100; ++i)
3798 set = isl_set_intersect(set, isl_set_copy(set));
3799 isl_set_free(set);
3800 if (!set)
3801 return isl_stat_error;
3802 return isl_stat_ok;
3803}
3804
3805/* Perform some intersection tests.
3806 */
3807static int test_intersect(isl_ctx *ctx)
3808{
3809 if (test_intersect_1(ctx) < 0)
3810 return -1;
3811 if (test_intersect_2(ctx) < 0)
3812 return -1;
3813
3814 return 0;
3815}
3816
3817int test_factorize(isl_ctx *ctx)
3818{
3819 const char *str;
3820 isl_basic_setisl_basic_map *bset;
3821 isl_factorizer *f;
3822
3823 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3824 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3825 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3826 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3827 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3828 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3829 "3i5 >= -2i0 - i2 + 3i4 }";
3830 bset = isl_basic_set_read_from_str(ctx, str);
3831 f = isl_basic_set_factorizer(bset);
3832 isl_basic_set_free(bset);
3833 isl_factorizer_free(f);
3834 if (!f)
3835 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3836); return -1; } while (0)
3836 "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3836); return -1; } while (0)
;
3837
3838 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3839 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3840 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3841 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3842 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3843 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3844 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3845 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3846 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3847 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3848 bset = isl_basic_set_read_from_str(ctx, str);
3849 f = isl_basic_set_factorizer(bset);
3850 isl_basic_set_free(bset);
3851 isl_factorizer_free(f);
3852 if (!f)
3853 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3854); return -1; } while (0)
3854 "failed to construct factorizer", return -1)do { isl_handle_error(ctx, isl_error_unknown, "failed to construct factorizer"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3854); return -1; } while (0)
;
3855
3856 return 0;
3857}
3858
3859static isl_stat check_injective(__isl_take isl_map *map, void *user)
3860{
3861 int *injective = user;
3862
3863 *injective = isl_map_is_injective(map);
3864 isl_map_free(map);
3865
3866 if (*injective < 0 || !*injective)
3867 return isl_stat_error;
3868
3869 return isl_stat_ok;
3870}
3871
3872int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
3873 const char *r, const char *s, int tilable, int parallel)
3874{
3875 int i;
3876 isl_union_set *D;
3877 isl_union_map *W, *R, *S;
3878 isl_union_map *empty;
3879 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
3880 isl_union_map *validity, *proximity, *coincidence;
3881 isl_union_map *schedule;
3882 isl_union_map *test;
3883 isl_union_set *delta;
3884 isl_union_set *domain;
3885 isl_setisl_map *delta_set;
3886 isl_setisl_map *slice;
3887 isl_setisl_map *origin;
3888 isl_schedule_constraints *sc;
3889 isl_schedule *sched;
3890 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
3891
3892 D = isl_union_set_read_from_str(ctx, d);
3893 W = isl_union_map_read_from_str(ctx, w);
3894 R = isl_union_map_read_from_str(ctx, r);
3895 S = isl_union_map_read_from_str(ctx, s);
3896
3897 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
3898 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
3899
3900 empty = isl_union_map_empty(isl_union_map_get_space(S));
3901 isl_union_map_compute_flow(isl_union_map_copy(R),
3902 isl_union_map_copy(W), empty,
3903 isl_union_map_copy(S),
3904 &dep_raw, NULL((void*)0), NULL((void*)0), NULL((void*)0));
3905 isl_union_map_compute_flow(isl_union_map_copy(W),
3906 isl_union_map_copy(W),
3907 isl_union_map_copy(R),
3908 isl_union_map_copy(S),
3909 &dep_waw, &dep_war, NULL((void*)0), NULL((void*)0));
3910
3911 dep = isl_union_map_union(dep_waw, dep_war);
3912 dep = isl_union_map_union(dep, dep_raw);
3913 validity = isl_union_map_copy(dep);
3914 coincidence = isl_union_map_copy(dep);
3915 proximity = isl_union_map_copy(dep);
3916
3917 sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D));
3918 sc = isl_schedule_constraints_set_validity(sc, validity);
3919 sc = isl_schedule_constraints_set_coincidence(sc, coincidence);
3920 sc = isl_schedule_constraints_set_proximity(sc, proximity);
3921 sched = isl_schedule_constraints_compute_schedule(sc);
3922 schedule = isl_schedule_get_map(sched);
3923 isl_schedule_free(sched);
3924 isl_union_map_free(W);
3925 isl_union_map_free(R);
3926 isl_union_map_free(S);
3927
3928 is_injection = 1;
3929 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
3930
3931 domain = isl_union_map_domain(isl_union_map_copy(schedule));
3932 is_complete = isl_union_set_is_subset(D, domain);
3933 isl_union_set_free(D);
3934 isl_union_set_free(domain);
3935
3936 test = isl_union_map_reverse(isl_union_map_copy(schedule));
3937 test = isl_union_map_apply_range(test, dep);
3938 test = isl_union_map_apply_range(test, schedule);
3939
3940 delta = isl_union_map_deltas(test);
3941 if (isl_union_set_n_set(delta) == 0) {
3942 is_tilable = 1;
3943 is_parallel = 1;
3944 is_nonneg = 1;
3945 isl_union_set_free(delta);
3946 } else {
3947 delta_set = isl_set_from_union_set(delta);
3948
3949 slice = isl_set_universe(isl_set_get_space(delta_set));
3950 for (i = 0; i < tilable; ++i)
3951 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
3952 is_tilable = isl_set_is_subset(delta_set, slice);
3953 isl_set_free(slice);
3954
3955 slice = isl_set_universe(isl_set_get_space(delta_set));
3956 for (i = 0; i < parallel; ++i)
3957 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
3958 is_parallel = isl_set_is_subset(delta_set, slice);
3959 isl_set_free(slice);
3960
3961 origin = isl_set_universe(isl_set_get_space(delta_set));
3962 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
3963 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
3964
3965 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
3966 delta_set = isl_set_lexmin(delta_set);
3967
3968 is_nonneg = isl_set_is_equal(delta_set, origin);
3969
3970 isl_set_free(origin);
3971 isl_set_free(delta_set);
3972 }
3973
3974 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
3975 is_injection < 0 || is_complete < 0)
3976 return -1;
3977 if (!is_complete)
3978 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3979); return -1; } while (0)
3979 "generated schedule incomplete", return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule incomplete"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3979); return -1; } while (0)
;
3980 if (!is_injection)
3981 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3983); return -1; } while (0)
3982 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3983); return -1; } while (0)
3983 return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not injective on each statement"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3983); return -1; } while (0)
;
3984 if (!is_nonneg)
3985 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3987); return -1; } while (0)
3986 "negative dependences in generated schedule",do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3987); return -1; } while (0)
3987 return -1)do { isl_handle_error(ctx, isl_error_unknown, "negative dependences in generated schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3987); return -1; } while (0)
;
3988 if (!is_tilable)
3989 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3991); return -1; } while (0)
3990 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3991); return -1; } while (0)
3991 return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as tilable as expected"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3991); return -1; } while (0)
;
3992 if (!is_parallel)
3993 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3995); return -1; } while (0)
3994 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3995); return -1; } while (0)
3995 return -1)do { isl_handle_error(ctx, isl_error_unknown, "generated schedule not as parallel as expected"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 3995); return -1; } while (0)
;
3996
3997 return 0;
3998}
3999
4000/* Compute a schedule for the given instance set, validity constraints,
4001 * proximity constraints and context and return a corresponding union map
4002 * representation.
4003 */
4004static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx,
4005 const char *domain, const char *validity, const char *proximity,
4006 const char *context)
4007{
4008 isl_setisl_map *con;
4009 isl_union_set *dom;
4010 isl_union_map *dep;
4011 isl_union_map *prox;
4012 isl_schedule_constraints *sc;
4013 isl_schedule *schedule;
4014 isl_union_map *sched;
4015
4016 con = isl_set_read_from_str(ctx, context);
4017 dom = isl_union_set_read_from_str(ctx, domain);
4018 dep = isl_union_map_read_from_str(ctx, validity);
4019 prox = isl_union_map_read_from_str(ctx, proximity);
4020 sc = isl_schedule_constraints_on_domain(dom);
4021 sc = isl_schedule_constraints_set_context(sc, con);
4022 sc = isl_schedule_constraints_set_validity(sc, dep);
4023 sc = isl_schedule_constraints_set_proximity(sc, prox);
4024 schedule = isl_schedule_constraints_compute_schedule(sc);
4025 sched = isl_schedule_get_map(schedule);
4026 isl_schedule_free(schedule);
4027
4028 return sched;
4029}
4030
4031/* Compute a schedule for the given instance set, validity constraints and
4032 * proximity constraints and return a corresponding union map representation.
4033 */
4034static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
4035 const char *domain, const char *validity, const char *proximity)
4036{
4037 return compute_schedule_with_context(ctx, domain, validity, proximity,
4038 "{ : }");
4039}
4040
4041/* Check that a schedule can be constructed on the given domain
4042 * with the given validity and proximity constraints.
4043 */
4044static int test_has_schedule(isl_ctx *ctx, const char *domain,
4045 const char *validity, const char *proximity)
4046{
4047 isl_union_map *sched;
4048
4049 sched = compute_schedule(ctx, domain, validity, proximity);
4050 if (!sched)
4051 return -1;
4052
4053 isl_union_map_free(sched);
4054 return 0;
4055}
4056
4057int test_special_schedule(isl_ctx *ctx, const char *domain,
4058 const char *validity, const char *proximity, const char *expected_sched)
4059{
4060 isl_union_map *sched1, *sched2;
4061 int equal;
4062
4063 sched1 = compute_schedule(ctx, domain, validity, proximity);
4064 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
4065
4066 equal = isl_union_map_is_equal(sched1, sched2);
4067 isl_union_map_free(sched1);
4068 isl_union_map_free(sched2);
4069
4070 if (equal < 0)
4071 return -1;
4072 if (!equal)
4073 isl_die(ctx, isl_error_unknown, "unexpected schedule",do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4074); return -1; } while (0)
4074 return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4074); return -1; } while (0)
;
4075
4076 return 0;
4077}
4078
4079/* Check that the schedule map is properly padded, i.e., that the range
4080 * lives in a single space.
4081 */
4082static int test_padded_schedule(isl_ctx *ctx)
4083{
4084 const char *str;
4085 isl_union_set *D;
4086 isl_union_map *validity, *proximity;
4087 isl_schedule_constraints *sc;
4088 isl_schedule *sched;
4089 isl_union_map *umap;
4090 isl_union_set *range;
4091 isl_setisl_map *set;
4092
4093 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4094 D = isl_union_set_read_from_str(ctx, str);
4095 validity = isl_union_map_empty(isl_union_set_get_space(D));
4096 proximity = isl_union_map_copy(validity);
4097 sc = isl_schedule_constraints_on_domain(D);
4098 sc = isl_schedule_constraints_set_validity(sc, validity);
4099 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4100 sched = isl_schedule_constraints_compute_schedule(sc);
4101 umap = isl_schedule_get_map(sched);
4102 isl_schedule_free(sched);
4103 range = isl_union_map_range(umap);
4104 set = isl_set_from_union_set(range);
4105 isl_set_free(set);
4106
4107 if (!set)
4108 return -1;
4109
4110 return 0;
4111}
4112
4113/* Check that conditional validity constraints are also taken into
4114 * account across bands.
4115 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4116 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4117 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4118 * is enforced by the rest of the schedule.
4119 */
4120static int test_special_conditional_schedule_constraints(isl_ctx *ctx)
4121{
4122 const char *str;
4123 isl_union_set *domain;
4124 isl_union_map *validity, *proximity, *condition;
4125 isl_union_map *sink, *source, *dep;
4126 isl_schedule_constraints *sc;
4127 isl_schedule *schedule;
4128 isl_union_access_info *access;
4129 isl_union_flow *flow;
4130 int empty;
4131
4132 str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4133 "A[k] : k >= 1 and k <= -1 + n; "
4134 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4135 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4136 domain = isl_union_set_read_from_str(ctx, str);
4137 sc = isl_schedule_constraints_on_domain(domain);
4138 str = "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4139 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4140 "D[k, i] -> C[1 + k, i] : "
4141 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4142 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4143 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4144 validity = isl_union_map_read_from_str(ctx, str);
4145 sc = isl_schedule_constraints_set_validity(sc, validity);
4146 str = "[n] -> { C[k, i] -> D[k, i] : "
4147 "0 <= i <= -1 + k and k <= -1 + n }";
4148 proximity = isl_union_map_read_from_str(ctx, str);
4149 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4150 str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4151 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4152 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4153 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4154 condition = isl_union_map_read_from_str(ctx, str);
4155 str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4156 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4157 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4158 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4159 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4160 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4161 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4162 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4163 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4164 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4165 validity = isl_union_map_read_from_str(ctx, str);
4166 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4167 validity);
4168 schedule = isl_schedule_constraints_compute_schedule(sc);
4169 str = "{ D[2,0] -> [] }";
4170 sink = isl_union_map_read_from_str(ctx, str);
4171 access = isl_union_access_info_from_sink(sink);
4172 str = "{ C[2,1] -> [] }";
4173 source = isl_union_map_read_from_str(ctx, str);
4174 access = isl_union_access_info_set_must_source(access, source);
4175 access = isl_union_access_info_set_schedule(access, schedule);
4176 flow = isl_union_access_info_compute_flow(access);
4177 dep = isl_union_flow_get_must_dependence(flow);
4178 isl_union_flow_free(flow);
4179 empty = isl_union_map_is_empty(dep);
4180 isl_union_map_free(dep);
4181
4182 if (empty < 0)
4183 return -1;
4184 if (empty)
4185 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4186); return -1; } while (0)
4186 "conditional validity not respected", return -1)do { isl_handle_error(ctx, isl_error_unknown, "conditional validity not respected"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4186); return -1; } while (0)
;
4187
4188 return 0;
4189}
4190
4191/* Check that the test for violated conditional validity constraints
4192 * is not confused by domain compression.
4193 * In particular, earlier versions of isl would apply
4194 * a schedule on the compressed domains to the original domains,
4195 * resulting in a failure to detect that the default schedule
4196 * violates the conditional validity constraints.
4197 */
4198static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx)
4199{
4200 const char *str;
4201 isl_bool empty;
4202 isl_union_set *domain;
4203 isl_union_map *validity, *condition;
4204 isl_schedule_constraints *sc;
4205 isl_schedule *schedule;
4206 isl_union_map *umap;
4207 isl_map *map, *ge;
4208
4209 str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4210 domain = isl_union_set_read_from_str(ctx, str);
4211 sc = isl_schedule_constraints_on_domain(domain);
4212 str = "{ B[1, i] -> A[0, i + 1] }";
4213 condition = isl_union_map_read_from_str(ctx, str);
4214 str = "{ A[0, i] -> B[1, i - 1] }";
4215 validity = isl_union_map_read_from_str(ctx, str);
4216 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4217 isl_union_map_copy(validity));
4218 schedule = isl_schedule_constraints_compute_schedule(sc);
4219 umap = isl_schedule_get_map(schedule);
4220 isl_schedule_free(schedule);
4221 validity = isl_union_map_apply_domain(validity,
4222 isl_union_map_copy(umap));
4223 validity = isl_union_map_apply_range(validity, umap);
4224 map = isl_map_from_union_map(validity);
4225 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4226 map = isl_map_intersect(map, ge);
4227 empty = isl_map_is_empty(map);
4228 isl_map_free(map);
4229
4230 if (empty < 0)
4231 return -1;
4232 if (!empty)
4233 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4235); return -1; } while (0)
4234 "conditional validity constraints not satisfied",do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4235); return -1; } while (0)
4235 return -1)do { isl_handle_error(ctx, isl_error_unknown, "conditional validity constraints not satisfied"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4235); return -1; } while (0)
;
4236
4237 return 0;
4238}
4239
4240/* Input for testing of schedule construction based on
4241 * conditional constraints.
4242 *
4243 * domain is the iteration domain
4244 * flow are the flow dependences, which determine the validity and
4245 * proximity constraints
4246 * condition are the conditions on the conditional validity constraints
4247 * conditional_validity are the conditional validity constraints
4248 * outer_band_n is the expected number of members in the outer band
4249 */
4250struct {
4251 const char *domain;
4252 const char *flow;
4253 const char *condition;
4254 const char *conditional_validity;
4255 int outer_band_n;
4256} live_range_tests[] = {
4257 /* Contrived example that illustrates that we need to keep
4258 * track of tagged condition dependences and
4259 * tagged conditional validity dependences
4260 * in isl_sched_edge separately.
4261 * In particular, the conditional validity constraints on A
4262 * cannot be satisfied,
4263 * but they can be ignored because there are no corresponding
4264 * condition constraints. However, we do have an additional
4265 * conditional validity constraint that maps to the same
4266 * dependence relation
4267 * as the condition constraint on B. If we did not make a distinction
4268 * between tagged condition and tagged conditional validity
4269 * dependences, then we
4270 * could end up treating this shared dependence as an condition
4271 * constraint on A, forcing a localization of the conditions,
4272 * which is impossible.
4273 */
4274 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4275 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4276 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4277 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4278 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4279 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4280 1
4281 },
4282 /* TACO 2013 Fig. 7 */
4283 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4284 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4285 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4286 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4287 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4288 "0 <= i < n and 0 <= j < n - 1 }",
4289 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4290 "0 <= i < n and 0 <= j < j' < n;"
4291 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4292 "0 <= i < i' < n and 0 <= j,j' < n;"
4293 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4294 "0 <= i,j,j' < n and j < j' }",
4295 2
4296 },
4297 /* TACO 2013 Fig. 7, without tags */
4298 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4299 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4300 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4301 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4302 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4303 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4304 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4305 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4306 1
4307 },
4308 /* TACO 2013 Fig. 12 */
4309 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4310 "S3[i,3] : 0 <= i <= 1 }",
4311 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4312 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4313 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4314 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4315 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4316 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4317 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4318 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4319 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4320 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4321 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4322 1
4323 }
4324};
4325
4326/* Test schedule construction based on conditional constraints.
4327 * In particular, check the number of members in the outer band node
4328 * as an indication of whether tiling is possible or not.
4329 */
4330static int test_conditional_schedule_constraints(isl_ctx *ctx)
4331{
4332 int i;
4333 isl_union_set *domain;
4334 isl_union_map *condition;
4335 isl_union_map *flow;
4336 isl_union_map *validity;
4337 isl_schedule_constraints *sc;
4338 isl_schedule *schedule;
4339 isl_schedule_node *node;
4340 int n_member;
4341
4342 if (test_special_conditional_schedule_constraints(ctx) < 0)
4343 return -1;
4344 if (test_special_conditional_schedule_constraints_2(ctx) < 0)
4345 return -1;
4346
4347 for (i = 0; i < ARRAY_SIZE(live_range_tests)(sizeof(live_range_tests)/sizeof(*live_range_tests)); ++i) {
4348 domain = isl_union_set_read_from_str(ctx,
4349 live_range_tests[i].domain);
4350 flow = isl_union_map_read_from_str(ctx,
4351 live_range_tests[i].flow);
4352 condition = isl_union_map_read_from_str(ctx,
4353 live_range_tests[i].condition);
4354 validity = isl_union_map_read_from_str(ctx,
4355 live_range_tests[i].conditional_validity);
4356 sc = isl_schedule_constraints_on_domain(domain);
4357 sc = isl_schedule_constraints_set_validity(sc,
4358 isl_union_map_copy(flow));
4359 sc = isl_schedule_constraints_set_proximity(sc, flow);
4360 sc = isl_schedule_constraints_set_conditional_validity(sc,
4361 condition, validity);
4362 schedule = isl_schedule_constraints_compute_schedule(sc);
4363 node = isl_schedule_get_root(schedule);
4364 while (node &&
4365 isl_schedule_node_get_type(node) != isl_schedule_node_band)
4366 node = isl_schedule_node_first_child(node);
4367 n_member = isl_schedule_node_band_n_member(node);
4368 isl_schedule_node_free(node);
4369 isl_schedule_free(schedule);
4370
4371 if (!schedule)
4372 return -1;
4373 if (n_member != live_range_tests[i].outer_band_n)
4374 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4376); return -1; } while (0)
4375 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4376); return -1; } while (0)
4376 return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected number of members in outer band"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4376); return -1; } while (0)
;
4377 }
4378 return 0;
4379}
4380
4381/* Check that the schedule computed for the given instance set and
4382 * dependence relation strongly satisfies the dependences.
4383 * In particular, check that no instance is scheduled before
4384 * or together with an instance on which it depends.
4385 * Earlier versions of isl would produce a schedule that
4386 * only weakly satisfies the dependences.
4387 */
4388static int test_strongly_satisfying_schedule(isl_ctx *ctx)
4389{
4390 const char *domain, *dep;
4391 isl_union_map *D, *schedule;
4392 isl_map *map, *ge;
4393 int empty;
4394
4395 domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4396 "A[i0] : 0 <= i0 <= 1 }";
4397 dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4398 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4399 schedule = compute_schedule(ctx, domain, dep, dep);
4400 D = isl_union_map_read_from_str(ctx, dep);
4401 D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule));
4402 D = isl_union_map_apply_range(D, schedule);
4403 map = isl_map_from_union_map(D);
4404 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4405 map = isl_map_intersect(map, ge);
4406 empty = isl_map_is_empty(map);
4407 isl_map_free(map);
4408
4409 if (empty < 0)
4410 return -1;
4411 if (!empty)
4412 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4413); return -1; } while (0)
4413 "dependences not strongly satisfied", return -1)do { isl_handle_error(ctx, isl_error_unknown, "dependences not strongly satisfied"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4413); return -1; } while (0)
;
4414
4415 return 0;
4416}
4417
4418/* Compute a schedule for input where the instance set constraints
4419 * conflict with the context constraints.
4420 * Earlier versions of isl did not properly handle this situation.
4421 */
4422static int test_conflicting_context_schedule(isl_ctx *ctx)
4423{
4424 isl_union_map *schedule;
4425 const char *domain, *context;
4426
4427 domain = "[n] -> { A[] : n >= 0 }";
4428 context = "[n] -> { : n < 0 }";
4429 schedule = compute_schedule_with_context(ctx,
4430 domain, "{}", "{}", context);
4431 isl_union_map_free(schedule);
4432
4433 if (!schedule)
4434 return -1;
4435
4436 return 0;
4437}
4438
4439/* Check that the dependence carrying step is not confused by
4440 * a bound on the coefficient size.
4441 * In particular, force the scheduler to move to a dependence carrying
4442 * step by demanding outer coincidence and bound the size of
4443 * the coefficients. Earlier versions of isl would take this
4444 * bound into account while carrying dependences, breaking
4445 * fundamental assumptions.
4446 * On the other hand, the dependence carrying step now tries
4447 * to prevent loop coalescing by default, so check that indeed
4448 * no loop coalescing occurs by comparing the computed schedule
4449 * to the expected non-coalescing schedule.
4450 */
4451static int test_bounded_coefficients_schedule(isl_ctx *ctx)
4452{
4453 const char *domain, *dep;
4454 isl_union_set *I;
4455 isl_union_map *D;
4456 isl_schedule_constraints *sc;
4457 isl_schedule *schedule;
4458 isl_union_map *sched1, *sched2;
4459 isl_bool equal;
4460
4461 domain = "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
4462 dep = "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
4463 "i1 <= -2 + i0; "
4464 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
4465 I = isl_union_set_read_from_str(ctx, domain);
4466 D = isl_union_map_read_from_str(ctx, dep);
4467 sc = isl_schedule_constraints_on_domain(I);
4468 sc = isl_schedule_constraints_set_validity(sc, isl_union_map_copy(D));
4469 sc = isl_schedule_constraints_set_coincidence(sc, D);
4470 isl_options_set_schedule_outer_coincidence(ctx, 1);
4471 isl_options_set_schedule_max_coefficient(ctx, 20);
4472 schedule = isl_schedule_constraints_compute_schedule(sc);
4473 isl_options_set_schedule_max_coefficient(ctx, -1);
4474 isl_options_set_schedule_outer_coincidence(ctx, 0);
4475 sched1 = isl_schedule_get_map(schedule);
4476 isl_schedule_free(schedule);
4477
4478 sched2 = isl_union_map_read_from_str(ctx, "{ C[x,y] -> [x,y] }");
4479 equal = isl_union_map_is_equal(sched1, sched2);
4480 isl_union_map_free(sched1);
4481 isl_union_map_free(sched2);
4482
4483 if (equal < 0)
4484 return -1;
4485 if (!equal)
4486 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4487); return -1; } while (0)
4487 "unexpected schedule", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4487); return -1; } while (0)
;
4488
4489 return 0;
4490}
4491
4492/* Check that the bounds on the coefficients are respected.
4493 * This function checks for a particular output schedule,
4494 * but the exact output is not important, only that it does
4495 * not contain any coefficients greater than 4.
4496 * It is, however, easier to check for a particular output.
4497 * This test is only run for the whole component scheduler
4498 * because the incremental scheduler produces a slightly different schedule.
4499 */
4500static int test_bounded_coefficients_schedule_whole(isl_ctx *ctx)
4501{
4502 const char *domain, *dep, *str;
4503 isl_union_set *I;
4504 isl_union_map *D;
4505 isl_schedule_constraints *sc;
4506 isl_schedule *schedule;
4507 isl_union_map *sched1, *sched2;
4508 isl_bool equal;
4509
4510 domain = "{ S_4[i, j, k] : 0 <= i < j <= 10 and 0 <= k <= 100; "
4511 "S_2[i, j] : 0 <= i < j <= 10; S_6[i, j] : 0 <= i < j <= 10 }";
4512 dep = "{ S_2[0, j] -> S_4[0, j, 0] : 0 < j <= 10; "
4513 "S_4[0, j, 100] -> S_6[0, j] : 0 < j <= 10 }";
4514 I = isl_union_set_read_from_str(ctx, domain);
4515 D = isl_union_map_read_from_str(ctx, dep);
4516 sc = isl_schedule_constraints_on_domain(I);
4517 sc = isl_schedule_constraints_set_validity(sc, D);
4518 isl_options_set_schedule_max_constant_term(ctx, 10);
4519 isl_options_set_schedule_max_coefficient(ctx, 4);
4520 schedule = isl_schedule_constraints_compute_schedule(sc);
4521 isl_options_set_schedule_max_coefficient(ctx, -1);
4522 isl_options_set_schedule_max_constant_term(ctx, -1);
4523 sched1 = isl_schedule_get_map(schedule);
4524 isl_schedule_free(schedule);
4525
4526 str = "{ S_4[i, j, k] -> [i, j, 10 - k]; "
4527 "S_2[i, j] -> [0, i, j]; S_6[i, j] -> [0, 10 + i, j] }";
4528 sched2 = isl_union_map_read_from_str(ctx, str);
4529 equal = isl_union_map_is_equal(sched1, sched2);
4530 isl_union_map_free(sched1);
4531 isl_union_map_free(sched2);
4532
4533 if (equal < 0)
4534 return -1;
4535 if (!equal)
4536 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4537); return -1; } while (0)
4537 "unexpected schedule", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected schedule"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4537); return -1; } while (0)
;
4538
4539 return 0;
4540}
4541
4542/* Check that a set of schedule constraints that only allow for
4543 * a coalescing schedule still produces a schedule even if the user
4544 * request a non-coalescing schedule. Earlier versions of isl
4545 * would not handle this case correctly.
4546 */
4547static int test_coalescing_schedule(isl_ctx *ctx)
4548{
4549 const char *domain, *dep;
4550 isl_union_set *I;
4551 isl_union_map *D;
4552 isl_schedule_constraints *sc;
4553 isl_schedule *schedule;
4554 int treat_coalescing;
4555
4556 domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4557 dep = "{ S[a, b] -> S[a + b, 1 - b] }";
4558 I = isl_union_set_read_from_str(ctx, domain);
4559 D = isl_union_map_read_from_str(ctx, dep);
4560 sc = isl_schedule_constraints_on_domain(I);
4561 sc = isl_schedule_constraints_set_validity(sc, D);
4562 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4563 isl_options_set_schedule_treat_coalescing(ctx, 1);
4564 schedule = isl_schedule_constraints_compute_schedule(sc);
4565 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4566 isl_schedule_free(schedule);
4567 if (!schedule)
4568 return -1;
4569 return 0;
4570}
4571
4572/* Check that the scheduler does not perform any needless
4573 * compound skewing. Earlier versions of isl would compute
4574 * schedules in terms of transformed schedule coefficients and
4575 * would not accurately keep track of the sum of the original
4576 * schedule coefficients. It could then produce the schedule
4577 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4578 * for the input below instead of the schedule below.
4579 */
4580static int test_skewing_schedule(isl_ctx *ctx)
4581{
4582 const char *D, *V, *P, *S;
4583
4584 D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4585 V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4586 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4587 "-1 <= a-i + b-j + c-k <= 1 }";
4588 P = "{ }";
4589 S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4590
4591 return test_special_schedule(ctx, D, V, P, S);
4592}
4593
4594int test_schedule(isl_ctx *ctx)
4595{
4596 const char *D, *W, *R, *V, *P, *S;
4597 int max_coincidence;
4598 int treat_coalescing;
4599
4600 /* Handle resulting schedule with zero bands. */
4601 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4602 return -1;
4603
4604 /* Jacobi */
4605 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4606 W = "{ S1[t,i] -> a[t,i] }";
4607 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4608 "S1[t,i] -> a[t-1,i+1] }";
4609 S = "{ S1[t,i] -> [t,i] }";
4610 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4611 return -1;
4612
4613 /* Fig. 5 of CC2008 */
4614 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4615 "j <= -1 + N }";
4616 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4617 "j >= 2 and j <= -1 + N }";
4618 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4619 "j >= 2 and j <= -1 + N; "
4620 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4621 "j >= 2 and j <= -1 + N }";
4622 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4623 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4624 return -1;
4625
4626 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4627 W = "{ S1[i] -> a[i] }";
4628 R = "{ S2[i] -> a[i+1] }";
4629 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4630 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4631 return -1;
4632
4633 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4634 W = "{ S1[i] -> a[i] }";
4635 R = "{ S2[i] -> a[9-i] }";
4636 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4637 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4638 return -1;
4639
4640 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4641 W = "{ S1[i] -> a[i] }";
4642 R = "[N] -> { S2[i] -> a[N-1-i] }";
4643 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4644 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4645 return -1;
4646
4647 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4648 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4649 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4650 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4651 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4652 return -1;
4653
4654 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4655 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4656 R = "{ S2[i,j] -> a[i-1,j] }";
4657 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4658 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4659 return -1;
4660
4661 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4662 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4663 R = "{ S2[i,j] -> a[i,j-1] }";
4664 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4665 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4666 return -1;
4667
4668 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4669 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4670 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4671 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4672 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4673 "S_0[] -> [0, 0, 0] }";
4674 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
4675 return -1;
4676 ctx->opt->schedule_parametric = 0;
4677 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4678 return -1;
4679 ctx->opt->schedule_parametric = 1;
4680
4681 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4682 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4683 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4684 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4685 "S4[i] -> a[i,N] }";
4686 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4687 "S4[i] -> [4,i,0] }";
4688 max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx);
4689 isl_options_set_schedule_maximize_coincidence(ctx, 0);
4690 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4691 return -1;
4692 isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence);
4693
4694 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4695 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4696 "j <= N }";
4697 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4698 "j <= N; "
4699 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4700 "j <= N }";
4701 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4702 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4703 return -1;
4704
4705 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4706 " S_2[t] : t >= 0 and t <= -1 + N; "
4707 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4708 "i <= -1 + N }";
4709 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4710 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4711 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4712 "i >= 0 and i <= -1 + N }";
4713 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4714 "i >= 0 and i <= -1 + N; "
4715 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4716 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4717 " S_0[t] -> [0, t, 0] }";
4718
4719 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4720 return -1;
4721 ctx->opt->schedule_parametric = 0;
4722 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4723 return -1;
4724 ctx->opt->schedule_parametric = 1;
4725
4726 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4727 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4728 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
4729 return -1;
4730
4731 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4732 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4733 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4734 "j >= 0 and j <= -1 + N; "
4735 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4736 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4737 "j >= 0 and j <= -1 + N; "
4738 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4739 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4740 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4741 return -1;
4742
4743 D = "{ S_0[i] : i >= 0 }";
4744 W = "{ S_0[i] -> a[i] : i >= 0 }";
4745 R = "{ S_0[i] -> a[0] : i >= 0 }";
4746 S = "{ S_0[i] -> [0, i, 0] }";
4747 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4748 return -1;
4749
4750 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4751 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4752 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4753 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4754 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4755 return -1;
4756
4757 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4758 "k <= -1 + n and k >= 0 }";
4759 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4760 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4761 "k <= -1 + n and k >= 0; "
4762 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4763 "k <= -1 + n and k >= 0; "
4764 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4765 "k <= -1 + n and k >= 0 }";
4766 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
4767 ctx->opt->schedule_outer_coincidence = 1;
4768 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4769 return -1;
4770 ctx->opt->schedule_outer_coincidence = 0;
4771
4772 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
4773 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4774 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4775 "Stmt_for_body24[i0, i1, 1, 0]:"
4776 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4777 "Stmt_for_body7[i0, i1, i2]:"
4778 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4779 "i2 <= 7 }";
4780
4781 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
4782 "Stmt_for_body24[1, i1, i2, i3]:"
4783 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4784 "i2 >= 1;"
4785 "Stmt_for_body24[0, i1, i2, i3] -> "
4786 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4787 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4788 "i3 >= 0;"
4789 "Stmt_for_body24[0, i1, i2, i3] ->"
4790 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4791 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4792 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4793 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4794 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4795 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4796 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4797 "i1 <= 6 and i1 >= 0;"
4798 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4799 "Stmt_for_body7[i0, i1, i2] -> "
4800 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4801 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4802 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4803 "Stmt_for_body7[i0, i1, i2] -> "
4804 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4805 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4806 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4807 P = V;
4808
4809 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4810 isl_options_set_schedule_treat_coalescing(ctx, 0);
4811 if (test_has_schedule(ctx, D, V, P) < 0)
4812 return -1;
4813 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4814
4815 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4816 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4817 "j >= 1 and j <= 7;"
4818 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4819 "j >= 1 and j <= 8 }";
4820 P = "{ }";
4821 S = "{ S_0[i, j] -> [i + j, i] }";
4822 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1;
4823 if (test_special_schedule(ctx, D, V, P, S) < 0)
4824 return -1;
4825 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0;
4826
4827 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4828 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4829 "j >= 0 and j <= -1 + i }";
4830 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4831 "i <= -1 + N and j >= 0;"
4832 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4833 "i <= -2 + N }";
4834 P = "{ }";
4835 S = "{ S_0[i, j] -> [i, j] }";
4836 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1;
4837 if (test_special_schedule(ctx, D, V, P, S) < 0)
4838 return -1;
4839 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0;
4840
4841 /* Test both algorithms on a case with only proximity dependences. */
4842 D = "{ S[i,j] : 0 <= i <= 10 }";
4843 V = "{ }";
4844 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4845 S = "{ S[i, j] -> [j, i] }";
4846 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1;
4847 if (test_special_schedule(ctx, D, V, P, S) < 0)
4848 return -1;
4849 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0;
4850 if (test_special_schedule(ctx, D, V, P, S) < 0)
4851 return -1;
4852
4853 D = "{ A[a]; B[] }";
4854 V = "{}";
4855 P = "{ A[a] -> B[] }";
4856 if (test_has_schedule(ctx, D, V, P) < 0)
4857 return -1;
4858
4859 if (test_padded_schedule(ctx) < 0)
4860 return -1;
4861
4862 /* Check that check for progress is not confused by rational
4863 * solution.
4864 */
4865 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4866 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4867 "i0 <= -2 + N; "
4868 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4869 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4870 P = "{}";
4871 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1;
4872 if (test_has_schedule(ctx, D, V, P) < 0)
4873 return -1;
4874 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0;
4875
4876 /* Check that we allow schedule rows that are only non-trivial
4877 * on some full-dimensional domains.
4878 */
4879 D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4880 V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4881 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4882 P = "{}";
4883 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER1;
4884 if (test_has_schedule(ctx, D, V, P) < 0)
4885 return -1;
4886 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL0;
4887
4888 if (test_conditional_schedule_constraints(ctx) < 0)
4889 return -1;
4890
4891 if (test_strongly_satisfying_schedule(ctx) < 0)
4892 return -1;
4893
4894 if (test_conflicting_context_schedule(ctx) < 0)
4895 return -1;
4896
4897 if (test_bounded_coefficients_schedule(ctx) < 0)
4898 return -1;
4899 if (test_coalescing_schedule(ctx) < 0)
4900 return -1;
4901 if (test_skewing_schedule(ctx) < 0)
4902 return -1;
4903
4904 return 0;
4905}
4906
4907/* Perform scheduling tests using the whole component scheduler.
4908 */
4909static int test_schedule_whole(isl_ctx *ctx)
4910{
4911 int whole;
4912 int r;
4913
4914 whole = isl_options_get_schedule_whole_component(ctx);
4915 isl_options_set_schedule_whole_component(ctx, 1);
4916 r = test_schedule(ctx);
4917 if (r >= 0)
4918 r = test_bounded_coefficients_schedule_whole(ctx);
4919 isl_options_set_schedule_whole_component(ctx, whole);
4920
4921 return r;
4922}
4923
4924/* Perform scheduling tests using the incremental scheduler.
4925 */
4926static int test_schedule_incremental(isl_ctx *ctx)
4927{
4928 int whole;
4929 int r;
4930
4931 whole = isl_options_get_schedule_whole_component(ctx);
4932 isl_options_set_schedule_whole_component(ctx, 0);
4933 r = test_schedule(ctx);
4934 isl_options_set_schedule_whole_component(ctx, whole);
4935
4936 return r;
4937}
4938
4939int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
4940{
4941 isl_union_map *umap;
4942 int test;
4943
4944 umap = isl_union_map_read_from_str(ctx, str);
4945 test = isl_union_map_plain_is_injective(umap);
4946 isl_union_map_free(umap);
4947 if (test < 0)
4948 return -1;
4949 if (test == injective)
4950 return 0;
4951 if (injective)
4952 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4953); return -1; } while (0)
4953 "map not detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map not detected as injective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4953); return -1; } while (0)
;
4954 else
4955 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4956); return -1; } while (0)
4956 "map detected as injective", return -1)do { isl_handle_error(ctx, isl_error_unknown, "map detected as injective"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 4956); return -1; } while (0)
;
4957}
4958
4959int test_injective(isl_ctx *ctx)
4960{
4961 const char *str;
4962
4963 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4964 return -1;
4965 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
4966 return -1;
4967 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
4968 return -1;
4969 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
4970 return -1;
4971 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4972 return -1;
4973 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4974 return -1;
4975 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4976 return -1;
4977 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4978 return -1;
4979
4980 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4981 if (test_plain_injective(ctx, str, 1))
4982 return -1;
4983 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4984 if (test_plain_injective(ctx, str, 0))
4985 return -1;
4986
4987 return 0;
4988}
4989
4990static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
4991{
4992 isl_aff *aff2;
4993 int equal;
4994
4995 if (!aff)
4996 return -1;
4997
4998 aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
4999 equal = isl_aff_plain_is_equal(aff, aff2);
5000 isl_aff_free(aff2);
5001
5002 return equal;
5003}
5004
5005static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
5006{
5007 int equal;
5008
5009 equal = aff_plain_is_equal(aff, str);
5010 if (equal < 0)
5011 return -1;
5012 if (!equal)
5013 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5014); return -1; } while (0)
5014 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5014); return -1; } while (0)
;
5015 return 0;
5016}
5017
5018/* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
5019 */
5020static isl_bool union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff *upa,
5021 const char *str)
5022{
5023 isl_ctx *ctx;
5024 isl_union_pw_aff *upa2;
5025 isl_bool equal;
5026
5027 if (!upa)
5028 return isl_bool_error;
5029
5030 ctx = isl_union_pw_aff_get_ctx(upa);
5031 upa2 = isl_union_pw_aff_read_from_str(ctx, str);
5032 equal = isl_union_pw_aff_plain_is_equal(upa, upa2);
5033 isl_union_pw_aff_free(upa2);
5034
5035 return equal;
5036}
5037
5038/* Check that "upa" is obviously equal to the isl_union_pw_aff
5039 * represented by "str".
5040 */
5041static isl_stat union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff *upa,
5042 const char *str)
5043{
5044 isl_bool equal;
5045
5046 equal = union_pw_aff_plain_is_equal(upa, str);
5047 if (equal < 0)
5048 return isl_stat_error;
5049 if (!equal)
5050 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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5051); return isl_stat_error; } while (0)
5051 "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-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5051); return isl_stat_error; } while (0)
;
5052 return isl_stat_ok;
5053}
5054
5055/* Basic tests on isl_union_pw_aff.
5056 *
5057 * In particular, check that isl_union_pw_aff_aff_on_domain
5058 * aligns the parameters of the input objects and
5059 * that isl_union_pw_aff_param_on_domain_id properly
5060 * introduces the parameter.
5061 */
5062static int test_upa(isl_ctx *ctx)
5063{
5064 const char *str;
5065 isl_id *id;
5066 isl_aff *aff;
5067 isl_union_set *domain;
5068 isl_union_pw_aff *upa;
5069 isl_stat ok;
5070
5071 aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }");
5072 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5073 domain = isl_union_set_read_from_str(ctx, str);
5074 upa = isl_union_pw_aff_aff_on_domain(domain, aff);
5075 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5076 ok = union_pw_aff_check_plain_equal(upa, str);
5077 isl_union_pw_aff_free(upa);
5078 if (ok < 0)
5079 return -1;
5080
5081 id = isl_id_alloc(ctx, "N", NULL((void*)0));
5082 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5083 domain = isl_union_set_read_from_str(ctx, str);
5084 upa = isl_union_pw_aff_param_on_domain_id(domain, id);
5085 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5086 ok = union_pw_aff_check_plain_equal(upa, str);
5087 isl_union_pw_aff_free(upa);
5088 if (ok < 0)
5089 return -1;
5090
5091 return 0;
5092}
5093
5094struct {
5095 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5096 __isl_take isl_aff *aff2);
5097} aff_bin_op[] = {
5098 ['+'] = { &isl_aff_add },
5099 ['-'] = { &isl_aff_sub },
5100 ['*'] = { &isl_aff_mul },
5101 ['/'] = { &isl_aff_div },
5102};
5103
5104struct {
5105 const char *arg1;
5106 unsigned char op;
5107 const char *arg2;
5108 const char *res;
5109} aff_bin_tests[] = {
5110 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5111 "{ [i] -> [2i] }" },
5112 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5113 "{ [i] -> [0] }" },
5114 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5115 "{ [i] -> [2i] }" },
5116 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5117 "{ [i] -> [2i] }" },
5118 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5119 "{ [i] -> [i/2] }" },
5120 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5121 "{ [i] -> [i] }" },
5122 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5123 "{ [i] -> [NaN] }" },
5124 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5125 "{ [i] -> [NaN] }" },
5126 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5127 "{ [i] -> [NaN] }" },
5128 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5129 "{ [i] -> [NaN] }" },
5130 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5131 "{ [i] -> [NaN] }" },
5132 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5133 "{ [i] -> [NaN] }" },
5134 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5135 "{ [i] -> [NaN] }" },
5136 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5137 "{ [i] -> [NaN] }" },
5138 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5139 "{ [i] -> [NaN] }" },
5140 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5141 "{ [i] -> [NaN] }" },
5142 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5143 "{ [i] -> [NaN] }" },
5144 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5145 "{ [i] -> [NaN] }" },
5146};
5147
5148/* Perform some basic tests of binary operations on isl_aff objects.
5149 */
5150static int test_bin_aff(isl_ctx *ctx)
5151{
5152 int i;
5153 isl_aff *aff1, *aff2, *res;
5154 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5155 __isl_take isl_aff *aff2);
5156 int ok;
5157
5158 for (i = 0; i < ARRAY_SIZE(aff_bin_tests)(sizeof(aff_bin_tests)/sizeof(*aff_bin_tests)); ++i) {
5159 aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1);
5160 aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2);
5161 res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res);
5162 fn = aff_bin_op[aff_bin_tests[i].op].fn;
5163 aff1 = fn(aff1, aff2);
5164 if (isl_aff_is_nan(res))
5165 ok = isl_aff_is_nan(aff1);
5166 else
5167 ok = isl_aff_plain_is_equal(aff1, res);
5168 isl_aff_free(aff1);
5169 isl_aff_free(res);
5170 if (ok < 0)
5171 return -1;
5172 if (!ok)
5173 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5174); return -1; } while (0)
5174 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5174); return -1; } while (0)
;
5175 }
5176
5177 return 0;
5178}
5179
5180struct {
5181 __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1,
5182 __isl_take isl_pw_aff *pa2);
5183} pw_aff_bin_op[] = {
5184 ['m'] = { &isl_pw_aff_min },
5185 ['M'] = { &isl_pw_aff_max },
5186};
5187
5188/* Inputs for binary isl_pw_aff operation tests.
5189 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5190 * defined by pw_aff_bin_op, and "res" is the expected result.
5191 */
5192struct {
5193 const char *arg1;
5194 unsigned char op;
5195 const char *arg2;
5196 const char *res;
5197} pw_aff_bin_tests[] = {
5198 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5199 "{ [i] -> [i] }" },
5200 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5201 "{ [i] -> [i] }" },
5202 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5203 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5204 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5205 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5206 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5207 "{ [i] -> [NaN] }" },
5208 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5209 "{ [i] -> [NaN] }" },
5210};
5211
5212/* Perform some basic tests of binary operations on isl_pw_aff objects.
5213 */
5214static int test_bin_pw_aff(isl_ctx *ctx)
5215{
5216 int i;
5217 isl_bool ok;
5218 isl_pw_aff *pa1, *pa2, *res;
5219
5220 for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests)(sizeof(pw_aff_bin_tests)/sizeof(*pw_aff_bin_tests)); ++i) {
5221 pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1);
5222 pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2);
5223 res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res);
5224 pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2);
5225 if (isl_pw_aff_involves_nan(res))
5226 ok = isl_pw_aff_involves_nan(pa1);
5227 else
5228 ok = isl_pw_aff_plain_is_equal(pa1, res);
5229 isl_pw_aff_free(pa1);
5230 isl_pw_aff_free(res);
5231 if (ok < 0)
5232 return -1;
5233 if (!ok)
5234 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5235); return -1; } while (0)
5235 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5235); return -1; } while (0)
;
5236 }
5237
5238 return 0;
5239}
5240
5241struct {
5242 __isl_give isl_union_pw_multi_aff *(*fn)(
5243 __isl_take isl_union_pw_multi_aff *upma1,
5244 __isl_take isl_union_pw_multi_aff *upma2);
5245 const char *arg1;
5246 const char *arg2;
5247 const char *res;
5248} upma_bin_tests[] = {
5249 { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }",
5250 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5251 { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }",
5252 "{ B[x] -> [2] : x >= 0 }",
5253 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5254 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff,
5255 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5256 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5257 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5258 "D[i] -> B[2] : i >= 5 }" },
5259 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5260 "{ B[x] -> C[2] : x > 0 }",
5261 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5262 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5263 "{ B[x] -> A[2] : x >= 0 }",
5264 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5265};
5266
5267/* Perform some basic tests of binary operations on
5268 * isl_union_pw_multi_aff objects.
5269 */
5270static int test_bin_upma(isl_ctx *ctx)
5271{
5272 int i;
5273 isl_union_pw_multi_aff *upma1, *upma2, *res;
5274 int ok;
5275
5276 for (i = 0; i < ARRAY_SIZE(upma_bin_tests)(sizeof(upma_bin_tests)/sizeof(*upma_bin_tests)); ++i) {
5277 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5278 upma_bin_tests[i].arg1);
5279 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5280 upma_bin_tests[i].arg2);
5281 res = isl_union_pw_multi_aff_read_from_str(ctx,
5282 upma_bin_tests[i].res);
5283 upma1 = upma_bin_tests[i].fn(upma1, upma2);
5284 ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res);
5285 isl_union_pw_multi_aff_free(upma1);
5286 isl_union_pw_multi_aff_free(res);
5287 if (ok < 0)
5288 return -1;
5289 if (!ok)
5290 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5291); return -1; } while (0)
5291 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5291); return -1; } while (0)
;
5292 }
5293
5294 return 0;
5295}
5296
5297struct {
5298 __isl_give isl_union_pw_multi_aff *(*fn)(
5299 __isl_take isl_union_pw_multi_aff *upma1,
5300 __isl_take isl_union_pw_multi_aff *upma2);
5301 const char *arg1;
5302 const char *arg2;
5303} upma_bin_fail_tests[] = {
5304 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5305 "{ B[x] -> C[2] : x >= 0 }" },
5306};
5307
5308/* Perform some basic tests of binary operations on
5309 * isl_union_pw_multi_aff objects that are expected to fail.
5310 */
5311static int test_bin_upma_fail(isl_ctx *ctx)
5312{
5313 int i, n;
5314 isl_union_pw_multi_aff *upma1, *upma2;
5315 int on_error;
5316
5317 on_error = isl_options_get_on_error(ctx);
5318 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE1);
5319 n = ARRAY_SIZE(upma_bin_fail_tests)(sizeof(upma_bin_fail_tests)/sizeof(*upma_bin_fail_tests));
5320 for (i = 0; i < n; ++i) {
5321 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5322 upma_bin_fail_tests[i].arg1);
5323 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5324 upma_bin_fail_tests[i].arg2);
5325 upma1 = upma_bin_fail_tests[i].fn(upma1, upma2);
5326 isl_union_pw_multi_aff_free(upma1);
5327 if (upma1)
5328 break;
5329 }
5330 isl_options_set_on_error(ctx, on_error);
5331 if (i < n)
5332 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5333); return -1; } while (0)
5333 "operation not expected to succeed", return -1)do { isl_handle_error(ctx, isl_error_unknown, "operation not expected to succeed"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5333); return -1; } while (0)
;
5334
5335 return 0;
5336}
5337
5338/* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5339 * "fn" is the function that is tested.
5340 * "arg" is a string description of the input.
5341 * "res" is a string description of the expected result.
5342 */
5343struct {
5344 __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa);
5345 const char *arg;
5346 const char *res;
5347} mpa_un_tests[] = {
5348 { &isl_multi_pw_aff_range_factor_domain,
5349 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5350 "{ A[x] -> B[(1 : x >= 5)] }" },
5351 { &isl_multi_pw_aff_range_factor_range,
5352 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5353 "{ A[y] -> C[(2 : y <= 10)] }" },
5354 { &isl_multi_pw_aff_range_factor_domain,
5355 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5356 "{ A[x] -> B[(1 : x >= 5)] }" },
5357 { &isl_multi_pw_aff_range_factor_range,
5358 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5359 "{ A[y] -> C[] }" },
5360 { &isl_multi_pw_aff_range_factor_domain,
5361 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5362 "{ A[x] -> B[] }" },
5363 { &isl_multi_pw_aff_range_factor_range,
5364 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5365 "{ A[y] -> C[(2 : y <= 10)] }" },
5366 { &isl_multi_pw_aff_range_factor_domain,
5367 "{ A[x] -> [B[] -> C[]] }",
5368 "{ A[x] -> B[] }" },
5369 { &isl_multi_pw_aff_range_factor_range,
5370 "{ A[x] -> [B[] -> C[]] }",
5371 "{ A[y] -> C[] }" },
5372 { &isl_multi_pw_aff_factor_range,
5373 "{ [B[] -> C[]] }",
5374 "{ C[] }" },
5375 { &isl_multi_pw_aff_range_factor_domain,
5376 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5377 "{ A[x] -> B[] : x >= 0 }" },
5378 { &isl_multi_pw_aff_range_factor_range,
5379 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5380 "{ A[y] -> C[] : y >= 0 }" },
5381 { &isl_multi_pw_aff_factor_range,
5382 "[N] -> { [B[] -> C[]] : N >= 0 }",
5383 "[N] -> { C[] : N >= 0 }" },
5384};
5385
5386/* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5387 */
5388static int test_un_mpa(isl_ctx *ctx)
5389{
5390 int i;
5391 isl_bool ok;
5392 isl_multi_pw_aff *mpa, *res;
5393
5394 for (i = 0; i < ARRAY_SIZE(mpa_un_tests)(sizeof(mpa_un_tests)/sizeof(*mpa_un_tests)); ++i) {
5395 mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg);
5396 res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res);
5397 mpa = mpa_un_tests[i].fn(mpa);
5398 ok = isl_multi_pw_aff_plain_is_equal(mpa, res);
5399 isl_multi_pw_aff_free(mpa);
5400 isl_multi_pw_aff_free(res);
5401 if (ok < 0)
5402 return -1;
5403 if (!ok)
5404 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5405); return -1; } while (0)
5405 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5405); return -1; } while (0)
;
5406 }
5407
5408 return 0;
5409}
5410
5411/* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5412 * "fn" is the function that is tested.
5413 * "arg1" and "arg2" are string descriptions of the inputs.
5414 * "res" is a string description of the expected result.
5415 */
5416struct {
5417 __isl_give isl_multi_pw_aff *(*fn)(
5418 __isl_take isl_multi_pw_aff *mpa1,
5419 __isl_take isl_multi_pw_aff *mpa2);
5420 const char *arg1;
5421 const char *arg2;
5422 const char *res;
5423} mpa_bin_tests[] = {
5424 { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }",
5425 "{ A[] -> [3] }" },
5426 { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }",
5427 "{ A[x] -> [(x : x <= 10)] }",
5428 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5429 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5430 "{ A[x] -> [] : x <= 10 }",
5431 "{ A[x] -> [] : 5 <= x <= 10 }" },
5432 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5433 "[N] -> { A[x] -> [] : x <= N }",
5434 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5435 { &isl_multi_pw_aff_add,
5436 "[N] -> { A[x] -> [] : x <= N }",
5437 "{ A[x] -> [] : x >= 5 }",
5438 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5439 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5440 "{ A[y] -> C[(2 : y <= 10)] }",
5441 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5442 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5443 "{ A[y] -> C[2] : y <= 10 }",
5444 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5445 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5446 "[N] -> { A[y] -> C[2] : y <= N }",
5447 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5448 { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }",
5449 "{ A[y] -> C[2] : y <= 10 }",
5450 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5451 { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5452 "{ A[] -> [B[1] -> C[2]] }" },
5453 { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5454 "{ A[] -> [B[] -> C[]] }" },
5455 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5456 "{ A[y] -> C[] : y <= 10 }",
5457 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5458 { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }",
5459 "{ A[x] -> B[(1 : x >= 5)] }",
5460 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5461 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5462 "{ A[y] -> C[(2 : y <= 10)] }",
5463 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5464 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5465 "{ A[y] -> C[] : y <= 10 }",
5466 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5467 { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }",
5468 "{ A[x] -> B[(1 : x >= 5)] }",
5469 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5470 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5471 "[N] -> { A[y] -> C[] : y <= N }",
5472 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5473 { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }",
5474 "{ A[x] -> B[(1 : x >= 5)] }",
5475 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5476 { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }",
5477 "{ A[y] -> C[] : y <= 10 }",
5478 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5479 { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5480 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5481 { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5482 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5483 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5484 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5485 "{ A[a,b] -> C[b + 2a] }" },
5486 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5487 "{ B[i,j] -> C[i + 2j] }",
5488 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5489 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5490 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5491 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5492 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5493 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5494 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5495 "{ B[i,j] -> C[] }",
5496 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5497 "{ A[a,b] -> C[] }" },
5498 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5499 "{ B[i,j] -> C[] : i > j }",
5500 "{ A[a,b] -> B[b,a] }",
5501 "{ A[a,b] -> C[] : b > a }" },
5502 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5503 "{ B[i,j] -> C[] : j > 5 }",
5504 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5505 "{ A[a,b] -> C[] : b > a > 5 }" },
5506 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5507 "[N] -> { B[i,j] -> C[] : j > N }",
5508 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5509 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5510 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5511 "[M,N] -> { B[] -> C[] : N > 5 }",
5512 "[M,N] -> { A[] -> B[] : M > N }",
5513 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5514};
5515
5516/* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5517 */
5518static int test_bin_mpa(isl_ctx *ctx)
5519{
5520 int i;
5521 isl_bool ok;
5522 isl_multi_pw_aff *mpa1, *mpa2, *res;
5523
5524 for (i = 0; i < ARRAY_SIZE(mpa_bin_tests)(sizeof(mpa_bin_tests)/sizeof(*mpa_bin_tests)); ++i) {
5525 mpa1 = isl_multi_pw_aff_read_from_str(ctx,
5526 mpa_bin_tests[i].arg1);
5527 mpa2 = isl_multi_pw_aff_read_from_str(ctx,
5528 mpa_bin_tests[i].arg2);
5529 res = isl_multi_pw_aff_read_from_str(ctx,
5530 mpa_bin_tests[i].res);
5531 mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2);
5532 ok = isl_multi_pw_aff_plain_is_equal(mpa1, res);
5533 isl_multi_pw_aff_free(mpa1);
5534 isl_multi_pw_aff_free(res);
5535 if (ok < 0)
5536 return -1;
5537 if (!ok)
5538 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5539); return -1; } while (0)
5539 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5539); return -1; } while (0)
;
5540 }
5541
5542 return 0;
5543}
5544
5545/* Inputs for basic tests of unary operations on
5546 * isl_multi_union_pw_aff objects.
5547 * "fn" is the function that is tested.
5548 * "arg" is a string description of the input.
5549 * "res" is a string description of the expected result.
5550 */
5551struct {
5552 __isl_give isl_multi_union_pw_aff *(*fn)(
5553 __isl_take isl_multi_union_pw_aff *mupa);
5554 const char *arg;
5555 const char *res;
5556} mupa_un_tests[] = {
5557 { &isl_multi_union_pw_aff_factor_range,
5558 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5559 "C[{ A[] -> [2] }]" },
5560 { &isl_multi_union_pw_aff_factor_range,
5561 "[B[] -> C[{ A[] -> [2] }]]",
5562 "C[{ A[] -> [2] }]" },
5563 { &isl_multi_union_pw_aff_factor_range,
5564 "[B[{ A[] -> [1] }] -> C[]]",
5565 "C[]" },
5566 { &isl_multi_union_pw_aff_factor_range,
5567 "[B[] -> C[]]",
5568 "C[]" },
5569 { &isl_multi_union_pw_aff_factor_range,
5570 "([B[] -> C[]] : { A[x] : x >= 0 })",
5571 "(C[] : { A[x] : x >= 0 })" },
5572 { &isl_multi_union_pw_aff_factor_range,
5573 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5574 "[N] -> (C[] : { A[x] : x <= N })" },
5575 { &isl_multi_union_pw_aff_factor_range,
5576 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5577 "[N] -> (C[] : { : N >= 0 })" },
5578};
5579
5580/* Perform some basic tests of unary operations on
5581 * isl_multi_union_pw_aff objects.
5582 */
5583static int test_un_mupa(isl_ctx *ctx)
5584{
5585 int i;
5586 isl_bool ok;
5587 isl_multi_union_pw_aff *mupa, *res;
5588
5589 for (i = 0; i < ARRAY_SIZE(mupa_un_tests)(sizeof(mupa_un_tests)/sizeof(*mupa_un_tests)); ++i) {
5590 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5591 mupa_un_tests[i].arg);
5592 res = isl_multi_union_pw_aff_read_from_str(ctx,
5593 mupa_un_tests[i].res);
5594 mupa = mupa_un_tests[i].fn(mupa);
5595 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5596 isl_multi_union_pw_aff_free(mupa);
5597 isl_multi_union_pw_aff_free(res);
5598 if (ok < 0)
5599 return -1;
5600 if (!ok)
5601 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5602); return -1; } while (0)
5602 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5602); return -1; } while (0)
;
5603 }
5604
5605 return 0;
5606}
5607
5608/* Inputs for basic tests of binary operations on
5609 * isl_multi_union_pw_aff objects.
5610 * "fn" is the function that is tested.
5611 * "arg1" and "arg2" are string descriptions of the inputs.
5612 * "res" is a string description of the expected result.
5613 */
5614struct {
5615 __isl_give isl_multi_union_pw_aff *(*fn)(
5616 __isl_take isl_multi_union_pw_aff *mupa1,
5617 __isl_take isl_multi_union_pw_aff *mupa2);
5618 const char *arg1;
5619 const char *arg2;
5620 const char *res;
5621} mupa_bin_tests[] = {
5622 { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5623 "[{ A[] -> [3] }]" },
5624 { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5625 "[{ A[] -> [-1] }]" },
5626 { &isl_multi_union_pw_aff_add,
5627 "[{ A[] -> [1]; B[] -> [4] }]",
5628 "[{ A[] -> [2]; C[] -> [5] }]",
5629 "[{ A[] -> [3] }]" },
5630 { &isl_multi_union_pw_aff_union_add,
5631 "[{ A[] -> [1]; B[] -> [4] }]",
5632 "[{ A[] -> [2]; C[] -> [5] }]",
5633 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5634 { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]",
5635 "[{ A[x] -> [(x)] : x <= 10 }]",
5636 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5637 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
5638 "([] : { A[x] : x <= 10 })",
5639 "([] : { A[x] : 5 <= x <= 10 })" },
5640 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
5641 "[N] -> ([] : { A[x] : x <= N })",
5642 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5643 { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })",
5644 "([] : { A[x] : x <= 10 })",
5645 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5646 { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]",
5647 "[{ A[x] -> [(x)] : x <= 10 }]",
5648 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5649 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5650 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })",
5651 "([] : { A[x] : x <= 10 })",
5652 "([] : { A[x] })" },
5653 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })",
5654 "[N] -> ([] : { A[x] : x >= N })",
5655 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5656 { &isl_multi_union_pw_aff_union_add,
5657 "[N] -> ([] : { A[] : N >= 0})",
5658 "[N] -> ([] : { A[] : N <= 0})",
5659 "[N] -> ([] : { A[] })" },
5660 { &isl_multi_union_pw_aff_union_add,
5661 "[N] -> ([] : { A[] })",
5662 "[N] -> ([] : { : })",
5663 "[N] -> ([] : { : })" },
5664 { &isl_multi_union_pw_aff_union_add,
5665 "[N] -> ([] : { : })",
5666 "[N] -> ([] : { A[] })",
5667 "[N] -> ([] : { : })" },
5668 { &isl_multi_union_pw_aff_union_add,
5669 "[N] -> ([] : { : N >= 0})",
5670 "[N] -> ([] : { : N <= 0})",
5671 "[N] -> ([] : { : })" },
5672 { &isl_multi_union_pw_aff_range_product,
5673 "B[{ A[] -> [1] }]",
5674 "C[{ A[] -> [2] }]",
5675 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5676 { &isl_multi_union_pw_aff_range_product,
5677 "(B[] : { A[x] : x >= 5 })",
5678 "(C[] : { A[x] : x <= 10 })",
5679 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5680 { &isl_multi_union_pw_aff_range_product,
5681 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5682 "(C[] : { A[x] : x <= 10 })",
5683 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5684 { &isl_multi_union_pw_aff_range_product,
5685 "(C[] : { A[x] : x <= 10 })",
5686 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5687 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5688 { &isl_multi_union_pw_aff_range_product,
5689 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5690 "[N] -> (C[] : { A[x] : x <= N })",
5691 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5692 { &isl_multi_union_pw_aff_range_product,
5693 "[N] -> (C[] : { A[x] : x <= N })",
5694 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5695 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5696 { &isl_multi_union_pw_aff_range_product,
5697 "B[{ A[] -> [1]; D[] -> [3] }]",
5698 "C[{ A[] -> [2] }]",
5699 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5700 { &isl_multi_union_pw_aff_range_product,
5701 "B[] }]",
5702 "(C[] : { A[x] })",
5703 "([B[] -> C[]] : { A[x] })" },
5704 { &isl_multi_union_pw_aff_range_product,
5705 "(B[] : { A[x] })",
5706 "C[] }]",
5707 "([B[] -> C[]] : { A[x] })" },
5708};
5709
5710/* Perform some basic tests of binary operations on
5711 * isl_multi_union_pw_aff objects.
5712 */
5713static int test_bin_mupa(isl_ctx *ctx)
5714{
5715 int i;
5716 isl_bool ok;
5717 isl_multi_union_pw_aff *mupa1, *mupa2, *res;
5718
5719 for (i = 0; i < ARRAY_SIZE(mupa_bin_tests)(sizeof(mupa_bin_tests)/sizeof(*mupa_bin_tests)); ++i) {
5720 mupa1 = isl_multi_union_pw_aff_read_from_str(ctx,
5721 mupa_bin_tests[i].arg1);
5722 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx,
5723 mupa_bin_tests[i].arg2);
5724 res = isl_multi_union_pw_aff_read_from_str(ctx,
5725 mupa_bin_tests[i].res);
5726 mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2);
5727 ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res);
5728 isl_multi_union_pw_aff_free(mupa1);
5729 isl_multi_union_pw_aff_free(res);
5730 if (ok < 0)
5731 return -1;
5732 if (!ok)
5733 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5734); return -1; } while (0)
5734 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5734); return -1; } while (0)
;
5735 }
5736
5737 return 0;
5738}
5739
5740/* Inputs for basic tests of binary operations on
5741 * pairs of isl_multi_union_pw_aff and isl_set objects.
5742 * "fn" is the function that is tested.
5743 * "arg1" and "arg2" are string descriptions of the inputs.
5744 * "res" is a string description of the expected result.
5745 */
5746struct {
5747 __isl_give isl_multi_union_pw_aff *(*fn)(
5748 __isl_take isl_multi_union_pw_aff *mupa,
5749 __isl_take isl_setisl_map *set);
5750 const char *arg1;
5751 const char *arg2;
5752 const char *res;
5753} mupa_set_tests[] = {
5754 { &isl_multi_union_pw_aff_intersect_range,
5755 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5756 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5757 { &isl_multi_union_pw_aff_intersect_range,
5758 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5759 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5760 { &isl_multi_union_pw_aff_intersect_range,
5761 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5762 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5763 { &isl_multi_union_pw_aff_intersect_range,
5764 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5765 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5766 { &isl_multi_union_pw_aff_intersect_range,
5767 "C[]", "{ C[] }", "C[]" },
5768 { &isl_multi_union_pw_aff_intersect_range,
5769 "[N] -> (C[] : { : N >= 0 })",
5770 "{ C[] }",
5771 "[N] -> (C[] : { : N >= 0 })" },
5772 { &isl_multi_union_pw_aff_intersect_range,
5773 "(C[] : { A[a,b] })",
5774 "{ C[] }",
5775 "(C[] : { A[a,b] })" },
5776 { &isl_multi_union_pw_aff_intersect_range,
5777 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5778 "{ C[] }",
5779 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5780 { &isl_multi_union_pw_aff_intersect_range,
5781 "C[]",
5782 "[N] -> { C[] : N >= 0 }",
5783 "[N] -> (C[] : { : N >= 0 })" },
5784 { &isl_multi_union_pw_aff_intersect_range,
5785 "(C[] : { A[a,b] })",
5786 "[N] -> { C[] : N >= 0 }",
5787 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5788 { &isl_multi_union_pw_aff_intersect_range,
5789 "[N] -> (C[] : { : N >= 0 })",
5790 "[N] -> { C[] : N < 1024 }",
5791 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5792 { &isl_multi_union_pw_aff_intersect_params,
5793 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5794 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5795 { &isl_multi_union_pw_aff_intersect_params,
5796 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5797 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5798 { &isl_multi_union_pw_aff_intersect_params,
5799 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5800 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5801 { &isl_multi_union_pw_aff_intersect_params,
5802 "C[]", "[N] -> { : N >= 0 }",
5803 "[N] -> (C[] : { : N >= 0 })" },
5804 { &isl_multi_union_pw_aff_intersect_params,
5805 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5806 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5807 { &isl_multi_union_pw_aff_intersect_params,
5808 "[N] -> (C[] : { A[a,N] })", "{ : }",
5809 "[N] -> (C[] : { A[a,N] })" },
5810 { &isl_multi_union_pw_aff_intersect_params,
5811 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5812 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5813};
5814
5815/* Perform some basic tests of binary operations on
5816 * pairs of isl_multi_union_pw_aff and isl_set objects.
5817 */
5818static int test_mupa_set(isl_ctx *ctx)
5819{
5820 int i;
5821 isl_bool ok;
5822 isl_multi_union_pw_aff *mupa, *res;
5823 isl_setisl_map *set;
5824
5825 for (i = 0; i < ARRAY_SIZE(mupa_set_tests)(sizeof(mupa_set_tests)/sizeof(*mupa_set_tests)); ++i) {
5826 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5827 mupa_set_tests[i].arg1);
5828 set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2);
5829 res = isl_multi_union_pw_aff_read_from_str(ctx,
5830 mupa_set_tests[i].res);
5831 mupa = mupa_set_tests[i].fn(mupa, set);
5832 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5833 isl_multi_union_pw_aff_free(mupa);
5834 isl_multi_union_pw_aff_free(res);
5835 if (ok < 0)
5836 return -1;
5837 if (!ok)
5838 isl_die(ctx, isl_error_unknown,do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5839); return -1; } while (0)
5839 "unexpected result", return -1)do { isl_handle_error(ctx, isl_error_unknown, "unexpected result"
, "/build/llvm-toolchain-snapshot-7~svn336939/tools/polly/lib/External/isl/isl_test.c"
, 5839); return -1; } while (0)
;
5840 }
5841
5842 return 0;
5843}
5844
5845/* Inputs for basic tests of binary operations on
5846 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5847 * "fn" is the function that is tested.
5848 * "arg1" and "arg2" are string descriptions of the inputs.
5849 * "res" is a string description of the expected result.
5850 */
5851struct {
5852 __isl_give isl_multi_union_pw_aff *(*fn)(
5853 __isl_take isl_multi_union_pw_aff *mupa,
5854 __isl_take isl_union_set *uset);
5855 const char *arg1;
5856 const char *arg2;
5857 const char *res;
5858} mupa_uset_tests[] = {
5859 { &isl_multi_union_pw_aff_intersect_domain,
5860 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5861 "C[{ B[i,i] -> [3i] }]" },
5862 { &isl_multi_union_pw_aff_intersect_domain,
5863 "(C[] : { B[i,j] })", "{ B[i,i] }",
5864 "(C[] : { B[i,i] })" },
5865 { &isl_multi_union_pw_aff_intersect_domain,
5866 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5867 "[N] -> (C[] : { B[N,N] })" },
5868 { &isl_multi_union_pw_aff_intersect_domain,
5869 "C[]", "{ B[i,i] }",
5870 "(C[] : { B[i,i] })" },
5871 { &isl_multi_union_pw_aff_intersect_domain,
5872 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5873 "[N] -> (C[] : { B[i,i] : N >= 0 })" },