From 92db9306b4c1a71e3054e7429f56000d4bf376dc Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 30 Apr 2013 21:01:02 +0200 Subject: [PATCH] isl_multi_templ.c: isl_multi_*_set_*: extract out check for matching space We will be adding isl_multi_val next, where such a check does not make sense. Signed-off-by: Sven Verdoolaege --- isl_aff.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ isl_aff_private.h | 6 +++++ isl_multi_templ.c | 12 ++-------- 3 files changed, 77 insertions(+), 10 deletions(-) diff --git a/isl_aff.c b/isl_aff.c index de1a0ca..1156d09 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -2659,6 +2659,41 @@ __isl_give isl_pw_aff_list *isl_pw_aff_list_set_rational( return list; } +/* Check that the domain space of "aff" matches "space". + * + * Return 0 on success and -1 on error. + */ +int isl_aff_check_match_domain_space(__isl_keep isl_aff *aff, + __isl_keep isl_space *space) +{ + isl_space *aff_space; + int match; + + if (!aff || !space) + return -1; + + aff_space = isl_aff_get_domain_space(aff); + + match = isl_space_match(space, isl_dim_param, aff_space, isl_dim_param); + if (match < 0) + goto error; + if (!match) + isl_die(isl_aff_get_ctx(aff), isl_error_invalid, + "parameters don't match", goto error); + match = isl_space_tuple_match(space, isl_dim_in, + aff_space, isl_dim_set); + if (match < 0) + goto error; + if (!match) + isl_die(isl_aff_get_ctx(aff), isl_error_invalid, + "domains don't match", goto error); + isl_space_free(aff_space); + return 0; +error: + isl_space_free(aff_space); + return -1; +} + #undef BASE #define BASE aff @@ -4678,6 +4713,40 @@ error: return NULL; } +/* Check that the domain space of "pa" matches "space". + * + * Return 0 on success and -1 on error. + */ +int isl_pw_aff_check_match_domain_space(__isl_keep isl_pw_aff *pa, + __isl_keep isl_space *space) +{ + isl_space *pa_space; + int match; + + if (!pa || !space) + return -1; + + pa_space = isl_pw_aff_get_space(pa); + + match = isl_space_match(space, isl_dim_param, pa_space, isl_dim_param); + if (match < 0) + goto error; + if (!match) + isl_die(isl_pw_aff_get_ctx(pa), isl_error_invalid, + "parameters don't match", goto error); + match = isl_space_tuple_match(space, isl_dim_in, pa_space, isl_dim_in); + if (match < 0) + goto error; + if (!match) + isl_die(isl_pw_aff_get_ctx(pa), isl_error_invalid, + "domains don't match", goto error); + isl_space_free(pa_space); + return 0; +error: + isl_space_free(pa_space); + return -1; +} + #undef BASE #define BASE pw_aff diff --git a/isl_aff_private.h b/isl_aff_private.h index 2fb245a..e89b36c 100644 --- a/isl_aff_private.h +++ b/isl_aff_private.h @@ -88,6 +88,9 @@ __isl_give isl_pw_aff *isl_pw_aff_set_rational(__isl_take isl_pw_aff *pwaff); __isl_give isl_pw_aff_list *isl_pw_aff_list_set_rational( __isl_take isl_pw_aff_list *list); +int isl_aff_check_match_domain_space(__isl_keep isl_aff *aff, + __isl_keep isl_space *space); + #undef BASE #define BASE aff @@ -120,6 +123,9 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_substitute( __isl_take isl_pw_multi_aff *pma, enum isl_dim_type type, unsigned pos, __isl_keep isl_pw_aff *subs); +int isl_pw_aff_check_match_domain_space(__isl_keep isl_pw_aff *pa, + __isl_keep isl_space *space); + #undef BASE #define BASE pw_aff diff --git a/isl_multi_templ.c b/isl_multi_templ.c index a275f1b..ddbfc01 100644 --- a/isl_multi_templ.c +++ b/isl_multi_templ.c @@ -227,16 +227,8 @@ __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)( goto error; multi_space = FN(MULTI(BASE),get_space)(multi); - el_space = FN(EL,get_space)(el); - - if (!isl_space_match(multi_space, isl_dim_param, - el_space, isl_dim_param)) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "parameters don't match", goto error); - if (!isl_space_tuple_match(multi_space, isl_dim_in, - el_space, isl_dim_in)) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "domains don't match", goto error); + if (FN(EL,check_match_domain_space)(el, multi_space) < 0) + goto error; if (pos < 0 || pos >= multi->n) isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, -- 2.7.4