From 3822f9778eba9974d293b5b237bfb2e4111af256 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 14 Feb 2015 11:06:41 +0100 Subject: [PATCH] export isl_ast_build_expr_from_set Polly needs this to generate run-time tests. Tested-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- doc/user.pod | 6 +++++- include/isl/ast_build.h | 2 ++ isl_ast_build_expr.c | 32 ++++++++++++++++++++++++++++++-- isl_ast_build_expr.h | 2 +- isl_ast_codegen.c | 2 +- isl_ast_graft.c | 2 +- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index e4287bab..a6bddf65 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -8655,6 +8655,9 @@ C of type C only. It is meant to represent the address of the C. #include + __isl_give isl_ast_expr *isl_ast_build_expr_from_set( + __isl_keep isl_ast_build *build, + __isl_take isl_set *set); __isl_give isl_ast_expr *isl_ast_build_expr_from_pw_aff( __isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa); @@ -8675,7 +8678,8 @@ to represent the address of the C. __isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa); -The domains of C, C and C should correspond +The set and +the domains of C, C and C should correspond to the schedule space of C. The tuple id of C or C is used as the array being accessed or the function being called. diff --git a/include/isl/ast_build.h b/include/isl/ast_build.h index 4fa7b454..4668a79a 100644 --- a/include/isl/ast_build.h +++ b/include/isl/ast_build.h @@ -79,6 +79,8 @@ __isl_give isl_ast_build *isl_ast_build_set_create_leaf( __isl_give isl_ast_node *(*fn)(__isl_take isl_ast_build *build, void *user), void *user); +__isl_give isl_ast_expr *isl_ast_build_expr_from_set( + __isl_keep isl_ast_build *build, __isl_take isl_set *set); __isl_give isl_ast_expr *isl_ast_build_expr_from_pw_aff( __isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa); __isl_give isl_ast_expr *isl_ast_build_access_from_pw_multi_aff( diff --git a/isl_ast_build_expr.c b/isl_ast_build_expr.c index 36692522..83b12a13 100644 --- a/isl_ast_build_expr.c +++ b/isl_ast_build_expr.c @@ -1497,8 +1497,10 @@ static int expr_from_set(__isl_take isl_basic_set *bset, void *user) * The result is simplified in terms of build->domain. * * If "set" is an (obviously) empty set, then return the expression "0". + * + * "set" lives in the internal schedule space. */ -__isl_give isl_ast_expr *isl_ast_build_expr_from_set( +__isl_give isl_ast_expr *isl_ast_build_expr_from_set_internal( __isl_keep isl_ast_build *build, __isl_take isl_set *set) { struct isl_expr_from_set_data data = { build, 1, NULL }; @@ -1514,6 +1516,32 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_set( return data.res; } +/* Construct an isl_ast_expr that evaluates the conditions defining "set". + * The result is simplified in terms of build->domain. + * + * If "set" is an (obviously) empty set, then return the expression "0". + * + * "set" lives in the external schedule space. + * + * The internal AST expression generation assumes that there are + * no unknown divs, so make sure an explicit representation is available. + * Since the set comes from the outside, it may have constraints that + * are redundant with respect to the build domain. Remove them first. + */ +__isl_give isl_ast_expr *isl_ast_build_expr_from_set( + __isl_keep isl_ast_build *build, __isl_take isl_set *set) +{ + if (isl_ast_build_need_schedule_map(build)) { + isl_multi_aff *ma; + ma = isl_ast_build_get_schedule_map_multi_aff(build); + set = isl_set_preimage_multi_aff(set, ma); + } + + set = isl_set_compute_divs(set); + set = isl_ast_build_compute_gist(build, set); + return isl_ast_build_expr_from_set_internal(build, set); +} + struct isl_from_pw_aff_data { isl_ast_build *build; int n; @@ -1560,7 +1588,7 @@ static int ast_expr_from_pw_aff(__isl_take isl_set *set, ternary = isl_ast_expr_alloc_op(ctx, isl_ast_op_select, 3); gist = isl_set_gist(isl_set_copy(set), isl_set_copy(data->dom)); - arg = isl_ast_build_expr_from_set(data->build, gist); + arg = isl_ast_build_expr_from_set_internal(data->build, gist); ternary = isl_ast_expr_set_op_arg(ternary, 0, arg); build = isl_ast_build_copy(data->build); build = isl_ast_build_restrict_generated(build, set); diff --git a/isl_ast_build_expr.h b/isl_ast_build_expr.h index bf3af04c..362f2bff 100644 --- a/isl_ast_build_expr.h +++ b/isl_ast_build_expr.h @@ -6,7 +6,7 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_basic_set( __isl_keep isl_ast_build *build, __isl_take isl_basic_set *bset); -__isl_give isl_ast_expr *isl_ast_build_expr_from_set( +__isl_give isl_ast_expr *isl_ast_build_expr_from_set_internal( __isl_keep isl_ast_build *build, __isl_take isl_set *set); __isl_give isl_ast_expr *isl_ast_build_expr_from_pw_aff_internal( diff --git a/isl_ast_codegen.c b/isl_ast_codegen.c index 05e05018..84466f0a 100644 --- a/isl_ast_codegen.c +++ b/isl_ast_codegen.c @@ -986,7 +986,7 @@ static __isl_give isl_ast_graft *set_for_cond_from_set( if (!graft) return NULL; - cond = isl_ast_build_expr_from_set(build, isl_set_copy(set)); + cond = isl_ast_build_expr_from_set_internal(build, isl_set_copy(set)); graft->node->u.f.cond = cond; if (!graft->node->u.f.cond) return isl_ast_graft_free(graft); diff --git a/isl_ast_graft.c b/isl_ast_graft.c index 611ef5dc..c8d22725 100644 --- a/isl_ast_graft.c +++ b/isl_ast_graft.c @@ -278,7 +278,7 @@ static __isl_give isl_ast_node *ast_node_insert_if( isl_ast_node *if_node; isl_ast_expr *expr; - expr = isl_ast_build_expr_from_set(build, guard); + expr = isl_ast_build_expr_from_set_internal(build, guard); if_node = isl_ast_node_alloc_if(expr); return isl_ast_node_if_set_then(if_node, node); -- 2.11.4.GIT