-
-struct isl_dim *isl_dim_product(struct isl_dim *left, struct isl_dim *right)
-{
- isl_dim *dom1, *dom2, *nest1, *nest2;
-
- if (!left || !right)
- goto error;
-
- isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
- goto error);
-
- dom1 = isl_dim_domain(isl_dim_copy(left));
- dom2 = isl_dim_domain(isl_dim_copy(right));
- nest1 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
-
- dom1 = isl_dim_range(left);
- dom2 = isl_dim_range(right);
- nest2 = isl_dim_wrap(isl_dim_join(isl_dim_reverse(dom1), dom2));
-
- return isl_dim_join(isl_dim_reverse(nest1), nest2);
-error:
- isl_dim_free(left);
- isl_dim_free(right);
- return NULL;
-}
-
-__isl_give isl_dim *isl_dim_range_product(__isl_take isl_dim *left,
- __isl_take isl_dim *right)
-{
- isl_dim *dom, *ran1, *ran2, *nest;
-
- if (!left || !right)
- goto error;
-
- isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
- goto error);
- if (!isl_dim_tuple_match(left, isl_dim_in, right, isl_dim_in))
- isl_die(left->ctx, isl_error_invalid,
- "domains need to match", goto error);
-
- dom = isl_dim_domain(isl_dim_copy(left));
-
- ran1 = isl_dim_range(left);
- ran2 = isl_dim_range(right);
- nest = isl_dim_wrap(isl_dim_join(isl_dim_reverse(ran1), ran2));
-
- return isl_dim_join(isl_dim_reverse(dom), nest);
-error:
- isl_dim_free(left);
- isl_dim_free(right);
- return NULL;
-}
-
-__isl_give isl_dim *isl_dim_map_from_set(__isl_take isl_dim *dim)
-{
- struct isl_name **names = NULL;
-
- if (!dim)
- return NULL;
- isl_assert(dim->ctx, dim->n_in == 0, goto error);
- if (dim->n_out == 0 && !isl_dim_is_named_or_nested(dim, isl_dim_out))
- return dim;
- dim = isl_dim_cow(dim);
- if (!dim)
- return NULL;
- if (dim->names) {
- names = isl_calloc_array(dim->ctx, struct isl_name *,
- dim->nparam + dim->n_out + dim->n_out);
- if (!names)
- goto error;
- get_names(dim, isl_dim_param, 0, dim->nparam, names);
- get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->nparam);
- }
- dim->n_in = dim->n_out;
- if (names) {
- free(dim->names);
- dim->names = names;
- dim->n_name = dim->nparam + dim->n_out + dim->n_out;
- dim = copy_names(dim, isl_dim_out, 0, dim, isl_dim_in);
- }
- isl_name_free(dim->ctx, dim->tuple_name[0]);
- dim->tuple_name[0] = isl_name_copy(dim->ctx, dim->tuple_name[1]);
- isl_dim_free(dim->nested[0]);
- dim->nested[0] = isl_dim_copy(dim->nested[1]);
- return dim;
-error:
- isl_dim_free(dim);
- return NULL;
-}
-
-static struct isl_dim *set_names(struct isl_dim *dim, enum isl_dim_type type,
- unsigned first, unsigned n, struct isl_name **names)
-{
- int i;
-
- for (i = 0; i < n ; ++i)
- dim = set_name(dim, type, first+i, names[i]);
-
- return dim;
-}
-
-struct isl_dim *isl_dim_reverse(struct isl_dim *dim)
-{
- unsigned t;
- isl_dim *nested;
- struct isl_name **names = NULL;
- struct isl_name *name;
-
- if (!dim)
- return NULL;
- if (match(dim, isl_dim_in, dim, isl_dim_out))
- return dim;
-
- dim = isl_dim_cow(dim);
- if (!dim)
- return NULL;
-
- name = dim->tuple_name[0];
- dim->tuple_name[0] = dim->tuple_name[1];
- dim->tuple_name[1] = name;
-
- nested = dim->nested[0];
- dim->nested[0] = dim->nested[1];
- dim->nested[1] = nested;
-
- if (dim->names) {
- names = isl_alloc_array(dim->ctx, struct isl_name *,
- dim->n_in + dim->n_out);
- if (!names)
- goto error;
- get_names(dim, isl_dim_in, 0, dim->n_in, names);
- get_names(dim, isl_dim_out, 0, dim->n_out, names + dim->n_in);
- }
-
- t = dim->n_in;
- dim->n_in = dim->n_out;
- dim->n_out = t;
-
- if (dim->names) {
- dim = set_names(dim, isl_dim_out, 0, dim->n_out, names);
- dim = set_names(dim, isl_dim_in, 0, dim->n_in, names + dim->n_out);
- free(names);
- }
-
- return dim;
-error:
- free(names);
- isl_dim_free(dim);
- return NULL;
-}
-
-struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
- unsigned first, unsigned num)
-{
- int i;
-
- if (!dim)
- return NULL;
-
- if (num == 0)
- return isl_dim_reset(dim, type);
-
- if (!valid_dim_type(type))
- isl_die(dim->ctx, isl_error_invalid,
- "cannot drop dimensions of specified type", goto error);
-
- isl_assert(dim->ctx, first + num <= n(dim, type), goto error);
- dim = isl_dim_cow(dim);
- if (!dim)
- goto error;
- if (dim->names) {
- dim = extend_names(dim);
- if (!dim)
- goto error;
- for (i = 0; i < num; ++i)
- isl_name_free(dim->ctx, get_name(dim, type, first+i));
- for (i = first+num; i < n(dim, type); ++i)
- set_name(dim, type, i - num, get_name(dim, type, i));
- switch (type) {
- case isl_dim_param:
- get_names(dim, isl_dim_in, 0, dim->n_in,
- dim->names + offset(dim, isl_dim_in) - num);
- case isl_dim_in:
- get_names(dim, isl_dim_out, 0, dim->n_out,
- dim->names + offset(dim, isl_dim_out) - num);
- default:
- ;
- }
- dim->n_name -= num;
- }
- switch (type) {
- case isl_dim_param: dim->nparam -= num; break;
- case isl_dim_in: dim->n_in -= num; break;
- case isl_dim_out: dim->n_out -= num; break;
- default: ;
- }
- dim = isl_dim_reset(dim, type);
- if (type == isl_dim_param) {
- if (dim && dim->nested[0] &&
- !(dim->nested[0] = isl_dim_drop(dim->nested[0],
- isl_dim_param, first, num)))
- goto error;
- if (dim && dim->nested[1] &&
- !(dim->nested[1] = isl_dim_drop(dim->nested[1],
- isl_dim_param, first, num)))
- goto error;
- }
- return dim;
-error:
- isl_dim_free(dim);
- return NULL;
-}
-
-struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
- unsigned first, unsigned n)
-{
- if (!dim)
- return NULL;
- return isl_dim_drop(dim, isl_dim_in, first, n);
-}
-
-struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
- unsigned first, unsigned n)
-{
- if (!dim)
- return NULL;
- return isl_dim_drop(dim, isl_dim_out, first, n);
-}
-
-struct isl_dim *isl_dim_domain(struct isl_dim *dim)
-{
- if (!dim)
- return NULL;
- dim = isl_dim_drop_outputs(dim, 0, dim->n_out);
- return isl_dim_reverse(dim);
-}
-
-__isl_give isl_dim *isl_dim_from_domain(__isl_take isl_dim *dim)