2014-01-27 21:38:34 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2011 Sven Verdoolaege
|
2020-07-11 13:25:06 +02:00
|
|
|
|
* Copyright 2012-2014 Ecole Normale Superieure
|
2014-01-27 21:38:34 +01:00
|
|
|
|
*
|
|
|
|
|
* Use of this software is governed by the MIT license
|
|
|
|
|
*
|
|
|
|
|
* Written by Sven Verdoolaege,
|
|
|
|
|
* Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
|
|
|
|
|
*/
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
#include <isl/id.h>
|
2014-01-27 21:38:34 +01:00
|
|
|
|
#include <isl_space_private.h>
|
|
|
|
|
#include <isl/set.h>
|
|
|
|
|
#include <isl_reordering.h>
|
|
|
|
|
|
2018-07-03 21:52:50 +02:00
|
|
|
|
#include <isl_multi_macro.h>
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
#define MULTI_NAME(BASE) "isl_multi_" #BASE
|
|
|
|
|
|
|
|
|
|
isl_ctx *FN(MULTI(BASE),get_ctx)(__isl_keep MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
return multi ? isl_space_get_ctx(multi->space) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Return the space of "multi".
|
|
|
|
|
*/
|
|
|
|
|
__isl_keep isl_space *FN(MULTI(BASE),peek_space)(__isl_keep MULTI(BASE) *multi)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
return multi ? multi->space : NULL;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
__isl_give isl_space *FN(MULTI(BASE),get_space)(__isl_keep MULTI(BASE) *multi)
|
2018-07-03 21:52:50 +02:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
return isl_space_copy(FN(MULTI(BASE),peek_space)(multi));
|
2018-07-03 21:52:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
__isl_give isl_space *FN(MULTI(BASE),get_domain_space)(
|
|
|
|
|
__isl_keep MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
return multi ? isl_space_domain(isl_space_copy(multi->space)) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Allocate a multi expression living in "space".
|
|
|
|
|
*
|
|
|
|
|
* If the number of base expressions is zero, then make sure
|
|
|
|
|
* there is enough room in the structure for the explicit domain,
|
|
|
|
|
* in case the type supports such an explicit domain.
|
|
|
|
|
*/
|
2014-01-27 21:38:34 +01:00
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),alloc)(__isl_take isl_space *space)
|
|
|
|
|
{
|
|
|
|
|
isl_ctx *ctx;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size n;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
MULTI(BASE) *multi;
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
n = isl_space_dim(space, isl_dim_out);
|
|
|
|
|
if (n < 0)
|
|
|
|
|
goto error;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
ctx = isl_space_get_ctx(space);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (n > 0)
|
|
|
|
|
multi = isl_calloc(ctx, MULTI(BASE),
|
2014-01-27 21:38:34 +01:00
|
|
|
|
sizeof(MULTI(BASE)) + (n - 1) * sizeof(struct EL *));
|
2020-07-11 13:25:06 +02:00
|
|
|
|
else
|
|
|
|
|
multi = isl_calloc(ctx, MULTI(BASE), sizeof(MULTI(BASE)));
|
2014-01-27 21:38:34 +01:00
|
|
|
|
if (!multi)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
multi->space = space;
|
|
|
|
|
multi->n = n;
|
|
|
|
|
multi->ref = 1;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi))
|
|
|
|
|
multi = FN(MULTI(BASE),init_explicit_domain)(multi);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
return multi;
|
|
|
|
|
error:
|
|
|
|
|
isl_space_free(space);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),dup)(__isl_keep MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
MULTI(BASE) *dup;
|
|
|
|
|
|
|
|
|
|
if (!multi)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
dup = FN(MULTI(BASE),alloc)(isl_space_copy(multi->space));
|
|
|
|
|
if (!dup)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < multi->n; ++i)
|
|
|
|
|
dup = FN(FN(MULTI(BASE),set),BASE)(dup, i,
|
2020-07-11 13:25:06 +02:00
|
|
|
|
FN(EL,copy)(multi->u.p[i]));
|
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi))
|
|
|
|
|
dup = FN(MULTI(BASE),copy_explicit_domain)(dup, multi);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
return dup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),cow)(__isl_take MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
if (!multi)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (multi->ref == 1)
|
|
|
|
|
return multi;
|
|
|
|
|
|
|
|
|
|
multi->ref--;
|
|
|
|
|
return FN(MULTI(BASE),dup)(multi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),copy)(__isl_keep MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
if (!multi)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
multi->ref++;
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 21:52:50 +02:00
|
|
|
|
__isl_null MULTI(BASE) *FN(MULTI(BASE),free)(__isl_take MULTI(BASE) *multi)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (!multi)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (--multi->ref > 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
isl_space_free(multi->space);
|
|
|
|
|
for (i = 0; i < multi->n; ++i)
|
2020-07-11 13:25:06 +02:00
|
|
|
|
FN(EL,free)(multi->u.p[i]);
|
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi))
|
|
|
|
|
FN(MULTI(BASE),free_explicit_domain)(multi);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
free(multi);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size FN(MULTI(BASE),dim)(__isl_keep MULTI(BASE) *multi,
|
2018-07-03 21:52:50 +02:00
|
|
|
|
enum isl_dim_type type)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
return isl_space_dim(FN(MULTI(BASE),peek_space)(multi), type);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Return the number of base expressions in "multi".
|
2018-07-03 21:52:50 +02:00
|
|
|
|
*/
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size FN(MULTI(BASE),size)(__isl_keep MULTI(BASE) *multi)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
return multi ? multi->n : isl_size_error;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
#undef TYPE
|
|
|
|
|
#define TYPE MULTI(BASE)
|
|
|
|
|
static
|
|
|
|
|
#include "check_type_range_templ.c"
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* 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)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_ctx *ctx;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
return NULL;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
ctx = FN(MULTI(BASE),get_ctx)(multi);
|
|
|
|
|
return FN(EL,copy)(multi->u.p[pos]);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* This is an alternative name for the function above.
|
2018-07-03 21:52:50 +02:00
|
|
|
|
*/
|
2020-07-11 13:25:06 +02:00
|
|
|
|
__isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi,
|
|
|
|
|
int pos)
|
2018-07-03 21:52:50 +02:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
return FN(MULTI(BASE),get_at)(multi, pos);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Set the element at position "pos" of "multi" to "el",
|
|
|
|
|
* where the position may be empty if "multi" has only a single reference.
|
2018-07-03 21:52:50 +02:00
|
|
|
|
*/
|
2020-07-11 13:25:06 +02:00
|
|
|
|
static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
|
2018-07-03 21:52:50 +02:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
multi = FN(MULTI(BASE),cow)(multi);
|
|
|
|
|
if (!multi || !el)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
FN(EL,free)(multi->u.p[pos]);
|
|
|
|
|
multi->u.p[pos] = el;
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
error:
|
|
|
|
|
FN(MULTI(BASE),free)(multi);
|
|
|
|
|
FN(EL,free)(el);
|
|
|
|
|
return NULL;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Set the element at position "pos" of "multi" to "el",
|
|
|
|
|
* where the position may be empty if "multi" has only a single reference.
|
|
|
|
|
* However, the space of "multi" is available and is checked
|
|
|
|
|
* for compatibility with "el".
|
|
|
|
|
*/
|
|
|
|
|
static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore_check_space)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_space *space;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
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);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Replace the base expression at position "pos" in "multi" with "el".
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),set_at)(
|
2014-01-27 21:38:34 +01:00
|
|
|
|
__isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
|
|
|
|
|
{
|
|
|
|
|
isl_space *multi_space = NULL;
|
|
|
|
|
isl_space *el_space = NULL;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
isl_bool match;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
multi_space = FN(MULTI(BASE),get_space)(multi);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
match = FN(EL,matching_params)(el, multi_space);
|
|
|
|
|
if (match < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
if (!match) {
|
|
|
|
|
multi = FN(MULTI(BASE),align_params)(multi,
|
|
|
|
|
FN(EL,get_space)(el));
|
|
|
|
|
isl_space_free(multi_space);
|
|
|
|
|
multi_space = FN(MULTI(BASE),get_space)(multi);
|
|
|
|
|
el = FN(EL,align_params)(el, isl_space_copy(multi_space));
|
|
|
|
|
}
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
multi = FN(MULTI(BASE),restore_check_space)(multi, pos, el);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
isl_space_free(multi_space);
|
|
|
|
|
isl_space_free(el_space);
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
error:
|
|
|
|
|
FN(MULTI(BASE),free)(multi);
|
|
|
|
|
FN(EL,free)(el);
|
|
|
|
|
isl_space_free(multi_space);
|
|
|
|
|
isl_space_free(el_space);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* This is an alternative name for the function above.
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
|
|
|
|
|
{
|
|
|
|
|
return FN(MULTI(BASE),set_at)(multi, pos, el);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
/* Return the base expressions of "multi" as a list.
|
|
|
|
|
*/
|
|
|
|
|
__isl_give LIST(EL) *FN(MULTI(BASE),get_list)(
|
|
|
|
|
__isl_keep MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
isl_size n;
|
|
|
|
|
int i;
|
|
|
|
|
LIST(EL) *list;
|
|
|
|
|
|
|
|
|
|
n = FN(MULTI(BASE),size)(multi);
|
|
|
|
|
if (n < 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
list = FN(LIST(EL),alloc)(FN(MULTI(BASE),get_ctx(multi)), n);
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
|
EL *el = FN(MULTI(BASE),get_at)(multi, i);
|
|
|
|
|
list = FN(LIST(EL),add)(list, el);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
/* Reset the space of "multi". This function is called from isl_pw_templ.c
|
|
|
|
|
* and doesn't know if the space of an element object is represented
|
|
|
|
|
* directly or through its domain. It therefore passes along both,
|
2018-07-03 21:52:50 +02:00
|
|
|
|
* which we pass along to the element function since we don't know how
|
2014-01-27 21:38:34 +01:00
|
|
|
|
* that is represented either.
|
2020-07-11 13:25:06 +02:00
|
|
|
|
*
|
|
|
|
|
* If "multi" has an explicit domain, then the caller is expected
|
|
|
|
|
* to make sure that any modification that would change the dimensions
|
|
|
|
|
* of the explicit domain has bee applied before this function is called.
|
2014-01-27 21:38:34 +01:00
|
|
|
|
*/
|
|
|
|
|
__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)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
multi = FN(MULTI(BASE),cow)(multi);
|
|
|
|
|
if (!multi || !space || !domain)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < multi->n; ++i) {
|
2020-07-11 13:25:06 +02:00
|
|
|
|
multi->u.p[i] = FN(EL,reset_domain_space)(multi->u.p[i],
|
2014-01-27 21:38:34 +01:00
|
|
|
|
isl_space_copy(domain));
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (!multi->u.p[i])
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi)) {
|
|
|
|
|
multi = FN(MULTI(BASE),reset_explicit_domain_space)(multi,
|
|
|
|
|
isl_space_copy(domain));
|
|
|
|
|
if (!multi)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
isl_space_free(domain);
|
|
|
|
|
isl_space_free(multi->space);
|
|
|
|
|
multi->space = space;
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
error:
|
|
|
|
|
isl_space_free(domain);
|
|
|
|
|
isl_space_free(space);
|
|
|
|
|
FN(MULTI(BASE),free)(multi);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),reset_domain_space)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi, __isl_take isl_space *domain)
|
|
|
|
|
{
|
|
|
|
|
isl_space *space;
|
|
|
|
|
|
|
|
|
|
space = isl_space_extend_domain_with_range(isl_space_copy(domain),
|
|
|
|
|
isl_space_copy(multi->space));
|
|
|
|
|
return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
|
|
|
|
|
{
|
|
|
|
|
isl_space *domain;
|
|
|
|
|
|
|
|
|
|
domain = isl_space_domain(isl_space_copy(space));
|
|
|
|
|
return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 21:52:50 +02:00
|
|
|
|
/* Reset the user pointer on all identifiers of parameters and tuples
|
|
|
|
|
* of the space of "multi".
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),reset_user)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
isl_space *space;
|
|
|
|
|
|
|
|
|
|
space = FN(MULTI(BASE),get_space)(multi);
|
|
|
|
|
space = isl_space_reset_user(space);
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
return FN(MULTI(BASE),reset_space)(multi, space);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),realign_domain)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi, __isl_take isl_reordering *exp)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_space *space;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
multi = FN(MULTI(BASE),cow)(multi);
|
|
|
|
|
if (!multi || !exp)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < multi->n; ++i) {
|
2020-07-11 13:25:06 +02:00
|
|
|
|
multi->u.p[i] = FN(EL,realign_domain)(multi->u.p[i],
|
2014-01-27 21:38:34 +01:00
|
|
|
|
isl_reordering_copy(exp));
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (!multi->u.p[i])
|
2014-01-27 21:38:34 +01:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
space = isl_reordering_get_space(exp);
|
|
|
|
|
multi = FN(MULTI(BASE),reset_domain_space)(multi, space);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
isl_reordering_free(exp);
|
|
|
|
|
return multi;
|
|
|
|
|
error:
|
|
|
|
|
isl_reordering_free(exp);
|
|
|
|
|
FN(MULTI(BASE),free)(multi);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Align the parameters of "multi" to those of "model".
|
2020-07-11 13:25:06 +02:00
|
|
|
|
*
|
|
|
|
|
* If "multi" has an explicit domain, then align the parameters
|
|
|
|
|
* of the domain first.
|
2014-01-27 21:38:34 +01:00
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),align_params)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi, __isl_take isl_space *model)
|
|
|
|
|
{
|
|
|
|
|
isl_ctx *ctx;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
isl_bool equal_params;
|
|
|
|
|
isl_reordering *exp;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
if (!multi || !model)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2018-07-03 21:52:50 +02:00
|
|
|
|
equal_params = isl_space_has_equal_params(multi->space, model);
|
|
|
|
|
if (equal_params < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
if (equal_params) {
|
|
|
|
|
isl_space_free(model);
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
ctx = isl_space_get_ctx(model);
|
|
|
|
|
if (!isl_space_has_named_params(model))
|
|
|
|
|
isl_die(ctx, isl_error_invalid,
|
|
|
|
|
"model has unnamed parameters", goto error);
|
|
|
|
|
if (!isl_space_has_named_params(multi->space))
|
|
|
|
|
isl_die(ctx, isl_error_invalid,
|
|
|
|
|
"input has unnamed parameters", goto error);
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi)) {
|
|
|
|
|
multi = FN(MULTI(BASE),align_explicit_domain_params)(multi,
|
|
|
|
|
isl_space_copy(model));
|
|
|
|
|
if (!multi)
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2018-07-03 21:52:50 +02:00
|
|
|
|
exp = isl_parameter_alignment_reordering(multi->space, model);
|
|
|
|
|
exp = isl_reordering_extend_space(exp,
|
2014-01-27 21:38:34 +01:00
|
|
|
|
FN(MULTI(BASE),get_domain_space)(multi));
|
2018-07-03 21:52:50 +02:00
|
|
|
|
multi = FN(MULTI(BASE),realign_domain)(multi, exp);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
isl_space_free(model);
|
|
|
|
|
return multi;
|
|
|
|
|
error:
|
|
|
|
|
isl_space_free(model);
|
|
|
|
|
FN(MULTI(BASE),free)(multi);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Create a multi expression in the given space with the elements of "list"
|
|
|
|
|
* as base expressions.
|
|
|
|
|
*
|
|
|
|
|
* Since isl_multi_*_restore_* assumes that the element and
|
|
|
|
|
* the multi expression have matching spaces, the alignment
|
|
|
|
|
* (if any) needs to be performed beforehand.
|
|
|
|
|
*/
|
2014-01-27 21:38:34 +01:00
|
|
|
|
__isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),LIST(BASE))(
|
|
|
|
|
__isl_take isl_space *space, __isl_take LIST(EL) *list)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size n, dim;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
isl_ctx *ctx;
|
|
|
|
|
MULTI(BASE) *multi;
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
dim = isl_space_dim(space, isl_dim_out);
|
|
|
|
|
n = FN(FN(LIST(EL),n),BASE)(list);
|
|
|
|
|
if (dim < 0 || n < 0)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
ctx = isl_space_get_ctx(space);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (n != dim)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
isl_die(ctx, isl_error_invalid,
|
|
|
|
|
"invalid number of elements in list", goto error);
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
|
EL *el = FN(LIST(EL),peek)(list, i);
|
|
|
|
|
space = isl_space_align_params(space, FN(EL,get_space)(el));
|
|
|
|
|
}
|
2014-01-27 21:38:34 +01:00
|
|
|
|
multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
2020-07-11 13:25:06 +02:00
|
|
|
|
EL *el = FN(FN(LIST(EL),get),BASE)(list, i);
|
|
|
|
|
el = FN(EL,align_params)(el, isl_space_copy(space));
|
|
|
|
|
multi = FN(MULTI(BASE),restore_check_space)(multi, i, el);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isl_space_free(space);
|
|
|
|
|
FN(LIST(EL),free)(list);
|
|
|
|
|
return multi;
|
|
|
|
|
error:
|
|
|
|
|
isl_space_free(space);
|
|
|
|
|
FN(LIST(EL),free)(list);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
/* This function performs the same operation as isl_multi_*_from_*_list,
|
|
|
|
|
* but is considered as a function on an isl_space when exported.
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(isl_space_multi,BASE)(__isl_take isl_space *space,
|
|
|
|
|
__isl_take LIST(EL) *list)
|
|
|
|
|
{
|
|
|
|
|
return FN(FN(MULTI(BASE),from),LIST(BASE))(space, list);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi,
|
|
|
|
|
enum isl_dim_type type, unsigned first, unsigned n)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
multi = FN(MULTI(BASE),cow)(multi);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),check_range)(multi, type, first, n) < 0)
|
|
|
|
|
return FN(MULTI(BASE),free)(multi);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
multi->space = isl_space_drop_dims(multi->space, type, first, n);
|
|
|
|
|
if (!multi->space)
|
2018-07-03 21:52:50 +02:00
|
|
|
|
return FN(MULTI(BASE),free)(multi);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
if (type == isl_dim_out) {
|
|
|
|
|
for (i = 0; i < n; ++i)
|
2020-07-11 13:25:06 +02:00
|
|
|
|
FN(EL,free)(multi->u.p[first + i]);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
for (i = first; i + n < multi->n; ++i)
|
2020-07-11 13:25:06 +02:00
|
|
|
|
multi->u.p[i] = multi->u.p[i + n];
|
2014-01-27 21:38:34 +01:00
|
|
|
|
multi->n -= n;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (n > 0 && FN(MULTI(BASE),has_explicit_domain)(multi))
|
|
|
|
|
multi = FN(MULTI(BASE),init_explicit_domain)(multi);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi))
|
|
|
|
|
multi = FN(MULTI(BASE),drop_explicit_domain_dims)(multi,
|
|
|
|
|
type, first, n);
|
|
|
|
|
if (!multi)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
for (i = 0; i < multi->n; ++i) {
|
2020-07-11 13:25:06 +02:00
|
|
|
|
multi->u.p[i] = FN(EL,drop_dims)(multi->u.p[i], type, first, n);
|
|
|
|
|
if (!multi->u.p[i])
|
2018-07-03 21:52:50 +02:00
|
|
|
|
return FN(MULTI(BASE),free)(multi);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
#undef TYPE
|
|
|
|
|
#define TYPE MULTI(BASE)
|
2018-07-03 21:52:50 +02:00
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
#include "isl_check_named_params_templ.c"
|
|
|
|
|
static
|
|
|
|
|
#include "isl_align_params_bin_templ.c"
|
2018-07-03 21:52:50 +02:00
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
/* Given two MULTI(BASE)s A -> B and C -> D,
|
2018-07-03 21:52:50 +02:00
|
|
|
|
* construct a MULTI(BASE) (A * C) -> [B -> D].
|
|
|
|
|
*
|
2020-07-11 13:25:06 +02:00
|
|
|
|
* If "multi1" and/or "multi2" has an explicit domain, then
|
|
|
|
|
* intersect the domain of the result with these explicit domains.
|
2014-01-27 21:38:34 +01:00
|
|
|
|
*/
|
2022-07-15 15:05:28 +02:00
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),range_product)(
|
2014-01-27 21:38:34 +01:00
|
|
|
|
__isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
|
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
int i;
|
|
|
|
|
isl_size n1, n2;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
EL *el;
|
|
|
|
|
isl_space *space;
|
|
|
|
|
MULTI(BASE) *res;
|
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
FN(MULTI(BASE),align_params_bin)(&multi1, &multi2);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
n1 = FN(MULTI(BASE),size)(multi1);
|
|
|
|
|
n2 = FN(MULTI(BASE),size)(multi2);
|
|
|
|
|
if (n1 < 0 || n2 < 0)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
space = isl_space_range_product(FN(MULTI(BASE),get_space)(multi1),
|
|
|
|
|
FN(MULTI(BASE),get_space)(multi2));
|
|
|
|
|
res = FN(MULTI(BASE),alloc)(space);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n1; ++i) {
|
|
|
|
|
el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
|
|
|
|
|
res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n2; ++i) {
|
|
|
|
|
el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
|
|
|
|
|
res = FN(FN(MULTI(BASE),set),BASE)(res, n1 + i, el);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi1))
|
|
|
|
|
res = FN(MULTI(BASE),intersect_explicit_domain)(res, multi1);
|
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi2))
|
|
|
|
|
res = FN(MULTI(BASE),intersect_explicit_domain)(res, multi2);
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
FN(MULTI(BASE),free)(multi1);
|
|
|
|
|
FN(MULTI(BASE),free)(multi2);
|
|
|
|
|
return res;
|
|
|
|
|
error:
|
|
|
|
|
FN(MULTI(BASE),free)(multi1);
|
|
|
|
|
FN(MULTI(BASE),free)(multi2);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 21:52:50 +02:00
|
|
|
|
/* Is the range of "multi" a wrapped relation?
|
|
|
|
|
*/
|
|
|
|
|
isl_bool FN(MULTI(BASE),range_is_wrapping)(__isl_keep MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
if (!multi)
|
|
|
|
|
return isl_bool_error;
|
|
|
|
|
return isl_space_range_is_wrapping(multi->space);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given a function A -> [B -> C], extract the function A -> B.
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),range_factor_domain)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
isl_space *space;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size total, keep;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
total = FN(MULTI(BASE),dim)(multi, isl_dim_out);
|
|
|
|
|
if (total < 0)
|
|
|
|
|
return FN(MULTI(BASE),free)(multi);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
if (!isl_space_range_is_wrapping(multi->space))
|
|
|
|
|
isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
|
|
|
|
|
"range is not a product",
|
|
|
|
|
return FN(MULTI(BASE),free)(multi));
|
|
|
|
|
|
|
|
|
|
space = FN(MULTI(BASE),get_space)(multi);
|
|
|
|
|
space = isl_space_range_factor_domain(space);
|
|
|
|
|
keep = isl_space_dim(space, isl_dim_out);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (keep < 0)
|
|
|
|
|
multi = FN(MULTI(BASE),free)(multi);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
multi = FN(MULTI(BASE),drop_dims)(multi,
|
|
|
|
|
isl_dim_out, keep, total - keep);
|
|
|
|
|
multi = FN(MULTI(BASE),reset_space)(multi, space);
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given a function A -> [B -> C], extract the function A -> C.
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),range_factor_range)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
isl_space *space;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size total, keep;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
total = FN(MULTI(BASE),dim)(multi, isl_dim_out);
|
|
|
|
|
if (total < 0)
|
|
|
|
|
return FN(MULTI(BASE),free)(multi);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
if (!isl_space_range_is_wrapping(multi->space))
|
|
|
|
|
isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
|
|
|
|
|
"range is not a product",
|
|
|
|
|
return FN(MULTI(BASE),free)(multi));
|
|
|
|
|
|
|
|
|
|
space = FN(MULTI(BASE),get_space)(multi);
|
|
|
|
|
space = isl_space_range_factor_range(space);
|
|
|
|
|
keep = isl_space_dim(space, isl_dim_out);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (keep < 0)
|
|
|
|
|
multi = FN(MULTI(BASE),free)(multi);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_out, 0, total - keep);
|
|
|
|
|
multi = FN(MULTI(BASE),reset_space)(multi, space);
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given a function [B -> C], extract the function C.
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),factor_range)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
isl_space *space;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size total, keep;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
total = FN(MULTI(BASE),dim)(multi, isl_dim_set);
|
|
|
|
|
if (total < 0)
|
|
|
|
|
return FN(MULTI(BASE),free)(multi);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
if (!isl_space_is_wrapping(multi->space))
|
|
|
|
|
isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
|
|
|
|
|
"not a product", return FN(MULTI(BASE),free)(multi));
|
|
|
|
|
|
|
|
|
|
space = FN(MULTI(BASE),get_space)(multi);
|
|
|
|
|
space = isl_space_factor_range(space);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
keep = isl_space_dim(space, isl_dim_set);
|
|
|
|
|
if (keep < 0)
|
|
|
|
|
multi = FN(MULTI(BASE),free)(multi);
|
|
|
|
|
multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_set, 0, total - keep);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
multi = FN(MULTI(BASE),reset_space)(multi, space);
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
__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;
|
|
|
|
|
|
|
|
|
|
multi->space = isl_space_flatten_range(multi->space);
|
|
|
|
|
if (!multi->space)
|
|
|
|
|
return FN(MULTI(BASE),free)(multi);
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given two MULTI(BASE)s A -> B and C -> D,
|
2018-07-03 21:52:50 +02:00
|
|
|
|
* construct a MULTI(BASE) (A * C) -> (B, D).
|
2014-01-27 21:38:34 +01:00
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),flat_range_product)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
|
|
|
|
|
{
|
|
|
|
|
MULTI(BASE) *multi;
|
|
|
|
|
|
|
|
|
|
multi = FN(MULTI(BASE),range_product)(multi1, multi2);
|
|
|
|
|
multi = FN(MULTI(BASE),flatten_range)(multi);
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given two multi expressions, "multi1"
|
|
|
|
|
*
|
|
|
|
|
* [A] -> [B1 B2]
|
|
|
|
|
*
|
|
|
|
|
* where B2 starts at position "pos", and "multi2"
|
|
|
|
|
*
|
|
|
|
|
* [A] -> [D]
|
|
|
|
|
*
|
|
|
|
|
* return the multi expression
|
|
|
|
|
*
|
|
|
|
|
* [A] -> [B1 D B2]
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),range_splice)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi1, unsigned pos,
|
|
|
|
|
__isl_take MULTI(BASE) *multi2)
|
|
|
|
|
{
|
|
|
|
|
MULTI(BASE) *res;
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size dim;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
dim = FN(MULTI(BASE),size)(multi1);
|
|
|
|
|
if (dim < 0 || !multi2)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
goto error;
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),check_range)(multi1, isl_dim_out, pos, 0) < 0)
|
|
|
|
|
goto error;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
res = FN(MULTI(BASE),copy)(multi1);
|
|
|
|
|
res = FN(MULTI(BASE),drop_dims)(res, isl_dim_out, pos, dim - pos);
|
|
|
|
|
multi1 = FN(MULTI(BASE),drop_dims)(multi1, isl_dim_out, 0, pos);
|
|
|
|
|
|
|
|
|
|
res = FN(MULTI(BASE),flat_range_product)(res, multi2);
|
|
|
|
|
res = FN(MULTI(BASE),flat_range_product)(res, multi1);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
error:
|
|
|
|
|
FN(MULTI(BASE),free)(multi1);
|
|
|
|
|
FN(MULTI(BASE),free)(multi2);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
#undef TYPE
|
|
|
|
|
#define TYPE MULTI(BASE)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
static
|
|
|
|
|
#include "isl_type_has_equal_space_bin_templ.c"
|
|
|
|
|
static
|
|
|
|
|
#include "isl_type_check_equal_space_templ.c"
|
2014-01-27 21:38:34 +01:00
|
|
|
|
|
|
|
|
|
/* This function is currently only used from isl_aff.c
|
|
|
|
|
*/
|
|
|
|
|
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 *))
|
|
|
|
|
__attribute__ ((unused));
|
|
|
|
|
|
|
|
|
|
/* Pairwise perform "fn" to the elements of "multi1" and "multi2" and
|
|
|
|
|
* return the result.
|
2020-07-11 13:25:06 +02:00
|
|
|
|
*
|
|
|
|
|
* If "multi2" has an explicit domain, then
|
|
|
|
|
* intersect the domain of the result with this explicit domain.
|
2014-01-27 21:38:34 +01:00
|
|
|
|
*/
|
|
|
|
|
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 *))
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
FN(MULTI(BASE),align_params_bin)(&multi1, &multi2);
|
2014-01-27 21:38:34 +01:00
|
|
|
|
multi1 = FN(MULTI(BASE),cow)(multi1);
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),check_equal_space)(multi1, multi2) < 0)
|
2014-01-27 21:38:34 +01:00
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < multi1->n; ++i) {
|
2020-07-11 13:25:06 +02:00
|
|
|
|
multi1->u.p[i] = fn(multi1->u.p[i],
|
|
|
|
|
FN(EL,copy)(multi2->u.p[i]));
|
|
|
|
|
if (!multi1->u.p[i])
|
2014-01-27 21:38:34 +01:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi2))
|
|
|
|
|
multi1 = FN(MULTI(BASE),intersect_explicit_domain)(multi1,
|
|
|
|
|
multi2);
|
|
|
|
|
|
2014-01-27 21:38:34 +01:00
|
|
|
|
FN(MULTI(BASE),free)(multi2);
|
|
|
|
|
return multi1;
|
|
|
|
|
error:
|
|
|
|
|
FN(MULTI(BASE),free)(multi1);
|
|
|
|
|
FN(MULTI(BASE),free)(multi2);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Only used on some multi-expressions.
|
2018-07-03 21:52:50 +02:00
|
|
|
|
*/
|
2020-07-11 13:25:06 +02:00
|
|
|
|
static isl_bool FN(MULTI(BASE),any)(__isl_keep MULTI(BASE) *multi,
|
|
|
|
|
isl_bool (*test)(__isl_keep EL *)) __attribute__ ((unused));
|
2018-07-03 21:52:50 +02:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
/* Does "test" succeed on any base expression of "multi"?
|
2014-01-27 21:38:34 +01:00
|
|
|
|
*/
|
2020-07-11 13:25:06 +02:00
|
|
|
|
static isl_bool FN(MULTI(BASE),any)(__isl_keep MULTI(BASE) *multi,
|
|
|
|
|
isl_bool (*test)(__isl_keep EL *))
|
2014-01-27 21:38:34 +01:00
|
|
|
|
{
|
2020-07-11 13:25:06 +02:00
|
|
|
|
isl_size n;
|
2014-01-27 21:38:34 +01:00
|
|
|
|
int i;
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
n = FN(MULTI(BASE),size)(multi);
|
|
|
|
|
if (n < 0)
|
|
|
|
|
return isl_bool_error;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
|
isl_bool any = test(multi->u.p[i]);
|
|
|
|
|
if (any < 0 || any)
|
|
|
|
|
return any;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
return isl_bool_false;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 15:05:28 +02:00
|
|
|
|
/* Only used on some multi-expressions.
|
|
|
|
|
*/
|
|
|
|
|
static isl_bool FN(MULTI(BASE),every)(__isl_keep MULTI(BASE) *multi,
|
|
|
|
|
isl_bool (*test)(__isl_keep EL *)) __attribute__ ((unused));
|
|
|
|
|
|
|
|
|
|
/* Does "test" succeed on every base expression of "multi"?
|
|
|
|
|
*/
|
|
|
|
|
static isl_bool FN(MULTI(BASE),every)(__isl_keep MULTI(BASE) *multi,
|
|
|
|
|
isl_bool (*test)(__isl_keep EL *))
|
|
|
|
|
{
|
|
|
|
|
isl_size n;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
n = FN(MULTI(BASE),size)(multi);
|
|
|
|
|
if (n < 0)
|
|
|
|
|
return isl_bool_error;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
|
isl_bool every = test(multi->u.p[i]);
|
|
|
|
|
if (every < 0 || !every)
|
|
|
|
|
return every;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isl_bool_true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 21:52:50 +02:00
|
|
|
|
/* Convert a multiple expression defined over a parameter domain
|
|
|
|
|
* into one that is defined over a zero-dimensional set.
|
|
|
|
|
*/
|
|
|
|
|
__isl_give MULTI(BASE) *FN(MULTI(BASE),from_range)(
|
|
|
|
|
__isl_take MULTI(BASE) *multi)
|
|
|
|
|
{
|
|
|
|
|
isl_space *space;
|
|
|
|
|
|
|
|
|
|
if (!multi)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (!isl_space_is_set(multi->space))
|
|
|
|
|
isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
|
|
|
|
|
"not living in a set space",
|
|
|
|
|
return FN(MULTI(BASE),free)(multi));
|
|
|
|
|
|
|
|
|
|
space = FN(MULTI(BASE),get_space)(multi);
|
|
|
|
|
space = isl_space_from_range(space);
|
|
|
|
|
multi = FN(MULTI(BASE),reset_space)(multi, space);
|
|
|
|
|
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Are "multi1" and "multi2" obviously equal?
|
|
|
|
|
*/
|
|
|
|
|
isl_bool FN(MULTI(BASE),plain_is_equal)(__isl_keep MULTI(BASE) *multi1,
|
|
|
|
|
__isl_keep MULTI(BASE) *multi2)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
isl_bool equal;
|
|
|
|
|
|
|
|
|
|
if (!multi1 || !multi2)
|
|
|
|
|
return isl_bool_error;
|
|
|
|
|
if (multi1->n != multi2->n)
|
|
|
|
|
return isl_bool_false;
|
|
|
|
|
equal = isl_space_is_equal(multi1->space, multi2->space);
|
|
|
|
|
if (equal < 0 || !equal)
|
|
|
|
|
return equal;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < multi1->n; ++i) {
|
2020-07-11 13:25:06 +02:00
|
|
|
|
equal = FN(EL,plain_is_equal)(multi1->u.p[i], multi2->u.p[i]);
|
2018-07-03 21:52:50 +02:00
|
|
|
|
if (equal < 0 || !equal)
|
|
|
|
|
return equal;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
if (FN(MULTI(BASE),has_explicit_domain)(multi1) ||
|
|
|
|
|
FN(MULTI(BASE),has_explicit_domain)(multi2)) {
|
|
|
|
|
equal = FN(MULTI(BASE),equal_explicit_domain)(multi1, multi2);
|
|
|
|
|
if (equal < 0 || !equal)
|
|
|
|
|
return equal;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 13:25:06 +02:00
|
|
|
|
return isl_bool_true;
|
2018-07-03 21:52:50 +02:00
|
|
|
|
}
|