isl_basic_map_project_out: extract out insert_div_rows
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 17 Mar 2013 19:47:42 +0000 (20:47 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 19 Mar 2013 09:55:29 +0000 (10:55 +0100)
The new insert_div_rows function will be reused in the next commit.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_map.c

index 47f3aa7..486e676 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -3366,31 +3366,22 @@ static __isl_give isl_basic_map *move_last(__isl_take isl_basic_map *bmap,
        return res;
 }
 
-/* Turn the n dimensions of type type, starting at first
- * into existentially quantified variables.
+/* Insert "n" rows in the divs of "bmap".
+ *
+ * The number of columns is not changed, which means that the last
+ * dimensions of "bmap" are being reintepreted as the new divs.
+ * The space of "bmap" is not adjusted, however, which means
+ * that "bmap" is left in an inconsistent state.  Removing "n" dimensions
+ * from the space of "bmap" is the responsibility of the caller.
  */
-__isl_give isl_basic_map *isl_basic_map_project_out(
-               __isl_take isl_basic_map *bmap,
-               enum isl_dim_type type, unsigned first, unsigned n)
+static __isl_give isl_basic_map *insert_div_rows(__isl_take isl_basic_map *bmap,
+       int n)
 {
        int i;
        size_t row_size;
        isl_int **new_div;
        isl_int *old;
 
-       if (n == 0)
-               return basic_map_space_reset(bmap, type);
-
-       if (!bmap)
-               return NULL;
-
-       if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL))
-               return isl_basic_map_remove_dims(bmap, type, first, n);
-
-       isl_assert(bmap->ctx, first + n <= isl_basic_map_dim(bmap, type),
-                       goto error);
-
-       bmap = move_last(bmap, type, first, n);
        bmap = isl_basic_map_cow(bmap);
        if (!bmap)
                return NULL;
@@ -3400,10 +3391,10 @@ __isl_give isl_basic_map *isl_basic_map_project_out(
        bmap->block2 = isl_blk_extend(bmap->ctx, bmap->block2,
                                        (bmap->extra + n) * (1 + row_size));
        if (!bmap->block2.data)
-               goto error;
+               return isl_basic_map_free(bmap);
        new_div = isl_alloc_array(bmap->ctx, isl_int *, bmap->extra + n);
        if (!new_div)
-               goto error;
+               return isl_basic_map_free(bmap);
        for (i = 0; i < n; ++i) {
                new_div[i] = bmap->block2.data +
                                (bmap->extra + i) * (1 + row_size);
@@ -3416,6 +3407,34 @@ __isl_give isl_basic_map *isl_basic_map_project_out(
        bmap->n_div += n;
        bmap->extra += n;
 
+       return bmap;
+}
+
+/* Turn the n dimensions of type type, starting at first
+ * into existentially quantified variables.
+ */
+__isl_give isl_basic_map *isl_basic_map_project_out(
+               __isl_take isl_basic_map *bmap,
+               enum isl_dim_type type, unsigned first, unsigned n)
+{
+       if (n == 0)
+               return basic_map_space_reset(bmap, type);
+
+       if (!bmap)
+               return NULL;
+
+       if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL))
+               return isl_basic_map_remove_dims(bmap, type, first, n);
+
+       isl_assert(bmap->ctx, first + n <= isl_basic_map_dim(bmap, type),
+                       goto error);
+
+       bmap = move_last(bmap, type, first, n);
+       bmap = isl_basic_map_cow(bmap);
+       bmap = insert_div_rows(bmap, n);
+       if (!bmap)
+               return NULL;
+
        bmap->dim = isl_space_drop_dims(bmap->dim, type, first, n);
        if (!bmap->dim)
                goto error;