/*
* Copyright 2010 INRIA Saclay
*
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
* Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
* 91893 Orsay, France
*/
+#define ISL_DIM_H
#include <isl_map_private.h>
#include <isl_union_map_private.h>
#include <isl_polynomial_private.h>
#include <isl_point_private.h>
-#include <isl_dim_private.h>
+#include <isl_space_private.h>
#include <isl/lp.h>
#include <isl/seq.h>
#include <isl_mat_private.h>
}
static __isl_give isl_qpolynomial_fold *qpolynomial_fold_alloc(
- enum isl_fold type, __isl_take isl_dim *dim, int n)
+ enum isl_fold type, __isl_take isl_space *dim, int n)
{
isl_qpolynomial_fold *fold;
return fold;
error:
- isl_dim_free(dim);
+ isl_space_free(dim);
return NULL;
}
return fold ? fold->dim->ctx : NULL;
}
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_dim(
- __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim)
+__isl_give isl_space *isl_qpolynomial_fold_get_domain_space(
+ __isl_keep isl_qpolynomial_fold *fold)
+{
+ return fold ? isl_space_copy(fold->dim) : NULL;
+}
+
+__isl_give isl_space *isl_qpolynomial_fold_get_space(
+ __isl_keep isl_qpolynomial_fold *fold)
+{
+ isl_space *space;
+ if (!fold)
+ return NULL;
+ space = isl_space_copy(fold->dim);
+ space = isl_space_from_domain(space);
+ space = isl_space_add_dims(space, isl_dim_out, 1);
+ return space;
+}
+
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_domain_space(
+ __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *dim)
{
int i;
goto error;
for (i = 0; i < fold->n; ++i) {
- fold->qp[i] = isl_qpolynomial_reset_dim(fold->qp[i],
- isl_dim_copy(dim));
+ fold->qp[i] = isl_qpolynomial_reset_domain_space(fold->qp[i],
+ isl_space_copy(dim));
if (!fold->qp[i])
goto error;
}
- isl_dim_free(fold->dim);
+ isl_space_free(fold->dim);
fold->dim = dim;
return fold;
error:
isl_qpolynomial_fold_free(fold);
- isl_dim_free(dim);
+ isl_space_free(dim);
return NULL;
}
+/* Reset the space of "fold". 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.
+ */
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_reset_space_and_domain(
+ __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *space,
+ __isl_take isl_space *domain)
+{
+ isl_space_free(space);
+ return isl_qpolynomial_fold_reset_domain_space(fold, domain);
+}
+
int isl_qpolynomial_fold_involves_dims(__isl_keep isl_qpolynomial_fold *fold,
enum isl_dim_type type, unsigned first, unsigned n)
{
fold = isl_qpolynomial_fold_cow(fold);
if (!fold)
return NULL;
- fold->dim = isl_dim_set_name(fold->dim, type, pos, s);
+ fold->dim = isl_space_set_dim_name(fold->dim, type, pos, s);
if (!fold->dim)
goto error;
enum isl_dim_type type, unsigned first, unsigned n)
{
int i;
+ enum isl_dim_type set_type;
if (!fold)
return NULL;
if (n == 0)
return fold;
+ set_type = type == isl_dim_in ? isl_dim_set : type;
+
fold = isl_qpolynomial_fold_cow(fold);
if (!fold)
return NULL;
- fold->dim = isl_dim_drop(fold->dim, type, first, n);
+ fold->dim = isl_space_drop_dims(fold->dim, set_type, first, n);
if (!fold->dim)
goto error;
if (!fold)
return NULL;
- if (n == 0 && !isl_dim_is_named_or_nested(fold->dim, type))
+ if (n == 0 && !isl_space_is_named_or_nested(fold->dim, type))
return fold;
fold = isl_qpolynomial_fold_cow(fold);
if (!fold)
return NULL;
- fold->dim = isl_dim_insert(fold->dim, type, first, n);
+ fold->dim = isl_space_insert_dims(fold->dim, type, first, n);
if (!fold->dim)
goto error;
if (!rec)
return 0;
- d = isl_dim_total(qp->dim);
+ d = isl_space_dim(qp->dim, isl_dim_all);
v = isl_vec_alloc(set->ctx, 2 + d);
if (!v)
return 0;
isl_qpolynomial *r, *q;
isl_qpolynomial *t;
- min = isl_qpolynomial_cst(isl_dim_copy(qp->dim), l);
- base = isl_qpolynomial_var_pow(isl_dim_copy(qp->dim),
+ min = isl_qpolynomial_cst_on_domain(isl_space_copy(qp->dim), l);
+ base = isl_qpolynomial_var_pow_on_domain(isl_space_copy(qp->dim),
qp->upoly->var, 1);
- r = isl_qpolynomial_alloc(isl_dim_copy(qp->dim), 0,
+ r = isl_qpolynomial_alloc(isl_space_copy(qp->dim), 0,
isl_upoly_copy(rec->p[rec->n - 1]));
q = isl_qpolynomial_copy(r);
for (i = rec->n - 2; i >= 0; --i) {
r = isl_qpolynomial_mul(r, isl_qpolynomial_copy(min));
- t = isl_qpolynomial_alloc(isl_dim_copy(qp->dim), 0,
+ t = isl_qpolynomial_alloc(isl_space_copy(qp->dim), 0,
isl_upoly_copy(rec->p[i]));
r = isl_qpolynomial_add(r, t);
if (i == 0)
goto error;
isl_assert(fold1->dim->ctx, fold1->type == fold2->type, goto error);
- isl_assert(fold1->dim->ctx, isl_dim_equal(fold1->dim, fold2->dim),
+ isl_assert(fold1->dim->ctx, isl_space_is_equal(fold1->dim, fold2->dim),
goto error);
better = fold1->type == isl_fold_max ? -1 : 1;
return fold1;
}
- res = qpolynomial_fold_alloc(fold1->type, isl_dim_copy(fold1->dim),
+ res = qpolynomial_fold_alloc(fold1->type, isl_space_copy(fold1->dim),
fold1->n + fold2->n);
if (!res)
goto error;
return NULL;
}
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_gist_params(
+ __isl_take isl_qpolynomial_fold *fold, __isl_take isl_set *context)
+{
+ isl_space *space = isl_qpolynomial_fold_get_domain_space(fold);
+ isl_set *dom_context = isl_set_universe(space);
+ dom_context = isl_set_intersect_params(dom_context, context);
+ return isl_qpolynomial_fold_gist(fold, dom_context);
+}
+
#define HAS_TYPE
#undef PW
#define PW isl_pw_qpolynomial_fold
#undef EL
#define EL isl_qpolynomial_fold
+#undef EL_IS_ZERO
+#define EL_IS_ZERO is_empty
+#undef ZERO
+#define ZERO zero
#undef IS_ZERO
-#define IS_ZERO is_empty
+#define IS_ZERO is_zero
#undef FIELD
#define FIELD fold
+#undef DEFAULT_IS_ZERO
+#define DEFAULT_IS_ZERO 1
+
+#define NO_NEG
+#define NO_PULLBACK
#include <isl_pw_templ.c>
#define PART isl_pw_qpolynomial_fold
#undef PARTS
#define PARTS pw_qpolynomial_fold
+#define ALIGN_DOMAIN
+
+#define NO_SUB
#include <isl_union_templ.c>
__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_empty(enum isl_fold type,
- __isl_take isl_dim *dim)
+ __isl_take isl_space *dim)
{
return qpolynomial_fold_alloc(type, dim, 0);
}
if (!qp)
return NULL;
- fold = qpolynomial_fold_alloc(type, isl_dim_copy(qp->dim), 1);
+ fold = qpolynomial_fold_alloc(type, isl_space_copy(qp->dim), 1);
if (!fold)
goto error;
if (!fold)
return NULL;
dup = qpolynomial_fold_alloc(fold->type,
- isl_dim_copy(fold->dim), fold->n);
+ isl_space_copy(fold->dim), fold->n);
if (!dup)
return NULL;
for (i = 0; i < fold->n; ++i)
isl_qpolynomial_free(fold->qp[i]);
- isl_dim_free(fold->dim);
+ isl_space_free(fold->dim);
free(fold);
}
goto error;
isl_assert(fold1->dim->ctx, fold1->type == fold2->type, goto error);
- isl_assert(fold1->dim->ctx, isl_dim_equal(fold1->dim, fold2->dim),
+ isl_assert(fold1->dim->ctx, isl_space_is_equal(fold1->dim, fold2->dim),
goto error);
if (isl_qpolynomial_fold_is_empty(fold1)) {
return fold1;
}
- res = qpolynomial_fold_alloc(fold1->type, isl_dim_copy(fold1->dim),
+ res = qpolynomial_fold_alloc(fold1->type, isl_space_copy(fold1->dim),
fold1->n + fold2->n);
if (!res)
goto error;
if (!pw1 || !pw2)
goto error;
- isl_assert(pw1->dim->ctx, isl_dim_equal(pw1->dim, pw2->dim), goto error);
+ isl_assert(pw1->dim->ctx, isl_space_is_equal(pw1->dim, pw2->dim), goto error);
if (isl_pw_qpolynomial_fold_is_zero(pw1)) {
isl_pw_qpolynomial_fold_free(pw1);
"fold types don't match", goto error);
n = (pw1->n + 1) * (pw2->n + 1);
- res = isl_pw_qpolynomial_fold_alloc_(isl_dim_copy(pw1->dim),
+ res = isl_pw_qpolynomial_fold_alloc_size(isl_space_copy(pw1->dim),
pw1->type, n);
for (i = 0; i < pw1->n; ++i) {
if (!part || !u)
goto error;
- isl_assert(u->dim->ctx, isl_dim_match(part->dim, isl_dim_param, u->dim,
+ isl_assert(u->dim->ctx, isl_space_match(part->dim, isl_dim_param, u->dim,
isl_dim_param), goto error);
- hash = isl_dim_get_hash(part->dim);
+ hash = isl_space_get_hash(part->dim);
entry = isl_hash_table_find(u->dim->ctx, &u->table, hash,
&has_dim, part->dim, 1);
if (!entry)
if (!pwqp)
return NULL;
- pwf = isl_pw_qpolynomial_fold_alloc_(isl_dim_copy(pwqp->dim), type,
- pwqp->n);
+ pwf = isl_pw_qpolynomial_fold_alloc_size(isl_space_copy(pwqp->dim),
+ type, pwqp->n);
for (i = 0; i < pwqp->n; ++i)
pwf = isl_pw_qpolynomial_fold_add_piece(pwf,
return pwf;
}
+__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_add(
+ __isl_take isl_pw_qpolynomial_fold *pwf1,
+ __isl_take isl_pw_qpolynomial_fold *pwf2)
+{
+ return isl_pw_qpolynomial_fold_union_add_(pwf1, pwf2);
+}
+
int isl_qpolynomial_fold_plain_is_equal(__isl_keep isl_qpolynomial_fold *fold1,
__isl_keep isl_qpolynomial_fold *fold2)
{
if (!fold || !pnt)
goto error;
- isl_assert(pnt->dim->ctx, isl_dim_equal(pnt->dim, fold->dim), goto error);
+ isl_assert(pnt->dim->ctx, isl_space_is_equal(pnt->dim, fold->dim), goto error);
isl_assert(pnt->dim->ctx,
fold->type == isl_fold_max || fold->type == isl_fold_min,
goto error);
if (fold->n == 0)
- qp = isl_qpolynomial_zero(isl_dim_copy(fold->dim));
+ qp = isl_qpolynomial_zero_on_domain(isl_space_copy(fold->dim));
else {
int i;
qp = isl_qpolynomial_eval(isl_qpolynomial_copy(fold->qp[0]),
goto error;
if (fold->n == 0) {
- isl_dim *dim = isl_dim_copy(fold->dim);
+ isl_space *dim = isl_space_copy(fold->dim);
isl_set_free(set);
isl_qpolynomial_fold_free(fold);
- return isl_qpolynomial_zero(dim);
+ return isl_qpolynomial_zero_on_domain(dim);
}
opt = isl_qpolynomial_opt_on_domain(isl_qpolynomial_copy(fold->qp[0]),
return 1;
}
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph(
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph_domain(
__isl_take isl_qpolynomial_fold *fold, __isl_take isl_morph *morph)
{
int i;
goto error;
ctx = fold->dim->ctx;
- isl_assert(ctx, isl_dim_equal(fold->dim, morph->dom->dim), goto error);
+ isl_assert(ctx, isl_space_is_equal(fold->dim, morph->dom->dim), goto error);
fold = isl_qpolynomial_fold_cow(fold);
if (!fold)
goto error;
- isl_dim_free(fold->dim);
- fold->dim = isl_dim_copy(morph->ran->dim);
+ isl_space_free(fold->dim);
+ fold->dim = isl_space_copy(morph->ran->dim);
if (!fold->dim)
goto error;
for (i = 0; i < fold->n; ++i) {
- fold->qp[i] = isl_qpolynomial_morph(fold->qp[i],
+ fold->qp[i] = isl_qpolynomial_morph_domain(fold->qp[i],
isl_morph_copy(morph));
if (!fold->qp[i])
goto error;
}
__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_lift(
- __isl_take isl_qpolynomial_fold *fold, __isl_take isl_dim *dim)
+ __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *dim)
{
int i;
if (!fold || !dim)
goto error;
- if (isl_dim_equal(fold->dim, dim)) {
- isl_dim_free(dim);
+ if (isl_space_is_equal(fold->dim, dim)) {
+ isl_space_free(dim);
return fold;
}
if (!fold)
goto error;
- isl_dim_free(fold->dim);
- fold->dim = isl_dim_copy(dim);
+ isl_space_free(fold->dim);
+ fold->dim = isl_space_copy(dim);
if (!fold->dim)
goto error;
for (i = 0; i < fold->n; ++i) {
fold->qp[i] = isl_qpolynomial_lift(fold->qp[i],
- isl_dim_copy(dim));
+ isl_space_copy(dim));
if (!fold->qp[i])
goto error;
}
- isl_dim_free(dim);
+ isl_space_free(dim);
return fold;
error:
isl_qpolynomial_fold_free(fold);
- isl_dim_free(dim);
+ isl_space_free(dim);
return NULL;
}
if (!fold)
return NULL;
- fold->dim = isl_dim_move(fold->dim, dst_type, dst_pos,
+ fold->dim = isl_space_move_dims(fold->dim, dst_type, dst_pos,
src_type, src_pos, n);
if (!fold->dim)
goto error;
upwf = (isl_union_pw_qpolynomial_fold **)user;
ctx = pwqp->dim->ctx;
- hash = isl_dim_get_hash(pwqp->dim);
+ hash = isl_space_get_hash(pwqp->dim);
entry = isl_hash_table_find(ctx, &(*upwf)->table,
hash, &has_dim, pwqp->dim, 1);
if (!entry)
__isl_take isl_union_pw_qpolynomial *upwqp)
{
upwf = isl_union_pw_qpolynomial_fold_align_params(upwf,
- isl_union_pw_qpolynomial_get_dim(upwqp));
+ isl_union_pw_qpolynomial_get_space(upwqp));
upwqp = isl_union_pw_qpolynomial_align_params(upwqp,
- isl_union_pw_qpolynomial_fold_get_dim(upwf));
+ isl_union_pw_qpolynomial_fold_get_space(upwf));
upwf = isl_union_pw_qpolynomial_fold_cow(upwf);
if (!upwf || !upwqp)
return NULL;
}
-static int compatible_range(__isl_keep isl_dim *dim1, __isl_keep isl_dim *dim2)
+static int join_compatible(__isl_keep isl_space *dim1, __isl_keep isl_space *dim2)
{
int m;
- m = isl_dim_match(dim1, isl_dim_param, dim2, isl_dim_param);
+ m = isl_space_match(dim1, isl_dim_param, dim2, isl_dim_param);
if (m < 0 || !m)
return m;
- return isl_dim_tuple_match(dim1, isl_dim_out, dim2, isl_dim_set);
+ return isl_space_tuple_match(dim1, isl_dim_out, dim2, isl_dim_in);
}
/* Compute the intersection of the range of the map and the domain
{
isl_ctx *ctx;
isl_set *dom;
- isl_dim *map_dim;
- isl_dim *pwf_dim;
+ isl_space *map_dim;
+ isl_space *pwf_dim;
unsigned n_in;
int ok;
if (!ctx)
goto error;
- map_dim = isl_map_get_dim(map);
- pwf_dim = isl_pw_qpolynomial_fold_get_dim(pwf);
- ok = compatible_range(map_dim, pwf_dim);
- isl_dim_free(map_dim);
- isl_dim_free(pwf_dim);
+ map_dim = isl_map_get_space(map);
+ pwf_dim = isl_pw_qpolynomial_fold_get_space(pwf);
+ ok = join_compatible(map_dim, pwf_dim);
+ isl_space_free(map_dim);
+ isl_space_free(pwf_dim);
if (!ok)
isl_die(ctx, isl_error_invalid, "incompatible dimensions",
goto error);
n_in = isl_map_dim(map, isl_dim_in);
- pwf = isl_pw_qpolynomial_fold_insert_dims(pwf, isl_dim_set, 0, n_in);
+ pwf = isl_pw_qpolynomial_fold_insert_dims(pwf, isl_dim_in, 0, n_in);
dom = isl_map_wrap(map);
- pwf = isl_pw_qpolynomial_fold_reset_dim(pwf, isl_set_get_dim(dom));
+ pwf = isl_pw_qpolynomial_fold_reset_domain_space(pwf,
+ isl_set_get_space(dom));
pwf = isl_pw_qpolynomial_fold_intersect_domain(pwf, dom);
pwf = isl_pw_qpolynomial_fold_bound(pwf, tight);
__isl_take isl_set *set, __isl_take isl_pw_qpolynomial_fold *pwf,
int *tight)
{
- isl_map *map;
-
- map = isl_map_from_range(set);
- return isl_map_apply_pw_qpolynomial_fold(map, pwf, tight);
+ return isl_map_apply_pw_qpolynomial_fold(set, pwf, tight);
}
struct isl_apply_fold_data {
static int pw_qpolynomial_fold_apply(__isl_take isl_pw_qpolynomial_fold *pwf,
void *user)
{
- isl_dim *map_dim;
- isl_dim *pwf_dim;
+ isl_space *map_dim;
+ isl_space *pwf_dim;
struct isl_apply_fold_data *data = user;
int ok;
- map_dim = isl_map_get_dim(data->map);
- pwf_dim = isl_pw_qpolynomial_fold_get_dim(pwf);
- ok = compatible_range(map_dim, pwf_dim);
- isl_dim_free(map_dim);
- isl_dim_free(pwf_dim);
+ map_dim = isl_map_get_space(data->map);
+ pwf_dim = isl_pw_qpolynomial_fold_get_space(pwf);
+ ok = join_compatible(map_dim, pwf_dim);
+ isl_space_free(map_dim);
+ isl_space_free(pwf_dim);
if (ok) {
pwf = isl_map_apply_pw_qpolynomial_fold(isl_map_copy(data->map),
__isl_take isl_union_map *umap,
__isl_take isl_union_pw_qpolynomial_fold *upwf, int *tight)
{
- isl_dim *dim;
+ isl_space *dim;
enum isl_fold type;
struct isl_apply_fold_data data;
upwf = isl_union_pw_qpolynomial_fold_align_params(upwf,
- isl_union_map_get_dim(umap));
+ isl_union_map_get_space(umap));
umap = isl_union_map_align_params(umap,
- isl_union_pw_qpolynomial_fold_get_dim(upwf));
+ isl_union_pw_qpolynomial_fold_get_space(upwf));
data.upwf = upwf;
data.tight = tight ? 1 : 0;
- dim = isl_union_pw_qpolynomial_fold_get_dim(upwf);
+ dim = isl_union_pw_qpolynomial_fold_get_space(upwf);
type = isl_union_pw_qpolynomial_fold_get_type(upwf);
data.res = isl_union_pw_qpolynomial_fold_zero(dim, type);
if (isl_union_map_foreach_map(umap, &map_apply, &data) < 0)
/* Reorder the dimension of "fold" according to the given reordering.
*/
-__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign(
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign_domain(
__isl_take isl_qpolynomial_fold *fold, __isl_take isl_reordering *r)
{
int i;
goto error;
for (i = 0; i < fold->n; ++i) {
- fold->qp[i] = isl_qpolynomial_realign(fold->qp[i],
+ fold->qp[i] = isl_qpolynomial_realign_domain(fold->qp[i],
isl_reordering_copy(r));
if (!fold->qp[i])
goto error;
}
- fold = isl_qpolynomial_fold_reset_dim(fold, isl_dim_copy(r->dim));
+ fold = isl_qpolynomial_fold_reset_domain_space(fold,
+ isl_space_copy(r->dim));
isl_reordering_free(r);
return fold;
if (fold && isl_int_is_zero(v)) {
isl_qpolynomial_fold *zero;
- isl_dim *dim = isl_dim_copy(fold->dim);
+ isl_space *dim = isl_space_copy(fold->dim);
zero = isl_qpolynomial_fold_empty(fold->type, dim);
isl_qpolynomial_fold_free(fold);
return zero;
isl_qpolynomial_fold_free(fold);
return NULL;
}
+
+__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_scale(
+ __isl_take isl_qpolynomial_fold *fold, isl_int v)
+{
+ return isl_qpolynomial_fold_mul_isl_int(fold, v);
+}