From 4b02c5168c8edff5de6ccf2832485d2fe336d9ff Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 25 Aug 2012 11:18:40 +0200 Subject: [PATCH] add isl_set_preimage_pw_multi_aff Signed-off-by: Sven Verdoolaege --- doc/user.pod | 5 ++++- include/isl/set.h | 2 ++ isl_map.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index 7a4707eb..f5ca6e67 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2782,11 +2782,14 @@ a parametric set as well. __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_preimage_pw_multi_aff( + __isl_take isl_set *set, + __isl_take isl_pw_multi_aff *pma); 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 +Objects of types C and C are described in L. =item * Cartesian Product diff --git a/include/isl/set.h b/include/isl/set.h index 8ade721a..9dc59e8e 100644 --- a/include/isl/set.h +++ b/include/isl/set.h @@ -305,6 +305,8 @@ __isl_give isl_set *isl_set_apply( __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_preimage_pw_multi_aff(__isl_take isl_set *set, + __isl_take isl_pw_multi_aff *pma); __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 e862aacb..5c693b06 100644 --- a/isl_map.c +++ b/isl_map.c @@ -11210,3 +11210,67 @@ error: isl_multi_aff_free(ma); return isl_set_free(set); } + +/* Compute the preimage of "set" under the function represented by "pma". + * In other words, plug in "pma" in "set. The result is a set + * that lives in the domain space of "pma". + */ +static __isl_give isl_set *set_preimage_pw_multi_aff(__isl_take isl_set *set, + __isl_take isl_pw_multi_aff *pma) +{ + int i; + isl_set *res; + + if (!pma) + goto error; + + if (pma->n == 0) { + isl_pw_multi_aff_free(pma); + res = isl_set_empty(isl_set_get_space(set)); + isl_set_free(set); + return res; + } + + res = isl_set_preimage_multi_aff(isl_set_copy(set), + isl_multi_aff_copy(pma->p[0].maff)); + res = isl_set_intersect(res, isl_set_copy(pma->p[0].set)); + + for (i = 1; i < pma->n; ++i) { + isl_set *res_i; + + res_i = isl_set_preimage_multi_aff(isl_set_copy(set), + isl_multi_aff_copy(pma->p[i].maff)); + res_i = isl_set_intersect(res_i, isl_set_copy(pma->p[i].set)); + res = isl_set_union(res, res_i); + } + + isl_pw_multi_aff_free(pma); + isl_set_free(set); + return res; +error: + isl_pw_multi_aff_free(pma); + isl_set_free(set); + return NULL; +} + +__isl_give isl_set *isl_set_preimage_pw_multi_aff(__isl_take isl_set *set, + __isl_take isl_pw_multi_aff *pma) +{ + if (!set || !pma) + goto error; + + if (isl_space_match(set->dim, isl_dim_param, pma->dim, isl_dim_param)) + return set_preimage_pw_multi_aff(set, pma); + + if (!isl_space_has_named_params(set->dim) || + !isl_space_has_named_params(pma->dim)) + isl_die(set->ctx, isl_error_invalid, + "unaligned unnamed parameters", goto error); + set = isl_set_align_params(set, isl_pw_multi_aff_get_space(pma)); + pma = isl_pw_multi_aff_align_params(pma, isl_set_get_space(set)); + + return set_preimage_pw_multi_aff(set, pma); +error: + isl_pw_multi_aff_free(pma); + return isl_set_free(set); +} -- 2.11.4.GIT