#include "isl_sample.h"
#include "isl_tab.h"
#include "isl_vec.h"
-#include <isl_dim_private.h>
/* Maps dst positions to src positions */
struct isl_dim_map {
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
int i;
+ struct isl_dim_map *dim_map;
+ struct isl_basic_map *res;
+ enum isl_dim_type t;
+ unsigned total, off;
if (!bmap)
return NULL;
isl_assert(bmap->ctx, src_pos + n <= isl_basic_map_dim(bmap, src_type),
goto error);
- /* just the simple case for now */
- isl_assert(bmap->ctx,
- pos(bmap->dim, dst_type) + dst_pos ==
- pos(bmap->dim, src_type) + src_pos + ((src_type < dst_type) ? n : 0),
- goto error);
+ if (dst_type == src_type && dst_pos == src_pos)
+ return bmap;
+
+ isl_assert(bmap->ctx, dst_type != src_type, goto error);
+
+ if (pos(bmap->dim, dst_type) + dst_pos ==
+ pos(bmap->dim, src_type) + src_pos +
+ ((src_type < dst_type) ? n : 0)) {
+ bmap = isl_basic_map_cow(bmap);
+ if (!bmap)
+ return NULL;
+
+ bmap->dim = isl_dim_move(bmap->dim, dst_type, dst_pos,
+ src_type, src_pos, n);
+ if (!bmap->dim)
+ goto error;
- if (dst_type == src_type)
return bmap;
+ }
- bmap = isl_basic_map_cow(bmap);
- if (!bmap)
- return NULL;
+ total = isl_basic_map_total_dim(bmap);
+ dim_map = isl_dim_map_alloc(bmap->ctx, total);
+
+ off = 0;
+ for (t = isl_dim_param; t <= isl_dim_out; ++t) {
+ unsigned size = isl_dim_size(bmap->dim, t);
+ if (t == dst_type) {
+ isl_dim_map_dim_range(dim_map, bmap->dim, t,
+ 0, dst_pos, off);
+ off += dst_pos;
+ isl_dim_map_dim_range(dim_map, bmap->dim, src_type,
+ src_pos, n, off);
+ off += n;
+ isl_dim_map_dim_range(dim_map, bmap->dim, t,
+ dst_pos, size - dst_pos, off);
+ off += size - dst_pos;
+ } else if (t == src_type) {
+ isl_dim_map_dim_range(dim_map, bmap->dim, t,
+ 0, src_pos, off);
+ off += src_pos;
+ isl_dim_map_dim_range(dim_map, bmap->dim, t,
+ src_pos + n, size - src_pos - n, off);
+ off += size - src_pos - n;
+ } else {
+ isl_dim_map_dim(dim_map, bmap->dim, t, off);
+ off += size;
+ }
+ }
+ isl_dim_map_div(dim_map, bmap, off + n);
- bmap->dim = isl_dim_move(bmap->dim, dst_type, dst_pos, src_type, src_pos, n);
+ res = isl_basic_map_alloc_dim(isl_basic_map_get_dim(bmap),
+ bmap->n_div, bmap->n_eq, bmap->n_ineq);
+ bmap = add_constraints_dim_map(res, bmap, dim_map);
+
+ bmap->dim = isl_dim_move(bmap->dim, dst_type, dst_pos,
+ src_type, src_pos, n);
if (!bmap->dim)
goto error;
isl_assert(map->ctx, src_pos + n <= isl_map_dim(map, src_type),
goto error);
- /* just the simple case for now */
- isl_assert(map->ctx,
- map_offset(map, dst_type) + dst_pos ==
- map_offset(map, src_type) + src_pos + ((src_type < dst_type) ? n : 0),
- goto error);
-
- if (dst_type == src_type)
+ if (dst_type == src_type && dst_pos == src_pos)
return map;
+ isl_assert(map->ctx, dst_type != src_type, goto error);
+
map = isl_map_cow(map);
if (!map)
return NULL;
return NULL;
}
+__isl_give isl_set *isl_set_split_dims(__isl_take isl_set *set,
+ enum isl_dim_type type, unsigned first, unsigned n)
+{
+ int i;
+ isl_basic_set *nonneg = NULL;
+ isl_basic_set *neg = NULL;
+
+ if (!set)
+ return NULL;
+ if (n == 0)
+ return set;
+
+ isl_assert(set->ctx, first + n <= isl_set_dim(set, type), goto error);
+
+ for (i = 0; i < n; ++i) {
+ int k;
+
+ neg = NULL;
+ nonneg = isl_basic_set_alloc_dim(isl_set_get_dim(set), 0, 0, 1);
+ k = isl_basic_set_alloc_inequality(nonneg);
+ if (k < 0)
+ goto error;
+ isl_seq_clr(nonneg->ineq[k], 1 + isl_basic_set_total_dim(nonneg));
+ isl_int_set_si(nonneg->ineq[k][pos(set->dim, type) + first + i], 1);
+
+ neg = isl_basic_set_alloc_dim(isl_set_get_dim(set), 0, 0, 1);
+ k = isl_basic_set_alloc_inequality(neg);
+ if (k < 0)
+ goto error;
+ isl_seq_clr(neg->ineq[k], 1 + isl_basic_set_total_dim(neg));
+ isl_int_set_si(neg->ineq[k][0], -1);
+ isl_int_set_si(neg->ineq[k][pos(set->dim, type) + first + i], -1);
+
+ set = isl_set_intersect(set, isl_basic_set_union(nonneg, neg));
+ }
+
+ return set;
+error:
+ isl_basic_set_free(nonneg);
+ isl_basic_set_free(neg);
+ isl_set_free(set);
+ return NULL;
+}
+
int isl_set_is_equal(struct isl_set *set1, struct isl_set *set2)
{
return isl_map_is_equal((struct isl_map *)set1, (struct isl_map *)set2);