#include <isl/union_map.h>
#include <isl_factorization.h>
#include <isl/schedule.h>
+#include <isl_options_private.h>
+#include <isl/vertices.h>
+
+#define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
static char *srcdir;
isl_map_free(map);
}
-void test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
+int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
{
isl_map *map, *map2;
+ int equal;
map = isl_map_read_from_str(ctx, str);
map2 = isl_map_read_from_str(ctx, str2);
- assert(map && map2 && isl_map_is_equal(map, map2));
+ equal = isl_map_is_equal(map, map2);
isl_map_free(map);
isl_map_free(map2);
+
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "maps not equal",
+ return -1);
+
+ return 0;
}
void test_parse_pwqp(isl_ctx *ctx, const char *str)
isl_pw_aff_free(pwaff);
}
-void test_parse(struct isl_ctx *ctx)
+int test_parse(struct isl_ctx *ctx)
{
isl_map *map, *map2;
const char *str, *str2;
str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
str2 = "{ [x, y] : 2y >= 6 - x }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
- test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
- "{ [x,y] : x <= y, 2*y + 3 }");
+ if (test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
+ "{ [x,y] : x <= y, 2*y + 3 }") < 0)
+ return -1;
str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
- test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }", str);
+ if (test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }",
+ str) < 0)
+ return -1;
str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
map = isl_map_read_from_str(ctx, str);
str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
str2 = "{ [i,j] -> [min(i,j)] }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i,j] : i != j }";
str2 = "{ [i,j] : i < j or i > j }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i,j] : (i+1)*2 >= j }";
str2 = "{ [i, j] : j <= 2 + 2i }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i] -> [i > 0 ? 4 : 5] }";
str2 = "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "[N=2,M] -> { [i=[(M+N)/4]] }";
str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [x] : x >= 0 }";
str2 = "{ [x] : x-0 >= 0 }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
str = "{ [i] : ((i > 10)) }";
str2 = "{ [i] : i >= 11 }";
- test_parse_map_equal(ctx, str, str2);
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
+
+ str = "{ [i] -> [0] }";
+ str2 = "{ [i] -> [0 * i] }";
+ if (test_parse_map_equal(ctx, str, str2) < 0)
+ return -1;
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]) }");
+
+ if (test_parse_map_equal(ctx, "{ [a] -> [b] : (not false) }",
+ "{ [a] -> [b] : true }") < 0)
+ return -1;
+
+ return 0;
}
void test_read(struct isl_ctx *ctx)
isl_map_free(map2);
}
-void test_div(struct isl_ctx *ctx)
+static int test_div(isl_ctx *ctx)
{
+ const char *str;
isl_int v;
isl_space *dim;
+ isl_set *set;
isl_local_space *ls;
struct isl_basic_set *bset;
struct isl_constraint *c;
isl_basic_set_free(bset);
isl_int_clear(v);
+
+ str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
+ "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
+ set = isl_set_read_from_str(ctx, str);
+ set = isl_set_compute_divs(set);
+ isl_set_free(set);
+ if (!set)
+ return -1;
+
+ return 0;
}
void test_application_case(struct isl_ctx *ctx, const char *name)
fclose(input);
}
-void test_affine_hull(struct isl_ctx *ctx)
+int test_affine_hull(struct isl_ctx *ctx)
{
+ const char *str;
+ isl_set *set;
+ isl_basic_set *bset;
+ int n;
+
test_affine_hull_case(ctx, "affine2");
test_affine_hull_case(ctx, "affine");
test_affine_hull_case(ctx, "affine3");
+
+ str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
+ "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
+ "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
+ "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
+ set = isl_set_read_from_str(ctx, str);
+ bset = isl_set_affine_hull(set);
+ n = isl_basic_set_dim(bset, isl_dim_div);
+ isl_basic_set_free(bset);
+ if (n != 0)
+ isl_die(ctx, isl_error_unknown, "not expecting any divs",
+ return -1);
+
+ return 0;
}
void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
isl_basic_set_free(bset1);
}
-void test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
+int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
{
isl_set *set, *set2;
+ int equal;
+ int one;
set = isl_set_read_from_str(ctx, str);
set = isl_set_coalesce(set);
set2 = isl_set_read_from_str(ctx, str);
- assert(isl_set_is_equal(set, set2));
- if (check_one)
- assert(set && set->n == 1);
+ equal = isl_set_is_equal(set, set2);
+ one = set && set->n == 1;
isl_set_free(set);
isl_set_free(set2);
+
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown,
+ "coalesced set not equal to input", return -1);
+ if (check_one && !one)
+ isl_die(ctx, isl_error_unknown,
+ "coalesced set should not be a union", return -1);
+
+ return 0;
}
-void test_coalesce(struct isl_ctx *ctx)
+int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
+{
+ int r = 0;
+ int bounded;
+
+ bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
+ isl_options_set_coalesce_bounded_wrapping(ctx, 0);
+
+ if (test_coalesce_set(ctx,
+ "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
+ "-x - y + 1 >= 0 and -3 <= z <= 3;"
+ "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
+ "x-z + 20 >= 0 and x+z + 20 >= 0 and "
+ "-10 <= y <= 0}", 1) < 0)
+ goto error;
+ if (test_coalesce_set(ctx,
+ "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
+ goto error;
+ if (test_coalesce_set(ctx,
+ "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
+ goto error;
+
+ if (0) {
+error:
+ r = -1;
+ }
+
+ isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
+
+ return r;
+}
+
+int test_coalesce(struct isl_ctx *ctx)
{
const char *str;
struct isl_set *set, *set2;
test_coalesce_set(ctx,
"{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
"(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
- test_coalesce_set(ctx,
- "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
- "-x - y + 1 >= 0 and -3 <= z <= 3;"
- "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
- "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
- test_coalesce_set(ctx,
- "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
- test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
- test_coalesce_set(ctx,
- "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
- test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
- test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
- test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
- test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
- test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
- test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
- test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
+ if (test_coalesce_unbounded_wrapping(ctx) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [a, b] : exists e : 2e = a and "
+ "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx,
+ "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
+ "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
+ "j >= 1 and j' <= i + j - i' and i >= 1; "
+ "[1, 1, 1, 1] }", 0) < 0)
+ return -1;
+ if (test_coalesce_set(ctx, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
+ "[i,j] : exists a : j = 3a }", 1) < 0)
+ return -1;
+ return 0;
}
void test_closure(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 equal;
}
+static int map_check_equal(__isl_keep isl_map *map, const char *str)
+{
+ int equal;
+
+ equal = map_is_equal(map, str);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(isl_map_get_ctx(map), isl_error_unknown,
+ "result not as expected", return -1);
+ return 0;
+}
+
void test_dep(struct isl_ctx *ctx)
{
const char *str;
isl_set_free(set2);
}
-void test_factorize(isl_ctx *ctx)
+int test_factorize(isl_ctx *ctx)
{
const char *str;
isl_basic_set *bset;
"3i5 >= -2i0 - i2 + 3i4 }";
bset = isl_basic_set_read_from_str(ctx, str);
f = isl_basic_set_factorizer(bset);
- assert(f);
isl_basic_set_free(bset);
isl_factorizer_free(f);
+ if (!f)
+ isl_die(ctx, isl_error_unknown,
+ "failed to construct factorizer", return -1);
str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
"i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
"9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
bset = isl_basic_set_read_from_str(ctx, str);
f = isl_basic_set_factorizer(bset);
- assert(f);
isl_basic_set_free(bset);
isl_factorizer_free(f);
+ if (!f)
+ isl_die(ctx, isl_error_unknown,
+ "failed to construct factorizer", return -1);
+
+ return 0;
}
static int check_injective(__isl_take isl_map *map, void *user)
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)
return 0;
}
+static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
+{
+ isl_aff *aff2;
+ int equal;
+
+ if (!aff)
+ return -1;
+
+ aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
+ equal = isl_aff_plain_is_equal(aff, aff2);
+ isl_aff_free(aff2);
+
+ return equal;
+}
+
+static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
+{
+ int equal;
+
+ equal = aff_plain_is_equal(aff, str);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(isl_aff_get_ctx(aff), isl_error_unknown,
+ "result not as expected", return -1);
+ return 0;
+}
+
int test_aff(isl_ctx *ctx)
{
const char *str;
isl_set *set;
- isl_space *dim;
+ isl_space *space;
isl_local_space *ls;
isl_aff *aff;
- int zero;
+ int zero, equal;
- dim = isl_space_set_alloc(ctx, 0, 1);
- ls = isl_local_space_from_space(dim);
+ space = isl_space_set_alloc(ctx, 0, 1);
+ ls = isl_local_space_from_space(space);
aff = isl_aff_zero_on_domain(ls);
aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
if (!zero)
isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
+ aff = isl_aff_read_from_str(ctx, "{ [-1] }");
+ aff = isl_aff_scale_down_ui(aff, 64);
+ aff = isl_aff_floor(aff);
+ equal = aff_check_plain_equal(aff, "{ [-1] }");
+ isl_aff_free(aff);
+ if (equal < 0)
+ return -1;
+
return 0;
}
{
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 test_sample(isl_ctx *ctx)
+{
+ const char *str;
+ isl_basic_set *bset1, *bset2;
+ int empty, subset;
+
+ str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
+ "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
+ "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
+ "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
+ "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
+ "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
+ "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
+ "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
+ "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
+ "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
+ "3i >= 1 + 2b - 2c + e + 2f + 3g and "
+ "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
+ "d - 1073741821e and "
+ "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
+ "3j >= 1 - a + b + 2e and "
+ "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
+ "3i <= 4 - a + 4b - e and "
+ "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
+ "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
+ "c <= -1 + a and 3i >= -2 - a + 3e and "
+ "1073741822e <= 1073741823 - a + 1073741822b + c and "
+ "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
+ "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
+ "1073741823e >= 1 + 1073741823b - d and "
+ "3i >= 1073741823b + c - 1073741823e - f and "
+ "3i >= 1 + 2b + e + 3g }";
+ bset1 = isl_basic_set_read_from_str(ctx, str);
+ bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
+ empty = isl_basic_set_is_empty(bset2);
+ subset = isl_basic_set_is_subset(bset2, bset1);
+ isl_basic_set_free(bset1);
+ isl_basic_set_free(bset2);
+ if (empty)
+ isl_die(ctx, isl_error_unknown, "point not found", return -1);
+ if (!subset)
+ isl_die(ctx, isl_error_unknown, "bad point found", return -1);
+
+ return 0;
+}
+
+int test_fixed_power(isl_ctx *ctx)
+{
+ const char *str;
+ isl_map *map;
+ isl_int exp;
+ int equal;
+
+ isl_int_init(exp);
+ str = "{ [i] -> [i + 1] }";
+ map = isl_map_read_from_str(ctx, str);
+ isl_int_set_si(exp, 23);
+ map = isl_map_fixed_power(map, exp);
+ equal = map_check_equal(map, "{ [i] -> [i + 23] }");
+ isl_int_clear(exp);
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ return 0;
+}
+
+int test_slice(isl_ctx *ctx)
+{
+ const char *str;
+ isl_map *map;
+ int equal;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
+ equal = map_check_equal(map, "{ [i] -> [i] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
+ equal = map_check_equal(map, "{ [i] -> [j] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
+ equal = map_check_equal(map, "{ [i] -> [-i] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
+ equal = map_check_equal(map, "{ [0] -> [j] }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
+ equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ str = "{ [i] -> [j] }";
+ map = isl_map_read_from_str(ctx, str);
+ map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
+ equal = map_check_equal(map, "{ [i] -> [j] : false }");
+ isl_map_free(map);
+ if (equal < 0)
+ return -1;
+
+ return 0;
+}
+
+struct {
+ const char *name;
+ int (*fn)(isl_ctx *ctx);
+} tests [] = {
+ { "div", &test_div },
+ { "slice", &test_slice },
+ { "fixed power", &test_fixed_power },
+ { "sample", &test_sample },
+ { "output", &test_output },
+ { "vertices", &test_vertices },
+ { "fixed", &test_fixed },
+ { "equal", &test_equal },
+ { "product", &test_product },
+ { "dim_max", &test_dim_max },
+ { "affine", &test_aff },
+ { "injective", &test_injective },
+ { "schedule", &test_schedule },
+ { "union_pw", &test_union_pw },
+ { "parse", &test_parse },
+ { "single-valued", &test_sv },
+ { "affine hull", &test_affine_hull },
+ { "coalesce", &test_coalesce },
+ { "factorize", &test_factorize },
+};
+
int main()
{
+ int i;
struct isl_ctx *ctx;
srcdir = getenv("srcdir");
assert(srcdir);
ctx = isl_ctx_alloc();
- if (test_fixed(ctx) < 0)
- goto error;
- if (test_equal(ctx) < 0)
- goto error;
- if (test_product(ctx) < 0)
- goto error;
- if (test_dim_max(ctx) < 0)
- goto error;
- if (test_aff(ctx) < 0)
- goto error;
- if (test_injective(ctx) < 0)
- goto error;
- if (test_schedule(ctx) < 0)
- goto error;
- test_factorize(ctx);
+ for (i = 0; i < ARRAY_SIZE(tests); ++i) {
+ printf("%s\n", tests[i].name);
+ if (tests[i].fn(ctx) < 0)
+ goto error;
+ }
test_subset(ctx);
test_lift(ctx);
test_bound(ctx);
test_union(ctx);
test_split_periods(ctx);
- test_parse(ctx);
test_pwqp(ctx);
test_lex(ctx);
- if (test_sv(ctx) < 0)
- goto error;
test_bijective(ctx);
test_dep(ctx);
test_read(ctx);
test_bounded(ctx);
test_construction(ctx);
test_dim(ctx);
- test_div(ctx);
test_application(ctx);
- test_affine_hull(ctx);
test_convex_hull(ctx);
test_gist(ctx);
- test_coalesce(ctx);
test_closure(ctx);
test_lexmin(ctx);
isl_ctx_free(ctx);