From 4710eefda78c69e70e49ad6690349ad1781a3373 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 5 Jun 2014 11:08:45 +0200 Subject: [PATCH] extract out shared isl_basic_map_output_defining_equality isl_pw_multi_aff_from_map calls isl_basic_map_plain_is_single_valued to check if there is a defining equality for each output dimension and, if so, it calls extract_isl_aff_from_basic_map to extract an isl_aff from these defining equalities. Both functions check for these equalities in the same way. Extract out the check into a separate function. This reduces code duplication and also allows us to more easily change the kind of constraints that we consider to be defining equalities. Signed-off-by: Sven Verdoolaege --- isl_aff.c | 25 ++++++++----------------- isl_map.c | 50 +++++++++++++++++++++++++++++++++++++------------- isl_map_private.h | 3 +++ 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/isl_aff.c b/isl_aff.c index 30d11e6f..d54d590e 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -4255,9 +4255,8 @@ error: static __isl_give isl_aff *extract_isl_aff_from_basic_map( __isl_take isl_basic_map *bmap) { - int i; + int eq; unsigned offset; - unsigned total; isl_local_space *ls; isl_aff *aff; @@ -4267,29 +4266,21 @@ static __isl_give isl_aff *extract_isl_aff_from_basic_map( isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, "basic map should have a single output dimension", goto error); - offset = isl_basic_map_offset(bmap, isl_dim_out); - total = isl_basic_map_total_dim(bmap); - for (i = 0; i < bmap->n_eq; ++i) { - if (isl_int_is_zero(bmap->eq[i][offset])) - continue; - if (isl_seq_first_non_zero(bmap->eq[i] + offset + 1, - 1 + total - (offset + 1)) != -1) - continue; - break; - } - if (i >= bmap->n_eq) + eq = isl_basic_map_output_defining_equality(bmap, 0); + if (eq >= bmap->n_eq) isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, "unable to find suitable equality", goto error); ls = isl_basic_map_get_local_space(bmap); aff = isl_aff_alloc(isl_local_space_domain(ls)); if (!aff) goto error; - if (isl_int_is_neg(bmap->eq[i][offset])) - isl_seq_cpy(aff->v->el + 1, bmap->eq[i], offset); + offset = isl_basic_map_offset(bmap, isl_dim_out); + if (isl_int_is_neg(bmap->eq[eq][offset])) + isl_seq_cpy(aff->v->el + 1, bmap->eq[eq], offset); else - isl_seq_neg(aff->v->el + 1, bmap->eq[i], offset); + isl_seq_neg(aff->v->el + 1, bmap->eq[eq], offset); isl_seq_clr(aff->v->el + 1 + offset, aff->v->size - (1 + offset)); - isl_int_abs(aff->v->el[0], bmap->eq[i][offset]); + isl_int_abs(aff->v->el[0], bmap->eq[eq][offset]); isl_basic_map_free(bmap); aff = isl_aff_remove_unused_divs(aff); diff --git a/isl_map.c b/isl_map.c index b1223a06..e4d7d995 100644 --- a/isl_map.c +++ b/isl_map.c @@ -10297,6 +10297,36 @@ int isl_basic_set_dims_get_sign(__isl_keep isl_basic_set *bset, return isl_basic_set_vars_get_sign(bset, first, n, signs); } +/* Return the index of the equality of "bmap" that defines + * the output dimension "pos" in terms of earlier dimensions. + * Return bmap->n_eq if there is no such equality. + * Return -1 on error. + */ +int isl_basic_map_output_defining_equality(__isl_keep isl_basic_map *bmap, + int pos) +{ + int j; + unsigned total; + unsigned n_out, o_out; + + if (!bmap) + return -1; + + total = 1 + isl_basic_map_total_dim(bmap); + n_out = isl_basic_map_dim(bmap, isl_dim_out); + o_out = isl_basic_map_offset(bmap, isl_dim_out); + + for (j = 0; j < bmap->n_eq; ++j) { + if (isl_int_is_zero(bmap->eq[j][o_out + pos])) + continue; + if (isl_seq_first_non_zero(bmap->eq[j] + o_out + pos + 1, + total - (o_out + pos + 1)) == -1) + return j; + } + + return bmap->n_eq; +} + /* Check if the given basic map is obviously single-valued. * In particular, for each output dimension, check that there is * an equality that defines the output dimension in terms of @@ -10304,27 +10334,21 @@ int isl_basic_set_dims_get_sign(__isl_keep isl_basic_set *bset, */ int isl_basic_map_plain_is_single_valued(__isl_keep isl_basic_map *bmap) { - int i, j; - unsigned total; + int i; unsigned n_out; - unsigned o_out; if (!bmap) return -1; - total = 1 + isl_basic_map_total_dim(bmap); n_out = isl_basic_map_dim(bmap, isl_dim_out); - o_out = isl_basic_map_offset(bmap, isl_dim_out); for (i = 0; i < n_out; ++i) { - for (j = 0; j < bmap->n_eq; ++j) { - if (isl_int_is_zero(bmap->eq[j][o_out + i])) - continue; - if (isl_seq_first_non_zero(bmap->eq[j] + o_out + i + 1, - total - (o_out + i + 1)) == -1) - break; - } - if (j >= bmap->n_eq) + int eq; + + eq = isl_basic_map_output_defining_equality(bmap, i); + if (eq < 0) + return -1; + if (eq >= bmap->n_eq) return 0; } diff --git a/isl_map_private.h b/isl_map_private.h index 616f8604..7f1cd589 100644 --- a/isl_map_private.h +++ b/isl_map_private.h @@ -393,6 +393,9 @@ __isl_give isl_set *isl_set_fix(__isl_take isl_set *set, int isl_map_plain_is_fixed(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos, isl_int *val); +int isl_basic_map_output_defining_equality(__isl_keep isl_basic_map *bmap, + int pos); + __isl_give isl_basic_set_list *isl_set_get_basic_set_list( __isl_keep isl_set *set); -- 2.11.4.GIT