add isl_local_space_insert_dims
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 28 Jun 2011 21:31:59 +0000 (23:31 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 30 Jun 2011 12:17:22 +0000 (14:17 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/local_space.h
isl_local_space.c

index 647adcd..32be371 100644 (file)
@@ -626,6 +626,9 @@ using the following functions.
        __isl_give isl_local_space *isl_local_space_add_dims(
                __isl_take isl_local_space *ls,
                enum isl_dim_type type, unsigned n);
+       __isl_give isl_local_space *isl_local_space_insert_dims(
+               __isl_take isl_local_space *ls,
+               enum isl_dim_type type, unsigned first, unsigned n);
        __isl_give isl_local_space *isl_local_space_drop_dims(
                __isl_take isl_local_space *ls,
                enum isl_dim_type type, unsigned first, unsigned n);
index 4636871..3faa041 100644 (file)
@@ -37,6 +37,9 @@ __isl_give isl_local_space *isl_local_space_add_dims(
 __isl_give isl_local_space *isl_local_space_drop_dims(
        __isl_take isl_local_space *ls,
        enum isl_dim_type type, unsigned first, unsigned n);
+__isl_give isl_local_space *isl_local_space_insert_dims(
+       __isl_take isl_local_space *ls,
+       enum isl_dim_type type, unsigned first, unsigned n);
 
 int isl_local_space_is_equal(__isl_keep isl_local_space *ls1,
        __isl_keep isl_local_space *ls2);
index 8a6b919..a57b31e 100644 (file)
@@ -373,30 +373,10 @@ __isl_give isl_local_space *isl_local_space_add_dims(
 {
        int pos;
 
-       if (n == 0)
-               return ls;
-
-       ls = isl_local_space_cow(ls);
        if (!ls)
                return NULL;
-
-       pos = isl_local_space_offset(ls, type);
-       pos += isl_local_space_dim(ls, type);
-
-       ls->div = isl_mat_insert_zero_cols(ls->div, 1 + pos, n);
-
-       if (type == isl_dim_div) {
-               ls->div = isl_mat_add_zero_rows(ls->div, n);
-       } else {
-               ls->dim = isl_dim_add(ls->dim, type, n);
-               if (!ls->dim)
-                       return isl_local_space_free(ls);
-       }
-
-       if (!ls->div)
-               return isl_local_space_free(ls);
-
-       return ls;
+       pos = isl_local_space_dim(ls, type);
+       return isl_local_space_insert_dims(ls, type, pos, n);
 }
 
 /* Remove common factor of non-constant terms and denominator.
@@ -507,3 +487,39 @@ __isl_give isl_local_space *isl_local_space_drop_dims(
 
        return ls;
 }
+
+__isl_give isl_local_space *isl_local_space_insert_dims(
+       __isl_take isl_local_space *ls,
+       enum isl_dim_type type, unsigned first, unsigned n)
+{
+       isl_ctx *ctx;
+
+       if (!ls)
+               return NULL;
+       if (n == 0 && !isl_local_space_is_named_or_nested(ls, type))
+               return ls;
+
+       ctx = isl_local_space_get_ctx(ls);
+       if (first > isl_local_space_dim(ls, type))
+               isl_die(ctx, isl_error_invalid, "position out of bounds",
+                       return isl_local_space_free(ls));
+
+       ls = isl_local_space_cow(ls);
+       if (!ls)
+               return NULL;
+
+       if (type == isl_dim_div) {
+               ls->div = isl_mat_insert_zero_rows(ls->div, first, n);
+       } else {
+               ls->dim = isl_dim_insert(ls->dim, type, first, n);
+               if (!ls->dim)
+                       return isl_local_space_free(ls);
+       }
+
+       first += 1 + isl_local_space_offset(ls, type);
+       ls->div = isl_mat_insert_zero_cols(ls->div, first, n);
+       if (!ls->div)
+               return isl_local_space_free(ls);
+
+       return ls;
+}