add private isl_local_space_realign
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 8 Jul 2011 10:18:32 +0000 (12:18 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 9 Jul 2011 14:11:41 +0000 (16:11 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_local_space.c
isl_local_space_private.h

index 51602f8..17ac9ea 100644 (file)
@@ -232,6 +232,67 @@ error:
        return NULL;
 }
 
+/* Reorder the columns of the given div definitions according to the
+ * given reordering.
+ * The order of the divs themselves is assumed not to change.
+ */
+static __isl_give isl_mat *reorder_divs(__isl_take isl_mat *div,
+       __isl_take isl_reordering *r)
+{
+       int i, j;
+       isl_mat *mat;
+       int extra;
+
+       if (!div || !r)
+               goto error;
+
+       extra = isl_dim_total(r->dim) + div->n_row - r->len;
+       mat = isl_mat_alloc(div->ctx, div->n_row, div->n_col + extra);
+       if (!mat)
+               goto error;
+
+       for (i = 0; i < div->n_row; ++i) {
+               isl_seq_cpy(mat->row[i], div->row[i], 2);
+               isl_seq_clr(mat->row[i] + 2, mat->n_col - 2);
+               for (j = 0; j < r->len; ++j)
+                       isl_int_set(mat->row[i][2 + r->pos[j]],
+                                   div->row[i][2 + j]);
+       }
+
+       isl_reordering_free(r);
+       isl_mat_free(div);
+       return mat;
+error:
+       isl_reordering_free(r);
+       isl_mat_free(div);
+       return NULL;
+}
+
+/* Reorder the dimensions of "ls" according to the given reordering.
+ * The reordering r is assumed to have been extended with the local
+ * variables, leaving them in the same order.
+ */
+__isl_give isl_local_space *isl_local_space_realign(
+       __isl_take isl_local_space *ls, __isl_take isl_reordering *r)
+{
+       ls = isl_local_space_cow(ls);
+       if (!ls || !r)
+               goto error;
+
+       ls->div = reorder_divs(ls->div, isl_reordering_copy(r));
+       if (!ls->div)
+               goto error;
+
+       ls = isl_local_space_reset_dim(ls, isl_dim_copy(r->dim));
+
+       isl_reordering_free(r);
+       return ls;
+error:
+       isl_local_space_free(ls);
+       isl_reordering_free(r);
+       return NULL;
+}
+
 __isl_give isl_local_space *isl_local_space_add_div(
        __isl_take isl_local_space *ls, __isl_take isl_vec *div)
 {
index 4e5cc04..6f3e93d 100644 (file)
@@ -37,5 +37,7 @@ int isl_local_space_is_named_or_nested(__isl_keep isl_local_space *ls,
 
 __isl_give isl_local_space *isl_local_space_reset_dim(
        __isl_take isl_local_space *ls, __isl_take isl_dim *dim);
+__isl_give isl_local_space *isl_local_space_realign(
+       __isl_take isl_local_space *ls, __isl_take isl_reordering *r);
 
 #endif