From 5f39123b07c88bad1a09abb6ac9bf60076a1976f Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 18 Jul 2012 12:41:32 +0200 Subject: [PATCH] add isl_set_preimage_multi_aff Signed-off-by: Sven Verdoolaege --- doc/user.pod | 5 +++- include/isl/set.h | 2 ++ isl_map.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index d4d4ca0c..7a4707eb 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2779,8 +2779,11 @@ a parametric set as well. isl_basic_set_preimage_multi_aff( __isl_take isl_basic_set *bset, __isl_take isl_multi_aff *ma); + __isl_give isl_set *isl_set_preimage_multi_aff( + __isl_take isl_set *set, + __isl_take isl_multi_aff *ma); -This function computes the preimage of the given set under +These functions compute the preimage of the given set under the given function. In other words, the expression is plugged into the set description. Objects of type C are described in diff --git a/include/isl/set.h b/include/isl/set.h index 60a99fe6..8ade721a 100644 --- a/include/isl/set.h +++ b/include/isl/set.h @@ -303,6 +303,8 @@ __isl_export __isl_give isl_set *isl_set_apply( __isl_take isl_set *set, __isl_take isl_map *map); +__isl_give isl_set *isl_set_preimage_multi_aff(__isl_take isl_set *set, + __isl_take isl_multi_aff *ma); __isl_give isl_set *isl_set_fix(__isl_take isl_set *set, enum isl_dim_type type, unsigned pos, isl_int value); struct isl_set *isl_set_fix_dim_si(struct isl_set *set, diff --git a/isl_map.c b/isl_map.c index a0ab7e3e..e862aacb 100644 --- a/isl_map.c +++ b/isl_map.c @@ -11140,3 +11140,73 @@ error: isl_basic_set_free(res); return NULL; } + +/* Check if the range of "ma" is compatible with "set". + * Return -1 if anything is wrong. + */ +static int check_set_compatible_range_multi_aff( + __isl_keep isl_set *set, __isl_keep isl_multi_aff *ma) +{ + return check_space_compatible_range_multi_aff(set->dim, ma); +} + +/* Compute the preimage of "set" under the function represented by "ma". + * In other words, plug in "ma" in "set. The result is a set + * that lives in the domain space of "ma". + */ +static __isl_give isl_set *set_preimage_multi_aff(__isl_take isl_set *set, + __isl_take isl_multi_aff *ma) +{ + int i; + + set = isl_set_cow(set); + ma = isl_multi_aff_align_divs(ma); + if (!set || !ma) + goto error; + if (check_set_compatible_range_multi_aff(set, ma) < 0) + goto error; + + for (i = 0; i < set->n; ++i) { + set->p[i] = isl_basic_set_preimage_multi_aff(set->p[i], + isl_multi_aff_copy(ma)); + if (!set->p[i]) + goto error; + } + + isl_space_free(set->dim); + set->dim = isl_multi_aff_get_domain_space(ma); + if (!set->dim) + goto error; + + isl_multi_aff_free(ma); + if (set->n > 1) + ISL_F_CLR(set, ISL_MAP_DISJOINT); + ISL_F_CLR(set, ISL_SET_NORMALIZED); + return set; +error: + isl_multi_aff_free(ma); + isl_set_free(set); + return NULL; +} + +__isl_give isl_set *isl_set_preimage_multi_aff(__isl_take isl_set *set, + __isl_take isl_multi_aff *ma) +{ + if (!set || !ma) + goto error; + + if (isl_space_match(set->dim, isl_dim_param, ma->space, isl_dim_param)) + return set_preimage_multi_aff(set, ma); + + if (!isl_space_has_named_params(set->dim) || + !isl_space_has_named_params(ma->space)) + isl_die(set->ctx, isl_error_invalid, + "unaligned unnamed parameters", goto error); + set = isl_set_align_params(set, isl_multi_aff_get_space(ma)); + ma = isl_multi_aff_align_params(ma, isl_set_get_space(set)); + + return set_preimage_multi_aff(set, ma); +error: + isl_multi_aff_free(ma); + return isl_set_free(set); +} -- 2.11.4.GIT