From a413bd286f0748af489288fd73675bad00cfac07 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 22 Aug 2013 15:12:54 +0200 Subject: [PATCH] gpu_array_info: replace read_only by read_only_scalar The original field only contained meaningful information if the corresponding array is a scalar, which could be confusing. The new field is set iff the array is a scalar and it is read-only. Extract the corresponding check into a separate function to reduce clutter. Signed-off-by: Sven Verdoolaege --- gpu.c | 42 ++++++++++++++++++++++++++---------------- gpu.h | 4 ++-- gpu_print.c | 2 +- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/gpu.c b/gpu.c index 66b252d..e02c43d 100644 --- a/gpu.c +++ b/gpu.c @@ -375,6 +375,30 @@ static __isl_give isl_set *compute_extent(struct pet_array *array, return extent; } +/* Is the array "array" being extracted a read-only scalar? + * + * That is, is "array" a scalar that is never written to. + */ +static int is_read_only_scalar(struct gpu_array_info *array, + struct gpu_prog *prog) +{ + isl_set *space; + isl_union_map *write; + int empty; + + if (array->n_index != 0) + return 0; + + write = isl_union_map_copy(prog->write); + space = isl_set_universe(isl_space_copy(array->space)); + write = isl_union_map_intersect_range(write, + isl_union_set_from_set(space)); + empty = isl_union_map_is_empty(write); + isl_union_map_free(write); + + return empty; +} + /* Compute bounds on the host arrays based on the accessed elements * and collect all references to the array. * @@ -415,21 +439,7 @@ static int extract_array_info(__isl_take isl_set *array, void *user) info->type = strdup(pa->element_type); info->size = pa->element_size; info->local = pa->declared && !pa->exposed; - - if (n_index == 0) { - isl_set *space; - isl_union_map *write; - int empty; - - write = isl_union_map_copy(prog->write); - space = isl_set_universe(isl_set_get_space(array)); - write = isl_union_map_intersect_range(write, - isl_union_set_from_set(space)); - empty = isl_union_map_is_empty(write); - isl_union_map_free(write); - - info->read_only = empty; - } + info->read_only_scalar = is_read_only_scalar(info, prog); extent = compute_extent(pa, array); for (i = 0; i < n_index; ++i) { @@ -515,7 +525,7 @@ int gpu_array_is_scalar(struct gpu_array_info *array) */ int gpu_array_is_read_only_scalar(struct gpu_array_info *array) { - return gpu_array_is_scalar(array) && array->read_only; + return array->read_only_scalar; } /* Internal data structure for extract_size_of_type. diff --git a/gpu.h b/gpu.h index 2ac98ec..4789f04 100644 --- a/gpu.h +++ b/gpu.h @@ -31,8 +31,8 @@ struct gpu_array_info { int n_group; struct gpu_array_ref_group **groups; - /* For scalars, is this scalar read-only within the entire program? */ - int read_only; + /* Is this a scalar that is read-only within the entire program? */ + int read_only_scalar; /* Is the array local to the scop? */ int local; diff --git a/gpu_print.c b/gpu_print.c index dc9a7ab..1af3bcd 100644 --- a/gpu_print.c +++ b/gpu_print.c @@ -81,7 +81,7 @@ static __isl_give isl_printer *stmt_print_global_index( isl_ast_expr *index; if (gpu_array_is_scalar(array)) { - if (!array->read_only) + if (!gpu_array_is_read_only_scalar(array)) p = isl_printer_print_str(p, "*"); p = isl_printer_print_str(p, array->name); return p; -- 2.11.4.GIT