From a61948594142d2e20b86c0d871d18815e7a269cb Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 20 Jul 2012 15:28:12 +0200 Subject: [PATCH] add isl_pw_*_pullback_multi_aff Signed-off-by: Sven Verdoolaege --- doc/user.pod | 11 ++++++-- include/isl/aff.h | 6 +++++ isl_fold.c | 1 + isl_polynomial.c | 2 ++ isl_pw_templ.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 2 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 521773ac..0fd72bc5 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -3483,10 +3483,13 @@ remainder. __isl_give isl_aff *isl_aff_pullback_multi_aff( __isl_take isl_aff *aff, __isl_take isl_multi_aff *ma); + __isl_give isl_pw_aff *isl_pw_aff_pullback_multi_aff( + __isl_take isl_pw_aff *pa, + __isl_take isl_multi_aff *ma); -This function precomposes the input expression by the given +These functions precompose the input expression by the given C. In other words, the C is plugged -into the affine expression. +into the (piecewise) affine expression. Objects of type C are described in L. @@ -3936,6 +3939,10 @@ the lifting applied. __isl_give isl_multi_aff *isl_multi_aff_pullback_multi_aff( __isl_take isl_multi_aff *ma1, __isl_take isl_multi_aff *ma2); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_pullback_multi_aff( + __isl_take isl_pw_multi_aff *pma, + __isl_take isl_multi_aff *ma); The function C precomposes C by C. In other words, C is plugged diff --git a/include/isl/aff.h b/include/isl/aff.h index 3f548ff3..79d82d2d 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -219,6 +219,9 @@ __isl_give isl_pw_aff *isl_pw_aff_gist(__isl_take isl_pw_aff *pwaff, __isl_give isl_pw_aff *isl_pw_aff_gist_params(__isl_take isl_pw_aff *pwaff, __isl_take isl_set *context); +__isl_give isl_pw_aff *isl_pw_aff_pullback_multi_aff( + __isl_take isl_pw_aff *pa, __isl_take isl_multi_aff *ma); + int isl_pw_aff_n_piece(__isl_keep isl_pw_aff *pwaff); int isl_pw_aff_foreach_piece(__isl_keep isl_pw_aff *pwaff, int (*fn)(__isl_take isl_set *set, __isl_take isl_aff *aff, @@ -443,6 +446,9 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_gist_params( __isl_give isl_pw_multi_aff *isl_pw_multi_aff_gist( __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_pullback_multi_aff( + __isl_take isl_pw_multi_aff *pma, __isl_take isl_multi_aff *ma); + int isl_pw_multi_aff_foreach_piece(__isl_keep isl_pw_multi_aff *pma, int (*fn)(__isl_take isl_set *set, __isl_take isl_multi_aff *maff, void *user), void *user); diff --git a/isl_fold.c b/isl_fold.c index 1c3abe81..ba93a698 100644 --- a/isl_fold.c +++ b/isl_fold.c @@ -638,6 +638,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_gist_params( #define DEFAULT_IS_ZERO 1 #define NO_NEG +#define NO_PULLBACK #include diff --git a/isl_polynomial.c b/isl_polynomial.c index f026763d..7a55ed15 100644 --- a/isl_polynomial.c +++ b/isl_polynomial.c @@ -2608,6 +2608,8 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_qpolynomial( #undef DEFAULT_IS_ZERO #define DEFAULT_IS_ZERO 1 +#define NO_PULLBACK + #include #undef UNION diff --git a/isl_pw_templ.c b/isl_pw_templ.c index 6830cf20..c2e871c3 100644 --- a/isl_pw_templ.c +++ b/isl_pw_templ.c @@ -1,3 +1,5 @@ +#include + #define xFN(TYPE,NAME) TYPE ## _ ## NAME #define FN(TYPE,NAME) xFN(TYPE,NAME) #define xS(TYPE,NAME) struct TYPE ## _ ## NAME @@ -1616,3 +1618,79 @@ error: FN(PW,free)(pw2); return -1; } + +#ifndef NO_PULLBACK +static __isl_give PW *FN(PW,align_params_pw_multi_aff_and)(__isl_take PW *pw, + __isl_take isl_multi_aff *ma, + __isl_give PW *(*fn)(__isl_take PW *pw, __isl_take isl_multi_aff *ma)) +{ + isl_ctx *ctx; + isl_space *ma_space; + + ma_space = isl_multi_aff_get_space(ma); + if (!pw || !ma || !ma_space) + goto error; + if (isl_space_match(pw->dim, isl_dim_param, ma_space, isl_dim_param)) { + isl_space_free(ma_space); + return fn(pw, ma); + } + ctx = FN(PW,get_ctx)(pw); + if (!isl_space_has_named_params(pw->dim) || + !isl_space_has_named_params(ma_space)) + isl_die(ctx, isl_error_invalid, + "unaligned unnamed parameters", goto error); + pw = FN(PW,align_params)(pw, ma_space); + ma = isl_multi_aff_align_params(ma, FN(PW,get_space)(pw)); + return fn(pw, ma); +error: + isl_space_free(ma_space); + FN(PW,free)(pw); + isl_multi_aff_free(ma); + return NULL; +} + +/* Compute the pullback of "pw" by the function represented by "ma". + * In other words, plug in "ma" in "pw". + */ +static __isl_give PW *FN(PW,pullback_multi_aff_aligned)(__isl_take PW *pw, + __isl_take isl_multi_aff *ma) +{ + int i; + isl_space *space = NULL; + + ma = isl_multi_aff_align_divs(ma); + pw = FN(PW,cow)(pw); + if (!pw || !ma) + goto error; + + space = isl_space_join(isl_multi_aff_get_space(ma), + FN(PW,get_space)(pw)); + + for (i = 0; i < pw->n; ++i) { + pw->p[i].set = isl_set_preimage_multi_aff(pw->p[i].set, + isl_multi_aff_copy(ma)); + if (!pw->p[i].set) + goto error; + pw->p[i].FIELD = FN(EL,pullback_multi_aff)(pw->p[i].FIELD, + isl_multi_aff_copy(ma)); + if (!pw->p[i].FIELD) + goto error; + } + + pw = FN(PW,reset_space)(pw, space); + isl_multi_aff_free(ma); + return pw; +error: + isl_space_free(space); + isl_multi_aff_free(ma); + FN(PW,free)(pw); + return NULL; +} + +__isl_give PW *FN(PW,pullback_multi_aff)(__isl_take PW *pw, + __isl_take isl_multi_aff *ma) +{ + return FN(PW,align_params_pw_multi_aff_and)(pw, ma, + &FN(PW,pullback_multi_aff_aligned)); +} +#endif -- 2.11.4.GIT