From 26d75c926067452820ab9ab1088130e73b9779b4 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 16 Mar 2014 21:24:41 +0100 Subject: [PATCH] PetScan::get_array_size: cache results This is already useful when two or more arrays of the same type are used inside a scop, but it will become even more useful when we start reusing the method to figure out which parameters are needed in the size expressions. Signed-off-by: Sven Verdoolaege --- scan.cc | 12 ++++++++++++ scan.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/scan.cc b/scan.cc index 6203d2d..12d1582 100644 --- a/scan.cc +++ b/scan.cc @@ -191,6 +191,11 @@ static __isl_give isl_id *create_decl_id(isl_ctx *ctx, NamedDecl *decl) PetScan::~PetScan() { + std::map::iterator it; + + for (it = type_size.begin(); it != type_size.end(); ++it) + pet_expr_free(it->second); + isl_union_map_free(value_bounds); } @@ -1738,12 +1743,18 @@ __isl_give pet_expr *PetScan::set_upper_bounds(__isl_take pet_expr *expr, * in a given dimension, then the corresponding argument is set to infinity. * In fact, we initialize all arguments to infinity and then update * them if we are able to figure out the size. + * + * The result is stored in the type_size cache so that we can reuse + * it if this method gets called on the same type again later on. */ __isl_give pet_expr *PetScan::get_array_size(const Type *type) { int depth; pet_expr *expr, *inf; + if (type_size.find(type) != type_size.end()) + return pet_expr_copy(type_size[type]); + depth = array_depth(type); inf = pet_expr_new_int(isl_val_infty(ctx)); expr = pet_expr_new_call(ctx, "bounds", depth); @@ -1752,6 +1763,7 @@ __isl_give pet_expr *PetScan::get_array_size(const Type *type) pet_expr_free(inf); expr = set_upper_bounds(expr, type, 0); + type_size[type] = pet_expr_copy(expr); return expr; } diff --git a/scan.h b/scan.h index 928f2ce..4d2ccbe 100644 --- a/scan.h +++ b/scan.h @@ -52,6 +52,11 @@ struct PetScan { */ bool partial; + /* A cache of size expressions for array types as computed + * by PetScan::get_array_size. + */ + std::map type_size; + /* A union of mappings of the form * { identifier[] -> [i] : lower_bound <= i <= upper_bound } */ -- 2.11.4.GIT