add isl_basic_map_remove
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 18 Feb 2009 12:42:55 +0000 (13:42 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 22 Feb 2009 17:01:13 +0000 (18:01 +0100)
include/isl_dim.h
include/isl_map.h
isl_dim.c
isl_map.c
isl_map_private.h
isl_map_simplify.c

index 288927a..d443a88 100644 (file)
@@ -52,6 +52,8 @@ struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right);
 struct isl_dim *isl_dim_product(struct isl_dim *left, struct isl_dim *right);
 struct isl_dim *isl_dim_map(struct isl_dim *dim);
 struct isl_dim *isl_dim_reverse(struct isl_dim *dim);
+struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
+               unsigned first, unsigned num);
 struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
                unsigned first, unsigned n);
 struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
index 64f7482..8b05e7f 100644 (file)
@@ -150,6 +150,8 @@ struct isl_basic_map *isl_basic_map_apply_range(
 struct isl_basic_map *isl_basic_map_reverse(struct isl_basic_map *bmap);
 struct isl_basic_set *isl_basic_map_domain(struct isl_basic_map *bmap);
 struct isl_basic_set *isl_basic_map_range(struct isl_basic_map *bmap);
+struct isl_basic_map *isl_basic_map_remove(struct isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned first, unsigned n);
 struct isl_basic_map *isl_basic_map_from_basic_set(struct isl_basic_set *bset,
                struct isl_dim *dim);
 struct isl_basic_set *isl_basic_set_from_basic_map(struct isl_basic_map *bmap);
index 73783ca..b6af7e2 100644 (file)
--- a/isl_dim.c
+++ b/isl_dim.c
@@ -106,6 +106,15 @@ static struct isl_name *get_name(struct isl_dim *dim,
        return dim->names[pos];
 }
 
+static unsigned offset(struct isl_dim *dim, enum isl_dim_type type)
+{
+       switch (type) {
+       case isl_dim_param:     return 0;
+       case isl_dim_in:        return dim->nparam;
+       case isl_dim_out:       return dim->nparam + dim->n_in;
+       }
+}
+
 static unsigned n(struct isl_dim *dim, enum isl_dim_type type)
 {
        switch (type) {
@@ -448,8 +457,8 @@ error:
        return NULL;
 }
 
-struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
-               unsigned first, unsigned n)
+struct isl_dim *isl_dim_drop(struct isl_dim *dim, enum isl_dim_type type,
+               unsigned first, unsigned num)
 {
        int i;
 
@@ -459,57 +468,47 @@ struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
        if (n == 0)
                return dim;
 
-       isl_assert(dim->ctx, first + n <= dim->n_in, 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) {
-               for (i = 0; i < n; ++i) {
-                       isl_name_free(dim->ctx,
-                                       get_name(dim, isl_dim_in, first+i));
+               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);
+               case isl_dim_out:
+                       ;
                }
-               for (i = first+n; i < dim->n_in; ++i)
-                       set_name(dim, isl_dim_in, i - n,
-                               get_name(dim, isl_dim_in, i));
-               get_names(dim, isl_dim_out, 0, dim->n_out,
-                               dim->names + dim->nparam + dim->n_in - n);
        }
-       dim->n_in -= n;
+       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;
+       }
        return dim;
 error:
        isl_dim_free(dim);
        return NULL;
 }
 
-struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
+struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
                unsigned first, unsigned n)
 {
-       int i;
-
-       if (!dim)
-               return NULL;
-
-       if (n == 0)
-               return dim;
+       return isl_dim_drop(dim, isl_dim_in, first, n);
+}
 
-       isl_assert(dim->ctx, first + n <= dim->n_out, goto error);
-       dim = isl_dim_cow(dim);
-       if (!dim)
-               goto error;
-       if (dim->names) {
-               for (i = 0; i < n; ++i) {
-                       isl_name_free(dim->ctx,
-                                       get_name(dim, isl_dim_out, first+i));
-               }
-               for (i = first+n; i < dim->n_out; ++i)
-                       set_name(dim, isl_dim_out, i - n,
-                               get_name(dim, isl_dim_out, i));
-       }
-       dim->n_out -= n;
-       return dim;
-error:
-       isl_dim_free(dim);
-       return NULL;
+struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
+               unsigned first, unsigned n)
+{
+       return isl_dim_drop(dim, isl_dim_out, first, n);
 }
 
 struct isl_dim *isl_dim_domain(struct isl_dim *dim)
index 331398d..0928b59 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -107,7 +107,7 @@ unsigned isl_map_dim(const struct isl_map *map, enum isl_dim_type type)
        return n(map->dim, type);
 }
 
-static unsigned basic_map_offset(struct isl_basic_map *bmap,
+unsigned isl_basic_map_offset(struct isl_basic_map *bmap,
                                        enum isl_dim_type type)
 {
        struct isl_dim *dim = bmap->dim;
@@ -1101,6 +1101,24 @@ error:
        return NULL;
 }
 
+struct isl_basic_map *isl_basic_map_remove(struct isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned first, unsigned n)
+{
+       if (!bmap)
+               return NULL;
+       isl_assert(bmap->ctx, first + n <= isl_basic_map_dim(bmap, type),
+                       goto error);
+       if (n == 0)
+               return bmap;
+       bmap = isl_basic_map_eliminate_vars(bmap,
+                       isl_basic_map_offset(bmap, type) - 1 + first, n);
+       bmap = isl_basic_map_drop(bmap, type, first, n);
+       return bmap;
+error:
+       isl_basic_map_free(bmap);
+       return NULL;
+}
+
 /* Project out n inputs starting at first using Fourier-Motzkin */
 struct isl_map *isl_map_remove_inputs(struct isl_map *map,
        unsigned first, unsigned n)
@@ -1862,7 +1880,7 @@ struct isl_basic_map *isl_basic_map_neg(struct isl_basic_map *bmap)
                return NULL;
 
        n = isl_basic_map_dim(bmap, isl_dim_out);
-       off = basic_map_offset(bmap, isl_dim_out);
+       off = isl_basic_map_offset(bmap, isl_dim_out);
        for (i = 0; i < bmap->n_eq; ++i)
                for (j = 0; j < n; ++j)
                        isl_int_neg(bmap->eq[i][off+j], bmap->eq[i][off+j]);
@@ -2629,7 +2647,7 @@ struct isl_basic_map *isl_basic_map_fix_si(struct isl_basic_map *bmap,
        if (!bmap)
                return NULL;
        isl_assert(bmap->ctx, pos < isl_basic_map_dim(bmap, type), goto error);
-       return isl_basic_map_fix_pos(bmap, basic_map_offset(bmap, type) + pos,
+       return isl_basic_map_fix_pos(bmap, isl_basic_map_offset(bmap, type) + pos,
                                        value);
 error:
        isl_basic_map_free(bmap);
@@ -3935,7 +3953,7 @@ int isl_basic_map_fast_is_fixed(struct isl_basic_map *bmap,
        if (pos >= isl_basic_map_dim(bmap, type))
                return -1;
        return isl_basic_map_fast_has_fixed_var(bmap,
-               basic_map_offset(bmap, type) - 1 + pos, val);
+               isl_basic_map_offset(bmap, type) - 1 + pos, val);
 }
 
 /* Check if dimension dim has fixed value and if so and if val is not NULL,
index f8b4f64..ac426ed 100644 (file)
@@ -1,6 +1,9 @@
 #include "isl_set.h"
 #include "isl_map.h"
 
+unsigned isl_basic_map_offset(struct isl_basic_map *bmap,
+                                       enum isl_dim_type type);
+
 int isl_map_compatible_domain(struct isl_map *map, struct isl_set *set);
 int isl_basic_map_compatible_domain(struct isl_basic_map *bmap,
                struct isl_basic_set *bset);
@@ -64,6 +67,8 @@ struct isl_basic_set *isl_basic_map_underlying_set(struct isl_basic_map *bmap);
 struct isl_set *isl_map_underlying_set(struct isl_map *map);
 struct isl_basic_map *isl_basic_map_overlying_set(struct isl_basic_set *bset,
        struct isl_basic_map *like);
+struct isl_basic_map *isl_basic_map_drop(struct isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned first, unsigned n);
 struct isl_basic_set *isl_basic_set_drop_dims(
                struct isl_basic_set *bset, unsigned first, unsigned n);
 struct isl_set *isl_set_drop_dims(
index d1c23d2..8302ed4 100644 (file)
@@ -116,21 +116,19 @@ error:
  * the div array too as the number of rows in this array is assumed
  * to be equal to extra.
  */
-struct isl_basic_map *isl_basic_map_drop_inputs(
-               struct isl_basic_map *bmap, unsigned first, unsigned n)
+struct isl_basic_map *isl_basic_map_drop(struct isl_basic_map *bmap,
+       enum isl_dim_type type, unsigned first, unsigned n)
 {
        int i;
-       unsigned nparam;
-       unsigned n_in;
-       unsigned n_out;
+       unsigned dim;
+       unsigned offset;
+       unsigned left;
 
        if (!bmap)
                goto error;
 
-       nparam = isl_basic_map_n_param(bmap);
-       n_in = isl_basic_map_n_in(bmap);
-       n_out = isl_basic_map_n_out(bmap);
-       isl_assert(bmap->ctx, first + n <= n_in, goto error);
+       dim = isl_basic_map_dim(bmap, type);
+       isl_assert(bmap->ctx, first + n <= dim, goto error);
 
        if (n == 0)
                return bmap;
@@ -139,19 +137,18 @@ struct isl_basic_map *isl_basic_map_drop_inputs(
        if (!bmap)
                return NULL;
 
+       offset = isl_basic_map_offset(bmap, type) + first;
+       left = isl_basic_map_total_dim(bmap) - (offset - 1) - n;
        for (i = 0; i < bmap->n_eq; ++i)
-               constraint_drop_vars(bmap->eq[i]+1+nparam+first, n,
-                                (n_in-first-n)+n_out+bmap->extra);
+               constraint_drop_vars(bmap->eq[i]+offset, n, left);
 
        for (i = 0; i < bmap->n_ineq; ++i)
-               constraint_drop_vars(bmap->ineq[i]+1+nparam+first, n,
-                                (n_in-first-n)+n_out+bmap->extra);
+               constraint_drop_vars(bmap->ineq[i]+offset, n, left);
 
        for (i = 0; i < bmap->n_div; ++i)
-               constraint_drop_vars(bmap->div[i]+1+1+nparam+first, n,
-                                (n_in-first-n)+n_out+bmap->extra);
+               constraint_drop_vars(bmap->div[i]+1+offset, n, left);
 
-       bmap->dim = isl_dim_drop_inputs(bmap->dim, first, n);
+       bmap->dim = isl_dim_drop(bmap->dim, type, first, n);
        if (!bmap->dim)
                goto error;
 
@@ -163,6 +160,12 @@ error:
        return NULL;
 }
 
+struct isl_basic_map *isl_basic_map_drop_inputs(
+               struct isl_basic_map *bmap, unsigned first, unsigned n)
+{
+       return isl_basic_map_drop(bmap, isl_dim_in, first, n);
+}
+
 struct isl_map *isl_map_drop_inputs(
                struct isl_map *map, unsigned first, unsigned n)
 {