isl_multi_templ.c: isl_multi_*_set_*: extract out check for matching space
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 30 Apr 2013 19:01:02 +0000 (21:01 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 28 May 2013 16:15:04 +0000 (18:15 +0200)
We will be adding isl_multi_val next, where such a check does not make sense.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_aff.c
isl_aff_private.h
isl_multi_templ.c

index de1a0ca..1156d09 100644 (file)
--- 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
 
index 2fb245a..e89b36c 100644 (file)
@@ -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
 
index a275f1b..ddbfc01 100644 (file)
@@ -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,