From 8a0b8a3fa186af32124303ecf9c90ff6a1d6566e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 10 Mar 2014 15:10:40 +0100 Subject: [PATCH] pet_create_test_index: allow specification of domain space We want to change the extraction of a pet_scop from a pet_tree from a bottom-up process to a top-down process. Whereas, currently, the index expression for virtual arrays starts out as a mapping from an anonymous 0D space that is modified as we move up the pet_tree, in the top-down process, the statement domain space will be known by the time this function is called and we will create an identity mapping on this space instead. We allow the users to pass this domain space to pet_create_test_index. In the top-down process, the constraints derived from the outer constructs will be stored in the pet_context. We therefore obtain the domain space from the pet_context whenever it is already available and take the current anonymous 0D space as input otherwise. The latter will be changed to take the domain space from the pet_context in subsequent commits. Signed-off-by: Sven Verdoolaege --- scop.c | 15 +++++++++------ scop.h | 3 ++- skip.c | 10 ++++++++-- tree2scop.c | 12 +++++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/scop.c b/scop.c index b457b28..5b31b33 100644 --- a/scop.c +++ b/scop.c @@ -3271,19 +3271,22 @@ error: * Unlike other accessed data, the id of the array is NULL as * there is no ValueDecl in the program corresponding to the virtual * array. - * The array starts out as a scalar, but grows along with the + * The index expression is created as an identity mapping on "space". + * That is, the dimension of the array is the same as that of "space". + * Currently, the array starts out as a scalar, but grows along with the * statement writing to the array in pet_scop_embed. */ -__isl_give isl_multi_pw_aff *pet_create_test_index(isl_ctx *ctx, int test_nr) +__isl_give isl_multi_pw_aff *pet_create_test_index(__isl_take isl_space *space, + int test_nr) { - isl_space *dim = isl_space_alloc(ctx, 0, 0, 0); isl_id *id; char name[50]; snprintf(name, sizeof(name), "__pet_test_%d", test_nr); - id = isl_id_alloc(ctx, name, NULL); - dim = isl_space_set_tuple_id(dim, isl_dim_out, id); - return isl_multi_pw_aff_zero(dim); + id = isl_id_alloc(isl_space_get_ctx(space), name, NULL); + space = isl_space_map_from_set(space); + space = isl_space_set_tuple_id(space, isl_dim_out, id); + return isl_multi_pw_aff_identity(space); } /* Add an array with the given extent (range of "index") to the list diff --git a/scop.h b/scop.h index c808ed2..517dc5b 100644 --- a/scop.h +++ b/scop.h @@ -87,7 +87,8 @@ void pet_scop_reset_skip(struct pet_scop *scop, enum pet_skip type); struct pet_scop *pet_scop_add_array(struct pet_scop *scop, struct pet_array *array); -__isl_give isl_multi_pw_aff *pet_create_test_index(isl_ctx *ctx, int test_nr); +__isl_give isl_multi_pw_aff *pet_create_test_index(__isl_take isl_space *space, + int test_nr); struct pet_scop *pet_scop_add_boolean_array(struct pet_scop *scop, __isl_take isl_multi_pw_aff *index, int int_size); diff --git a/skip.c b/skip.c index e417cad..070b0e3 100644 --- a/skip.c +++ b/skip.c @@ -228,10 +228,13 @@ static void pet_skip_info_if_extract_type(struct pet_skip_info *skip, __isl_keep isl_multi_pw_aff *mpa, enum pet_skip type, struct pet_state *state) { + isl_space *space; + if (!skip->skip[type]) return; - skip->index[type] = pet_create_test_index(skip->ctx, state->n_test++); + space = isl_space_set_alloc(skip->ctx, 0, 0); + skip->index[type] = pet_create_test_index(space, state->n_test++); skip->scop[type] = extract_skip_if(isl_multi_pw_aff_copy(mpa), isl_multi_pw_aff_copy(skip->index[type]), skip->u.i.scop_then, skip->u.i.scop_else, @@ -406,10 +409,13 @@ void pet_skip_info_seq_init(struct pet_skip_info *skip, isl_ctx *ctx, static void pet_skip_info_seq_extract_type(struct pet_skip_info *skip, enum pet_skip type, struct pet_state *state) { + isl_space *space; + if (!skip->skip[type]) return; - skip->index[type] = pet_create_test_index(skip->ctx, state->n_test++); + space = isl_space_set_alloc(skip->ctx, 0, 0); + skip->index[type] = pet_create_test_index(space, state->n_test++); skip->scop[type] = extract_skip_seq( isl_multi_pw_aff_copy(skip->index[type]), skip->u.s.scop1, skip->u.s.scop2, type, state); diff --git a/tree2scop.c b/tree2scop.c index 918ec12..9d512ed 100644 --- a/tree2scop.c +++ b/tree2scop.c @@ -607,6 +607,7 @@ static struct pet_scop *scop_from_non_affine_while(__isl_take pet_expr *cond, { isl_ctx *ctx; isl_id *id, *id_test, *id_break_test; + isl_space *space; isl_multi_pw_aff *test_index; isl_set *domain; isl_set *skip; @@ -616,7 +617,8 @@ static struct pet_scop *scop_from_non_affine_while(__isl_take pet_expr *cond, int has_var_break; ctx = state->ctx; - test_index = pet_create_test_index(ctx, state->n_test++); + space = pet_context_get_space(pc); + test_index = pet_create_test_index(space, state->n_test++); scop = scop_from_non_affine_condition(cond, state->n_stmt++, isl_multi_pw_aff_copy(test_index), pet_loc_copy(loc), pc); @@ -1246,8 +1248,10 @@ static struct pet_scop *scop_from_affine_for(__isl_keep pet_tree *tree, wrap = identity_aff(domain); if (is_non_affine) { + isl_space *space; isl_multi_pw_aff *test_index; - test_index = pet_create_test_index(state->ctx, state->n_test++); + space = pet_context_get_space(pc); + test_index = pet_create_test_index(space, state->n_test++); scop_cond = scop_from_non_affine_condition( pet_expr_copy(tree->u.l.cond), state->n_stmt++, isl_multi_pw_aff_copy(test_index), @@ -1511,13 +1515,15 @@ static struct pet_scop *scop_from_non_affine_if(__isl_keep pet_tree *tree, __isl_take pet_context *pc, struct pet_state *state) { int has_else; + isl_space *space; isl_multi_pw_aff *test_index; struct pet_skip_info skip; struct pet_scop *scop, *scop_then, *scop_else = NULL; has_else = tree->type == pet_tree_if_else; - test_index = pet_create_test_index(state->ctx, state->n_test++); + space = pet_context_get_space(pc); + test_index = pet_create_test_index(space, state->n_test++); scop = scop_from_non_affine_condition(pet_expr_copy(tree->u.i.cond), state->n_stmt++, isl_multi_pw_aff_copy(test_index), pet_tree_get_loc(tree), pc); -- 2.11.4.GIT