From e918a02ad88a737b8196ecd6a1975e4dc4325aa5 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 10 Nov 2015 15:22:50 +0100 Subject: [PATCH] extract out shared isl_local_reorder This removes some code duplication. Signed-off-by: Sven Verdoolaege --- isl_local.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ isl_local.h | 4 ++++ isl_local_space.c | 38 +------------------------------------ isl_polynomial.c | 37 +----------------------------------- 4 files changed, 63 insertions(+), 73 deletions(-) diff --git a/isl_local.c b/isl_local.c index 4c15d6b7..2b421756 100644 --- a/isl_local.c +++ b/isl_local.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -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. diff --git a/isl_local.h b/isl_local.h index 80720a5a..74138ee0 100644 --- a/isl_local.h +++ b/isl_local.h @@ -2,6 +2,7 @@ #define ISL_LOCAL_H #include +#include 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); diff --git a/isl_local_space.c b/isl_local_space.c index 619173bf..f581c01c 100644 --- a/isl_local_space.c +++ b/isl_local_space.c @@ -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; diff --git a/isl_polynomial.c b/isl_polynomial.c index b7a8c2fe..67ab819b 100644 --- a/isl_polynomial.c +++ b/isl_polynomial.c @@ -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; -- 2.11.4.GIT