From 72f6e81316093dd9a0cf96fb6792f97d414be7b9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 9 Jun 2017 11:23:02 +0200 Subject: [PATCH] add isl_set_get_stride This function performs the same operation as isl_set_get_stride_info, but only returns the stride. This is useful when the offset is not relevant or known to be zero. Signed-off-by: Sven Verdoolaege --- doc/user.pod | 7 ++++++- include/isl/set.h | 2 ++ isl_stride.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/doc/user.pod b/doc/user.pod index 9a23aac9..53e40b40 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -3928,13 +3928,18 @@ can be found then assign C<1> to C<*modulo> and C<1> to C<*residue>. #include __isl_give isl_stride_info *isl_set_get_stride_info( __isl_keep isl_set *set, int pos); + __isl_give isl_val *isl_set_get_stride( + __isl_keep isl_set *set, int pos); Check if the values of the given set dimension are equal to some affine expression of the other dimensions (the offset) modulo some integer stride. If no more specific information can be found, then the stride is taken to be one and the offset is taken to be the zero expression. -The stride and offset can be extracted from the returned object +The function C performs the same +computation but only returns the stride. +Otherwise, +the stride and offset can be extracted from the returned object using the following functions. #include diff --git a/include/isl/set.h b/include/isl/set.h index 0ebb5c3e..8d5cf05a 100644 --- a/include/isl/set.h +++ b/include/isl/set.h @@ -438,6 +438,8 @@ __isl_null isl_stride_info *isl_stride_info_free( __isl_take isl_stride_info *si); __isl_give isl_stride_info *isl_set_get_stride_info(__isl_keep isl_set *set, int pos); +__isl_export +__isl_give isl_val *isl_set_get_stride(__isl_keep isl_set *set, int pos); __isl_export __isl_give isl_set *isl_set_coalesce(__isl_take isl_set *set); diff --git a/isl_stride.c b/isl_stride.c index 6b4fbcc3..8e960645 100644 --- a/isl_stride.c +++ b/isl_stride.c @@ -76,12 +76,15 @@ __isl_give isl_aff *isl_stride_info_get_offset(__isl_keep isl_stride_info *si) /* Information used inside detect_stride. * * "pos" is the set dimension at which the stride is being determined. + * "want_offset" is set if the offset should be computed. * "found" is set if some stride was found already. * "stride" and "offset" contain the (combined) stride and offset * found so far and are NULL when "found" is not set. + * If "want_offset" is not set, then "offset" remains NULL. */ struct isl_detect_stride_data { int pos; + int want_offset; int found; isl_val *stride; isl_aff *offset; @@ -137,16 +140,24 @@ static isl_stat set_stride(struct isl_detect_stride_data *data, b = isl_val_mul(b, isl_val_copy(stride2)); stride = isl_val_mul(stride, stride2); - offset2 = data->offset; - offset2 = isl_aff_scale_val(offset2, a); - offset = isl_aff_scale_val(offset, b); - offset = isl_aff_add(offset, offset2); + if (!data->want_offset) { + isl_val_free(a); + isl_val_free(b); + } else { + offset2 = data->offset; + offset2 = isl_aff_scale_val(offset2, a); + offset = isl_aff_scale_val(offset, b); + offset = isl_aff_add(offset, offset2); + } } data->found = 1; data->stride = stride; - data->offset = offset; - if (!data->stride || !data->offset) + if (data->want_offset) + data->offset = offset; + else + isl_aff_free(offset); + if (!data->stride || (data->want_offset && !data->offset)) return isl_stat_error; return isl_stat_ok; @@ -267,13 +278,15 @@ static void set_detect_stride(__isl_keep isl_set *set, int pos, goto error; if (!data->found) { - isl_space *space; - isl_local_space *ls; - data->stride = isl_val_one(isl_set_get_ctx(set)); - space = isl_set_get_space(set); - ls = isl_local_space_from_space(space); - data->offset = isl_aff_zero_on_domain(ls); + if (data->want_offset) { + isl_space *space; + isl_local_space *ls; + + space = isl_set_get_space(set); + ls = isl_local_space_from_space(space); + data->offset = isl_aff_zero_on_domain(ls); + } } isl_basic_set_free(hull); return; @@ -291,7 +304,21 @@ __isl_give isl_stride_info *isl_set_get_stride_info(__isl_keep isl_set *set, { struct isl_detect_stride_data data; + data.want_offset = 1; set_detect_stride(set, pos, &data); return isl_stride_info_alloc(data.stride, data.offset); } + +/* Check if the constraints in "set" imply any stride on set dimension "pos" and + * return this stride. + */ +__isl_give isl_val *isl_set_get_stride(__isl_keep isl_set *set, int pos) +{ + struct isl_detect_stride_data data; + + data.want_offset = 0; + set_detect_stride(set, pos, &data); + + return data.stride; +} -- 2.11.4.GIT