isl_map_underlying_set: drop names from dimesion in underlying set
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 3 Jan 2009 10:21:23 +0000 (11:21 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 8 Jan 2009 15:07:27 +0000 (16:07 +0100)
When applying isl_mat transforamtions on sets, we currently
assume that these sets have no names for the dimensions.

include/isl_dim.h
isl_dim.c
isl_map.c

index 9a6529a..0d37b2a 100644 (file)
@@ -54,6 +54,7 @@ struct isl_dim *isl_dim_drop_inputs(struct isl_dim *dim,
 struct isl_dim *isl_dim_drop_outputs(struct isl_dim *dim,
                unsigned first, unsigned n);
 struct isl_dim *isl_dim_domain(struct isl_dim *dim);
+struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div);
 
 int isl_dim_equal(struct isl_dim *dim1, struct isl_dim *dim2);
 int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2);
index 9ea54d7..61926ca 100644 (file)
--- a/isl_dim.c
+++ b/isl_dim.c
@@ -458,6 +458,29 @@ struct isl_dim *isl_dim_domain(struct isl_dim *dim)
        return isl_dim_reverse(dim);
 }
 
+struct isl_dim *isl_dim_underlying(struct isl_dim *dim, unsigned n_div)
+{
+       int i;
+
+       if (!dim)
+               return NULL;
+       if (n_div == 0 &&
+           dim->nparam == 0 && dim->n_in == 0 && dim->n_name == 0)
+               return dim;
+       dim = isl_dim_cow(dim);
+       if (!dim)
+               return NULL;
+       dim->n_out += dim->nparam + dim->n_in + n_div;
+       dim->nparam = 0;
+       dim->n_in = 0;
+
+       for (i = 0; i < dim->n_name; ++i)
+               isl_name_free(dim->ctx, get_name(dim, isl_dim_out, i));
+       dim->n_name = 0;
+
+       return dim;
+}
+
 unsigned isl_dim_total(struct isl_dim *dim)
 {
        return dim->nparam + dim->n_in + dim->n_out;
index e05cc54..9248537 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -1925,12 +1925,9 @@ struct isl_basic_set *isl_basic_map_underlying_set(
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                goto error;
-       bmap->dim = isl_dim_cow(bmap->dim);
+       bmap->dim = isl_dim_underlying(bmap->dim, bmap->n_div);
        if (!bmap->dim)
                goto error;
-       bmap->dim->n_out += bmap->dim->nparam + bmap->dim->n_in + bmap->n_div;
-       bmap->dim->nparam = 0;
-       bmap->dim->n_in = 0;
        bmap->extra -= bmap->n_div;
        bmap->n_div = 0;
        bmap = isl_basic_map_finalize(bmap);
@@ -2066,11 +2063,13 @@ struct isl_set *isl_map_underlying_set(struct isl_map *map)
                        goto error;
        }
        if (map->n == 0)
-               map->dim->n_out += map->dim->nparam + map->dim->n_in;
-       else
-               map->dim->n_out = map->p[0]->dim->n_out;
-       map->dim->nparam = 0;
-       map->dim->n_in = 0;
+               map->dim = isl_dim_underlying(map->dim, 0);
+       else {
+               isl_dim_free(map->dim);
+               map->dim = isl_dim_copy(map->p[0]->dim);
+       }
+       if (!map->dim)
+               goto error;
        return (struct isl_set *)map;
 error:
        isl_map_free(map);