{
const char *str;
isl_set *set;
- isl_basic_set *bset;
+ isl_basic_set *bset, *bset2;
int n;
+ int subset;
test_affine_hull_case(ctx, "affine2");
test_affine_hull_case(ctx, "affine");
isl_die(ctx, isl_error_unknown, "not expecting any divs",
return -1);
+ /* Check that isl_map_affine_hull is not confused by
+ * the reordering of divs in isl_map_align_divs.
+ */
+ str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
+ "32e0 = b and 32e1 = c); "
+ "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
+ set = isl_set_read_from_str(ctx, str);
+ bset = isl_set_affine_hull(set);
+ isl_basic_set_free(bset);
+ if (!bset)
+ return -1;
+
+ str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
+ "32e2 = 31 + 31e0 }";
+ set = isl_set_read_from_str(ctx, str);
+ bset = isl_set_affine_hull(set);
+ str = "{ [a] : exists e : a = 32 e }";
+ bset2 = isl_basic_set_read_from_str(ctx, str);
+ subset = isl_basic_set_is_subset(bset, bset2);
+ isl_basic_set_free(bset);
+ isl_basic_set_free(bset2);
+ if (subset < 0)
+ return -1;
+ if (!subset)
+ isl_die(ctx, isl_error_unknown, "not as accurate as expected",
+ return -1);
+
return 0;
}
return 0;
}
+/* Check that the schedule map is properly padded, even after being
+ * reconstructed from the band forest.
+ */
+static int test_padded_schedule(isl_ctx *ctx)
+{
+ const char *str;
+ isl_union_set *D;
+ isl_union_map *validity, *proximity;
+ isl_schedule *sched;
+ isl_union_map *map1, *map2;
+ isl_band_list *list;
+ int equal;
+
+ str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
+ D = isl_union_set_read_from_str(ctx, str);
+ validity = isl_union_map_empty(isl_union_set_get_space(D));
+ proximity = isl_union_map_copy(validity);
+ sched = isl_union_set_compute_schedule(D, validity, proximity);
+ map1 = isl_schedule_get_map(sched);
+ list = isl_schedule_get_band_forest(sched);
+ isl_band_list_free(list);
+ map2 = isl_schedule_get_map(sched);
+ isl_schedule_free(sched);
+ equal = isl_union_map_is_equal(map1, map2);
+ isl_union_map_free(map1);
+ isl_union_map_free(map2);
+
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown,
+ "reconstructed schedule map not the same as original",
+ return -1);
+
+ return 0;
+}
+
int test_schedule(isl_ctx *ctx)
{
const char *D, *W, *R, *V, *P, *S;
if (test_has_schedule(ctx, D, V, P) < 0)
return -1;
+ if (test_padded_schedule(ctx) < 0)
+ return -1;
+
return 0;
}
"{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
};
-int test_preimage(isl_ctx *ctx)
+static int test_preimage_basic_set(isl_ctx *ctx)
{
int i;
isl_basic_set *bset1, *bset2;
}
struct {
+ const char *map;
+ const char *ma;
+ const char *res;
+} preimage_domain_tests[] = {
+ { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
+ "{ A[j,i] -> B[i,j] }",
+ "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
+ { "{ B[i] -> C[i]; D[i] -> E[i] }",
+ "{ A[i] -> B[i + 1] }",
+ "{ A[i] -> C[i + 1] }" },
+ { "{ B[i] -> C[i]; B[i] -> E[i] }",
+ "{ A[i] -> B[i + 1] }",
+ "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
+ { "{ B[i] -> C[([i/2])] }",
+ "{ A[i] -> B[2i] }",
+ "{ A[i] -> C[i] }" },
+ { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
+ "{ A[i] -> B[([i/5]), ([i/7])] }",
+ "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
+ { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
+ "[N] -> { A[] -> B[([N/5])] }",
+ "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
+ { "{ B[i] -> C[i] : exists a : i = 5 a }",
+ "{ A[i] -> B[2i] }",
+ "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
+ { "{ B[i] -> C[i] : exists a : i = 2 a; "
+ "B[i] -> D[i] : exists a : i = 2 a + 1 }",
+ "{ A[i] -> B[2i] }",
+ "{ A[i] -> C[2i] }" },
+};
+
+static int test_preimage_union_map(isl_ctx *ctx)
+{
+ int i;
+ isl_union_map *umap1, *umap2;
+ isl_multi_aff *ma;
+ int equal;
+
+ for (i = 0; i < ARRAY_SIZE(preimage_domain_tests); ++i) {
+ umap1 = isl_union_map_read_from_str(ctx,
+ preimage_domain_tests[i].map);
+ ma = isl_multi_aff_read_from_str(ctx,
+ preimage_domain_tests[i].ma);
+ umap2 = isl_union_map_read_from_str(ctx,
+ preimage_domain_tests[i].res);
+ umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma);
+ equal = isl_union_map_is_equal(umap1, umap2);
+ isl_union_map_free(umap1);
+ isl_union_map_free(umap2);
+ if (equal < 0)
+ return -1;
+ if (!equal)
+ isl_die(ctx, isl_error_unknown, "bad preimage",
+ return -1);
+ }
+
+ return 0;
+}
+
+static int test_preimage(isl_ctx *ctx)
+{
+ if (test_preimage_basic_set(ctx) < 0)
+ return -1;
+ if (test_preimage_union_map(ctx) < 0)
+ return -1;
+
+ return 0;
+}
+
+struct {
const char *ma1;
const char *ma;
const char *res;
return 0;
}
+/* This function is called for each leaf in the AST generated
+ * from test_ast_gen5.
+ *
+ * We finalize the AST generation by extending the outer schedule
+ * with a zero-dimensional schedule. If this results in any for loops,
+ * then this means that we did not pass along enough information
+ * about the outer schedule to the inner AST generation.
+ */
+static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
+ void *user)
+{
+ isl_union_map *schedule, *extra;
+ isl_ast_node *tree;
+
+ schedule = isl_ast_build_get_schedule(build);
+ extra = isl_union_map_copy(schedule);
+ extra = isl_union_map_from_domain(isl_union_map_domain(extra));
+ schedule = isl_union_map_range_product(schedule, extra);
+ tree = isl_ast_build_ast_from_schedule(build, schedule);
+ isl_ast_build_free(build);
+
+ if (!tree)
+ return NULL;
+
+ if (isl_ast_node_get_type(tree) == isl_ast_node_for)
+ isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
+ "code should not contain any for loop",
+ return isl_ast_node_free(tree));
+
+ return tree;
+}
+
+/* Check that we do not lose any information when going back and
+ * forth between internal and external schedule.
+ *
+ * In particular, we create an AST where we unroll the only
+ * non-constant dimension in the schedule. We therefore do
+ * not expect any for loops in the AST. However, older versions
+ * of isl would not pass along enough information about the outer
+ * schedule when performing an inner code generation from a create_leaf
+ * callback, resulting in the inner code generation producing a for loop.
+ */
+static int test_ast_gen5(isl_ctx *ctx)
+{
+ const char *str;
+ isl_set *set;
+ isl_union_map *schedule, *options;
+ isl_ast_build *build;
+ isl_ast_node *tree;
+
+ str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
+ schedule = isl_union_map_read_from_str(ctx, str);
+
+ str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
+ "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
+ options = isl_union_map_read_from_str(ctx, str);
+
+ set = isl_set_universe(isl_space_params_alloc(ctx, 0));
+ build = isl_ast_build_from_context(set);
+ build = isl_ast_build_set_options(build, options);
+ build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
+ tree = isl_ast_build_ast_from_schedule(build, schedule);
+ isl_ast_build_free(build);
+ isl_ast_node_free(tree);
+ if (!tree)
+ return -1;
+
+ return 0;
+}
+
static int test_ast_gen(isl_ctx *ctx)
{
if (test_ast_gen1(ctx) < 0)
return -1;
if (test_ast_gen4(ctx) < 0)
return -1;
+ if (test_ast_gen5(ctx) < 0)
+ return -1;
return 0;
}