isl_dim_move: update parameters of nested spaces
[platform/upstream/isl.git] / isl_dim.c
index b692188..2d19663 100644 (file)
--- a/isl_dim.c
+++ b/isl_dim.c
@@ -118,7 +118,8 @@ static struct isl_dim *set_name(struct isl_dim *dim,
                goto error;
 
        pos = global_pos(dim, type, pos);
-       isl_assert(ctx, pos != isl_dim_total(dim), goto error);
+       if (pos == isl_dim_total(dim))
+               goto error;
 
        if (pos >= dim->n_name) {
                if (!name)
@@ -344,6 +345,7 @@ struct isl_dim *isl_dim_set_name(struct isl_dim *dim,
                return NULL;
        if (!name_ok(dim->ctx, s))
                goto error;
+       isl_name_free(dim->ctx, get_name(dim, type, pos));
        name = isl_name_get(dim->ctx, s);
        if (!name)
                goto error;
@@ -574,6 +576,8 @@ __isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim,
        enum isl_dim_type dst_type, unsigned dst_pos,
        enum isl_dim_type src_type, unsigned src_pos, unsigned n)
 {
+       int i;
+
        if (!dim)
                return NULL;
        if (n == 0)
@@ -645,6 +649,18 @@ __isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim,
        case isl_dim_out:       dim->n_out -= n; break;
        }
 
+       if (dst_type != isl_dim_param && src_type != isl_dim_param)
+               return dim;
+
+       for (i = 0; i < 2; ++i) {
+               if (!dim->nested[i])
+                       continue;
+               dim->nested[i] = isl_dim_replace(dim->nested[i],
+                                                isl_dim_param, dim);
+               if (!dim->nested[i])
+                       goto error;
+       }
+
        return dim;
 error:
        isl_dim_free(dim);
@@ -987,13 +1003,13 @@ static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_dim *dim)
 
        for (i = 0; i < dim->nparam; ++i) {
                name = get_name(dim, isl_dim_param, i);
-               hash = isl_hash_builtin(hash, name);
+               hash = isl_hash_name(hash, name);
        }
 
        name = tuple_name(dim, isl_dim_in);
-       hash = isl_hash_builtin(hash, name);
+       hash = isl_hash_name(hash, name);
        name = tuple_name(dim, isl_dim_out);
-       hash = isl_hash_builtin(hash, name);
+       hash = isl_hash_name(hash, name);
 
        hash = isl_hash_dim(hash, dim->nested[0]);
        hash = isl_hash_dim(hash, dim->nested[1]);