From 786bb547a6502d7f14edd6f661b6f6f5c199d8a4 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 10 Mar 2014 22:31:55 +0100 Subject: [PATCH] pet_scop_add_boolean_array: allow specification of domain constraints 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 extent of virtual arrays starts out as a universe 0D set that is modified as we move up the pet_tree, in the top-down process, the domain constraints will be known by the time this function is called and we will create an array with an extent that matches the domain constraints from the start. We allow the users to pass this domain to pet_scop_add_boolean_array. In the top-down process, the constraints derived from the outer constructs will be stored in the pet_context. We therefore obtain the domain constraints from the pet_context. Signed-off-by: Sven Verdoolaege --- scop.c | 11 ++++++++--- scop.h | 3 ++- skip.c | 14 ++++++++------ tree2scop.c | 11 ++++++++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/scop.c b/scop.c index 84469c2..d622e7a 100644 --- a/scop.c +++ b/scop.c @@ -3300,21 +3300,24 @@ __isl_give isl_multi_pw_aff *pet_create_test_index(__isl_take isl_space *space, return isl_multi_pw_aff_identity(space); } -/* Add an array with the given extent (range of "index") to the list +/* Add an array with the given extent to the list * of arrays in "scop" and return the extended pet_scop. + * Specifically, the extent is determined by the image of "domain" + * under "index". * "int_size" is the number of bytes needed to represent values of type "int". * The array is marked as attaining values 0 and 1 only and * as each element being assigned at most once. */ struct pet_scop *pet_scop_add_boolean_array(struct pet_scop *scop, - __isl_take isl_multi_pw_aff *index, int int_size) + __isl_take isl_set *domain, __isl_take isl_multi_pw_aff *index, + int int_size) { isl_ctx *ctx; isl_space *space; struct pet_array *array; isl_map *access; - if (!scop || !index) + if (!scop || !domain || !index) goto error; ctx = isl_multi_pw_aff_get_ctx(index); @@ -3323,6 +3326,7 @@ struct pet_scop *pet_scop_add_boolean_array(struct pet_scop *scop, goto error; access = isl_map_from_multi_pw_aff(index); + access = isl_map_intersect_domain(access, domain); array->extent = isl_map_range(access); space = isl_space_params_alloc(ctx, 0); array->context = isl_set_universe(space); @@ -3343,6 +3347,7 @@ struct pet_scop *pet_scop_add_boolean_array(struct pet_scop *scop, return scop; error: + isl_set_free(domain); isl_multi_pw_aff_free(index); return pet_scop_free(scop); } diff --git a/scop.h b/scop.h index f63738e..55eb5bc 100644 --- a/scop.h +++ b/scop.h @@ -91,7 +91,8 @@ struct pet_scop *pet_scop_add_array(struct pet_scop *scop, __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); + __isl_take isl_set *domain, __isl_take isl_multi_pw_aff *index, + int int_size); struct pet_scop *pet_scop_update_start_end(struct pet_scop *scop, unsigned start, unsigned end); diff --git a/skip.c b/skip.c index d4a1053..2d81b1c 100644 --- a/skip.c +++ b/skip.c @@ -142,11 +142,12 @@ static struct pet_scop *extract_skip_if(__isl_take isl_multi_pw_aff *test_index, expr_skip = pet_expr_access_set_read(expr_skip, 0); expr = pet_expr_new_binary(1, pet_op_assign, expr_skip, expr); domain = pet_context_get_domain(pc); - stmt = pet_stmt_from_pet_expr(domain, &pet_loc_dummy, NULL, - state->n_stmt++, expr); + stmt = pet_stmt_from_pet_expr(isl_set_copy(domain), &pet_loc_dummy, + NULL, state->n_stmt++, expr); scop = pet_scop_from_pet_stmt(pet_context_get_space(pc), stmt); - scop = pet_scop_add_boolean_array(scop, skip_index, state->int_size); + scop = pet_scop_add_boolean_array(scop, domain, skip_index, + state->int_size); return scop; error: @@ -380,11 +381,12 @@ static struct pet_scop *extract_skip_seq( expr_skip = pet_expr_access_set_read(expr_skip, 0); expr = pet_expr_new_binary(1, pet_op_assign, expr_skip, expr); domain = pet_context_get_domain(pc); - stmt = pet_stmt_from_pet_expr(domain, &pet_loc_dummy, NULL, - state->n_stmt++, expr); + stmt = pet_stmt_from_pet_expr(isl_set_copy(domain), &pet_loc_dummy, + NULL, state->n_stmt++, expr); scop = pet_scop_from_pet_stmt(pet_context_get_space(pc), stmt); - scop = pet_scop_add_boolean_array(scop, skip_index, state->int_size); + scop = pet_scop_add_boolean_array(scop, domain, skip_index, + state->int_size); return scop; error: diff --git a/tree2scop.c b/tree2scop.c index cadd193..e97c2a9 100644 --- a/tree2scop.c +++ b/tree2scop.c @@ -620,7 +620,9 @@ static struct pet_scop *scop_from_non_affine_while(__isl_take pet_expr *cond, isl_multi_pw_aff_copy(test_index), pet_loc_copy(loc), pc); id_test = isl_multi_pw_aff_get_tuple_id(test_index, isl_dim_out); - scop = pet_scop_add_boolean_array(scop, test_index, state->int_size); + domain = pet_context_get_domain(pc); + scop = pet_scop_add_boolean_array(scop, domain, + test_index, state->int_size); id = isl_id_alloc(ctx, "t", NULL); domain = infinite_domain(isl_id_copy(id)); @@ -1255,7 +1257,8 @@ static struct pet_scop *scop_from_affine_for(__isl_keep pet_tree *tree, pet_tree_get_loc(tree), pc); id_test = isl_multi_pw_aff_get_tuple_id(test_index, isl_dim_out); - scop_cond = pet_scop_add_boolean_array(scop_cond, test_index, + scop_cond = pet_scop_add_boolean_array(scop_cond, + pet_context_get_domain(pc), test_index, state->int_size); scop_cond = pet_scop_prefix(scop_cond, 0); scop_cond = pet_scop_embed(scop_cond, isl_set_copy(domain), @@ -1513,6 +1516,7 @@ static struct pet_scop *scop_from_non_affine_if(__isl_keep pet_tree *tree, { int has_else; isl_space *space; + isl_set *domain; isl_multi_pw_aff *test_index; struct pet_skip_info skip; struct pet_scop *scop, *scop_then, *scop_else = NULL; @@ -1524,7 +1528,8 @@ static struct pet_scop *scop_from_non_affine_if(__isl_keep pet_tree *tree, 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); - scop = pet_scop_add_boolean_array(scop, + domain = pet_context_get_domain(pc); + scop = pet_scop_add_boolean_array(scop, domain, isl_multi_pw_aff_copy(test_index), state->int_size); scop_then = scop_from_tree(tree->u.i.then_body, pc, state); -- 2.11.4.GIT