From 3b49fefd7671b88e9eb9b60dc3c745543e8845d2 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 14 Feb 2018 12:13:32 +0100 Subject: [PATCH] isl_pw_templ.c: extract out isl_pw_eval.c This will make it easier to support isl_pw_*_eval on other types. Signed-off-by: Sven Verdoolaege --- Makefile.am | 1 + isl_aff.c | 2 -- isl_fold.c | 1 + isl_polynomial.c | 1 + isl_pw_eval.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ isl_pw_templ.c | 64 ---------------------------------------------- 6 files changed, 81 insertions(+), 66 deletions(-) create mode 100644 isl_pw_eval.c diff --git a/Makefile.am b/Makefile.am index e4cdf1bc..e300b1c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -369,6 +369,7 @@ EXTRA_DIST = \ isl_pw_macro.h \ isl_pw_templ.c \ isl_pw_templ.h \ + isl_pw_eval.c \ isl_pw_hash.c \ isl_pw_union_opt.c \ read_in_string_templ.c \ diff --git a/isl_aff.c b/isl_aff.c index b27d2d46..56ca1d36 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -2639,7 +2639,6 @@ __isl_give isl_pw_aff *isl_pw_aff_from_aff(__isl_take isl_aff *aff) #undef DEFAULT_IS_ZERO #define DEFAULT_IS_ZERO 0 -#define NO_EVAL #define NO_OPT #define NO_LIFT #define NO_MORPH @@ -4242,7 +4241,6 @@ __isl_give isl_set *isl_multi_aff_lex_gt_set(__isl_take isl_multi_aff *ma1, #define DEFAULT_IS_ZERO 0 #define NO_SUB -#define NO_EVAL #define NO_OPT #define NO_INVOLVES_DIMS #define NO_INSERT_DIMS diff --git a/isl_fold.c b/isl_fold.c index be5c7f75..c08d6439 100644 --- a/isl_fold.c +++ b/isl_fold.c @@ -685,6 +685,7 @@ __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_gist_params( #define NO_PULLBACK #include +#include #undef UNION #define UNION isl_union_pw_qpolynomial_fold diff --git a/isl_polynomial.c b/isl_polynomial.c index 2c5a5f5f..4813a489 100644 --- a/isl_polynomial.c +++ b/isl_polynomial.c @@ -2957,6 +2957,7 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_qpolynomial( #define NO_PULLBACK #include +#include #undef UNION #define UNION isl_union_pw_qpolynomial diff --git a/isl_pw_eval.c b/isl_pw_eval.c new file mode 100644 index 00000000..d5d81a19 --- /dev/null +++ b/isl_pw_eval.c @@ -0,0 +1,78 @@ +/* + * Copyright 2010 INRIA Saclay + * Copyright 2013 Ecole Normale Superieure + * + * Use of this software is governed by the MIT license + * + * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France, + * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod, + * 91893 Orsay, France + * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France + */ + +#include +#include +#include + +#include + +/* Evaluate "pw" in the void point "pnt". + * In particular, return the value NaN. + */ +static __isl_give isl_val *FN(PW,eval_void)(__isl_take PW *pw, + __isl_take isl_point *pnt) +{ + isl_ctx *ctx; + + ctx = isl_point_get_ctx(pnt); + FN(PW,free)(pw); + isl_point_free(pnt); + return isl_val_nan(ctx); +} + +__isl_give isl_val *FN(PW,eval)(__isl_take PW *pw, __isl_take isl_point *pnt) +{ + int i; + isl_bool is_void; + isl_bool found; + isl_ctx *ctx; + isl_bool ok; + isl_space *pnt_space, *pw_space; + isl_val *v; + + pnt_space = isl_point_peek_space(pnt); + pw_space = FN(PW,peek_space)(pw); + ok = isl_space_is_domain_internal(pnt_space, pw_space); + if (ok < 0) + goto error; + ctx = isl_point_get_ctx(pnt); + if (!ok) + isl_die(ctx, isl_error_invalid, + "incompatible spaces", goto error); + is_void = isl_point_is_void(pnt); + if (is_void < 0) + goto error; + if (is_void) + return FN(PW,eval_void)(pw, pnt); + + found = isl_bool_false; + for (i = 0; i < pw->n; ++i) { + found = isl_set_contains_point(pw->p[i].set, pnt); + if (found < 0) + goto error; + if (found) + break; + } + if (found) + v = FN(EL,eval)(FN(EL,copy)(pw->p[i].FIELD), + isl_point_copy(pnt)); + else + v = isl_val_zero(ctx); + FN(PW,free)(pw); + isl_point_free(pnt); + return v; +error: + FN(PW,free)(pw); + isl_point_free(pnt); + return NULL; +} diff --git a/isl_pw_templ.c b/isl_pw_templ.c index 4049ad5f..4d358074 100644 --- a/isl_pw_templ.c +++ b/isl_pw_templ.c @@ -14,7 +14,6 @@ #include #include #include -#include #include @@ -700,69 +699,6 @@ __isl_give PW *FN(PW,sub)(__isl_take PW *pw1, __isl_take PW *pw2) } #endif -#ifndef NO_EVAL -/* Evaluate "pw" in the void point "pnt". - * In particular, return the value NaN. - */ -static __isl_give isl_val *FN(PW,eval_void)(__isl_take PW *pw, - __isl_take isl_point *pnt) -{ - isl_ctx *ctx; - - ctx = isl_point_get_ctx(pnt); - FN(PW,free)(pw); - isl_point_free(pnt); - return isl_val_nan(ctx); -} - -__isl_give isl_val *FN(PW,eval)(__isl_take PW *pw, __isl_take isl_point *pnt) -{ - int i; - isl_bool is_void; - isl_bool found; - isl_ctx *ctx; - isl_bool ok; - isl_space *pnt_space, *pw_space; - isl_val *v; - - pnt_space = isl_point_peek_space(pnt); - pw_space = FN(PW,peek_space)(pw); - ok = isl_space_is_domain_internal(pnt_space, pw_space); - if (ok < 0) - goto error; - ctx = isl_point_get_ctx(pnt); - if (!ok) - isl_die(ctx, isl_error_invalid, - "incompatible spaces", goto error); - is_void = isl_point_is_void(pnt); - if (is_void < 0) - goto error; - if (is_void) - return FN(PW,eval_void)(pw, pnt); - - found = isl_bool_false; - for (i = 0; i < pw->n; ++i) { - found = isl_set_contains_point(pw->p[i].set, pnt); - if (found < 0) - goto error; - if (found) - break; - } - if (found) - v = FN(EL,eval)(FN(EL,copy)(pw->p[i].FIELD), - isl_point_copy(pnt)); - else - v = isl_val_zero(ctx); - FN(PW,free)(pw); - isl_point_free(pnt); - return v; -error: - FN(PW,free)(pw); - isl_point_free(pnt); - return NULL; -} -#endif - /* Return the parameter domain of "pw". */ __isl_give isl_set *FN(PW,params)(__isl_take PW *pw) -- 2.11.4.GIT