From 8202f352c7c68fb6920fb0c51c0d93a4cad7bf55 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 16 Apr 2014 13:46:44 +0200 Subject: [PATCH] generalize compute_to_inner to support pet_scop_compute_outer_to_inner compute_to_inner constructs a mapping from any array (including members of other arrays) to their innermost members. Sometimes is can be useful to map only the outermost arrays to their innermost members. Generalize compute_to_inner to support both the current computation from any array to innermost arrays as well as this computation from outermosts arrays to innermost array. Signed-off-by: Sven Verdoolaege --- include/pet.h | 6 ++++++ scop.c | 68 +++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/include/pet.h b/include/pet.h index 7dbd02b..8ba98f1 100644 --- a/include/pet.h +++ b/include/pet.h @@ -557,6 +557,12 @@ __isl_give isl_union_map *pet_scop_collect_tagged_must_kills( struct pet_scop *scop); __isl_give isl_union_map *pet_scop_collect_schedule(struct pet_scop *scop); +/* Compute a mapping from all outermost arrays (of structs) in scop + * to their innermost members. + */ +__isl_give isl_union_map *pet_scop_compute_outer_to_inner( + struct pet_scop *scop); + #if defined(__cplusplus) } #endif diff --git a/scop.c b/scop.c index 7d973d7..1bdc76e 100644 --- a/scop.c +++ b/scop.c @@ -2496,26 +2496,39 @@ int pet_stmt_is_assume(struct pet_stmt *stmt) return pet_tree_is_assume(stmt->body); } +/* Helper function to add a domain gisted copy of "map" (wrt "set") to "umap". + */ +static __isl_give isl_union_map *add_gisted(__isl_take isl_union_map *umap, + __isl_keep isl_map *map, __isl_keep isl_set *set) +{ + isl_map *gist; + + gist = isl_map_copy(map); + gist = isl_map_gist_domain(gist, isl_set_copy(set)); + return isl_union_map_add_map(umap, gist); +} + /* Compute a mapping from all arrays (of structs) in scop - * to their innermost arrays. + * to their innermost members. * - * In particular, for each array of a primitive type, the result - * contains the identity mapping on that array. - * For each array involving member accesses, the result - * contains a mapping from the elements of any intermediate array of structs - * to all corresponding elements of the innermost nested arrays. + * If "from_outermost" is set, then the domain only consists + * of outermost arrays. */ -static __isl_give isl_union_map *compute_to_inner(struct pet_scop *scop) +static __isl_give isl_union_map *compute_to_inner(struct pet_scop *scop, + int from_outermost) { int i; isl_union_map *to_inner; + if (!scop) + return NULL; + to_inner = isl_union_map_empty(isl_set_get_space(scop->context)); for (i = 0; i < scop->n_array; ++i) { struct pet_array *array = scop->arrays[i]; isl_set *set; - isl_map *map, *gist; + isl_map *map; if (array->element_is_record) continue; @@ -2523,32 +2536,51 @@ static __isl_give isl_union_map *compute_to_inner(struct pet_scop *scop) set = isl_set_copy(array->extent); map = isl_set_identity(isl_set_copy(set)); - gist = isl_map_copy(map); - gist = isl_map_gist_domain(gist, isl_set_copy(set)); - to_inner = isl_union_map_add_map(to_inner, gist); - while (set && isl_set_is_wrapping(set)) { isl_id *id; isl_map *wrapped; + if (!from_outermost) + to_inner = add_gisted(to_inner, map, set); + id = isl_set_get_tuple_id(set); wrapped = isl_set_unwrap(set); wrapped = isl_map_domain_map(wrapped); wrapped = isl_map_set_tuple_id(wrapped, isl_dim_in, id); map = isl_map_apply_domain(map, wrapped); set = isl_map_domain(isl_map_copy(map)); - gist = isl_map_copy(map); - gist = isl_map_gist_domain(gist, isl_set_copy(set)); - to_inner = isl_union_map_add_map(to_inner, gist); } - isl_set_free(set); - isl_map_free(map); + map = isl_map_gist_domain(map, set); + to_inner = isl_union_map_add_map(to_inner, map); } return to_inner; } +/* Compute a mapping from all arrays (of structs) in scop + * to their innermost arrays. + * + * In particular, for each array of a primitive type, the result + * contains the identity mapping on that array. + * For each array involving member accesses, the result + * contains a mapping from the elements of any intermediate array of structs + * to all corresponding elements of the innermost nested arrays. + */ +static __isl_give isl_union_map *pet_scop_compute_any_to_inner( + struct pet_scop *scop) +{ + return compute_to_inner(scop, 0); +} + +/* Compute a mapping from all outermost arrays (of structs) in scop + * to their innermost members. + */ +__isl_give isl_union_map *pet_scop_compute_outer_to_inner(struct pet_scop *scop) +{ + return compute_to_inner(scop, 1); +} + /* Collect and return all read access relations (if "read" is set) * and/or all write access relations (if "write" is set) in "scop". * If "kill" is set, then we only add the arguments of kill operations. @@ -2593,7 +2625,7 @@ static __isl_give isl_union_map *scop_collect_accesses(struct pet_scop *scop, } accesses = isl_union_map_intersect_range(accesses, arrays); - to_inner = compute_to_inner(scop); + to_inner = pet_scop_compute_any_to_inner(scop); accesses = isl_union_map_apply_range(accesses, to_inner); return accesses; -- 2.11.4.GIT