From 7495c3e8216879fb9b8eecfd1c5981dbdb786ce9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 31 Jan 2014 13:40:25 +0100 Subject: [PATCH] extract out pet_value_bounds_apply to a separate file This function is used from both access_gist and stmt_gist. The former will be moved to expr.c in the next commit. Signed-off-by: Sven Verdoolaege --- Makefile.am | 2 ++ scop.c | 60 ++----------------------------------- value_bounds.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ value_bounds.h | 21 +++++++++++++ 4 files changed, 119 insertions(+), 57 deletions(-) create mode 100644 value_bounds.c create mode 100644 value_bounds.h diff --git a/Makefile.am b/Makefile.am index a41163a..f626cd5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,8 @@ libpet_la_SOURCES = \ scop.c \ scop_plus.h \ scop_plus.cc \ + value_bounds.h \ + value_bounds.c \ version.h \ version.cc \ pet.cc diff --git a/scop.c b/scop.c index 3e3e602..e4d125e 100644 --- a/scop.c +++ b/scop.c @@ -40,6 +40,7 @@ #include "filter.h" #include "scop.h" #include "print.h" +#include "value_bounds.h" /* pet_scop with extra information that is used during parsing and printing. * @@ -2944,61 +2945,6 @@ struct pet_scop *pet_scop_anonymize(struct pet_scop *scop) return scop; } -/* If "value_bounds" contains any bounds on the variable accessed by "arg", - * then intersect the range of "map" with the valid set of values. - */ -static __isl_give isl_map *access_apply_value_bounds(__isl_take isl_map *map, - struct pet_expr *arg, __isl_keep isl_union_map *value_bounds) -{ - isl_id *id; - isl_map *vb; - isl_space *space; - isl_ctx *ctx = isl_map_get_ctx(map); - - id = pet_expr_access_get_id(arg); - space = isl_space_alloc(ctx, 0, 0, 1); - space = isl_space_set_tuple_id(space, isl_dim_in, id); - vb = isl_union_map_extract_map(value_bounds, space); - if (!isl_map_plain_is_empty(vb)) - map = isl_map_intersect_range(map, isl_map_range(vb)); - else - isl_map_free(vb); - - return map; -} - -/* Given a set "domain", return a wrapped relation with the given set - * as domain and a range of dimension "n_arg", where each coordinate - * is either unbounded or, if the corresponding element of args is of - * type pet_expr_access, bounded by the bounds specified by "value_bounds". - */ -static __isl_give isl_set *apply_value_bounds(__isl_take isl_set *domain, - unsigned n_arg, struct pet_expr **args, - __isl_keep isl_union_map *value_bounds) -{ - int i; - isl_map *map; - isl_space *space; - - map = isl_map_from_domain(domain); - space = isl_map_get_space(map); - space = isl_space_add_dims(space, isl_dim_out, 1); - - for (i = 0; i < n_arg; ++i) { - isl_map *map_i; - struct pet_expr *arg = args[i]; - - map_i = isl_map_universe(isl_space_copy(space)); - if (arg->type == pet_expr_access) - map_i = access_apply_value_bounds(map_i, arg, - value_bounds); - map = isl_map_flat_range_product(map, map_i); - } - isl_space_free(space); - - return isl_map_wrap(map); -} - /* Data used in access_gist() callback. */ struct pet_access_gist_data { @@ -3018,7 +2964,7 @@ static struct pet_expr *access_gist(struct pet_expr *expr, void *user) domain = isl_set_copy(data->domain); if (expr->n_arg > 0) - domain = apply_value_bounds(domain, expr->n_arg, expr->args, + domain = pet_value_bounds_apply(domain, expr->n_arg, expr->args, data->value_bounds); expr->acc.access = isl_map_gist_domain(expr->acc.access, @@ -3069,7 +3015,7 @@ static struct pet_stmt *stmt_gist(struct pet_stmt *stmt, domain = isl_set_universe(pet_stmt_get_space(stmt)); domain = isl_set_intersect_params(domain, isl_set_copy(context)); if (stmt->n_arg > 0) - domain = apply_value_bounds(domain, stmt->n_arg, stmt->args, + domain = pet_value_bounds_apply(domain, stmt->n_arg, stmt->args, value_bounds); stmt->domain = isl_set_gist(stmt->domain, domain); if (!stmt->domain) diff --git a/value_bounds.c b/value_bounds.c new file mode 100644 index 0000000..2cb9bf8 --- /dev/null +++ b/value_bounds.c @@ -0,0 +1,93 @@ +/* + * Copyright 2011 Leiden University. All rights reserved. + * Copyright 2012-2014 Ecole Normale Superieure. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as + * representing official policies, either expressed or implied, of + * Leiden University. + */ + +#include + +#include "expr.h" +#include "value_bounds.h" + +/* If "value_bounds" contains any bounds on the variable accessed by "arg", + * then intersect the range of "map" with the valid set of values. + */ +static __isl_give isl_map *access_apply_value_bounds(__isl_take isl_map *map, + struct pet_expr *arg, __isl_keep isl_union_map *value_bounds) +{ + isl_id *id; + isl_map *vb; + isl_space *space; + isl_ctx *ctx = isl_map_get_ctx(map); + + id = pet_expr_access_get_id(arg); + space = isl_space_alloc(ctx, 0, 0, 1); + space = isl_space_set_tuple_id(space, isl_dim_in, id); + vb = isl_union_map_extract_map(value_bounds, space); + if (!isl_map_plain_is_empty(vb)) + map = isl_map_intersect_range(map, isl_map_range(vb)); + else + isl_map_free(vb); + + return map; +} + +/* Given a set "domain", return a wrapped relation with the given set + * as domain and a range of dimension "n_arg", where each coordinate + * is either unbounded or, if the corresponding element of args is of + * type pet_expr_access, bounded by the bounds specified by "value_bounds". + */ +__isl_give isl_set *pet_value_bounds_apply(__isl_take isl_set *domain, + unsigned n_arg, struct pet_expr **args, + __isl_keep isl_union_map *value_bounds) +{ + int i; + isl_map *map; + isl_space *space; + + map = isl_map_from_domain(domain); + space = isl_map_get_space(map); + space = isl_space_add_dims(space, isl_dim_out, 1); + + for (i = 0; i < n_arg; ++i) { + isl_map *map_i; + struct pet_expr *arg = args[i]; + + map_i = isl_map_universe(isl_space_copy(space)); + if (arg->type == pet_expr_access) + map_i = access_apply_value_bounds(map_i, arg, + value_bounds); + map = isl_map_flat_range_product(map, map_i); + } + isl_space_free(space); + + return isl_map_wrap(map); +} diff --git a/value_bounds.h b/value_bounds.h new file mode 100644 index 0000000..c5bc588 --- /dev/null +++ b/value_bounds.h @@ -0,0 +1,21 @@ +#ifndef PET_VALUE_BOUNDS_H +#define PET_VALUE_BOUNDS_H + +#include +#include + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +__isl_give isl_set *pet_value_bounds_apply(__isl_take isl_set *domain, + unsigned n_arg, struct pet_expr **args, + __isl_keep isl_union_map *value_bounds); + +#if defined(__cplusplus) +} +#endif + +#endif -- 2.11.4.GIT