#include <isl/union_map.h>
#include <isl_factorization.h>
#include <isl/schedule.h>
+#include <isl_options_private.h>
+#include <isl/vertices.h>
static char *srcdir;
isl_pw_qpolynomial_free(pwqp);
}
+static void test_parse_pwaff(isl_ctx *ctx, const char *str)
+{
+ isl_pw_aff *pwaff;
+
+ pwaff = isl_pw_aff_read_from_str(ctx, str);
+ assert(pwaff);
+ isl_pw_aff_free(pwaff);
+}
+
void test_parse(struct isl_ctx *ctx)
{
isl_map *map, *map2;
str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
test_parse_map_equal(ctx, str, str2);
+ str = "{ [x] : x >= 0 }";
+ str2 = "{ [x] : x-0 >= 0 }";
+ test_parse_map_equal(ctx, str, str2);
+
+ str = "{ [i] : ((i > 10)) }";
+ str2 = "{ [i] : i >= 11 }";
+ test_parse_map_equal(ctx, str, str2);
+
+ str = "{ [i] -> [0] }";
+ str2 = "{ [i] -> [0 * i] }";
+ test_parse_map_equal(ctx, str, str2);
+
test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
+ test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
+ test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
}
void test_read(struct isl_ctx *ctx)
isl_map_free(map);
}
-static int consume_lexmin(__isl_take isl_basic_set *dom,
- __isl_take isl_aff_list *list, void *user)
-{
- isl_space *dim;
- isl_basic_map *bmap;
- isl_map **map = user;
-
- dim = isl_basic_set_get_space(dom);
- bmap = isl_basic_map_from_aff_list(dim, list);
- bmap = isl_basic_map_intersect_domain(bmap, dom);
-
- *map = isl_map_union(*map, isl_map_from_basic_map(bmap));
-
- return 0;
-}
-
void test_lexmin(struct isl_ctx *ctx)
{
const char *str;
isl_map *map, *map2;
isl_set *set;
isl_set *set2;
+ isl_pw_multi_aff *pma;
str = "[p0, p1] -> { [] -> [] : "
"exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
" 8i' <= i and 8i' >= -7 + i }";
bmap = isl_basic_map_read_from_str(ctx, str);
- map2 = isl_map_empty(isl_basic_map_get_space(bmap));
- isl_basic_map_foreach_lexmin(bmap, &consume_lexmin, &map2);
+ pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
+ map2 = isl_map_from_pw_multi_aff(pma);
map = isl_map_from_basic_map(bmap);
assert(isl_map_is_equal(map, map2));
isl_map_free(map);
isl_map_free(map2);
+
+ str = "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_lexmin(map);
+ str = "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
+ map2 = isl_map_read_from_str(ctx, str);
+ assert(isl_map_is_equal(map, map2));
+ isl_map_free(map);
+ isl_map_free(map2);
}
struct must_may {
return 0;
}
-int test_special_schedule(isl_ctx *ctx)
+int test_special_schedule(isl_ctx *ctx, const char *domain,
+ const char *validity, const char *proximity, const char *expected_sched)
{
- const char *str;
isl_union_set *dom;
- isl_union_map *empty;
isl_union_map *dep;
+ isl_union_map *prox;
isl_union_map *sched1, *sched2;
isl_schedule *schedule;
int equal;
- str = "{ S[i,j] : 0 <= i <= 10 }";
- dom = isl_union_set_read_from_str(ctx, str);
- str = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
- dep = isl_union_map_read_from_str(ctx, str);
- empty = isl_union_map_read_from_str(ctx, "{}");
- schedule = isl_union_set_compute_schedule(dom, empty, dep);
+ dom = isl_union_set_read_from_str(ctx, domain);
+ dep = isl_union_map_read_from_str(ctx, validity);
+ prox = isl_union_map_read_from_str(ctx, proximity);
+ schedule = isl_union_set_compute_schedule(dom, dep, prox);
sched1 = isl_schedule_get_map(schedule);
isl_schedule_free(schedule);
- str = "{ S[i, j] -> [j, i] }";
- sched2 = isl_union_map_read_from_str(ctx, str);
+ sched2 = isl_union_map_read_from_str(ctx, expected_sched);
equal = isl_union_map_is_equal(sched1, sched2);
isl_union_map_free(sched1);
int test_schedule(isl_ctx *ctx)
{
- const char *D, *W, *R, *S;
+ const char *D, *W, *R, *V, *P, *S;
/* Jacobi */
D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
return -1;
ctx->opt->schedule_outer_zero_distance = 0;
- return test_special_schedule(ctx);
+ D = "{Stmt_for_body24[i0, i1, i2, i3]:"
+ "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
+ "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
+ "Stmt_for_body24[i0, i1, 1, 0]:"
+ "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
+ "Stmt_for_body7[i0, i1, i2]:"
+ "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
+ "i2 <= 7 }";
+
+ V = "{Stmt_for_body24[0, i1, i2, i3] -> "
+ "Stmt_for_body24[1, i1, i2, i3]:"
+ "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
+ "i2 >= 1;"
+ "Stmt_for_body24[0, i1, i2, i3] -> "
+ "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
+ "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
+ "i3 >= 0;"
+ "Stmt_for_body24[0, i1, i2, i3] ->"
+ "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
+ "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
+ "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
+ "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
+ "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
+ "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
+ "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
+ "i1 <= 6 and i1 >= 0;"
+ "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
+ "Stmt_for_body7[i0, i1, i2] -> "
+ "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
+ "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
+ "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
+ "Stmt_for_body7[i0, i1, i2] -> "
+ "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
+ "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
+ "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
+ P = V;
+ S = "{ Stmt_for_body24[i0, i1, i2, i3] -> "
+ "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
+ "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
+
+ if (test_special_schedule(ctx, D, V, P, S) < 0)
+ return -1;
+
+ D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
+ V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
+ "j >= 1 and j <= 7;"
+ "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
+ "j >= 1 and j <= 8 }";
+ P = "{ }";
+ S = "{ S_0[i, j] -> [i + j, j] }";
+ ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
+ if (test_special_schedule(ctx, D, V, P, S) < 0)
+ return -1;
+ ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
+
+ /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
+ D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
+ "j >= 0 and j <= -1 + i }";
+ V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
+ "i <= -1 + N and j >= 0;"
+ "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
+ "i <= -2 + N }";
+ P = "{ }";
+ S = "{ S_0[i, j] -> [i, j] }";
+ ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
+ if (test_special_schedule(ctx, D, V, P, S) < 0)
+ return -1;
+ ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
+
+ /* Test both algorithms on a case with only proximity dependences. */
+ D = "{ S[i,j] : 0 <= i <= 10 }";
+ V = "{ }";
+ P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
+ S = "{ S[i, j] -> [j, i] }";
+ ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
+ if (test_special_schedule(ctx, D, V, P, S) < 0)
+ return -1;
+ ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
+ return test_special_schedule(ctx, D, V, P, S);
}
int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
{
const char *str;
isl_set *set;
+ isl_union_set *uset1, *uset2;
int ok;
str = "{ A[i] }";
if (!ok)
isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+ str = "{ [] }";
+ uset1 = isl_union_set_read_from_str(ctx, str);
+ uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
+ str = "{ [[] -> []] }";
+ uset2 = isl_union_set_read_from_str(ctx, str);
+ ok = isl_union_set_is_equal(uset1, uset2);
+ isl_union_set_free(uset1);
+ isl_union_set_free(uset2);
+ if (ok < 0)
+ return -1;
+ if (!ok)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
return 0;
}
return 0;
}
+int test_vertices(isl_ctx *ctx)
+{
+ const char *str;
+ isl_basic_set *bset;
+ isl_vertices *vertices;
+
+ str = "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
+ bset = isl_basic_set_read_from_str(ctx, str);
+ vertices = isl_basic_set_compute_vertices(bset);
+ isl_basic_set_free(bset);
+ isl_vertices_free(vertices);
+ if (!vertices)
+ return -1;
+
+ str = "{ A[t, i] : t = 14 and i = 1 }";
+ bset = isl_basic_set_read_from_str(ctx, str);
+ vertices = isl_basic_set_compute_vertices(bset);
+ isl_basic_set_free(bset);
+ isl_vertices_free(vertices);
+ if (!vertices)
+ return -1;
+
+ return 0;
+}
+
+int test_union_pw(isl_ctx *ctx)
+{
+ int equal;
+ const char *str;
+ isl_union_set *uset;
+ isl_union_pw_qpolynomial *upwqp1, *upwqp2;
+
+ str = "{ [x] -> x^2 }";
+ upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
+ upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
+ uset = isl_union_pw_qpolynomial_domain(upwqp1);
+ upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
+ upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
+ equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
+ isl_union_pw_qpolynomial_free(upwqp1);
+ isl_union_pw_qpolynomial_free(upwqp2);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
+ return 0;
+}
+
+int test_output(isl_ctx *ctx)
+{
+ char *s;
+ const char *str;
+ isl_pw_aff *pa;
+ isl_printer *p;
+ int equal;
+
+ str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
+ pa = isl_pw_aff_read_from_str(ctx, str);
+
+ p = isl_printer_to_str(ctx);
+ p = isl_printer_set_output_format(p, ISL_FORMAT_C);
+ p = isl_printer_print_pw_aff(p, pa);
+ s = isl_printer_get_str(p);
+ isl_printer_free(p);
+ isl_pw_aff_free(pa);
+ equal = !strcmp(s, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
+ free(s);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+
+ return 0;
+}
+
int main()
{
struct isl_ctx *ctx;
assert(srcdir);
ctx = isl_ctx_alloc();
+ if (test_output(ctx) < 0)
+ goto error;
+ if (test_vertices(ctx) < 0)
+ goto error;
if (test_fixed(ctx) < 0)
goto error;
if (test_equal(ctx) < 0)
goto error;
if (test_schedule(ctx) < 0)
goto error;
+ if (test_union_pw(ctx) < 0)
+ goto error;
test_factorize(ctx);
test_subset(ctx);
test_lift(ctx);