From 079ff1d53d7f54a534bd3f499a48b12468b8c7e4 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 7 Mar 2017 11:16:45 +0100 Subject: [PATCH] pet_scop_collect_arrays: consider all accessed data spaces of an array In particular, if there are any access relations associated to an array, then also consider the data space in those access relations and not just the data space of the index expression. In the current code base, this change does not have any effect since all subfields of an accessed arrays are recursively added to the list of arrays, but a subsequent commit will change that to only adding relevant subfields. In order to be able to determine which subfields are relevant, the code needs to consider the accesses in the access relations. Signed-off-by: Sven Verdoolaege --- expr.c | 47 +++++++++++++++++++++++++++++++++++++++++------ expr.h | 3 ++- scop_plus.cc | 41 +++++++++++++++++++++++++---------------- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/expr.c b/expr.c index f4d9702..eb1ea28 100644 --- a/expr.c +++ b/expr.c @@ -1302,22 +1302,57 @@ __isl_give isl_space *pet_expr_access_get_domain_space( return space; } -/* Return the space of the data accessed by "expr". +/* Internal data structure for pet_expr_access_foreach_data_space. */ -__isl_give isl_space *pet_expr_access_get_data_space(__isl_keep pet_expr *expr) +struct pet_foreach_data_space_data { + isl_stat (*fn)(__isl_take isl_space *space, void *user); + void *user; +}; + +/* Given a piece of an access relation, call data->fn on the data + * (i.e., range) space. + */ +static isl_stat foreach_data_space(__isl_take isl_map *map, void *user) { + struct pet_foreach_data_space_data *data = user; + isl_space *space; + + space = isl_map_get_space(map); + space = isl_space_range(space); + isl_map_free(map); + + return data->fn(space, data->user); +} + +/* Call "fn" on the data spaces accessed by "expr". + * In particular, call "fn" on the range space of the index expression, + * but if "expr" keeps track of any explicit access relations, + * then also call "fn" on the corresponding range spaces. + */ +isl_stat pet_expr_access_foreach_data_space(__isl_keep pet_expr *expr, + isl_stat (*fn)(__isl_take isl_space *space, void *user), void *user) +{ + struct pet_foreach_data_space_data data = { fn, user }; + enum pet_expr_access_type type; isl_space *space; if (!expr) - return NULL; + return isl_stat_error; if (expr->type != pet_expr_access) isl_die(pet_expr_get_ctx(expr), isl_error_invalid, - "not an access expression", return NULL); + "not an access expression", return isl_stat_error); + + for (type = pet_expr_access_begin; type < pet_expr_access_end; ++type) { + if (!expr->acc.access[type]) + continue; + if (isl_union_map_foreach_map(expr->acc.access[type], + &foreach_data_space, &data) < 0) + return isl_stat_error; + } space = isl_multi_pw_aff_get_space(expr->acc.index); space = isl_space_range(space); - - return space; + return fn(space, user); } /* Modify all subexpressions of "expr" by calling "fn" on them. diff --git a/expr.h b/expr.h index b0b5ace..5a8cf7c 100644 --- a/expr.h +++ b/expr.h @@ -177,7 +177,8 @@ __isl_give isl_space *pet_expr_access_get_augmented_domain_space( __isl_keep pet_expr *expr); __isl_give isl_space *pet_expr_access_get_domain_space( __isl_keep pet_expr *expr); -__isl_give isl_space *pet_expr_access_get_data_space(__isl_keep pet_expr *expr); +isl_stat pet_expr_access_foreach_data_space(__isl_keep pet_expr *expr, + isl_stat (*fn)(__isl_take isl_space *space, void *user), void *user); isl_bool pet_expr_access_has_any_access_relation(__isl_keep pet_expr *expr); __isl_give isl_union_map *pet_expr_access_get_dependent_access( diff --git a/scop_plus.cc b/scop_plus.cc index 35c70d7..4a4b8ac 100644 --- a/scop_plus.cc +++ b/scop_plus.cc @@ -85,12 +85,12 @@ static void collect_sub_arrays(ValueDecl *decl, } } -/* Extract one or more sequences of declarations from the access expression - * "expr" and add them to "arrays". +/* Extract one or more sequences of declarations from the accessed + * data space "space" and add them to "arrays". * - * If "expr" represents an array access, then the extracted sequence + * If "space" represents an array access, then the extracted sequence * contains a single element corresponding to the array declaration. - * Otherwise, if "expr" represents a member access, then the extracted + * Otherwise, if "space" represents a member access, then the extracted * sequences contain an element for the outer array of structures and * for each nested array or scalar. One such sequence is (recursively) * added for each member of the accessed outer array. @@ -104,38 +104,47 @@ static void collect_sub_arrays(ValueDecl *decl, * in "arrays", then its subfields have already been added as well, * so there is nothing left to do. */ -static void access_collect_arrays(__isl_keep pet_expr *expr, - array_desc_set &arrays) +static isl_stat space_collect_arrays(__isl_take isl_space *space, void *user) { + array_desc_set *arrays = (array_desc_set *) user; isl_id *id; - isl_space *space; ValueDecl *decl; isl_id_list *ancestors; - if (pet_expr_is_affine(expr)) - return; - - space = pet_expr_access_get_data_space(expr); - while (space && isl_space_is_wrapping(space)) space = isl_space_domain(isl_space_unwrap(space)); id = isl_space_get_tuple_id(space, isl_dim_set); isl_space_free(space); if (!id) - return; + return isl_stat_ok; decl = pet_id_get_decl(id); if (!decl) { isl_id_free(id); - return; + return isl_stat_ok; } ancestors = isl_id_list_from_id(id); - if (arrays.find(ancestors) == arrays.end()) - collect_sub_arrays(decl, ancestors, arrays); + if (arrays->find(ancestors) == arrays->end()) + collect_sub_arrays(decl, ancestors, *arrays); isl_id_list_free(ancestors); + + return isl_stat_ok; +} + +/* Extract one or more sequences of declarations from the access expression + * "expr" and add them to "arrays". + */ +static void access_collect_arrays(__isl_keep pet_expr *expr, + array_desc_set &arrays) +{ + if (pet_expr_is_affine(expr)) + return; + + pet_expr_access_foreach_data_space(expr, + &space_collect_arrays, &arrays); } static void expr_collect_arrays(__isl_keep pet_expr *expr, -- 2.11.4.GIT