Polly 23.0.0git
isl_test2.cc
Go to the documentation of this file.
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 * Copyright 2021-2022 Cerebras Systems
7 *
8 * Use of this software is governed by the MIT license
9 *
10 * Written by Sven Verdoolaege, K.U.Leuven, Departement
11 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
12 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
13 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
14 * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
15 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
16 * B.P. 105 - 78153 Le Chesnay, France
17 * and Cerebras Systems, 1237 E Arques Ave, Sunnyvale, CA, USA
18 */
19
20#include <assert.h>
21#include <stdlib.h>
22
23#include <functional>
24#include <ios>
25#include <iostream>
26#include <sstream>
27#include <string>
28#include <type_traits>
29#include <utility>
30#include <vector>
31
32#include <isl/cpp.h>
33
34/* A binary isl function that appears in the C++ bindings
35 * as a unary method in a class T, taking an extra argument
36 * of type A1 and returning an object of type R.
37 */
38template <typename A1, typename R, typename T>
39using binary_fn = R (T::*)(A1) const;
40
41/* A function for selecting an overload of a pointer to a unary C++ method
42 * based on the single argument type.
43 * The object type and the return type are meant to be deduced.
44 */
45template <typename A1, typename R, typename T>
47{
48 return fn;
49}
50
51/* A ternary isl function that appears in the C++ bindings
52 * as a binary method in a class T, taking extra arguments
53 * of type A1 and A2 and returning an object of type R.
54 */
55template <typename A1, typename A2, typename R, typename T>
56using ternary_fn = R (T::*)(A1, A2) const;
57
58/* A function for selecting an overload of a pointer to a binary C++ method
59 * based on the (first) argument type(s).
60 * The object type and the return type are meant to be deduced.
61 */
62template <typename A1, typename A2, typename R, typename T>
64{
65 return fn;
66}
67
68/* A description of the input and the output of a unary property.
69 */
70struct unary_prop {
71 const char *arg;
72 bool res;
73};
74
75/* A description of the input and the output of a unary operation.
76 */
77struct unary {
78 const char *arg;
79 const char *res;
80};
81
82/* A description of the inputs and the output of a binary operation.
83 */
84struct binary {
85 const char *arg1;
86 const char *arg2;
87 const char *res;
88};
89
90/* A description of the inputs and the output of a ternary operation.
91 */
92struct ternary {
93 const char *arg1;
94 const char *arg2;
95 const char *arg3;
96 const char *res;
97};
98
99/* A template function for checking whether two objects
100 * of the same (isl) type are (obviously) equal.
101 * The spelling depends on the isl type and
102 * in particular on whether an equality method is available or
103 * whether only obvious equality can be tested.
104 */
105template <typename T, typename std::decay<decltype(
106 std::declval<T>().is_equal(std::declval<T>()))>::type = true>
107static bool is_equal(const T &a, const T &b)
108{
109 return a.is_equal(b);
110}
111template <typename T, typename std::decay<decltype(
112 std::declval<T>().plain_is_equal(std::declval<T>()))>::type = true>
113static bool is_equal(const T &a, const T &b)
114{
115 return a.plain_is_equal(b);
116}
117
118/* A helper macro for throwing an isl::exception_invalid with message "msg".
119 */
120#define THROW_INVALID(msg) \
121 isl::exception::throw_error(isl_error_invalid, msg, __FILE__, __LINE__)
122
123/* Run a sequence of tests of function "fn" with stringification "name" and
124 * with input and output described by "tests",
125 * throwing an exception when an unexpected result is produced.
126 */
127template <typename T>
128static void test(isl::ctx ctx, bool fn(const T &), const std::string &name,
129 const std::vector<unary_prop> &tests)
130{
131 for (const auto &test : tests) {
132 T obj(ctx, test.arg);
133 bool res = fn(obj);
134 std::ostringstream ss;
135
136 if (test.res == res)
137 continue;
138
139 ss << name << "(" << test.arg << ") = "
140 << std::boolalpha << res << "\n"
141 << "expecting: "
142 << test.res;
143 THROW_INVALID(ss.str().c_str());
144 }
145}
146
147/* Run a sequence of tests of method "fn" with stringification "name" and
148 * with input and output described by "test",
149 * throwing an exception when an unexpected result is produced.
150 */
151template <typename R, typename T>
152static void test(isl::ctx ctx, R (T::*fn)() const, const std::string &name,
153 const std::vector<unary> &tests)
154{
155 for (const auto &test : tests) {
156 T obj(ctx, test.arg);
157 R expected(ctx, test.res);
158 const auto &res = (obj.*fn)();
159 std::ostringstream ss;
160
161 if (is_equal(expected, res))
162 continue;
163
164 ss << name << "(" << test.arg << ") =\n"
165 << res << "\n"
166 << "expecting:\n"
167 << expected;
168 THROW_INVALID(ss.str().c_str());
169 }
170}
171
172/* Run a sequence of tests of method "fn" with stringification "name" and
173 * with inputs and output described by "test",
174 * throwing an exception when an unexpected result is produced.
175 */
176template <typename R, typename T, typename A1>
177static void test(isl::ctx ctx, R (T::*fn)(A1) const, const std::string &name,
178 const std::vector<binary> &tests)
179{
180 for (const auto &test : tests) {
181 T obj(ctx, test.arg1);
182 A1 arg1(ctx, test.arg2);
183 R expected(ctx, test.res);
184 const auto &res = (obj.*fn)(arg1);
185 std::ostringstream ss;
186
187 if (is_equal(expected, res))
188 continue;
189
190 ss << name << "(" << test.arg1 << ", " << test.arg2 << ") =\n"
191 << res << "\n"
192 << "expecting:\n"
193 << expected;
194 THROW_INVALID(ss.str().c_str());
195 }
196}
197
198/* Run a sequence of tests of function "fn" with stringification "name" and
199 * with inputs and output described by "tests",
200 * throwing an exception when an unexpected result is produced.
201 */
202template <typename R, typename T, typename A1, typename A2, typename F>
203static void test_ternary(isl::ctx ctx, const F &fn,
204 const std::string &name, const std::vector<ternary> &tests)
205{
206 for (const auto &test : tests) {
207 T obj(ctx, test.arg1);
208 A1 arg1(ctx, test.arg2);
209 A2 arg2(ctx, test.arg3);
210 R expected(ctx, test.res);
211 const auto &res = fn(obj, arg1, arg2);
212 std::ostringstream ss;
213
214 if (is_equal(expected, res))
215 continue;
216
217 ss << name << "(" << test.arg1 << ", " << test.arg2 << ", "
218 << test.arg3 << ") =\n"
219 << res << "\n"
220 << "expecting:\n"
221 << expected;
222 THROW_INVALID(ss.str().c_str());
223 }
224}
225
226/* Run a sequence of tests of function "fn" with stringification "name" and
227 * with inputs and output described by "tests",
228 * throwing an exception when an unexpected result is produced.
229 *
230 * Simply call test_ternary.
231 */
232template <typename R, typename T, typename A1, typename A2>
233static void test(isl::ctx ctx, R fn(const T&, const A1&, const A2&),
234 const std::string &name, const std::vector<ternary> &tests)
235{
237}
238
239/* Run a sequence of tests of method "fn" with stringification "name" and
240 * with inputs and output described by "tests",
241 * throwing an exception when an unexpected result is produced.
242 *
243 * Wrap the method pointer into a function taking an object reference and
244 * call test_ternary.
245 */
246template <typename R, typename T, typename A1, typename A2>
247static void test(isl::ctx ctx, R (T::*fn)(A1, A2) const,
248 const std::string &name, const std::vector<ternary> &tests)
249{
250 const auto &wrap = [&] (const T &o, const A1 &arg1, const A2 &arg2) {
251 return (o.*fn)(arg1, arg2);
252 };
254}
255
256/* A helper macro that calls test with as implicit initial argument "ctx" and
257 * as extra argument a stringification of "FN".
258 */
259#define C(FN, ...) test(ctx, FN, #FN, __VA_ARGS__)
260
261/* Perform some basic isl::space tests.
262 */
263static void test_space(isl::ctx ctx)
264{
266 { "{ A[] -> B[] }", "{ A[] }" },
267 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ A[C[] -> D[]] }" },
268 });
269
271 { "{ A[] -> B[] }", "{ B[] }" },
272 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ B[E[] -> F[]] }" },
273 });
274
276 { "{ A[] -> B[] }", "{ : }" },
277 { "{ A[C[] -> D[]] -> B[E[] -> F[]] }", "{ : }" },
278 });
279}
280
281/* Is "fn" an expression defined over a single cell?
282 */
284{
285 const auto &domain = fn.domain();
286 return fn.gist(domain).isa_multi_aff();
287}
288
289/* Does the conversion of "obj" to an isl_pw_multi_aff
290 * result in an expression defined over a single cell?
291 */
292template <typename T>
293static bool has_single_cell_pma(const T &obj)
294{
295 return has_single_cell(obj.as_pw_multi_aff());
296}
297
298/* Perform some basic conversion tests.
299 *
300 * In particular, check that a map with an output dimension
301 * that is equal to some integer division over a domain involving
302 * a local variable without a known integer division expression or
303 * to some linear combination of integer divisions
304 * can be converted to a function expressed in the same way.
305 *
306 * Also, check that a nested modulo expression can be extracted
307 * from a set or binary relation representation, or at least
308 * that a conversion to a function does not result in multiple cells.
309 */
310static void test_conversion(isl::ctx ctx)
311{
313 { "[N=0:] -> { [] }",
314 "[N=0:] -> { [] }" },
315 });
316
318 { "[n] -> { [] : n >= 0 } ",
319 "[n] -> { [] : n >= 0 } " },
320 });
321
323 { "{ [a] -> [a//2] : "
324 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
325 "{ [a] -> [a//2] : "
326 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }" },
327 { "{ [a, b] -> [(2*floor((a)/8) + floor((b)/6))] }",
328 "{ [a, b] -> [(2*floor((a)/8) + floor((b)/6))] }" },
329 });
330
332 { "[s=0:23] -> { A[(s//4)%3, s%4, s//12] }", true },
333 });
334
336 { "{ [a] -> [a//2] : "
337 "exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
338 true },
339 { "{ [s=0:23, t] -> B[((s+1+2t)//4)%3, 2+(s+1+2t)%4, (s+1+2t)//12] }",
340 true },
341 { "{ [a=0:31] -> [b=0:3, c] : 4c = 28 - a + b }", true },
342 });
343}
344
345/* Perform some basic preimage tests.
346 */
347static void test_preimage(isl::ctx ctx)
348{
350 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
351 "{ A[j,i] -> B[i,j] }",
352 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
353 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
354 "{ A[a,b] -> B[a/2,b/6] }",
355 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
356 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
357 "{ A[a,b] -> B[a/2,b/6] }",
358 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
359 "exists i,j : a = 2 i and b = 6 j }" },
360 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
361 "[n] -> { : 0 <= n <= 100 }" },
362 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
363 "{ A[a] -> B[2a] }",
364 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
365 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
366 "{ A[a] -> B[([a/2])] }",
367 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
368 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
369 "{ A[a] -> B[a,a,a/3] }",
370 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
371 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
372 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
373 });
374
376 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
377 "{ A[j,i] -> B[i,j] : false }",
378 "{ A[j,i] : false }" },
379 });
380
382 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
383 "{ A[j,i] -> B[i,j] }",
384 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
385 { "{ B[i] -> C[i]; D[i] -> E[i] }",
386 "{ A[i] -> B[i + 1] }",
387 "{ A[i] -> C[i + 1] }" },
388 { "{ B[i] -> C[i]; B[i] -> E[i] }",
389 "{ A[i] -> B[i + 1] }",
390 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
391 { "{ B[i] -> C[([i/2])] }",
392 "{ A[i] -> B[2i] }",
393 "{ A[i] -> C[i] }" },
394 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
395 "{ A[i] -> B[([i/5]), ([i/7])] }",
396 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
397 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
398 "[N] -> { A[] -> B[([N/5])] }",
399 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
400 { "{ B[i] -> C[i] : exists a : i = 5 a }",
401 "{ A[i] -> B[2i] }",
402 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
403 { "{ B[i] -> C[i] : exists a : i = 2 a; "
404 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
405 "{ A[i] -> B[2i] }",
406 "{ A[i] -> C[2i] }" },
407 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
408 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
409 });
410
412 { "[M] -> { A[a] -> B[a] }", "[M] -> { C[] -> B[floor(M/2)] }",
413 "[M] -> { A[floor(M/2)] -> C[] }" },
414 });
415}
416
417/* Perform some basic fixed power tests.
418 */
420{
422 { "{ [i] -> [i + 1] }", "23",
423 "{ [i] -> [i + 23] }" },
424 { "{ [a = 0:1, b = 0:15, c = 0:1, d = 0:1, 0] -> [a, b, c, d, 1]; "
425 "[a = 0:1, b = 0:15, c = 0:1, 0, 1] -> [a, b, c, 1, 0]; "
426 "[a = 0:1, b = 0:15, 0, 1, 1] -> [a, b, 1, 0, 0]; "
427 "[a = 0:1, b = 0:14, 1, 1, 1] -> [a, 1 + b, 0, 0, 0]; "
428 "[0, 15, 1, 1, 1] -> [1, 0, 0, 0, 0] }",
429 "128",
430 "{ [0, b = 0:15, c = 0:1, d = 0:1, e = 0:1] -> [1, b, c, d, e] }" },
431 });
432}
433
434/* Perform some basic intersection tests.
435 */
436static void test_intersect(isl::ctx ctx)
437{
439 { "[n] -> { A[x] -> B[y] }", "[n] -> { : n >= 0 }",
440 "[n] -> { A[x] -> B[y] : n >= 0 }" },
441 });
442
444 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
445 "{ A[0] }",
446 "{ [A[0] -> B[y]] -> C[z] }" },
447 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
448 "{ A[0] }",
449 "{ }" },
450 { "{ T[A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
451 "{ A[0] }",
452 "{ T[A[0] -> B[y]] -> C[z] }" },
453 });
454
456 { "{ [A[x] -> B[y]] -> C[z]; [D[x] -> A[y]] -> E[z] }",
457 "{ A[0] }",
458 "{ }" },
459 { "{ C[z] -> [A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
460 "{ A[0] }",
461 "{ C[z] -> [A[0] -> B[y]] }" },
462 { "{ C[z] -> T[A[x] -> B[y]]; E[z] -> [D[x] -> A[y]] }",
463 "{ A[0] }",
464 "{ C[z] -> T[A[0] -> B[y]] }" },
465 });
466}
467
468/* Is the expression for the lexicographic minimum of "obj"
469 * defined over a single cell?
470 */
471template <typename T>
472static bool lexmin_has_single_cell(const T &obj)
473{
474 return has_single_cell(obj.lexmin_pw_multi_aff());
475}
476
477/* Perform some basic lexicographic minimization tests.
478 */
479static void test_lexmin(isl::ctx ctx)
480{
482 /* The following two inputs represent the same binary relation,
483 * the second with extra redundant constraints.
484 * The lexicographic minimum of both should consist of a single cell.
485 */
486 { "{ [a=0:11] -> [b] : -1 + b <= 2*floor((a)/6) <= b }", true },
487 { "{ [a=0:11] -> [b=0:3] : -1 + b <= 2*floor((a)/6) <= b }", true },
488
489 { "{ [a = 0:2, b = 0:1] -> [c = 0:9, d = (-a + b) mod 3] : "
490 "10a + 5b - 3c <= 5d <= 12 + 10a + 5b - 3c }", true },
491 { "{ [a=0:71] -> [(a//3)%8] }", true },
492 { "{ [a=0:71] -> [b=0:7] : (a - 3 * b + 21) % 24 >= 21 }", true },
493 { "{ [a=0:71] -> [b=0:7] : (a - 3 * b + 21) % 24 >= 20 }", false },
494 { "{ [a=0:71] -> [b=0:7] : (a - 3 * b + 21) % 24 >= 22 }", true },
495 { "{ [a=0:71] -> [b=-7:0] : (a + 3 * b + 21) % 24 >= 21 }", true },
496 { "{ [a=0:71] -> [b=-7:0] : (a + 3 * b + 21) % 24 >= 20 }", false },
497 { "{ [a=0:71] -> [b=-7:0] : (a + 3 * b + 21) % 24 >= 22 }", true },
498 });
499
501 /* The following two inputs represent the same binary relation,
502 * the second with some redundant constraints removed.
503 * The lexicographic minimum of both should consist of a single cell.
504 */
505 { "{ [a=0:3] -> [b=a//2] : 0 <= b <= 1 }",
506 "{ [a=0:3] -> [(floor((a)/2))] }" },
507 { "{ [a] -> [b=a//2] : 0 <= b <= 1 }",
508 "{ [a=0:3] -> [(floor((a)/2))] }" },
509
510 { "{ [a = 0:2, b = 0:1] -> [c = 0:9, d = (-a + b) mod 3] : "
511 "10a + 5b - 3c <= 5d <= 12 + 10a + 5b - 3c }",
512 "{ [a = 0:2, b = 0:1] -> [5*(2a + b)//3, (2a + b) mod 3] }" },
513 { "{ [a=0:71] -> [(a//3)%8] }",
514 "{ [a=0:71] -> [(a//3)%8] }" },
515 { "{ [a=0:71] -> [b=0:7] : (a - 3 * b + 21) % 24 >= 21 }",
516 "{ [a=0:71] -> [(a//3)%8] }" },
517 { "{ [a=0:71] -> [b=0:7] : (a - 3 * b + 21) % 24 >= 22 }",
518 "{ [a=0:71] -> [(a//3)%8] : a % 3 > 0 }" },
519 { "{ [a=0:71] -> [b=-7:0] : (a + 3 * b + 21) % 24 >= 21 }",
520 "{ [a=0:71] -> [(-7 + (-1 - floor((a)/3)) mod 8)] }" },
521 });
522
524 { "[a] -> { [b=a//2] : 0 <= b <= 1 }",
525 "[a=0:3] -> { [(floor((a)/2))] }" },
526 { "[a=0:71] -> { [(a//3)%8] }",
527 "[a=0:71] -> { [(a//3)%8] }" },
528 { "[a=0:71] -> { [b=0:7] : (a - 3 * b + 21) % 24 >= 21 }",
529 "[a=0:71] -> { [(a//3)%8] }" },
530 });
531}
532
533/* Compute the gist of "obj" with respect to "context",
534 * with "copy" an independent copy of "obj",
535 * but also check that applying the gist operation does
536 * not modify the input set (an earlier version of isl would do that) and
537 * that the test case is consistent, i.e., that the gist has the same
538 * intersection with the context as the input set.
539 */
540template <typename T>
541T gist(const T &obj, const T &copy, const T &context)
542{
543 const auto &res = obj.gist(context);
544 if (!is_equal(obj, copy)) {
545 std::ostringstream ss;
546 ss << "gist changed " << copy << " into " << obj;
547 THROW_INVALID(ss.str().c_str());
548 }
549 if (!is_equal(obj.intersect(context), res.intersect(context))) {
550 std::ostringstream ss;
551 ss << "inconsistent "
552 << obj << " % " << context << " = " << res;
553 THROW_INVALID(ss.str().c_str());
554 }
555 return res;
556}
557
558/* A helper macro for producing two instances of "x".
559 */
560#define TWO(x) (x), (x)
561
562/* Perform some basic gist tests.
563 *
564 * The gist() function is given two identical inputs so that
565 * it can check that the input to the call to the gist method
566 * is not modified.
567 */
568static void test_gist(isl::ctx ctx)
569{
571 { TWO("{ [i=100:] }"),
572 "{ [i] : exists a, b: 2b > 2i - 5a > 8b -3 i and 3b > 2a }",
573 "{ [i=100:] }" },
574 { TWO("{ [i=0:] }"),
575 "{ [i] : exists a, b: 2b > 2i - 5a > 8b -3 i and 3b > 2a }",
576 "{ [i] }" },
577 { TWO("{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
578 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }"),
579 "{ [i] : i >= 0 }",
580 "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
581 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }" },
582 { TWO("{ [i=0:10] : exists a, b: 2b > 2i - 5a > 8b -3 i and 3b > 2a }"),
583 "{ [i=0:10] }",
584 "{ [i] : exists a, b: 2b > 2i - 5a > 8b -3 i and 3b > 2a }" },
585 });
586
587 C(&gist<isl::set> , {
588 { TWO("{ [1, -1, 3] }"),
589 "{ [1, b, 2 - b] : -1 <= b <= 2 }",
590 "{ [a, -1, c] }" },
591 { TWO("{ [a, b, c] : a <= 15 and a >= 1 }"),
592 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
593 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
594 "{ [a, b, c] : a <= 15 }" },
595 { TWO("{ : }"), "{ : 1 = 0 }", "{ : }" },
596 { TWO("{ : 1 = 0 }"), "{ : 1 = 0 }", "{ : }" },
597 { TWO("[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }"),
598 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
599 { TWO("{ [m, n, a, b] : a <= 2147 + n }"),
600 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
601 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
602 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
603 "b >= 0) }",
604 "{ [m, n, ku, kl] }" },
605 { TWO("{ [a, a, b] : a >= 10 }"),
606 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
607 "{ [a, a, b] : a >= 10 }" },
608 { TWO("{ [i, j] : i >= 0 and i + j >= 0 }"), "{ [i, j] : i <= 0 }",
609 "{ [0, j] : j >= 0 }" },
610 /* Check that no constraints on i6 are introduced in the gist */
611 { TWO("[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
612 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
613 "5e0 <= 381 - t1 and i4 <= 1) }"),
614 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
615 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
616 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
617 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
618 "20e0 >= 1511 - 4t1 - 5i4) }" },
619 /* Check that no constraints on i6 are introduced in the gist */
620 { TWO("[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
621 "e1 = floor((1530 - 4t1 - 5i4)/20), "
622 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
623 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
624 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
625 "2e0 <= 1 + i4 and 2e0 >= i4 and "
626 "20e1 <= 1530 - 4t1 - 5i4 and "
627 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
628 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }"),
629 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
630 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
631 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
632 "10e0 <= -91 + 5i4 + 4i6 and "
633 "10e0 >= -105 + 5i4 + 4i6) }",
634 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
635 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
636 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
637 { TWO("{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }"),
638 "{ [a, b, q, p] : b >= 1 + a }",
639 "{ [a, b, q, p] : false }" },
640 { TWO("[n] -> { [x] : x = n && x mod 32 = 0 }"),
641 "[n] -> { [x] : x mod 32 = 0 }",
642 "[n] -> { [x = n] }" },
643 { TWO("{ [x] : x mod 6 = 0 }"), "{ [x] : x mod 3 = 0 }",
644 "{ [x] : x mod 2 = 0 }" },
645 { TWO("{ [x] : x mod 3200 = 0 }"), "{ [x] : x mod 10000 = 0 }",
646 "{ [x] : x mod 128 = 0 }" },
647 { TWO("{ [x] : x mod 3200 = 0 }"), "{ [x] : x mod 10 = 0 }",
648 "{ [x] : x mod 3200 = 0 }" },
649 { TWO("{ [a, b, c] : a mod 2 = 0 and a = c }"),
650 "{ [a, b, c] : b mod 2 = 0 and b = c }",
651 "{ [a, b, c = a] }" },
652 { TWO("{ [a, b, c] : a mod 6 = 0 and a = c }"),
653 "{ [a, b, c] : b mod 2 = 0 and b = c }",
654 "{ [a, b, c = a] : a mod 3 = 0 }" },
655 { TWO("{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }"),
656 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
657 "{ [x] }" },
658 { TWO("{ [x,y] : x < 0 and 0 <= y <= 4 or "
659 "x >= -2 and -x <= y <= 10 + x }"),
660 "{ [x,y] : 1 <= y <= 3 }",
661 "{ [x,y] }" },
662 });
663
665 { "{ [x] -> [x] : x != 0 }", "{ [x] : x < -1 or x > 1 }",
666 "{ [x] -> [x] }" },
667 });
668
670 { "[N] -> { D[x] -> [x] : N >= 0; D[x] -> [0] : N < 0 }",
671 "[N] -> { : N >= 0 }",
672 "[N] -> { D[x] -> [x] }" },
673 });
674
676 { "{ A[i] -> B[i, i] }", "{ A[0] }",
677 "{ A[i] -> B[0, 0] }" },
678 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { A[0] : N = 5 }",
679 "[N] -> { A[i] -> B[0, 5] }" },
680 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
681 "[N] -> { B[6, 5] }" },
682 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
683 "[N] -> { A[i] -> B[] }" },
684 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
685 "[N] -> { B[] }" },
686 });
687
689 { "[N] -> { A[i] -> B[i, N] }", "[N] -> { : N = 5 }",
690 "[N] -> { A[i] -> B[i, 5] }" },
691 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
692 "[N] -> { B[6, 5] }" },
693 { "[N] -> { A[i] -> B[] }", "[N] -> { : N = 5 }",
694 "[N] -> { A[i] -> B[] }" },
695 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
696 "[N] -> { B[] }" },
697 });
698
700 { "{ A[i] -> B[i, i] : i >= 0 }", "{ A[0] }",
701 "{ A[i] -> B[0, 0] }" },
702 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
703 "[N] -> { A[i] -> B[0, 5] }" },
704 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
705 "[N] -> { B[6, 5] }" },
706 { "[N] -> { A[i] -> B[] }", "[N] -> { A[0] : N = 5 }",
707 "[N] -> { A[i] -> B[] }" },
708 { "[N] -> { B[] }", "[N] -> { : N = 5 }",
709 "[N] -> { B[] }" },
710 { "{ A[i=0:10] -> B[i] }", "{ A[5] }",
711 "{ A[i] -> B[5] }" },
712 { "{ A[0:10] -> B[] }", "{ A[0:10] }",
713 "{ A[i] -> B[] }" },
714 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { A[0] : N = 5 }",
715 "[N] -> { A[i] -> B[] }" },
716 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
717 "[N] -> { B[] }" },
718 { "[N] -> { B[] : N = 5 }", "[N] -> { : N >= 0 }",
719 "[N] -> { B[] : N = 5 }" },
720 });
721
723 { "[N] -> { A[i] -> B[i, N] : N >= 0 }", "[N] -> { : N = 5 }",
724 "[N] -> { A[i] -> B[i, 5] }" },
725 { "[N] -> { B[N + 1, N] }", "[N] -> { : N = 5 }",
726 "[N] -> { B[6, 5] }" },
727 { "[N] -> { A[i] -> B[] : N >= 0 }", "[N] -> { : N = 5 }",
728 "[N] -> { A[i] -> B[] }" },
729 { "[N] -> { B[] : N >= 0 }", "[N] -> { : N = 5 }",
730 "[N] -> { B[] }" },
731 { "[N] -> { B[] : N >= 5 }", "[N] -> { : N >= 0 }",
732 "[N] -> { B[] : N >= 5 }" },
733 });
734
736 { "C[{ B[i,i] -> [3i] }]", "{ B[i,i] }",
737 "C[{ B[i,j] -> [3i] }]" },
738 { "(C[] : { B[i,i] })", "{ B[i,i] }",
739 "(C[] : { B[i,j] })" },
740 { "[N] -> (C[] : { B[N,N] })", "[N] -> { B[N,N] }",
741 "[N] -> (C[] : { B[i,j] })" },
742 { "C[]", "{ B[i,i] }",
743 "C[]" },
744 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "{ B[i,i] }",
745 "[N] -> (C[] : { B[i,j] : N >= 0 })" },
746 { "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
747 "[N] -> (C[] : { : N >= 0 })" },
748 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { B[i,i] : N >= 0 }",
749 "[N] -> C[]" },
750 });
751
753 { "[N] -> C[{ B[i,i] -> [3i + N] }]", "[N] -> { : N = 1 }",
754 "[N] -> C[{ B[i,i] -> [3i + 1] }]" },
755 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
756 "[N] -> C[{ B[i,i] -> [3i] }]" },
757 { "[N] -> C[{ B[i,i] -> [3i] : N >= 0 }]", "[N] -> { : N >= 0 }",
758 "[N] -> C[{ B[i,i] -> [3i] }]" },
759 { "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]", "[N] -> { : N >= 0 }",
760 "[N] -> C[{ B[i,i] -> [3i] : N >= 1 }]" },
761 { "[N] -> (C[] : { B[i,i] : N >= 0 })", "[N] -> { : N >= 0 }",
762 "[N] -> (C[] : { B[i,i] })" },
763 { "[N] -> (C[] : { : N >= 0 })", "[N] -> { : N >= 0 }",
764 "[N] -> C[]" },
765 { "C[{ B[i,i] -> [3i] }]", "[N] -> { : N >= 0 }",
766 "[N] -> C[{ B[i,i] -> [3i] }]" },
767 });
768}
769
770/* Perform tests that project out parameters.
771 */
772static void test_project(isl::ctx ctx)
773{
775 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "N",
776 "{ D[i] -> A[0:]; D[i] -> B[i] }" },
777 { "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }", "M",
778 "[N] -> { D[i] -> A[0:N-1]; D[i] -> B[i] }" },
779 });
780
782 { "[M, N, O] -> { D[i] -> A[j] : i <= j < M, N, O }", "(M, N)",
783 "[O] -> { D[i] -> A[j] : i <= j < O }" },
784 });
785}
786
787/* Perform some basic reverse tests.
788 */
789static void test_reverse(isl::ctx ctx)
790{
792 { "{ T[A[] -> B[*]] -> [0] }",
793 "{ [B[*] -> A[]] -> [0] }" },
794 { "{ T[A[] -> A[]] -> [0] }",
795 "{ T[A[] -> A[]] -> [0] }" },
796 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
797 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
798 });
799
801 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
802 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
803 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] }",
804 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] }" },
805 });
806
808 { "{ T[A[] -> B[*]] }",
809 "{ [B[*] -> A[]] }" },
810 { "{ T[A[] -> A[]] }",
811 "{ T[A[] -> A[]] }" },
812 { "{ [A[x] -> B[2x]] }",
813 "{ [B[y] -> A[x]] : y = 2x }" },
814 });
815
817 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] }",
818 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] }" },
819 { "{ [A[x] -> B[y]] -> [5*(x // 2) + 7*(y // 3)] : x > y }",
820 "{ [B[y] -> A[x]] -> [5*(x // 2) + 7*(y // 3)] : x > y }" },
821 { "{ [A[i] -> B[i + 1]] -> [i + 2] }",
822 "{ [B[i] -> A[i - 1]] -> [i + 1] }" },
823 });
824
826 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }",
827 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3), 0] : x > y }" },
828 { "{ [A[i] -> B[i + 1]] -> T[0, i + 2] }",
829 "{ [B[i] -> A[i - 1]] -> T[0, i + 1] }" },
830 });
831
833 { "{ [A[x] -> B[y]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }",
834 "{ [B[y] -> A[x]] -> T[5*(x // 2) + 7*(y // 3) : x > y, 0] }" },
835 });
836
838 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
839 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
840 { "{ N[B[] -> C[]] -> A[] }",
841 "{ [C[] -> B[]] -> A[] }" },
842 { "{ N[B[x] -> B[y]] -> A[] }",
843 "{ N[B[*] -> B[*]] -> A[] }" },
844 });
845
847 { "{ [A[] -> B[]] -> [C[] -> D[]] }",
848 "{ [B[] -> A[]] -> [C[] -> D[]] }" },
849 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
850 "{ }" },
851 { "{ N[B[] -> C[]] -> A[] }",
852 "{ [C[] -> B[]] -> A[] }" },
853 { "{ N[B[x] -> B[y]] -> A[] }",
854 "{ N[B[*] -> B[*]] -> A[] }" },
855 });
856
858 { "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
859 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
860 { "{ A[] -> N[B[] -> C[]] }",
861 "{ A[] -> [C[] -> B[]] }" },
862 { "{ A[] -> N[B[x] -> B[y]] }",
863 "{ A[] -> N[B[*] -> B[*]] }" },
864 });
865}
866
867/* Perform some basic scaling tests.
868 */
869static void test_scale(isl::ctx ctx)
870{
872 { "{ A[a] -> B[a, a + 1, a - 1] : a >= 0 }", "{ B[2, 7, 0] }",
873 "{ A[a] -> B[2a, 7a + 7, 0] : a >= 0 }" },
874 });
876 { "{ A[a] -> B[1, a - 1] : a >= 0 }", "{ B[1/2, 7] }",
877 "{ A[a] -> B[1/2, 7a - 7] : a >= 0 }" },
878 });
879
881 { "{ A[a] -> B[a, a + 1] : a >= 0 }", "{ B[2, 7] }",
882 "{ A[a] -> B[a/2, (a + 1)/7] : a >= 0 }" },
883 });
885 { "{ A[a] -> B[a, a - 1] : a >= 0 }", "{ B[2, 1/7] }",
886 "{ A[a] -> B[a/2, 7a - 7] : a >= 0 }" },
887 });
888}
889
890/* Perform some basic isl::id_to_id tests.
891 */
892static void test_id_to_id(isl::ctx ctx)
893{
895 { "{ }", "a", "b",
896 "{ a: b }" },
897 { "{ a: b }", "a", "b",
898 "{ a: b }" },
899 { "{ a: c }", "a", "b",
900 "{ a: b }" },
901 { "{ a: b }", "b", "a",
902 "{ a: b, b: a }" },
903 { "{ a: b }", "b", "a",
904 "{ b: a, a: b }" },
905 });
906}
907
908/* The list of tests to perform.
909 */
910static std::vector<std::pair<const char *, void (*)(isl::ctx)>> tests =
911{
912 { "space", &test_space },
913 { "conversion", &test_conversion },
914 { "preimage", &test_preimage },
915 { "fixed power", &test_fixed_power },
916 { "intersect", &test_intersect },
917 { "lexmin", &test_lexmin },
918 { "gist", &test_gist },
919 { "project out parameters", &test_project },
920 { "reverse", &test_reverse },
921 { "scale", &test_scale },
922 { "id-to-id", &test_id_to_id },
923};
924
925/* Perform some basic checks by means of the C++ bindings.
926 */
927int main(int argc, char **argv)
928{
929 int ret = EXIT_SUCCESS;
930 struct isl_ctx *ctx;
931 struct isl_options *options;
932
933 options = isl_options_new_with_defaults();
935 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
936 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
937
938 try {
939 for (const auto &f : tests) {
940 std::cout << f.first << "\n";
941 f.second(ctx);
942 }
943 } catch (const isl::exception &e) {
944 std::cerr << e.what() << "\n";
945 ret = EXIT_FAILURE;
946 }
947
948 isl_ctx_free(ctx);
949 return ret;
950}
#define ISL_ARG_ALL
Definition arg.h:288
isl::aff domain_reverse() const
isl::basic_map intersect_params(isl::basic_set bset) const
isl::id_to_id set(isl::id key, isl::id val) const
isl::pw_multi_aff as_pw_multi_aff() const
isl::map domain_reverse() const
isl::map fixed_power(isl::val exp) const
isl::pw_multi_aff lexmin_pw_multi_aff() const
isl::multi_aff gist_params(isl::set context) const
isl::multi_aff domain_reverse() const
isl::multi_aff gist(isl::set context) const
isl::multi_pw_aff gist(isl::set set) const
isl::multi_pw_aff gist_params(isl::set set) const
isl::set as_set() const
isl::multi_pw_aff domain_reverse() const
isl::multi_union_pw_aff gist_params(isl::set context) const
isl::multi_union_pw_aff gist(isl::union_set context) const
isl::pw_aff domain_reverse() const
isl::pw_aff gist_params(isl::set context) const
isl::pw_aff gist(isl::set context) const
isl::pw_multi_aff scale_down(isl::multi_val mv) const
isl::pw_multi_aff domain_reverse() const
isl::pw_multi_aff scale(isl::multi_val mv) const
isl::pw_multi_aff lexmin_pw_multi_aff() const
isl::set wrapped_reverse() const
isl::set preimage(isl::multi_aff ma) const
isl::pw_multi_aff as_pw_multi_aff() const
isl::space params() const
isl::space domain() const
isl::space range() const
isl::union_map preimage_domain(isl::multi_aff ma) const
isl::union_map domain_reverse() const
isl::union_map intersect_domain_wrapped_domain(isl::union_set domain) const
isl::union_map preimage_range(isl::multi_aff ma) const
isl::union_map range_reverse() const
isl::union_map project_out_param(isl::id id) const
isl::union_map intersect_range_wrapped_domain(isl::union_set domain) const
isl_ctx * isl_ctx_alloc_with_options(struct isl_args *args, __isl_take void *opt)
void isl_ctx_free(isl_ctx *ctx)
Definition isl_ctx.c:300
isl_stat isl_stat(* fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user)
Definition hmap.h:37
isl_bool isl_bool(* test)(__isl_keep ISL_KEY *key, __isl_keep ISL_VAL *val, void *user)
Definition hmap.h:41
static void test_preimage(isl::ctx ctx)
Definition isl_test2.cc:347
R(T::*)(A1, A2) const ternary_fn
Definition isl_test2.cc:56
static void test_id_to_id(isl::ctx ctx)
Definition isl_test2.cc:892
R(T::*)(A1) const binary_fn
Definition isl_test2.cc:39
static void test_project(isl::ctx ctx)
Definition isl_test2.cc:772
#define C(FN,...)
Definition isl_test2.cc:259
#define THROW_INVALID(msg)
Definition isl_test2.cc:120
static void test_gist(isl::ctx ctx)
Definition isl_test2.cc:568
static bool has_single_cell_pma(const T &obj)
Definition isl_test2.cc:293
static void test_intersect(isl::ctx ctx)
Definition isl_test2.cc:436
#define TWO(x)
Definition isl_test2.cc:560
static bool is_equal(const T &a, const T &b)
Definition isl_test2.cc:107
static bool has_single_cell(const isl::pw_multi_aff &fn)
Definition isl_test2.cc:283
static bool lexmin_has_single_cell(const T &obj)
Definition isl_test2.cc:472
static void test_scale(isl::ctx ctx)
Definition isl_test2.cc:869
static void test_lexmin(isl::ctx ctx)
Definition isl_test2.cc:479
static void test_space(isl::ctx ctx)
Definition isl_test2.cc:263
static void test_conversion(isl::ctx ctx)
Definition isl_test2.cc:310
static void test_ternary(isl::ctx ctx, const F &fn, const std::string &name, const std::vector< ternary > &tests)
Definition isl_test2.cc:203
static void test_fixed_power(isl::ctx ctx)
Definition isl_test2.cc:419
static void test_reverse(isl::ctx ctx)
Definition isl_test2.cc:789
const char * arg1
Definition isl_test.c:871
enum isl_fold type
Definition isl_test.c:3867
static int test_lexmin(struct isl_ctx *ctx)
Definition isl_test.c:2932
static int test_gist(struct isl_ctx *ctx)
Definition isl_test.c:1839
const char * arg2
Definition isl_test.c:873
const char * name
Definition isl_test.c:10749
const char * context
Definition isl_test.c:1792
const char * obj
Definition isl_test.c:3166
const char * res
Definition isl_test.c:783
struct @221223354274216223320306321046225142311132162156 tests[]
static int test_conversion(isl_ctx *ctx)
Definition isl_test.c:9224
const char * arg
Definition isl_test.c:782
const char * gist
Definition isl_test.c:1793
const char * f
Definition isl_test.c:8453
static int test_intersect(isl_ctx *ctx)
Definition isl_test.c:4241
#define assert(exp)
char * expected
a(0)
b(9)
const char * arg1
Definition isl_test2.cc:85
const char * res
Definition isl_test2.cc:87
const char * arg2
Definition isl_test2.cc:86
const char * res
Definition isl_test2.cc:96
const char * arg1
Definition isl_test2.cc:93
const char * arg3
Definition isl_test2.cc:95
const char * arg2
Definition isl_test2.cc:94
const char * arg
Definition isl_test2.cc:71
const char * res
Definition isl_test2.cc:79
const char * arg
Definition isl_test2.cc:78
static Signature wrap
static Signature domain