From 80702096058def238b9749918b89bca3cbd67fe5 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 28 Jun 2011 16:51:03 +0200 Subject: [PATCH] add isl_aff_involves_dims Signed-off-by: Sven Verdoolaege --- doc/user.pod | 5 ++++ include/isl/aff.h | 4 ++++ isl_aff.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/doc/user.pod b/doc/user.pod index 685c0688..f44f3f54 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -2246,6 +2246,11 @@ The expression can be inspected using __isl_give isl_div *isl_aff_get_div( __isl_keep isl_aff *aff, int pos); + int isl_aff_involves_dims(__isl_keep isl_aff *aff, + enum isl_dim_type type, unsigned first, unsigned n); + int isl_pw_aff_involves_dims(__isl_keep isl_pw_aff *pwaff, + enum isl_dim_type type, unsigned first, unsigned n); + isl_ctx *isl_pw_aff_get_ctx(__isl_keep isl_pw_aff *pwaff); unsigned isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff, enum isl_dim_type type); diff --git a/include/isl/aff.h b/include/isl/aff.h index 685e656c..2df4420c 100644 --- a/include/isl/aff.h +++ b/include/isl/aff.h @@ -21,6 +21,8 @@ void *isl_aff_free(__isl_take isl_aff *aff); isl_ctx *isl_aff_get_ctx(__isl_keep isl_aff *aff); int isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type); +int isl_aff_involves_dims(__isl_keep isl_aff *aff, + enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_dim *isl_aff_get_dim(__isl_keep isl_aff *aff); __isl_give isl_local_space *isl_aff_get_local_space(__isl_keep isl_aff *aff); @@ -95,6 +97,8 @@ __isl_give isl_pw_aff *isl_pw_aff_copy(__isl_keep isl_pw_aff *pwaff); void *isl_pw_aff_free(__isl_take isl_pw_aff *pwaff); unsigned isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff, enum isl_dim_type type); +int isl_pw_aff_involves_dims(__isl_keep isl_pw_aff *pwaff, + enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_set *isl_pw_aff_domain(__isl_take isl_pw_aff *pwaff); diff --git a/isl_aff.c b/isl_aff.c index 74c4b140..e61b73ca 100644 --- a/isl_aff.c +++ b/isl_aff.c @@ -753,6 +753,77 @@ int isl_aff_is_empty(__isl_keep isl_aff *aff) return 0; } +/* Set active[i] to 1 if the dimension at position i is involved + * in the affine expression. + */ +static int set_active(__isl_keep isl_aff *aff, int *active) +{ + int i, j; + unsigned total; + unsigned offset; + + if (!aff || !active) + return -1; + + total = aff->v->size - 2; + for (i = 0; i < total; ++i) + active[i] = !isl_int_is_zero(aff->v->el[2 + i]); + + offset = isl_local_space_offset(aff->ls, isl_dim_div) - 1; + for (i = aff->ls->div->n_row - 1; i >= 0; --i) { + if (!active[offset + i]) + continue; + for (j = 0; j < total; ++j) + active[j] |= + !isl_int_is_zero(aff->ls->div->row[i][2 + j]); + } + + return 0; +} + +/* Check whether the given affine expression has non-zero coefficient + * for any dimension in the given range or if any of these dimensions + * appear with non-zero coefficients in any of the integer divisions + * involved in the affine expression. + */ +int isl_aff_involves_dims(__isl_keep isl_aff *aff, + enum isl_dim_type type, unsigned first, unsigned n) +{ + int i; + isl_ctx *ctx; + int *active = NULL; + int involves = 0; + + if (!aff) + return -1; + if (n == 0) + return 0; + + ctx = isl_aff_get_ctx(aff); + if (first + n > isl_aff_dim(aff, type)) + isl_die(ctx, isl_error_invalid, + "range out of bounds", return -1); + + active = isl_calloc_array(ctx, int, + isl_local_space_dim(aff->ls, isl_dim_all)); + if (set_active(aff, active) < 0) + goto error; + + first += isl_local_space_offset(aff->ls, type) - 1; + for (i = 0; i < n; ++i) + if (active[first + i]) { + involves = 1; + break; + } + + free(active); + + return involves; +error: + free(active); + return -1; +} + #undef PW #define PW isl_pw_aff #undef EL @@ -768,7 +839,6 @@ int isl_aff_is_empty(__isl_keep isl_aff *aff) #define NO_EVAL #define NO_OPT -#define NO_INVOLVES_DIMS #define NO_MOVE_DIMS #define NO_DROP_DIMS #define NO_INSERT_DIMS -- 2.11.4.GIT