From: Sven Verdoolaege <
sv...@cerebras.net>
This removes some minor code duplication and improves error handling.
Makefile.am | 1 +
isl_aff.c | 10 ++++----
isl_multi_arith_templ.c | 25 ++++++--------------
isl_type_check_match_range_multi_val.c | 32 ++++++++++++++++++++++++++
4 files changed, 45 insertions(+), 23 deletions(-)
create mode 100644 isl_type_check_match_range_multi_val.c
diff --git a/Makefile.am b/Makefile.am
index 939dbea510..17f92489d5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -598,6 +598,7 @@ EXTRA_DIST = \
isl_test_list_templ.c \
isl_test_plain_equal_templ.c \
isl_type_check_equal_space_templ.c \
+ isl_type_check_match_range_multi_val.c \
isl_type_has_equal_space_bin_templ.c \
isl_type_has_equal_space_templ.c \
isl_type_has_space_templ.c \
diff --git a/isl_aff.c b/isl_aff.c
index 7f8793a004..8ac4b65228 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -6701,6 +6701,10 @@ __isl_give isl_multi_pw_aff *isl_map_max_multi_pw_aff(__isl_take isl_map *map)
return map_opt_mpa(map, &isl_map_dim_max);
}
+#undef TYPE
+#define TYPE isl_pw_multi_aff
+#include "isl_type_check_match_range_multi_val.c"
+
/* Scale the elements of "pma" by the corresponding elements of "mv".
*/
__isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_multi_val(
@@ -6710,12 +6714,8 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_multi_val(
isl_bool equal_params;
pma = isl_pw_multi_aff_cow(pma);
- if (!pma || !mv)
+ if (isl_pw_multi_aff_check_match_range_multi_val(pma, mv) < 0)
goto error;
- if (!isl_space_tuple_is_equal(pma->dim, isl_dim_out,
- mv->space, isl_dim_set))
- isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid,
- "spaces don't match", goto error);
equal_params = isl_space_has_equal_params(pma->dim, mv->space);
if (equal_params < 0)
goto error;
diff --git a/isl_multi_arith_templ.c b/isl_multi_arith_templ.c
index 6765bd23cb..76cdcdafec 100644
--- a/isl_multi_arith_templ.c
+++ b/isl_multi_arith_templ.c
@@ -106,6 +106,10 @@ error:
return FN(MULTI(BASE),free)(multi);
}
+#undef TYPE
+#define TYPE MULTI(BASE)
+#include "isl_type_check_match_range_multi_val.c"
+
/* Multiply the elements of "multi" by the corresponding element of "mv"
* and return the result.
*/
@@ -114,14 +118,9 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)(
{
int i;
- if (!multi || !mv)
+ if (FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
goto error;
- if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
- mv->space, isl_dim_set))
- isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
- "spaces don't match", goto error);
-
multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
goto error;
@@ -150,14 +149,9 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)(
{
int i;
- if (!multi || !mv)
+ if (FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
goto error;
- if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
- mv->space, isl_dim_set))
- isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
- "spaces don't match", goto error);
-
multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;
@@ -186,14 +180,9 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),mod_multi_val)(
{
int i;
- if (!multi || !mv)
+ if (FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
goto error;
- if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
- mv->space, isl_dim_set))
- isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
- "spaces don't match", goto error);
-
multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
goto error;
diff --git a/isl_type_check_match_range_multi_val.c b/isl_type_check_match_range_multi_val.c
new file mode 100644
index 0000000000..3b60e4db5b
--- /dev/null
+++ b/isl_type_check_match_range_multi_val.c
@@ -0,0 +1,32 @@
+#define xFN(TYPE,NAME) TYPE ## _ ## NAME
+#define FN(TYPE,NAME) xFN(TYPE,NAME)
+
+/* Does the range space of "obj" match the space of "mv" (ignoring parameters)?
+ */
+static isl_bool FN(TYPE,match_range_multi_val)(__isl_keep TYPE *obj,
+ __isl_keep isl_multi_val *mv)
+{
+ isl_space *space, *mv_space;
+
+ space = FN(TYPE,peek_space)(obj);
+ mv_space = isl_multi_val_peek_space(mv);
+ return isl_space_tuple_is_equal(space, isl_dim_out,
+ mv_space, isl_dim_set);
+}
+
+/* Check that the range space of "obj" matches the space of "mv"
+ * (ignoring parameters).
+ */
+static isl_stat FN(TYPE,check_match_range_multi_val)(__isl_keep TYPE *obj,
+ __isl_keep isl_multi_val *mv)
+{
+ isl_bool equal;
+
+ equal = FN(TYPE,match_range_multi_val)(obj, mv);
+ if (equal < 0)
+ return isl_stat_error;
+ if (!equal)
+ isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
+ "spaces don't match", return isl_stat_error);
+ return isl_stat_ok;
+}
--
2.25.1