This removes some code duplication.
Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
#include <isl/space.h>
#include <isl_vec_private.h>
#include <isl_mat_private.h>
+#include <isl_reordering.h>
#include <isl_seq.h>
#include <isl_local.h>
@@ -26,6 +27,25 @@ isl_ctx *isl_local_get_ctx(__isl_keep isl_local *local)
return isl_mat_get_ctx(local);
}
+/* Create an isl_local object from a matrix describing
+ * integer divisions.
+ *
+ * An isl_local object is current defined as exactly such a matrix,
+ * so simply return the input.
+ */
+__isl_give isl_local *isl_local_alloc_from_mat(__isl_take isl_mat *mat)
+{
+ return mat;
+}
+
+/* Free "local" and return NULL.
+ */
+__isl_null isl_local *isl_local_free(__isl_take isl_local *local)
+{
+ isl_mat_free(local);
+ return NULL;
+}
+
/* Return the number of local variables (isl_dim_div),
* the number of other variables (isl_dim_set) or
* the total number of variables (isl_dim_all) in "local".
@@ -185,6 +205,43 @@ int isl_local_cmp(__isl_keep isl_local *local1, __isl_keep isl_local *local2)
return 0;
}
+/* Reorder the columns of the given local variables according to the
+ * given reordering.
+ * The order of the local variables themselves is assumed not to change.
+ */
+__isl_give isl_local *isl_local_reorder(__isl_take isl_local *local,
+ __isl_take isl_reordering *r)
+{
+ isl_mat *div = local;
+ int i, j;
+ isl_mat *mat;
+ int extra;
+
+ if (!local || !r)
+ goto error;
+
+ extra = isl_space_dim(r->dim, isl_dim_all) + 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_local_free(local);
+ return isl_local_alloc_from_mat(mat);
+error:
+ isl_reordering_free(r);
+ isl_local_free(local);
+ return NULL;
+}
+
/* Extend a vector "v" representing an integer point
* in the domain space of "local"
* to one that also includes values for the local variables.
#define ISL_LOCAL_H
#include <isl/mat.h>
+#include <isl_reordering.h>
typedef isl_mat isl_local;
@@ -11,6 +12,9 @@ isl_bool isl_local_divs_known(__isl_keep isl_local *local);
int isl_local_cmp(__isl_keep isl_local *local1, __isl_keep isl_local *local2);
+__isl_give isl_local *isl_local_reorder(__isl_take isl_local *local,
+ __isl_take isl_reordering *r);
+
__isl_give isl_vec *isl_local_extend_point_vec(__isl_keep isl_local *local,
__isl_take isl_vec *v);
@@ -542,42 +542,6 @@ 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_space_dim(r->dim, isl_dim_all) + 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.
@@ -589,7 +553,7 @@ __isl_give isl_local_space *isl_local_space_realign(
if (!ls || !r)
goto error;
- ls->div = reorder_divs(ls->div, isl_reordering_copy(r));
+ ls->div = isl_local_reorder(ls->div, isl_reordering_copy(r));
if (!ls->div)
goto error;
@@ -4225,41 +4225,6 @@ __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_mul(
&isl_pw_qpolynomial_mul);
}
-/* Reorder the columns of the given div definitions according to the
- * given reordering.
- */
-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_space_dim(r->dim, isl_dim_all) + 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 dimension of "qp" according to the given reordering.
*/
__isl_give isl_qpolynomial *isl_qpolynomial_realign_domain(
@@ -4273,7 +4238,7 @@ __isl_give isl_qpolynomial *isl_qpolynomial_realign_domain(
if (!r)
goto error;
- qp->div = reorder_divs(qp->div, isl_reordering_copy(r));
+ qp->div = isl_local_reorder(qp->div, isl_reordering_copy(r));
if (!qp->div)
goto error;