[PATCH 01/39] isl_multi_*_apply_aligned_*: use isl_multi_*_size

6 views
Skip to first unread message

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:22 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_apply_templ.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/isl_multi_apply_templ.c b/isl_multi_apply_templ.c
index 870f2676c4..d8e3b03893 100644
--- a/isl_multi_apply_templ.c
+++ b/isl_multi_apply_templ.c
@@ -19,12 +19,14 @@ __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply_aligned),APPLY_DOMBASE)(
__isl_take MULTI(BASE) *multi, __isl_take APPLY_DOM *set,
__isl_give EL *(*fn)(EL *el, __isl_take APPLY_DOM *set))
{
+ isl_size n;
int i;

- if (!multi || !set)
+ n = FN(MULTI(BASE),size)(multi);
+ if (n < 0 || !set)
goto error;

- if (multi->n == 0) {
+ if (n == 0) {
FN(APPLY_DOM,free)(set);
return multi;
}
@@ -33,7 +35,7 @@ __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply_aligned),APPLY_DOMBASE)(
if (!multi)
goto error;

- for (i = 0; i < multi->n; ++i) {
+ for (i = 0; i < n; ++i) {
multi->u.p[i] = fn(multi->u.p[i], FN(APPLY_DOM,copy)(set));
if (!multi->u.p[i])
goto error;
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:24 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_arith_templ.c | 47 ++++++++++++++---------------------------
1 file changed, 16 insertions(+), 31 deletions(-)

diff --git a/isl_multi_arith_templ.c b/isl_multi_arith_templ.c
index 76cdcdafec..83f775709b 100644
--- a/isl_multi_arith_templ.c
+++ b/isl_multi_arith_templ.c
@@ -29,10 +29,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),sub)(__isl_take MULTI(BASE) *multi1,
return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,sub));
}

-/* Multiply the elements of "multi" by "v" and return the result.
+/* Depending on "fn", multiply or divide the elements of "multi" by "v" and
+ * return the result.
*/
-__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
- __isl_take isl_val *v)
+static __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val_fn)(
+ __isl_take MULTI(BASE) *multi, __isl_take isl_val *v,
+ __isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v))
{
int i;

@@ -53,8 +55,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
return NULL;

for (i = 0; i < multi->n; ++i) {
- multi->u.p[i] = FN(EL,scale_val)(multi->u.p[i],
- isl_val_copy(v));
+ multi->u.p[i] = fn(multi->u.p[i], isl_val_copy(v));
if (!multi->u.p[i])
goto error;
}
@@ -66,41 +67,25 @@ error:
return FN(MULTI(BASE),free)(multi);
}

+/* Multiply the elements of "multi" by "v" and return the result.
+ */
+__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
+ __isl_take isl_val *v)
+{
+ return FN(MULTI(BASE),scale_val_fn)(multi, v, &FN(EL,scale_val));
+}
+
/* Divide the elements of "multi" by "v" and return the result.
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_val *v)
{
- int i;
-
- if (!multi || !v)
+ if (!v)
goto error;
-
- if (isl_val_is_one(v)) {
- isl_val_free(v);
- return multi;
- }
-
- if (!isl_val_is_rat(v))
- isl_die(isl_val_get_ctx(v), isl_error_invalid,
- "expecting rational factor", goto error);
if (isl_val_is_zero(v))
isl_die(isl_val_get_ctx(v), isl_error_invalid,
"cannot scale down by zero", goto error);
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
-
- for (i = 0; i < multi->n; ++i) {
- multi->u.p[i] = FN(EL,scale_down_val)(multi->u.p[i],
- isl_val_copy(v));
- if (!multi->u.p[i])
- goto error;
- }
-
- isl_val_free(v);
- return multi;
+ return FN(MULTI(BASE),scale_val_fn)(multi, v, &FN(EL,scale_down_val));
error:
isl_val_free(v);
return FN(MULTI(BASE),free)(multi);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:25 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This will be reused for other multi expressions in upcoming commits.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
Makefile.am | 1 +
isl_multi_bin_val_templ.c | 35 +++++++++++++++++++++++++++++++++++
isl_val.c | 29 +----------------------------
3 files changed, 37 insertions(+), 28 deletions(-)
create mode 100644 isl_multi_bin_val_templ.c

diff --git a/Makefile.am b/Makefile.am
index 17f92489d5..08e4343987 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -535,6 +535,7 @@ EXTRA_DIST = \
isl_multi_apply_set.c \
isl_multi_apply_union_set.c \
isl_multi_arith_templ.c \
+ isl_multi_bin_val_templ.c \
isl_multi_bind_domain_templ.c \
isl_multi_cmp.c \
isl_multi_coalesce.c \
diff --git a/isl_multi_bin_val_templ.c b/isl_multi_bin_val_templ.c
new file mode 100644
index 0000000000..7cce2a0e7c
--- /dev/null
+++ b/isl_multi_bin_val_templ.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2013 Ecole Normale Superieure
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege,
+ * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
+ */
+
+/* Apply "fn" to each of the elements of "multi" with as second argument "v".
+ */
+static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_val)(
+ __isl_take MULTI(BASE) *multi,
+ __isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v),
+ __isl_take isl_val *v)
+{
+ int i;
+
+ multi = FN(MULTI(BASE),cow)(multi);
+ if (!multi || !v)
+ goto error;
+
+ for (i = 0; i < multi->n; ++i) {
+ multi->u.p[i] = fn(multi->u.p[i], isl_val_copy(v));
+ if (!multi->u.p[i])
+ goto error;
+ }
+
+ isl_val_free(v);
+ return multi;
+error:
+ isl_val_free(v);
+ FN(MULTI(BASE),free)(multi);
+ return NULL;
+}
diff --git a/isl_val.c b/isl_val.c
index 3744aa74d0..718a39a591 100644
--- a/isl_val.c
+++ b/isl_val.c
@@ -1577,6 +1577,7 @@ __isl_give isl_val *isl_val_zero_on_domain(__isl_take isl_local_space *ls)
#include <isl_multi_no_domain_templ.c>
#include <isl_multi_no_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_bin_val_templ.c>
#include <isl_multi_arith_templ.c>
#include <isl_multi_dim_id_templ.c>
#include <isl_multi_dims.c>
@@ -1594,34 +1595,6 @@ isl_bool isl_multi_val_is_zero(__isl_keep isl_multi_val *mv)
return isl_multi_val_every(mv, &isl_val_is_zero);
}

-/* Apply "fn" to each of the elements of "mv" with as second argument "v".
- */
-static __isl_give isl_multi_val *isl_multi_val_fn_val(
- __isl_take isl_multi_val *mv,
- __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
- __isl_take isl_val *v2),
- __isl_take isl_val *v)
-{
- int i;
-
- mv = isl_multi_val_cow(mv);
- if (!mv || !v)
- goto error;
-
- for (i = 0; i < mv->n; ++i) {
- mv->u.p[i] = fn(mv->u.p[i], isl_val_copy(v));
- if (!mv->u.p[i])
- goto error;
- }
-
- isl_val_free(v);
- return mv;
-error:
- isl_val_free(v);
- isl_multi_val_free(mv);
- return NULL;
-}
-
/* Add "v" to each of the elements of "mv".
*/
__isl_give isl_multi_val *isl_multi_val_add_val(__isl_take isl_multi_val *mv,
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:26 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_bin_val_templ.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/isl_multi_bin_val_templ.c b/isl_multi_bin_val_templ.c
index 7cce2a0e7c..fe74c62a6a 100644
--- a/isl_multi_bin_val_templ.c
+++ b/isl_multi_bin_val_templ.c
@@ -14,13 +14,22 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_val)(
__isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v),
__isl_take isl_val *v)
{
+ isl_size n;
int i;

+ n = FN(MULTI(BASE),size)(multi);
+ if (n < 0 || !v)
+ goto error;
+ if (n == 0) {
+ isl_val_free(v);
+ return multi;
+ }
+
multi = FN(MULTI(BASE),cow)(multi);
- if (!multi || !v)
+ if (!multi)
goto error;

- for (i = 0; i < multi->n; ++i) {
+ for (i = 0; i < n; ++i) {
multi->u.p[i] = fn(multi->u.p[i], isl_val_copy(v));

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:27 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 2 ++
isl_multi_add_constant_templ.c | 21 +++------------------
2 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 3542492aff..9c97f129bb 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -3873,6 +3873,7 @@ static __isl_give isl_basic_set *isl_multi_aff_domain(

#include <isl_multi_no_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_bin_val_templ.c>
#include <isl_multi_add_constant_templ.c>
#include <isl_multi_apply_set.c>
#include <isl_multi_arith_templ.c>
@@ -6560,6 +6561,7 @@ error:
#include <isl_multi_explicit_domain.c>
#include <isl_multi_pw_aff_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_bin_val_templ.c>
#include <isl_multi_add_constant_templ.c>
#include <isl_multi_apply_set.c>
#include <isl_multi_arith_templ.c>
diff --git a/isl_multi_add_constant_templ.c b/isl_multi_add_constant_templ.c
index fa4971fb73..75dd69ac87 100644
--- a/isl_multi_add_constant_templ.c
+++ b/isl_multi_add_constant_templ.c
@@ -15,31 +15,16 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),add_constant_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_val *v)
{
isl_bool zero;
- isl_size n;
- int i;

zero = isl_val_is_zero(v);
- n = FN(MULTI(BASE),size)(multi);
- if (zero < 0 || n < 0)
+ if (zero < 0)
goto error;
- if (zero || n == 0) {
+ if (zero) {
isl_val_free(v);
return multi;
}

- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- goto error;
-
- for (i = 0; i < n; ++i) {
- multi->u.p[i] = FN(EL,add_constant_val)(multi->u.p[i],
- isl_val_copy(v));
- if (!multi->u.p[i])
- goto error;
- }
-
- isl_val_free(v);
- return multi;
+ return FN(MULTI(BASE),fn_val)(multi, &FN(EL,add_constant_val), v);
error:
FN(MULTI(BASE),free)(multi);
isl_val_free(v);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:28 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 1 +
isl_multi_arith_templ.c | 15 +--------------
2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 9c97f129bb..e4acdd2ec7 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -8676,6 +8676,7 @@ error:
#include <isl_multi_explicit_domain.c>
#include <isl_multi_union_pw_aff_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_bin_val_templ.c>
#include <isl_multi_apply_set.c>
#include <isl_multi_apply_union_set.c>
#include <isl_multi_arith_templ.c>
diff --git a/isl_multi_arith_templ.c b/isl_multi_arith_templ.c
index 83f775709b..a5a5d9719e 100644
--- a/isl_multi_arith_templ.c
+++ b/isl_multi_arith_templ.c
@@ -36,8 +36,6 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val_fn)(
__isl_take MULTI(BASE) *multi, __isl_take isl_val *v,
__isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v))
{
- int i;
-
if (!multi || !v)
goto error;

@@ -50,18 +48,7 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val_fn)(
isl_die(isl_val_get_ctx(v), isl_error_invalid,
"expecting rational factor", goto error);

- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
-
- for (i = 0; i < multi->n; ++i) {
- multi->u.p[i] = fn(multi->u.p[i], isl_val_copy(v));
- if (!multi->u.p[i])
- goto error;
- }
-
- isl_val_free(v);
- return multi;
+ return FN(MULTI(BASE),fn_val)(multi, fn, v);

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:29 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_add_constant_templ.c | 31 +++-----------
isl_multi_arith_templ.c | 76 ++--------------------------------
isl_multi_bin_val_templ.c | 42 +++++++++++++++++++
3 files changed, 50 insertions(+), 99 deletions(-)

diff --git a/isl_multi_add_constant_templ.c b/isl_multi_add_constant_templ.c
index 75dd69ac87..a54f3fa720 100644
--- a/isl_multi_add_constant_templ.c
+++ b/isl_multi_add_constant_templ.c
@@ -37,40 +37,19 @@ error:
__isl_give MULTI(BASE) *FN(MULTI(BASE),add_constant_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
- isl_space *multi_space, *mv_space;
- isl_bool zero, equal;
- isl_size n;
- int i;
+ isl_bool zero;

zero = isl_multi_val_is_zero(mv);
- n = FN(MULTI(BASE),size)(multi);
- multi_space = FN(MULTI(BASE),peek_space)(multi);
- mv_space = isl_multi_val_peek_space(mv);
- equal = isl_space_tuple_is_equal(multi_space, isl_dim_out,
- mv_space, isl_dim_out);
- if (zero < 0 || n < 0 || equal < 0)
+ if (zero < 0)
goto error;
- if (!equal)
- isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
- "spaces don't match", goto error);
- if (zero || n == 0) {
+ if (zero) {
isl_multi_val_free(mv);
return multi;
}

- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- goto error;
+ return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,add_constant_val),
+ mv);

- for (i = 0; i < n; ++i) {
- isl_val *v = isl_multi_val_get_at(mv, i);
- multi->u.p[i] = FN(EL,add_constant_val)(multi->u.p[i], v);
- if (!multi->u.p[i])
- goto error;
- }
-
- isl_multi_val_free(mv);
- return multi;
error:
FN(MULTI(BASE),free)(multi);
isl_multi_val_free(mv);
diff --git a/isl_multi_arith_templ.c b/isl_multi_arith_templ.c
index a5a5d9719e..dd9f148a88 100644
--- a/isl_multi_arith_templ.c
+++ b/isl_multi_arith_templ.c
@@ -78,39 +78,13 @@ 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.
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
- int i;
-
- if (FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
- goto error;
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- goto error;
-
- for (i = 0; i < multi->n; ++i) {
- isl_val *v;
-
- v = isl_multi_val_get_val(mv, i);
- multi->u.p[i] = FN(EL,scale_val)(multi->u.p[i], v);
- if (!multi->u.p[i])
- goto error;
- }
-
- isl_multi_val_free(mv);
- return multi;
-error:
- isl_multi_val_free(mv);
- return FN(MULTI(BASE),free)(multi);
+ return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,scale_val), mv);
}

/* Divide the elements of "multi" by the corresponding element of "mv"
@@ -119,29 +93,7 @@ error:
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
- int i;
-
- if (FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
- goto error;
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
-
- for (i = 0; i < multi->n; ++i) {
- isl_val *v;
-
- v = isl_multi_val_get_val(mv, i);
- multi->u.p[i] = FN(EL,scale_down_val)(multi->u.p[i], v);
- if (!multi->u.p[i])
- goto error;
- }
-
- isl_multi_val_free(mv);
- return multi;
-error:
- isl_multi_val_free(mv);
- return FN(MULTI(BASE),free)(multi);
+ return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,scale_down_val), mv);
}

/* Compute the residues of the elements of "multi" modulo
@@ -150,29 +102,7 @@ error:
__isl_give MULTI(BASE) *FN(MULTI(BASE),mod_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
- int i;
-
- if (FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
- goto error;
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- goto error;
-
- for (i = 0; i < multi->n; ++i) {
- isl_val *v;
-
- v = isl_multi_val_get_val(mv, i);
- multi->u.p[i] = FN(EL,mod_val)(multi->u.p[i], v);
- if (!multi->u.p[i])
- goto error;
- }
-
- isl_multi_val_free(mv);
- return multi;
-error:
- isl_multi_val_free(mv);
- return FN(MULTI(BASE),free)(multi);
+ return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,mod_val), mv);
}

/* Return the opposite of "multi".
diff --git a/isl_multi_bin_val_templ.c b/isl_multi_bin_val_templ.c
index fe74c62a6a..96023439cd 100644
--- a/isl_multi_bin_val_templ.c
+++ b/isl_multi_bin_val_templ.c
@@ -42,3 +42,45 @@ error:
FN(MULTI(BASE),free)(multi);
return NULL;
}
+
+#undef TYPE
+#define TYPE MULTI(BASE)
+#include "isl_type_check_match_range_multi_val.c"
+
+/* Elementwise apply "fn" to "multi" and "mv".
+ */
+static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_multi_val)(
+ __isl_take MULTI(BASE) *multi,
+ __isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v),
+ __isl_take isl_multi_val *mv)
+{
+ isl_size n;
+ int i;
+
+ n = FN(MULTI(BASE),size)(multi);
+ if (n < 0 || FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
+ goto error;
+ if (n == 0) {
+ isl_multi_val_free(mv);
+ return multi;
+ }
+
+ multi = FN(MULTI(BASE),cow)(multi);
+ if (!multi)
+ goto error;
+
+ for (i = 0; i < n; ++i) {
+ isl_val *v;
+
+ v = isl_multi_val_get_val(mv, i);
+ multi->u.p[i] = fn(multi->u.p[i], v);
+ if (!multi->u.p[i])
+ goto error;
+ }
+
+ isl_multi_val_free(mv);
+ return multi;
+error:
+ isl_multi_val_free(mv);
+ return FN(MULTI(BASE),free)(multi);
+}
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:30 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
Makefile.am | 1 +
isl_aff.c | 3 +++
isl_multi_arith_templ.c | 14 +-------------
isl_multi_floor.c | 14 +-------------
isl_multi_un_op_templ.c | 30 ++++++++++++++++++++++++++++++
isl_val.c | 1 +
6 files changed, 37 insertions(+), 26 deletions(-)
create mode 100644 isl_multi_un_op_templ.c

diff --git a/Makefile.am b/Makefile.am
index 08e4343987..3b1f074975 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -558,6 +558,7 @@ EXTRA_DIST = \
isl_multi_read_no_explicit_domain_templ.c \
isl_multi_splice_templ.c \
isl_multi_tuple_id_templ.c \
+ isl_multi_un_op_templ.c \
isl_multi_unbind_params_templ.c \
isl_multi_union_add_templ.c \
isl_multi_zero_templ.c \
diff --git a/isl_aff.c b/isl_aff.c
index e4acdd2ec7..96aa756d65 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -3873,6 +3873,7 @@ static __isl_give isl_basic_set *isl_multi_aff_domain(

#include <isl_multi_no_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_un_op_templ.c>
#include <isl_multi_bin_val_templ.c>
#include <isl_multi_add_constant_templ.c>
#include <isl_multi_apply_set.c>
@@ -6561,6 +6562,7 @@ error:
#include <isl_multi_explicit_domain.c>
#include <isl_multi_pw_aff_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_un_op_templ.c>
#include <isl_multi_bin_val_templ.c>
#include <isl_multi_add_constant_templ.c>
#include <isl_multi_apply_set.c>
@@ -8676,6 +8678,7 @@ error:
#include <isl_multi_explicit_domain.c>
#include <isl_multi_union_pw_aff_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_un_op_templ.c>
#include <isl_multi_bin_val_templ.c>
#include <isl_multi_apply_set.c>
#include <isl_multi_apply_union_set.c>
diff --git a/isl_multi_arith_templ.c b/isl_multi_arith_templ.c
index dd9f148a88..dd497138a1 100644
--- a/isl_multi_arith_templ.c
+++ b/isl_multi_arith_templ.c
@@ -109,17 +109,5 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),mod_multi_val)(
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),neg)(__isl_take MULTI(BASE) *multi)
{
- int i;
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
-
- for (i = 0; i < multi->n; ++i) {
- multi->u.p[i] = FN(EL,neg)(multi->u.p[i]);
- if (!multi->u.p[i])
- return FN(MULTI(BASE),free)(multi);
- }
-
- return multi;
+ return FN(MULTI(BASE),un_op)(multi, &FN(EL,neg));
}
diff --git a/isl_multi_floor.c b/isl_multi_floor.c
index b9a8898831..0d8420f072 100644
--- a/isl_multi_floor.c
+++ b/isl_multi_floor.c
@@ -13,17 +13,5 @@
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),floor)(__isl_take MULTI(BASE) *multi)
{
- int i;
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
-
- for (i = 0; i < multi->n; ++i) {
- multi->u.p[i] = FN(EL,floor)(multi->u.p[i]);
- if (!multi->u.p[i])
- return FN(MULTI(BASE),free)(multi);
- }
-
- return multi;
+ return FN(MULTI(BASE),un_op)(multi, &FN(EL,floor));
}
diff --git a/isl_multi_un_op_templ.c b/isl_multi_un_op_templ.c
new file mode 100644
index 0000000000..9ffcceec31
--- /dev/null
+++ b/isl_multi_un_op_templ.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2014 Ecole Normale Superieure
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege,
+ * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
+ */
+
+#include <isl_multi_macro.h>
+
+/* Apply "fn" to each of the base expressions of "multi".
+ */
+static __isl_give MULTI(BASE) *FN(MULTI(BASE),un_op)(
+ __isl_take MULTI(BASE) *multi, __isl_give EL *(*fn)(__isl_take EL *el))
+{
+ int i;
+
+ multi = FN(MULTI(BASE),cow)(multi);
+ if (!multi)
+ return NULL;
+
+ for (i = 0; i < multi->n; ++i) {
+ multi->u.p[i] = fn(multi->u.p[i]);
+ if (!multi->u.p[i])
+ return FN(MULTI(BASE),free)(multi);
+ }
+
+ return multi;
+}
diff --git a/isl_val.c b/isl_val.c
index 718a39a591..8b77622d7f 100644
--- a/isl_val.c
+++ b/isl_val.c
@@ -1577,6 +1577,7 @@ __isl_give isl_val *isl_val_zero_on_domain(__isl_take isl_local_space *ls)
#include <isl_multi_no_domain_templ.c>
#include <isl_multi_no_explicit_domain.c>
#include <isl_multi_templ.c>
+#include <isl_multi_un_op_templ.c>
#include <isl_multi_bin_val_templ.c>
#include <isl_multi_arith_templ.c>
#include <isl_multi_dim_id_templ.c>
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:31 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_un_op_templ.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/isl_multi_un_op_templ.c b/isl_multi_un_op_templ.c
index 9ffcceec31..1273cd780a 100644
--- a/isl_multi_un_op_templ.c
+++ b/isl_multi_un_op_templ.c
@@ -15,12 +15,14 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),un_op)(
__isl_take MULTI(BASE) *multi, __isl_give EL *(*fn)(__isl_take EL *el))
{
int i;
+ isl_size n;

multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
+ n = FN(MULTI(BASE),size)(multi);
+ if (n < 0)
+ return FN(MULTI(BASE),free)(multi);

- for (i = 0; i < multi->n; ++i) {
+ for (i = 0; i < n; ++i) {
multi->u.p[i] = fn(multi->u.p[i]);
if (!multi->u.p[i])
return FN(MULTI(BASE),free)(multi);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:32 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

The function isl_multi_*_reset_space already performs this call.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_dim_id_templ.c | 8 --------
1 file changed, 8 deletions(-)

diff --git a/isl_multi_dim_id_templ.c b/isl_multi_dim_id_templ.c
index 80dd7db587..669bec8923 100644
--- a/isl_multi_dim_id_templ.c
+++ b/isl_multi_dim_id_templ.c
@@ -77,16 +77,8 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_id)(
{
isl_space *space;

- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi || !id)
- goto error;
-
space = FN(MULTI(BASE),get_space)(multi);
space = isl_space_set_dim_id(space, type, pos, id);

return FN(MULTI(BASE),reset_space)(multi, space);
-error:
- isl_id_free(id);
- FN(MULTI(BASE),free)(multi);
- return NULL;
}
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:33 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This simplifies the code, mimicking the isl_multi_*_set_dim_id
implementation.

Note that isl_multi_*_reset_space was not available
when isl_multi_*_set_dim_name was introduced in isl-0.07-194-g3d0da01fea
(add isl_multi_aff, Thu Sep 1 11:49:19 2011 +0200).

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_dim_id_templ.c | 22 ++++------------------
1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/isl_multi_dim_id_templ.c b/isl_multi_dim_id_templ.c
index 669bec8923..5103edf866 100644
--- a/isl_multi_dim_id_templ.c
+++ b/isl_multi_dim_id_templ.c
@@ -47,26 +47,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_name)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned pos, const char *s)
{
- int i;
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
-
- multi->space = isl_space_set_dim_name(multi->space, type, pos, s);
- if (!multi->space)
- return FN(MULTI(BASE),free)(multi);
+ isl_space *space;

- if (type == isl_dim_out)
- return multi;
- for (i = 0; i < multi->n; ++i) {
- multi->u.p[i] = FN(EL,set_dim_name)(multi->u.p[i],
- type, pos, s);
- if (!multi->u.p[i])
- return FN(MULTI(BASE),free)(multi);
- }
+ space = FN(MULTI(BASE),get_space)(multi);
+ space = isl_space_set_dim_name(space, type, pos, s);

- return multi;
+ return FN(MULTI(BASE),reset_space)(multi, space);
}

/* Set the id of the given dimension of "multi" to "id".
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:35 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_dims.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/isl_multi_dims.c b/isl_multi_dims.c
index a2775eab9f..749146b312 100644
--- a/isl_multi_dims.c
+++ b/isl_multi_dims.c
@@ -45,10 +45,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned first, unsigned n)
{
+ isl_size size;
int i;

- if (!multi)
- return NULL;
+ size = FN(MULTI(BASE),size)(multi);
+ if (size < 0)
+ return FN(MULTI(BASE),free)(multi);
if (type == isl_dim_out)
isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
"cannot insert output/set dimensions",
@@ -69,7 +71,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
if (!multi)
return NULL;

- for (i = 0; i < multi->n; ++i) {
+ for (i = 0; i < size; ++i) {
multi->u.p[i] = FN(EL,insert_dims)(multi->u.p[i],
type, first, n);
if (!multi->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:36 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_move_dims_templ.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/isl_multi_move_dims_templ.c b/isl_multi_move_dims_templ.c
index 9c88085794..3519e665c8 100644
--- a/isl_multi_move_dims_templ.c
+++ b/isl_multi_move_dims_templ.c
@@ -20,10 +20,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
enum isl_dim_type dst_type, unsigned dst_pos,
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
+ isl_size size;
int i;

- if (!multi)
- return NULL;
+ size = FN(MULTI(BASE),size)(multi);
+ if (size < 0)
+ return FN(MULTI(BASE),free)(multi);

if (n == 0 &&
!isl_space_is_named_or_nested(multi->space, src_type) &&
@@ -59,7 +61,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
if (!multi)
return NULL;

- for (i = 0; i < multi->n; ++i) {
+ for (i = 0; i < size; ++i) {
multi->u.p[i] = FN(EL,move_dims)(multi->u.p[i],
dst_type, dst_pos,
src_type, src_pos, n);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:37 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index 3777024d2e..cec379dc24 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -293,13 +293,15 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space_and_domain)(
__isl_take MULTI(BASE) *multi, __isl_take isl_space *space,
__isl_take isl_space *domain)
{
+ isl_size n;
int i;

multi = FN(MULTI(BASE),cow)(multi);
- if (!multi || !space || !domain)
+ n = FN(MULTI(BASE),size)(multi);
+ if (n < 0 || !space || !domain)
goto error;

- for (i = 0; i < multi->n; ++i) {
+ for (i = 0; i < n; ++i) {
multi->u.p[i] = FN(EL,reset_domain_space)(multi->u.p[i],
isl_space_copy(domain));
if (!multi->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:38 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index cec379dc24..78c1a5fbc3 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -362,13 +362,15 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),realign_domain)(
__isl_take MULTI(BASE) *multi, __isl_take isl_reordering *exp)
{
int i;
+ isl_size n;
isl_space *space;

multi = FN(MULTI(BASE),cow)(multi);
- if (!multi || !exp)
+ n = FN(MULTI(BASE),size)(multi);
+ if (n < 0 || !exp)
goto error;

- for (i = 0; i < multi->n; ++i) {
+ for (i = 0; i < n; ++i) {
multi->u.p[i] = FN(EL,realign_domain)(multi->u.p[i],
isl_reordering_copy(exp));
if (!multi->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:39 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

The handling of output dimensions is quite different from
that of other dimensions, so it is better to separate it out.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index 78c1a5fbc3..ba13ff1a2a 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -492,6 +492,29 @@ __isl_give MULTI(BASE) *FN(isl_space_multi,BASE)(__isl_take isl_space *space,
return FN(FN(MULTI(BASE),from),LIST(BASE))(space, list);
}

+/* Drop the "n" output dimensions of "multi" starting at "first",
+ * where the space is assumed to have been adjusted already.
+ */
+static __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_output_dims)(
+ __isl_take MULTI(BASE) *multi, unsigned first, unsigned n)
+{
+ int i;
+
+ multi = FN(MULTI(BASE),cow)(multi);
+ if (!multi)
+ return NULL;
+
+ for (i = 0; i < n; ++i)
+ FN(EL,free)(multi->u.p[first + i]);
+ for (i = first; i + n < multi->n; ++i)
+ multi->u.p[i] = multi->u.p[i + n];
+ multi->n -= n;
+ if (n > 0 && FN(MULTI(BASE),has_explicit_domain)(multi))
+ multi = FN(MULTI(BASE),init_explicit_domain)(multi);
+
+ return multi;
+}
+
__isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned first, unsigned n)
@@ -506,17 +529,8 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
if (!multi->space)
return FN(MULTI(BASE),free)(multi);

- if (type == isl_dim_out) {
- for (i = 0; i < n; ++i)
- FN(EL,free)(multi->u.p[first + i]);
- for (i = first; i + n < multi->n; ++i)
- multi->u.p[i] = multi->u.p[i + n];
- multi->n -= n;
- if (n > 0 && FN(MULTI(BASE),has_explicit_domain)(multi))
- multi = FN(MULTI(BASE),init_explicit_domain)(multi);
-
- return multi;
- }
+ if (type == isl_dim_out)
+ return FN(MULTI(BASE),drop_output_dims)(multi, first, n);

if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),drop_explicit_domain_dims)(multi,
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:40 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index ba13ff1a2a..aa2eb01007 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -519,6 +519,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned first, unsigned n)
{
+ isl_size size;
int i;

multi = FN(MULTI(BASE),cow)(multi);
@@ -535,10 +536,11 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),drop_explicit_domain_dims)(multi,
type, first, n);
- if (!multi)
- return NULL;

- for (i = 0; i < multi->n; ++i) {
+ size = FN(MULTI(BASE),size)(multi);
+ if (size < 0)
+ return FN(MULTI(BASE),free)(multi);
+ for (i = 0; i < size; ++i) {
multi->u.p[i] = FN(EL,drop_dims)(multi->u.p[i], type, first, n);
if (!multi->u.p[i])
return FN(MULTI(BASE),free)(multi);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:41 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index aa2eb01007..31b14263d9 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -793,14 +793,16 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)(
__isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
__isl_give EL *(*fn)(__isl_take EL *, __isl_take EL *))
{
+ isl_size n;
int i;

FN(MULTI(BASE),align_params_bin)(&multi1, &multi2);
multi1 = FN(MULTI(BASE),cow)(multi1);
- if (FN(MULTI(BASE),check_equal_space)(multi1, multi2) < 0)
+ n = FN(MULTI(BASE),size)(multi1);
+ if (n < 0 || FN(MULTI(BASE),check_equal_space)(multi1, multi2) < 0)
goto error;

- for (i = 0; i < multi1->n; ++i) {
+ for (i = 0; i < n; ++i) {
multi1->u.p[i] = fn(multi1->u.p[i],
FN(EL,copy)(multi2->u.p[i]));
if (!multi1->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:43 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 96aa756d65..351dd9b29f 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -4277,13 +4277,15 @@ __isl_give isl_pw_multi_aff *isl_space_identity_pw_multi_aff_on_domain(
static __isl_give isl_multi_aff *isl_multi_aff_substitute_equalities(
__isl_take isl_multi_aff *maff, __isl_take isl_basic_set *eq)
{
+ isl_size n;
int i;

maff = isl_multi_aff_cow(maff);
- if (!maff || !eq)
+ n = isl_multi_aff_size(maff);
+ if (n < 0 || !eq)
goto error;

- for (i = 0; i < maff->n; ++i) {
+ for (i = 0; i < n; ++i) {
maff->u.p[i] = isl_aff_substitute_equalities(maff->u.p[i],
isl_basic_set_copy(eq));
if (!maff->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:44 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 351dd9b29f..37f311846b 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -4303,13 +4303,15 @@ error:
__isl_give isl_multi_aff *isl_multi_aff_scale(__isl_take isl_multi_aff *maff,
isl_int f)
{
+ isl_size n;
int i;

maff = isl_multi_aff_cow(maff);
- if (!maff)
- return NULL;
+ n = isl_multi_aff_size(maff);
+ if (n < 0)
+ return isl_multi_aff_free(maff);

- for (i = 0; i < maff->n; ++i) {
+ for (i = 0; i < n; ++i) {
maff->u.p[i] = isl_aff_scale(maff->u.p[i], f);
if (!maff->u.p[i])
return isl_multi_aff_free(maff);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:45 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 37f311846b..8268d40152 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -5690,16 +5690,18 @@ __isl_give isl_multi_aff *isl_multi_aff_substitute(
__isl_take isl_multi_aff *maff, enum isl_dim_type type, unsigned pos,
__isl_keep isl_aff *subs)
{
+ isl_size n;
int i;

maff = isl_multi_aff_cow(maff);
- if (!maff || !subs)
+ n = isl_multi_aff_size(maff);
+ if (n < 0 || !subs)
return isl_multi_aff_free(maff);

if (type == isl_dim_in)
type = isl_dim_set;

- for (i = 0; i < maff->n; ++i) {
+ for (i = 0; i < n; ++i) {
maff->u.p[i] = isl_aff_substitute(maff->u.p[i],
type, pos, subs);
if (!maff->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:46 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 8268d40152..b5603eff6d 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -5970,18 +5970,20 @@ __isl_give isl_multi_aff *isl_multi_aff_pullback_multi_aff(
__isl_take isl_multi_aff *ma1, __isl_take isl_multi_aff *ma2)
{
int i;
+ isl_size n;
isl_space *space = NULL;

isl_multi_aff_align_params_bin(&ma1, &ma2);
ma2 = isl_multi_aff_align_divs(ma2);
ma1 = isl_multi_aff_cow(ma1);
- if (!ma1 || !ma2)
+ n = isl_multi_aff_size(ma1);
+ if (n < 0 || !ma2)
goto error;

space = isl_space_join(isl_multi_aff_get_space(ma2),
isl_multi_aff_get_space(ma1));

- for (i = 0; i < ma1->n; ++i) {
+ for (i = 0; i < n; ++i) {
ma1->u.p[i] = isl_aff_pullback_multi_aff(ma1->u.p[i],
isl_multi_aff_copy(ma2));
if (!ma1->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:47 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index b5603eff6d..7c0e337443 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -6060,19 +6060,21 @@ error:
__isl_give isl_multi_aff *isl_multi_aff_align_divs(
__isl_take isl_multi_aff *maff)
{
+ isl_size n;
int i;

- if (!maff)
- return NULL;
- if (maff->n == 0)
+ n = isl_multi_aff_size(maff);
+ if (n < 0)
+ return isl_multi_aff_free(maff);
+ if (n == 0)
return maff;
maff = isl_multi_aff_cow(maff);
if (!maff)
return NULL;

- for (i = 1; i < maff->n; ++i)
+ for (i = 1; i < n; ++i)
maff->u.p[0] = isl_aff_align_divs(maff->u.p[0], maff->u.p[i]);
- for (i = 1; i < maff->n; ++i) {
+ for (i = 1; i < n; ++i) {
maff->u.p[i] = isl_aff_align_divs(maff->u.p[i], maff->u.p[0]);
if (!maff->u.p[i])
return isl_multi_aff_free(maff);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:48 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This was missing from isl-0.20-394-g7872695ec9 (extract out
shared isl_multi_*_check_range, Mon Aug 13 16:48:50 2018 +0200).

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index 31b14263d9..a417ff0b91 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -160,11 +160,8 @@ static
*/
__isl_give EL *FN(MULTI(BASE),get_at)(__isl_keep MULTI(BASE) *multi, int pos)
{
- isl_ctx *ctx;
-
if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0)
return NULL;
- ctx = FN(MULTI(BASE),get_ctx)(multi);
return FN(EL,copy)(multi->u.p[pos]);
}

--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:49 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This function will be reused in the next commit.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index a417ff0b91..e06898912c 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -156,13 +156,21 @@ isl_size FN(MULTI(BASE),size)(__isl_keep MULTI(BASE) *multi)
static
#include "check_type_range_templ.c"

-/* Return a copy of the base expression at position "pos" in "multi".
+/* Return the base expression at position "pos" in "multi".
*/
-__isl_give EL *FN(MULTI(BASE),get_at)(__isl_keep MULTI(BASE) *multi, int pos)
+static __isl_give EL *FN(MULTI(BASE),peek_at)(__isl_keep MULTI(BASE) *multi,
+ int pos)
{
if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0)
return NULL;
- return FN(EL,copy)(multi->u.p[pos]);
+ return multi->u.p[pos];
+}
+
+/* Return a copy of the base expression at position "pos" in "multi".
+ */
+__isl_give EL *FN(MULTI(BASE),get_at)(__isl_keep MULTI(BASE) *multi, int pos)
+{
+ return FN(EL,copy)(FN(MULTI(BASE),peek_at)(multi, pos));
}

/* This is an alternative name for the function above.
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:50 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 7c0e337443..e5a0247a16 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -6060,6 +6060,7 @@ error:
__isl_give isl_multi_aff *isl_multi_aff_align_divs(
__isl_take isl_multi_aff *maff)
{
+ isl_aff *aff_0;
isl_size n;
int i;

@@ -6072,10 +6073,16 @@ __isl_give isl_multi_aff *isl_multi_aff_align_divs(
if (!maff)
return NULL;

- for (i = 1; i < n; ++i)
- maff->u.p[0] = isl_aff_align_divs(maff->u.p[0], maff->u.p[i]);
for (i = 1; i < n; ++i) {
- maff->u.p[i] = isl_aff_align_divs(maff->u.p[i], maff->u.p[0]);
+ isl_aff *aff_i;
+
+ aff_i = isl_multi_aff_peek_at(maff, i);
+ maff->u.p[0] = isl_aff_align_divs(maff->u.p[0], aff_i);
+ }
+
+ aff_0 = isl_multi_aff_peek_at(maff, 0);
+ for (i = 1; i < n; ++i) {
+ maff->u.p[i] = isl_aff_align_divs(maff->u.p[i], aff_0);

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:51 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

Nothing needs to be aligned if there is only a single element.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/isl_aff.c b/isl_aff.c
index e5a0247a16..1b93b5ea0e 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -6067,7 +6067,7 @@ __isl_give isl_multi_aff *isl_multi_aff_align_divs(
n = isl_multi_aff_size(maff);
if (n < 0)
return isl_multi_aff_free(maff);
- if (n == 0)
+ if (n <= 1)
return maff;
maff = isl_multi_aff_cow(maff);
if (!maff)
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:52 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 1b93b5ea0e..6af302d4c3 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -6113,15 +6113,16 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
{
int i;
isl_space *space;
- isl_size n_div;
+ isl_size n, n_div;

if (ls)
*ls = NULL;

- if (!maff)
- return NULL;
+ n = isl_multi_aff_size(maff);
+ if (n < 0)
+ return isl_multi_aff_free(maff);

- if (maff->n == 0) {
+ if (n == 0) {
if (ls) {
isl_space *space = isl_multi_aff_get_domain_space(maff);
*ls = isl_local_space_from_space(space);
@@ -6154,7 +6155,7 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
return isl_multi_aff_free(maff);
}

- for (i = 0; i < maff->n; ++i) {
+ for (i = 0; i < n; ++i) {
maff->u.p[i] = isl_aff_lift(maff->u.p[i]);
if (!maff->u.p[i])
goto error;
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:54 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 6af302d4c3..10e9832f64 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -6113,6 +6113,7 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
{
int i;
isl_space *space;
+ isl_aff *aff;
isl_size n, n_div;

if (ls)
@@ -6134,10 +6135,9 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,

maff = isl_multi_aff_cow(maff);
maff = isl_multi_aff_align_divs(maff);
- if (!maff)
- return NULL;

- n_div = isl_aff_dim(maff->u.p[0], isl_dim_div);
+ aff = isl_multi_aff_peek_at(maff, 0);
+ n_div = isl_aff_dim(aff, isl_dim_div);
if (n_div < 0)
return isl_multi_aff_free(maff);
space = isl_multi_aff_get_space(maff);
@@ -6150,7 +6150,8 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
maff->space = space;

if (ls) {
- *ls = isl_aff_get_domain_local_space(maff->u.p[0]);
+ aff = isl_multi_aff_peek_at(maff, 0);
+ *ls = isl_aff_get_domain_local_space(aff);
if (!*ls)
return isl_multi_aff_free(maff);
}
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:55 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 10e9832f64..e3bbbbe7d6 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -7143,6 +7143,16 @@ isl_bool isl_pw_multi_aff_is_equal(__isl_keep isl_pw_multi_aff *pma1,
return equal;
}

+#undef SUFFIX
+#define SUFFIX multi_aff
+#undef ARG1
+#define ARG1 isl_multi_pw_aff
+#undef ARG2
+#define ARG2 isl_multi_aff
+
+static
+#include "isl_align_params_templ.c"
+
/* Compute the pullback of "mpa" by the function represented by "ma".
* In other words, plug in "ma" in "mpa".
*
@@ -7196,22 +7206,8 @@ error:
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff(
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma)
{
- isl_bool equal_params;
-
- if (!mpa || !ma)
- goto error;
- equal_params = isl_space_has_equal_params(mpa->space, ma->space);
- if (equal_params < 0)
- goto error;
- if (equal_params)
- return isl_multi_pw_aff_pullback_multi_aff_aligned(mpa, ma);
- mpa = isl_multi_pw_aff_align_params(mpa, isl_multi_aff_get_space(ma));
- ma = isl_multi_aff_align_params(ma, isl_multi_pw_aff_get_space(mpa));
+ isl_multi_pw_aff_align_params_multi_aff(&mpa, &ma);
return isl_multi_pw_aff_pullback_multi_aff_aligned(mpa, ma);
-error:
- isl_multi_pw_aff_free(mpa);
- isl_multi_aff_free(ma);
- return NULL;
}

/* Compute the pullback of "mpa" by the function represented by "pma".
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:56 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

Since the previous commit, the alignment only takes one line
so there is no longer any need to do this in a separate function.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index e3bbbbe7d6..7222e7192d 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -7156,17 +7156,16 @@ static
/* Compute the pullback of "mpa" by the function represented by "ma".
* In other words, plug in "ma" in "mpa".
*
- * The parameters of "mpa" and "ma" are assumed to have been aligned.
- *
* If "mpa" has an explicit domain, then it is this domain
* that needs to undergo a pullback, i.e., a preimage.
*/
-static __isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff_aligned(
+__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff(
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma)
{
int i;
isl_space *space = NULL;

+ isl_multi_pw_aff_align_params_multi_aff(&mpa, &ma);
mpa = isl_multi_pw_aff_cow(mpa);
if (!mpa || !ma)
goto error;
@@ -7200,16 +7199,6 @@ error:
return NULL;
}

-/* Compute the pullback of "mpa" by the function represented by "ma".
- * In other words, plug in "ma" in "mpa".
- */
-__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff(
- __isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma)
-{
- isl_multi_pw_aff_align_params_multi_aff(&mpa, &ma);
- return isl_multi_pw_aff_pullback_multi_aff_aligned(mpa, ma);
-}
-
/* Compute the pullback of "mpa" by the function represented by "pma".
* In other words, plug in "pma" in "mpa".
*
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:57 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 7222e7192d..d42d5507b6 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -7199,6 +7199,16 @@ error:
return NULL;
}

+#undef SUFFIX
+#define SUFFIX pw_multi_aff
+#undef ARG1
+#define ARG1 isl_multi_pw_aff
+#undef ARG2
+#define ARG2 isl_pw_multi_aff
+
+static
+#include "isl_align_params_templ.c"
+
/* Compute the pullback of "mpa" by the function represented by "pma".
* In other words, plug in "pma" in "mpa".
*
@@ -7251,24 +7261,8 @@ error:
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_pw_multi_aff(
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_multi_aff *pma)
{
- isl_bool equal_params;
-
- if (!mpa || !pma)
- goto error;
- equal_params = isl_space_has_equal_params(mpa->space, pma->dim);
- if (equal_params < 0)
- goto error;
- if (equal_params)
- return isl_multi_pw_aff_pullback_pw_multi_aff_aligned(mpa, pma);
- mpa = isl_multi_pw_aff_align_params(mpa,
- isl_pw_multi_aff_get_space(pma));
- pma = isl_pw_multi_aff_align_params(pma,
- isl_multi_pw_aff_get_space(mpa));
+ isl_multi_pw_aff_align_params_pw_multi_aff(&mpa, &pma);
return isl_multi_pw_aff_pullback_pw_multi_aff_aligned(mpa, pma);
-error:
- isl_multi_pw_aff_free(mpa);
- isl_pw_multi_aff_free(pma);
- return NULL;
}

/* Apply "aff" to "mpa". The range of "mpa" needs to be compatible
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:58 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

Since the previous commit, the alignment only takes one line
so there is no longer any need to do this in a separate function.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index d42d5507b6..ccdb89f650 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -7212,18 +7212,16 @@ static
/* Compute the pullback of "mpa" by the function represented by "pma".
* In other words, plug in "pma" in "mpa".
*
- * The parameters of "mpa" and "mpa" are assumed to have been aligned.
- *
* If "mpa" has an explicit domain, then it is this domain
* that needs to undergo a pullback, i.e., a preimage.
*/
-static __isl_give isl_multi_pw_aff *
-isl_multi_pw_aff_pullback_pw_multi_aff_aligned(
+__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_pw_multi_aff(
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_multi_aff *pma)
{
int i;
isl_space *space = NULL;

+ isl_multi_pw_aff_align_params_pw_multi_aff(&mpa, &pma);
mpa = isl_multi_pw_aff_cow(mpa);
if (!mpa || !pma)
goto error;
@@ -7255,16 +7253,6 @@ error:
return NULL;
}

-/* Compute the pullback of "mpa" by the function represented by "pma".
- * In other words, plug in "pma" in "mpa".
- */
-__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_pw_multi_aff(
- __isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_multi_aff *pma)
-{
- isl_multi_pw_aff_align_params_pw_multi_aff(&mpa, &pma);
- return isl_multi_pw_aff_pullback_pw_multi_aff_aligned(mpa, pma);
-}
-
/* Apply "aff" to "mpa". The range of "mpa" needs to be compatible
* with the domain of "aff". The domain of the result is the same
* as that of "mpa".
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:50:59 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This removes some code duplication.

There were minor differences between the implementation.
In particular, isl_multi_pw_aff_pullback_pw_multi_aff
was missing an error check on the constructed space,
while isl_multi_pw_aff_pullback_multi_pw_aff used
a different way of setting the space.
Also, isl_multi_pw_aff_pullback_multi_pw_aff would
directly call isl_pw_aff_pullback_multi_pw_aff_aligned,
whereas it now calls isl_pw_aff_pullback_multi_pw_aff.
the performance difference, if any, should be minimal.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
Makefile.am | 1 +
isl_aff.c | 171 ++----------------------------
isl_multi_pw_aff_pullback_templ.c | 71 +++++++++++++
3 files changed, 81 insertions(+), 162 deletions(-)
create mode 100644 isl_multi_pw_aff_pullback_templ.c

diff --git a/Makefile.am b/Makefile.am
index 3b1f074975..423b7ed646 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -555,6 +555,7 @@ EXTRA_DIST = \
isl_multi_nan_templ.c \
isl_multi_param_templ.c \
isl_multi_product_templ.c \
+ isl_multi_pw_aff_pullback_templ.c \
isl_multi_read_no_explicit_domain_templ.c \
isl_multi_splice_templ.c \
isl_multi_tuple_id_templ.c \
diff --git a/isl_aff.c b/isl_aff.c
index ccdb89f650..cbc8674c49 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -7143,115 +7143,15 @@ isl_bool isl_pw_multi_aff_is_equal(__isl_keep isl_pw_multi_aff *pma1,
return equal;
}

-#undef SUFFIX
-#define SUFFIX multi_aff
-#undef ARG1
-#define ARG1 isl_multi_pw_aff
-#undef ARG2
-#define ARG2 isl_multi_aff
-
-static
-#include "isl_align_params_templ.c"
-
-/* Compute the pullback of "mpa" by the function represented by "ma".
- * In other words, plug in "ma" in "mpa".
- *
- * If "mpa" has an explicit domain, then it is this domain
- * that needs to undergo a pullback, i.e., a preimage.
- */
-__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff(
- __isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma)
-{
- int i;
- isl_space *space = NULL;
-
- isl_multi_pw_aff_align_params_multi_aff(&mpa, &ma);
- mpa = isl_multi_pw_aff_cow(mpa);
- if (!mpa || !ma)
- goto error;
-
- space = isl_space_join(isl_multi_aff_get_space(ma),
- isl_multi_pw_aff_get_space(mpa));
- if (!space)
- goto error;
-
- for (i = 0; i < mpa->n; ++i) {
- mpa->u.p[i] = isl_pw_aff_pullback_multi_aff(mpa->u.p[i],
- isl_multi_aff_copy(ma));
- if (!mpa->u.p[i])
- goto error;
- }
- if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
- mpa->u.dom = isl_set_preimage_multi_aff(mpa->u.dom,
- isl_multi_aff_copy(ma));
- if (!mpa->u.dom)
- goto error;
- }
-
- isl_multi_aff_free(ma);
- isl_space_free(mpa->space);
- mpa->space = space;
- return mpa;
-error:
- isl_space_free(space);
- isl_multi_pw_aff_free(mpa);
- isl_multi_aff_free(ma);
- return NULL;
-}
-
-#undef SUFFIX
-#define SUFFIX pw_multi_aff
-#undef ARG1
-#define ARG1 isl_multi_pw_aff
-#undef ARG2
-#define ARG2 isl_pw_multi_aff
-
-static
-#include "isl_align_params_templ.c"
-
-/* Compute the pullback of "mpa" by the function represented by "pma".
- * In other words, plug in "pma" in "mpa".
- *
- * If "mpa" has an explicit domain, then it is this domain
- * that needs to undergo a pullback, i.e., a preimage.
- */
-__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_pw_multi_aff(
- __isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_multi_aff *pma)
-{
- int i;
- isl_space *space = NULL;
-
- isl_multi_pw_aff_align_params_pw_multi_aff(&mpa, &pma);
- mpa = isl_multi_pw_aff_cow(mpa);
- if (!mpa || !pma)
- goto error;
+#undef BASE
+#define BASE multi_aff

- space = isl_space_join(isl_pw_multi_aff_get_space(pma),
- isl_multi_pw_aff_get_space(mpa));
+#include "isl_multi_pw_aff_pullback_templ.c"

- for (i = 0; i < mpa->n; ++i) {
- mpa->u.p[i] = isl_pw_aff_pullback_pw_multi_aff_aligned(
- mpa->u.p[i], isl_pw_multi_aff_copy(pma));
- if (!mpa->u.p[i])
- goto error;
- }
- if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
- mpa->u.dom = isl_set_preimage_pw_multi_aff(mpa->u.dom,
- isl_pw_multi_aff_copy(pma));
- if (!mpa->u.dom)
- goto error;
- }
+#undef BASE
+#define BASE pw_multi_aff

- isl_pw_multi_aff_free(pma);
- isl_space_free(mpa->space);
- mpa->space = space;
- return mpa;
-error:
- isl_space_free(space);
- isl_multi_pw_aff_free(mpa);
- isl_pw_multi_aff_free(pma);
- return NULL;
-}
+#include "isl_multi_pw_aff_pullback_templ.c"

/* Apply "aff" to "mpa". The range of "mpa" needs to be compatible
* with the domain of "aff". The domain of the result is the same
@@ -7423,18 +7323,6 @@ error:
return NULL;
}

-/* Compute the pullback of "pa" by the function represented by "mpa".
- * In other words, plug in "mpa" in "pa".
- * "pa" and "mpa" are assumed to have been aligned.
- *
- * The pullback is computed by applying "pa" to "mpa".
- */
-static __isl_give isl_pw_aff *isl_pw_aff_pullback_multi_pw_aff_aligned(
- __isl_take isl_pw_aff *pa, __isl_take isl_multi_pw_aff *mpa)
-{
- return isl_multi_pw_aff_apply_pw_aff_aligned(mpa, pa);
-}
-
/* Compute the pullback of "pa" by the function represented by "mpa".
* In other words, plug in "mpa" in "pa".
*
@@ -7446,51 +7334,10 @@ __isl_give isl_pw_aff *isl_pw_aff_pullback_multi_pw_aff(
return isl_multi_pw_aff_apply_pw_aff(mpa, pa);
}

-/* Compute the pullback of "mpa1" by the function represented by "mpa2".
- * In other words, plug in "mpa2" in "mpa1".
- *
- * We pullback each member of "mpa1" in turn.
- *
- * If "mpa1" has an explicit domain, then it is this domain
- * that needs to undergo a pullback instead, i.e., a preimage.
- */
-__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_pw_aff(
- __isl_take isl_multi_pw_aff *mpa1, __isl_take isl_multi_pw_aff *mpa2)
-{
- int i;
- isl_space *space = NULL;
-
- isl_multi_pw_aff_align_params_bin(&mpa1, &mpa2);
- mpa1 = isl_multi_pw_aff_cow(mpa1);
- if (!mpa1 || !mpa2)
- goto error;
-
- space = isl_space_join(isl_multi_pw_aff_get_space(mpa2),
- isl_multi_pw_aff_get_space(mpa1));
-
- for (i = 0; i < mpa1->n; ++i) {
- mpa1->u.p[i] = isl_pw_aff_pullback_multi_pw_aff_aligned(
- mpa1->u.p[i], isl_multi_pw_aff_copy(mpa2));
- if (!mpa1->u.p[i])
- goto error;
- }
-
- if (isl_multi_pw_aff_has_explicit_domain(mpa1)) {
- mpa1->u.dom = isl_set_preimage_multi_pw_aff(mpa1->u.dom,
- isl_multi_pw_aff_copy(mpa2));
- if (!mpa1->u.dom)
- goto error;
- }
- mpa1 = isl_multi_pw_aff_reset_space(mpa1, space);
+#undef BASE
+#define BASE multi_pw_aff

- isl_multi_pw_aff_free(mpa2);
- return mpa1;
-error:
- isl_space_free(space);
- isl_multi_pw_aff_free(mpa1);
- isl_multi_pw_aff_free(mpa2);
- return NULL;
-}
+#include "isl_multi_pw_aff_pullback_templ.c"

/* Align the parameters of "mpa1" and "mpa2", check that the ranges
* of "mpa1" and "mpa2" live in the same space, construct map space
diff --git a/isl_multi_pw_aff_pullback_templ.c b/isl_multi_pw_aff_pullback_templ.c
new file mode 100644
index 0000000000..c8448b2bbd
--- /dev/null
+++ b/isl_multi_pw_aff_pullback_templ.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2013 Ecole Normale Superieure
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege,
+ * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
+ */
+
+#define xCAT(A,B) A ## B
+#define CAT(A,B) xCAT(A,B)
+#undef TYPE
+#define TYPE CAT(isl_,BASE)
+#define xFN(TYPE,NAME) TYPE ## _ ## NAME
+#define FN(TYPE,NAME) xFN(TYPE,NAME)
+
+#undef SUFFIX
+#define SUFFIX BASE
+#undef ARG1
+#define ARG1 isl_multi_pw_aff
+#undef ARG2
+#define ARG2 TYPE
+
+static
+#include "isl_align_params_templ.c"
+
+/* Compute the pullback of "mpa" by the function represented by "fn".
+ * In other words, plug in "fn" in "mpa".
+ *
+ * If "mpa" has an explicit domain, then it is this domain
+ * that needs to undergo a pullback, i.e., a preimage.
+ */
+__isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(
+ __isl_take isl_multi_pw_aff *mpa, __isl_take TYPE *fn)
+{
+ int i;
+ isl_space *space = NULL;
+
+ FN(isl_multi_pw_aff_align_params,BASE)(&mpa, &fn);
+ mpa = isl_multi_pw_aff_cow(mpa);
+ if (!mpa || !fn)
+ goto error;
+
+ space = isl_space_join(FN(TYPE,get_space)(fn),
+ isl_multi_pw_aff_get_space(mpa));
+ if (!space)
+ goto error;
+
+ for (i = 0; i < mpa->n; ++i) {
+ mpa->u.p[i] = FN(isl_pw_aff_pullback,BASE)(mpa->u.p[i],
+ FN(TYPE,copy)(fn));
+ if (!mpa->u.p[i])
+ goto error;
+ }
+ if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
+ mpa->u.dom = FN(isl_set_preimage,BASE)(mpa->u.dom,
+ FN(TYPE,copy)(fn));
+ if (!mpa->u.dom)
+ goto error;
+ }
+
+ FN(TYPE,free)(fn);
+ isl_space_free(mpa->space);
+ mpa->space = space;
+ return mpa;
+error:
+ isl_space_free(space);
+ isl_multi_pw_aff_free(mpa);
+ FN(TYPE,free)(fn);
+ return NULL;
+}
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:51:00 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_pw_aff_pullback_templ.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_multi_pw_aff_pullback_templ.c b/isl_multi_pw_aff_pullback_templ.c
index c8448b2bbd..b5230b1053 100644
--- a/isl_multi_pw_aff_pullback_templ.c
+++ b/isl_multi_pw_aff_pullback_templ.c
@@ -34,11 +34,13 @@ __isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(
__isl_take isl_multi_pw_aff *mpa, __isl_take TYPE *fn)
{
int i;
+ isl_size n;
isl_space *space = NULL;

FN(isl_multi_pw_aff_align_params,BASE)(&mpa, &fn);
mpa = isl_multi_pw_aff_cow(mpa);
- if (!mpa || !fn)
+ n = isl_multi_pw_aff_size(mpa);
+ if (n < 0 || !fn)
goto error;

space = isl_space_join(FN(TYPE,get_space)(fn),
@@ -46,7 +48,7 @@ __isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(
if (!space)
goto error;

- for (i = 0; i < mpa->n; ++i) {
+ for (i = 0; i < n; ++i) {
mpa->u.p[i] = FN(isl_pw_aff_pullback,BASE)(mpa->u.p[i],
FN(TYPE,copy)(fn));
if (!mpa->u.p[i])
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:51:01 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index e06898912c..ecfb5e1233 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -808,8 +808,10 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)(
goto error;

for (i = 0; i < n; ++i) {
- multi1->u.p[i] = fn(multi1->u.p[i],
- FN(EL,copy)(multi2->u.p[i]));
+ EL *el2;
+
+ el2 = FN(MULTI(BASE),get_at)(multi2, i);
+ multi1->u.p[i] = fn(multi1->u.p[i], el2);
if (!multi1->u.p[i])
goto error;
}
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:51:02 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sk...@kotnet.org>

This reduces the dependence on the internal representation.

Note that in the case of isl_multi_*_flatten_range,
it is now isl_multi_*_restore_space that is responsible
for calling isl_multi_*_cow when needed.

Also note that even though a call to isl_multi_*_take_space
always needs to be followed by a corresponding call
to isl_multi_*_restore_space, it is perfectly fine
to call isl_multi_*_restore_space without a preceding call
to isl_multi_*_take_space.

Signed-off-by: Sven Verdoolaege <sven.ver...@gmail.com>
---
isl_aff.c | 7 ++-
isl_multi_dims.c | 10 ++--
isl_multi_move_dims_templ.c | 12 ++---
isl_multi_pw_aff_pullback_templ.c | 5 +-
isl_multi_templ.c | 82 +++++++++++++++++++++++--------
5 files changed, 76 insertions(+), 40 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index cbc8674c49..0aa5004c2d 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -6144,10 +6144,9 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
space = isl_space_lift(isl_space_domain(space), n_div);
space = isl_space_extend_domain_with_range(space,
isl_multi_aff_get_space(maff));
- if (!space)
- return isl_multi_aff_free(maff);
- isl_space_free(maff->space);
- maff->space = space;
+ maff = isl_multi_aff_restore_space(maff, space);
+ if (!maff)
+ return NULL;

if (ls) {
aff = isl_multi_aff_peek_at(maff, 0);
diff --git a/isl_multi_dims.c b/isl_multi_dims.c
index 749146b312..07bb16123f 100644
--- a/isl_multi_dims.c
+++ b/isl_multi_dims.c
@@ -45,6 +45,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned first, unsigned n)
{
+ isl_space *space;
isl_size size;
int i;

@@ -58,13 +59,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
if (n == 0 && !isl_space_is_named_or_nested(multi->space, type))
return multi;

+ space = FN(MULTI(BASE),take_space)(multi);
+ space = isl_space_insert_dims(space, type, first, n);
+ multi = FN(MULTI(BASE),restore_space)(multi, space);
+
multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;

- multi->space = isl_space_insert_dims(multi->space, type, first, n);
- if (!multi->space)
- return FN(MULTI(BASE),free)(multi);
if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),insert_explicit_domain_dims)(multi,
type, first, n);
diff --git a/isl_multi_move_dims_templ.c b/isl_multi_move_dims_templ.c
index 3519e665c8..832541804f 100644
--- a/isl_multi_move_dims_templ.c
+++ b/isl_multi_move_dims_templ.c
@@ -20,6 +20,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
enum isl_dim_type dst_type, unsigned dst_pos,
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
+ isl_space *space;
isl_size size;
int i;

@@ -47,14 +48,13 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
"moving dims within the same type not supported",
return FN(MULTI(BASE),free)(multi));

+ space = FN(MULTI(BASE),take_space)(multi);
+ space = isl_space_move_dims(space, dst_type, dst_pos,
+ src_type, src_pos, n);
+ multi = FN(MULTI(BASE),restore_space)(multi, space);
+
multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;

- multi->space = isl_space_move_dims(multi->space, dst_type, dst_pos,
- src_type, src_pos, n);
- if (!multi->space)
- return FN(MULTI(BASE),free)(multi);
if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),move_explicit_domain_dims)(multi,
dst_type, dst_pos, src_type, src_pos, n);
diff --git a/isl_multi_pw_aff_pullback_templ.c b/isl_multi_pw_aff_pullback_templ.c
index b5230b1053..89c4bfa47b 100644
--- a/isl_multi_pw_aff_pullback_templ.c
+++ b/isl_multi_pw_aff_pullback_templ.c
@@ -45,8 +45,6 @@ __isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(

space = isl_space_join(FN(TYPE,get_space)(fn),
isl_multi_pw_aff_get_space(mpa));
- if (!space)
- goto error;

for (i = 0; i < n; ++i) {
mpa->u.p[i] = FN(isl_pw_aff_pullback,BASE)(mpa->u.p[i],
@@ -62,8 +60,7 @@ __isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(
}

FN(TYPE,free)(fn);
- isl_space_free(mpa->space);
- mpa->space = space;
+ isl_multi_pw_aff_restore_space(mpa, space);
return mpa;
error:
isl_space_free(space);
diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index ecfb5e1233..61e41ad1cd 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -138,6 +138,56 @@ __isl_null MULTI(BASE) *FN(MULTI(BASE),free)(__isl_take MULTI(BASE) *multi)
return NULL;
}

+/* Return the space of "multi".
+ * The caller is not allowed to modify "multi" between this call
+ * and the call to *_restore_space because the number
+ * of references needs to stay the same.
+ * The only exception is that isl_multi_*_free can be called instead.
+ * No copy is taken of multi->space if "multi" has only one reference
+ * such that it can be modified inplace if both have only a single reference.
+ */
+__isl_give isl_space *FN(MULTI(BASE),take_space)(__isl_keep MULTI(BASE) *multi)
+{
+ isl_space *space;
+
+ if (!multi)
+ return NULL;
+ if (multi->ref != 1)
+ return FN(MULTI(BASE),get_space)(multi);
+ space = multi->space;
+ multi->space = NULL;
+ return space;
+}
+
+/* Set the space of "multi" to "space", where the space of "multi"
+ * may be missing due to a preceding call to isl_multi_*_take_space.
+ * However, in this case, "multi" only has a single reference and
+ * then the call to isl_multi_*_cow has no effect.
+ */
+__isl_give MULTI(BASE) *FN(MULTI(BASE),restore_space)(
+ __isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
+{
+ if (!multi || !space)
+ goto error;
+
+ if (multi->space == space) {
+ isl_space_free(space);
+ return multi;
+ }
+
+ multi = FN(MULTI(BASE),cow)(multi);
+ if (!multi)
+ goto error;
+ isl_space_free(multi->space);
+ multi->space = space;
+
+ return multi;
+error:
+ FN(MULTI(BASE),free)(multi);
+ isl_space_free(space);
+ return NULL;
+}
+
isl_size FN(MULTI(BASE),dim)(__isl_keep MULTI(BASE) *multi,
enum isl_dim_type type)
{
@@ -312,15 +362,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space_and_domain)(
if (!multi->u.p[i])
goto error;
}
- if (FN(MULTI(BASE),has_explicit_domain)(multi)) {
+ if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),reset_explicit_domain_space)(multi,
isl_space_copy(domain));
- if (!multi)
- goto error;
- }
isl_space_free(domain);
- isl_space_free(multi->space);
- multi->space = space;
+
+ multi = FN(MULTI(BASE),restore_space)(multi, space);

return multi;
error:
@@ -524,6 +571,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned first, unsigned n)
{
+ isl_space *space;
isl_size size;
int i;

@@ -531,9 +579,9 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
if (FN(MULTI(BASE),check_range)(multi, type, first, n) < 0)
return FN(MULTI(BASE),free)(multi);

- multi->space = isl_space_drop_dims(multi->space, type, first, n);
- if (!multi->space)
- return FN(MULTI(BASE),free)(multi);
+ space = FN(MULTI(BASE),take_space)(multi);
+ space = isl_space_drop_dims(space, type, first, n);
+ multi = FN(MULTI(BASE),restore_space)(multi, space);

if (type == isl_dim_out)
return FN(MULTI(BASE),drop_output_dims)(multi, first, n);
@@ -703,19 +751,11 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),factor_range)(
__isl_give MULTI(BASE) *FN(MULTI(BASE),flatten_range)(
__isl_take MULTI(BASE) *multi)
{
- if (!multi)
- return NULL;
-
- if (!multi->space->nested[1])
- return multi;
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- return NULL;
+ isl_space *space;

- multi->space = isl_space_flatten_range(multi->space);
- if (!multi->space)
- return FN(MULTI(BASE),free)(multi);
+ space = FN(MULTI(BASE),take_space)(multi);
+ space = isl_space_flatten_range(space);
+ multi = FN(MULTI(BASE),restore_space)(multi, space);

return multi;
}
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:51:04 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

That is, do not call isl_multi_*_cow if the element
already has the desired value.

This allows the function to be repurposed
as a isl_multi_*_restore_at corresponding to a isl_multi_*_take_at
in the next commit.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_multi_templ.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index 61e41ad1cd..5fec937f16 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -237,11 +237,16 @@ __isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi,
static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore)(
__isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
{
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi || !el)
+ if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0 || !el)
goto error;

- if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0)
+ if (multi->u.p[pos] == el) {
+ FN(EL,free)(el);
+ return multi;
+ }
+
+ multi = FN(MULTI(BASE),cow)(multi);
+ if (!multi)
goto error;

FN(EL,free)(multi->u.p[pos]);
--
2.25.1

skim...@kotnet.org

unread,
Aug 11, 2021, 3:51:05 PM8/11/21
to isl-dev...@googlegroups.com
From: Sven Verdoolaege <sv...@cerebras.net>

This reduces the dependence on the internal representation.

In practice, the already available isl_multi_*_restore
can simply be reused as a isl_multi_*_restore_at
to pair off with isl_multi_*_take_at.

Note that the calls to isl_multi_*_cow can be removed
because it is called by isl_multi_*_restore_at when needed.
Conversely, isl_multi_*_coalesce is not converted
to used isl_multi_*_{take,restore}_at because
it should perform its modifications inplace.

Signed-off-by: Sven Verdoolaege <sv...@cerebras.net>
---
isl_aff.c | 66 ++++++++++++++----------------
isl_multi_apply_templ.c | 17 +++-----
isl_multi_bin_val_templ.c | 31 ++++----------
isl_multi_dims.c | 13 +++---
isl_multi_move_dims_templ.c | 13 +++---
isl_multi_pw_aff_pullback_templ.c | 9 ++--
isl_multi_templ.c | 68 +++++++++++++++++++++----------
isl_multi_un_op_templ.c | 9 ++--
8 files changed, 113 insertions(+), 113 deletions(-)

diff --git a/isl_aff.c b/isl_aff.c
index 0aa5004c2d..d2ac33ec37 100644
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -4280,16 +4280,17 @@ static __isl_give isl_multi_aff *isl_multi_aff_substitute_equalities(
isl_size n;
int i;

- maff = isl_multi_aff_cow(maff);
n = isl_multi_aff_size(maff);
if (n < 0 || !eq)
goto error;

for (i = 0; i < n; ++i) {
- maff->u.p[i] = isl_aff_substitute_equalities(maff->u.p[i],
+ isl_aff *aff;
+
+ aff = isl_multi_aff_take_at(maff, i);
+ aff = isl_aff_substitute_equalities(aff,
isl_basic_set_copy(eq));
- if (!maff->u.p[i])
- goto error;
+ maff = isl_multi_aff_restore_at(maff, i, aff);
}

isl_basic_set_free(eq);
@@ -4306,15 +4307,16 @@ __isl_give isl_multi_aff *isl_multi_aff_scale(__isl_take isl_multi_aff *maff,
isl_size n;
int i;

- maff = isl_multi_aff_cow(maff);
n = isl_multi_aff_size(maff);
if (n < 0)
return isl_multi_aff_free(maff);

for (i = 0; i < n; ++i) {
- maff->u.p[i] = isl_aff_scale(maff->u.p[i], f);
- if (!maff->u.p[i])
- return isl_multi_aff_free(maff);
+ isl_aff *aff;
+
+ aff = isl_multi_aff_take_at(maff, i);
+ aff = isl_aff_scale(aff, f);
+ maff = isl_multi_aff_restore_at(maff, i, aff);
}

return maff;
@@ -5693,7 +5695,6 @@ __isl_give isl_multi_aff *isl_multi_aff_substitute(
isl_size n;
int i;

- maff = isl_multi_aff_cow(maff);
n = isl_multi_aff_size(maff);
if (n < 0 || !subs)
return isl_multi_aff_free(maff);
@@ -5702,10 +5703,11 @@ __isl_give isl_multi_aff *isl_multi_aff_substitute(
type = isl_dim_set;

for (i = 0; i < n; ++i) {
- maff->u.p[i] = isl_aff_substitute(maff->u.p[i],
- type, pos, subs);
- if (!maff->u.p[i])
- return isl_multi_aff_free(maff);
+ isl_aff *aff;
+
+ aff = isl_multi_aff_take_at(maff, i);
+ aff = isl_aff_substitute(aff, type, pos, subs);
+ maff = isl_multi_aff_restore_at(maff, i, aff);
}

return maff;
@@ -5975,7 +5977,6 @@ __isl_give isl_multi_aff *isl_multi_aff_pullback_multi_aff(

isl_multi_aff_align_params_bin(&ma1, &ma2);
ma2 = isl_multi_aff_align_divs(ma2);
- ma1 = isl_multi_aff_cow(ma1);
n = isl_multi_aff_size(ma1);
if (n < 0 || !ma2)
goto error;
@@ -5984,10 +5985,11 @@ __isl_give isl_multi_aff *isl_multi_aff_pullback_multi_aff(
isl_multi_aff_get_space(ma1));

for (i = 0; i < n; ++i) {
- ma1->u.p[i] = isl_aff_pullback_multi_aff(ma1->u.p[i],
- isl_multi_aff_copy(ma2));
- if (!ma1->u.p[i])
- goto error;
+ isl_aff *aff;
+
+ aff = isl_multi_aff_take_at(ma1, i);
+ aff = isl_aff_pullback_multi_aff(aff, isl_multi_aff_copy(ma2));
+ ma1 = isl_multi_aff_restore_at(ma1, i, aff);
}

ma1 = isl_multi_aff_reset_space(ma1, space);
@@ -6069,22 +6071,23 @@ __isl_give isl_multi_aff *isl_multi_aff_align_divs(
return isl_multi_aff_free(maff);
if (n <= 1)
return maff;
- maff = isl_multi_aff_cow(maff);
- if (!maff)
- return NULL;

+ aff_0 = isl_multi_aff_take_at(maff, 0);
for (i = 1; i < n; ++i) {
isl_aff *aff_i;

aff_i = isl_multi_aff_peek_at(maff, i);
- maff->u.p[0] = isl_aff_align_divs(maff->u.p[0], aff_i);
+ aff_0 = isl_aff_align_divs(aff_0, aff_i);
}
+ maff = isl_multi_aff_restore_at(maff, 0, aff_0);

aff_0 = isl_multi_aff_peek_at(maff, 0);
for (i = 1; i < n; ++i) {
- maff->u.p[i] = isl_aff_align_divs(maff->u.p[i], aff_0);
- if (!maff->u.p[i])
- return isl_multi_aff_free(maff);
+ isl_aff *aff_i;
+
+ aff_i = isl_multi_aff_take_at(maff, i);
+ aff_i = isl_aff_align_divs(aff_i, aff_0);
+ maff = isl_multi_aff_restore_at(maff, i, aff_i);
}

return maff;
@@ -6133,7 +6136,6 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
return maff;
}

- maff = isl_multi_aff_cow(maff);
maff = isl_multi_aff_align_divs(maff);

aff = isl_multi_aff_peek_at(maff, 0);
@@ -6145,8 +6147,6 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
space = isl_space_extend_domain_with_range(space,
isl_multi_aff_get_space(maff));
maff = isl_multi_aff_restore_space(maff, space);
- if (!maff)
- return NULL;

if (ls) {
aff = isl_multi_aff_peek_at(maff, 0);
@@ -6156,16 +6156,12 @@ __isl_give isl_multi_aff *isl_multi_aff_lift(__isl_take isl_multi_aff *maff,
}

for (i = 0; i < n; ++i) {
- maff->u.p[i] = isl_aff_lift(maff->u.p[i]);
- if (!maff->u.p[i])
- goto error;
+ aff = isl_multi_aff_take_at(maff, i);
+ aff = isl_aff_lift(aff);
+ maff = isl_multi_aff_restore_at(maff, i, aff);
}

return maff;
-error:
- if (ls)
- isl_local_space_free(*ls);
- return isl_multi_aff_free(maff);
}

#undef TYPE
diff --git a/isl_multi_apply_templ.c b/isl_multi_apply_templ.c
index d8e3b03893..31e27f26fb 100644
--- a/isl_multi_apply_templ.c
+++ b/isl_multi_apply_templ.c
@@ -26,19 +26,12 @@ __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply_aligned),APPLY_DOMBASE)(
if (n < 0 || !set)
goto error;

- if (n == 0) {
- FN(APPLY_DOM,free)(set);
- return multi;
- }
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- goto error;
-
for (i = 0; i < n; ++i) {
- multi->u.p[i] = fn(multi->u.p[i], FN(APPLY_DOM,copy)(set));
- if (!multi->u.p[i])
- goto error;
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = fn(el, FN(APPLY_DOM,copy)(set));
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

FN(APPLY_DOM,free)(set);
diff --git a/isl_multi_bin_val_templ.c b/isl_multi_bin_val_templ.c
index 96023439cd..a7a3913da9 100644
--- a/isl_multi_bin_val_templ.c
+++ b/isl_multi_bin_val_templ.c
@@ -20,19 +20,13 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_val)(
n = FN(MULTI(BASE),size)(multi);
if (n < 0 || !v)
goto error;
- if (n == 0) {
- isl_val_free(v);
- return multi;
- }
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- goto error;

for (i = 0; i < n; ++i) {
- multi->u.p[i] = fn(multi->u.p[i], isl_val_copy(v));
- if (!multi->u.p[i])
- goto error;
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = fn(el, isl_val_copy(v));
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

isl_val_free(v);
@@ -60,22 +54,15 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_multi_val)(
n = FN(MULTI(BASE),size)(multi);
if (n < 0 || FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
goto error;
- if (n == 0) {
- isl_multi_val_free(mv);
- return multi;
- }
-
- multi = FN(MULTI(BASE),cow)(multi);
- if (!multi)
- goto error;

for (i = 0; i < n; ++i) {
isl_val *v;
+ EL *el;

v = isl_multi_val_get_val(mv, i);
- multi->u.p[i] = fn(multi->u.p[i], v);
- if (!multi->u.p[i])
- goto error;
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = fn(el, v);
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

isl_multi_val_free(mv);
diff --git a/isl_multi_dims.c b/isl_multi_dims.c
index 07bb16123f..fb5cb1147b 100644
--- a/isl_multi_dims.c
+++ b/isl_multi_dims.c
@@ -63,19 +63,16 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
space = isl_space_insert_dims(space, type, first, n);
multi = FN(MULTI(BASE),restore_space)(multi, space);

- multi = FN(MULTI(BASE),cow)(multi);
-
if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),insert_explicit_domain_dims)(multi,
type, first, n);
- if (!multi)
- return NULL;

for (i = 0; i < size; ++i) {
- multi->u.p[i] = FN(EL,insert_dims)(multi->u.p[i],
- type, first, n);
- if (!multi->u.p[i])
- return FN(MULTI(BASE),free)(multi);
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = FN(EL,insert_dims)(el, type, first, n);
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

return multi;
diff --git a/isl_multi_move_dims_templ.c b/isl_multi_move_dims_templ.c
index 832541804f..ba9830e2b6 100644
--- a/isl_multi_move_dims_templ.c
+++ b/isl_multi_move_dims_templ.c
@@ -53,20 +53,17 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
src_type, src_pos, n);
multi = FN(MULTI(BASE),restore_space)(multi, space);

- multi = FN(MULTI(BASE),cow)(multi);
-
if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),move_explicit_domain_dims)(multi,
dst_type, dst_pos, src_type, src_pos, n);
- if (!multi)
- return NULL;

for (i = 0; i < size; ++i) {
- multi->u.p[i] = FN(EL,move_dims)(multi->u.p[i],
- dst_type, dst_pos,
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = FN(EL,move_dims)(el, dst_type, dst_pos,
src_type, src_pos, n);
- if (!multi->u.p[i])
- return FN(MULTI(BASE),free)(multi);
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

return multi;
diff --git a/isl_multi_pw_aff_pullback_templ.c b/isl_multi_pw_aff_pullback_templ.c
index 89c4bfa47b..fc5aed2b3f 100644
--- a/isl_multi_pw_aff_pullback_templ.c
+++ b/isl_multi_pw_aff_pullback_templ.c
@@ -47,9 +47,12 @@ __isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(
isl_multi_pw_aff_get_space(mpa));

for (i = 0; i < n; ++i) {
- mpa->u.p[i] = FN(isl_pw_aff_pullback,BASE)(mpa->u.p[i],
- FN(TYPE,copy)(fn));
- if (!mpa->u.p[i])
+ isl_pw_aff *pa;
+
+ pa = isl_multi_pw_aff_take_at(mpa, i);
+ pa = FN(isl_pw_aff_pullback,BASE)(pa, FN(TYPE,copy)(fn));
+ mpa = isl_multi_pw_aff_restore_at(mpa, i, pa);
+ if (!mpa)
goto error;
}
if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
diff --git a/isl_multi_templ.c b/isl_multi_templ.c
index 5fec937f16..ac4d480d3f 100644
--- a/isl_multi_templ.c
+++ b/isl_multi_templ.c
@@ -231,10 +231,36 @@ __isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi,
return FN(MULTI(BASE),get_at)(multi, pos);
}

+/* Return the base expression at position "pos" in "multi".
+ * This may be either a copy or the base expression itself
+ * if there is only one reference to "multi".
+ * This allows the base expression to be modified inplace
+ * if both the multi expression and this base expression
+ * have only a single reference.
+ * The caller is not allowed to modify "multi" between this call and
+ * the subsequent call to isl_multi_*_restore_at_*.
+ * The only exception is that isl_multi_*_free can be called instead.
+ */
+static __isl_give EL *FN(MULTI(BASE),take_at)(__isl_keep MULTI(BASE) *multi,
+ int pos)
+{
+ EL *el;
+
+ if (!multi)
+ return NULL;
+ if (multi->ref != 1)
+ return FN(MULTI(BASE),get_at)(multi, pos);
+ if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0)
+ return NULL;
+ el = multi->u.p[pos];
+ multi->u.p[pos] = NULL;
+ return el;
+}
+
/* Set the element at position "pos" of "multi" to "el",
* where the position may be empty if "multi" has only a single reference.
*/
-static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore)(
+static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore_at)(
__isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
{
if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0 || !el)
@@ -272,7 +298,7 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore_check_space)(
space = FN(MULTI(BASE),peek_space)(multi);
if (FN(EL,check_match_domain_space)(el, space) < 0)
multi = FN(MULTI(BASE),free)(multi);
- return FN(MULTI(BASE),restore)(multi, pos, el);
+ return FN(MULTI(BASE),restore_at)(multi, pos, el);
}

/* Replace the base expression at position "pos" in "multi" with "el".
@@ -356,16 +382,16 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space_and_domain)(
isl_size n;
int i;

- multi = FN(MULTI(BASE),cow)(multi);
n = FN(MULTI(BASE),size)(multi);
if (n < 0 || !space || !domain)
goto error;

for (i = 0; i < n; ++i) {
- multi->u.p[i] = FN(EL,reset_domain_space)(multi->u.p[i],
- isl_space_copy(domain));
- if (!multi->u.p[i])
- goto error;
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = FN(EL,reset_domain_space)(el, isl_space_copy(domain));
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}
if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),reset_explicit_domain_space)(multi,
@@ -422,16 +448,16 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),realign_domain)(
isl_size n;
isl_space *space;

- multi = FN(MULTI(BASE),cow)(multi);
n = FN(MULTI(BASE),size)(multi);
if (n < 0 || !exp)
goto error;

for (i = 0; i < n; ++i) {
- multi->u.p[i] = FN(EL,realign_domain)(multi->u.p[i],
- isl_reordering_copy(exp));
- if (!multi->u.p[i])
- goto error;
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = FN(EL,realign_domain)(el, isl_reordering_copy(exp));
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

space = isl_reordering_get_space(exp);
@@ -580,7 +606,6 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
isl_size size;
int i;

- multi = FN(MULTI(BASE),cow)(multi);
if (FN(MULTI(BASE),check_range)(multi, type, first, n) < 0)
return FN(MULTI(BASE),free)(multi);

@@ -599,9 +624,11 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
if (size < 0)
return FN(MULTI(BASE),free)(multi);
for (i = 0; i < size; ++i) {
- multi->u.p[i] = FN(EL,drop_dims)(multi->u.p[i], type, first, n);
- if (!multi->u.p[i])
- return FN(MULTI(BASE),free)(multi);
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = FN(EL,drop_dims)(el, type, first, n);
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

return multi;
@@ -847,18 +874,17 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)(
int i;

FN(MULTI(BASE),align_params_bin)(&multi1, &multi2);
- multi1 = FN(MULTI(BASE),cow)(multi1);
n = FN(MULTI(BASE),size)(multi1);
if (n < 0 || FN(MULTI(BASE),check_equal_space)(multi1, multi2) < 0)
goto error;

for (i = 0; i < n; ++i) {
- EL *el2;
+ EL *el1, *el2;

el2 = FN(MULTI(BASE),get_at)(multi2, i);
- multi1->u.p[i] = fn(multi1->u.p[i], el2);
- if (!multi1->u.p[i])
- goto error;
+ el1 = FN(MULTI(BASE),take_at)(multi1, i);
+ el1 = fn(el1, el2);
+ multi1 = FN(MULTI(BASE),restore_at)(multi1, i, el1);
}

if (FN(MULTI(BASE),has_explicit_domain)(multi2))
diff --git a/isl_multi_un_op_templ.c b/isl_multi_un_op_templ.c
index 1273cd780a..bbf105b592 100644
--- a/isl_multi_un_op_templ.c
+++ b/isl_multi_un_op_templ.c
@@ -17,15 +17,16 @@ static __isl_give MULTI(BASE) *FN(MULTI(BASE),un_op)(
int i;
isl_size n;

- multi = FN(MULTI(BASE),cow)(multi);
n = FN(MULTI(BASE),size)(multi);
if (n < 0)
return FN(MULTI(BASE),free)(multi);

for (i = 0; i < n; ++i) {
- multi->u.p[i] = fn(multi->u.p[i]);
- if (!multi->u.p[i])
- return FN(MULTI(BASE),free)(multi);
+ EL *el;
+
+ el = FN(MULTI(BASE),take_at)(multi, i);
+ el = fn(el);
+ multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

return multi;
--
2.25.1

Reply all
Reply to author
Forward
0 new messages