From bb27eba19877f387cae5df70c9466ffd3065c8e1 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 20 Feb 2014 11:31:22 +0100 Subject: [PATCH] pet_check_code.c: use pet_expr_extract_affine Now that pet_expr_extract_affine has been exposed, we can use it instead of our partial implementation of essentially the same functionality. Signed-off-by: Sven Verdoolaege --- pet_check_code.c | 226 ++----------------------------------------------------- 1 file changed, 7 insertions(+), 219 deletions(-) diff --git a/pet_check_code.c b/pet_check_code.c index 3360577..3957cba 100644 --- a/pet_check_code.c +++ b/pet_check_code.c @@ -42,8 +42,6 @@ #include #include -#include "aff.h" - struct options { struct isl_options *isl; struct pet_options *pet; @@ -60,226 +58,16 @@ ISL_ARGS_END ISL_ARG_DEF(options, struct options, options_args) -static __isl_give isl_pw_aff *expr_extract_pw_aff(__isl_keep pet_expr *expr, - __isl_keep isl_space *space); - -/* Extract an affine expression from the call to floord in "expr". - * - * "space" is the iteration space of the statement containing the expression. - */ -static __isl_give isl_pw_aff *expr_extract_floord(__isl_keep pet_expr *expr, - __isl_keep isl_space *space) -{ - isl_pw_aff *lhs, *rhs; - pet_expr *arg; - - arg = pet_expr_get_arg(expr, 0); - lhs = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - arg = pet_expr_get_arg(expr, 1); - rhs = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - return isl_pw_aff_floor(isl_pw_aff_div(lhs, rhs)); -} - -/* Extract an affine expression from the call in "expr". - * - * "space" is the iteration space of the statement containing the expression. - * - * We only support calls to the "floord" function for now. - */ -static __isl_give isl_pw_aff *call_expr_extract_pw_aff( - __isl_keep pet_expr *expr, __isl_keep isl_space *space) -{ - const char *name; - - name = pet_expr_call_get_name(expr); - if (!name) - return NULL; - if (!strcmp(name, "floord")) - return expr_extract_floord(expr, space); - - isl_die(isl_space_get_ctx(space), isl_error_unsupported, - "unsupported expression", return NULL); -} - -/* Extract an affine expression from the access to a named space in "index". - * - * We assume we are accessing a 0D space and - * we turn that into an expression equal to a parameter of the same name. - */ -static __isl_give isl_pw_aff *resolve_access(__isl_take isl_multi_pw_aff *index) -{ - isl_id *id; - isl_set *dom; - isl_aff *aff; - isl_local_space *ls; - isl_pw_aff *pa; - - id = isl_multi_pw_aff_get_tuple_id(index, isl_dim_out); - dom = isl_multi_pw_aff_domain(index); - dom = isl_set_insert_dims(dom, isl_dim_param, 0, 1); - dom = isl_set_set_dim_id(dom, isl_dim_param, 0, id); - ls = isl_local_space_from_space(isl_set_get_space(dom)); - aff = isl_aff_var_on_domain(ls, isl_dim_param, 0); - pa = isl_pw_aff_alloc(dom, aff); - - return pa; -} - -/* Extract an affine expression from the access expression "expr". - * - * If we are accessing a (1D) anonymous space, then we are actually - * computing an affine expression and we simply return that expression. - * Otherwise, we try and convert the access to an affine expression in - * resolve_access(). - */ -static __isl_give isl_pw_aff *access_expr_extract_pw_aff( - __isl_keep pet_expr *expr) -{ - isl_pw_aff *pa; - isl_multi_pw_aff *index; - - index = pet_expr_access_get_index(expr); - if (isl_multi_pw_aff_has_tuple_id(index, isl_dim_out)) { - pa = resolve_access(index); - } else { - pa = isl_multi_pw_aff_get_pw_aff(index, 0); - isl_multi_pw_aff_free(index); - } - return pa; -} - -/* Extract an affine expression defined over iteration space "space" - * from the integer expression "expr". - */ -static __isl_give isl_pw_aff *int_expr_extract_pw_aff( - __isl_keep pet_expr *expr, __isl_keep isl_space *space) -{ - isl_local_space *ls; - isl_aff *aff; - - ls = isl_local_space_from_space(isl_space_copy(space)); - aff = isl_aff_zero_on_domain(ls); - aff = isl_aff_add_constant_val(aff, pet_expr_int_get_val(expr)); - return isl_pw_aff_from_aff(aff); -} - -/* Extract an affine expression from the operation in "expr". - * - * "space" is the iteration space of the statement containing the expression. - * - * We only handle the kinds of expressions that we would expect - * as arguments to a function call in code generated by isl. - */ -static __isl_give isl_pw_aff *op_expr_extract_pw_aff(__isl_keep pet_expr *expr, - __isl_keep isl_space *space) -{ - isl_pw_aff *pa, *pa1, *pa2; - pet_expr *arg; - enum pet_op_type type; - - switch (pet_expr_get_n_arg(expr)) { - case 1: - if (pet_expr_op_get_type(expr) == pet_op_minus) { - arg = pet_expr_get_arg(expr, 0); - pa = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - return isl_pw_aff_neg(pa); - } - assert(0); - case 2: - arg = pet_expr_get_arg(expr, 0); - pa1 = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - arg = pet_expr_get_arg(expr, 1); - pa2 = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - type = pet_expr_op_get_type(expr); - switch (type) { - case pet_op_mul: - pa = isl_pw_aff_mul(pa1, pa2); - break; - case pet_op_add: - pa = isl_pw_aff_add(pa1, pa2); - break; - case pet_op_sub: - pa = isl_pw_aff_sub(pa1, pa2); - break; - case pet_op_div: - pa = isl_pw_aff_tdiv_q(pa1, pa2); - break; - case pet_op_mod: - pa = isl_pw_aff_tdiv_r(pa1, pa2); - break; - case pet_op_eq: - case pet_op_ne: - case pet_op_le: - case pet_op_ge: - case pet_op_lt: - case pet_op_gt: - pa = pet_comparison(type, pa1, pa2); - break; - case pet_op_land: - case pet_op_lor: - pa = pet_boolean(type, pa1, pa2); - break; - default: - assert(0); - } - return pa; - case 3: - arg = pet_expr_get_arg(expr, 0); - pa = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - arg = pet_expr_get_arg(expr, 1); - pa1 = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - arg = pet_expr_get_arg(expr, 2); - pa2 = expr_extract_pw_aff(arg, space); - pet_expr_free(arg); - return isl_pw_aff_cond(pa, pa1, pa2); - default: - assert(0); - } -} - -/* Extract an affine expression from "expr" in the form of an isl_pw_aff. - * - * "space" is the iteration space of the statement containing the expression. - * - * We only handle the kinds of expressions that we would expect - * as arguments to a function call in code generated by isl. - */ -static __isl_give isl_pw_aff *expr_extract_pw_aff(__isl_keep pet_expr *expr, - __isl_keep isl_space *space) -{ - switch (pet_expr_get_type(expr)) { - case pet_expr_int: - return int_expr_extract_pw_aff(expr, space); - case pet_expr_access: - return access_expr_extract_pw_aff(expr); - case pet_expr_op: - return op_expr_extract_pw_aff(expr, space); - case pet_expr_call: - return call_expr_extract_pw_aff(expr, space); - case pet_expr_cast: - case pet_expr_double: - case pet_expr_error: - assert(0); - } -} - /* Extract an affine expression from "expr" in the form of an isl_map. * - * "space" is the iteration space of the statement containing the expression. + * The domain of the created expression is that of "pc". */ static __isl_give isl_map *expr_extract_map(__isl_keep pet_expr *expr, - __isl_keep isl_space *space) + __isl_keep pet_context *pc) { isl_pw_aff *pa; - pa = expr_extract_pw_aff(expr, space); + pa = pet_expr_extract_affine(expr, pc); return isl_map_from_pw_aff(pa); } @@ -295,25 +83,25 @@ static __isl_give isl_map *stmt_extract_call(struct pet_stmt *stmt) isl_set *domain; isl_map *call; const char *name; + pet_context *pc; domain = isl_set_copy(stmt->domain); call = isl_map_from_domain(domain); assert(pet_expr_get_type(stmt->body) == pet_expr_call); + pc = pet_context_alloc(isl_set_copy(stmt->domain)); n = pet_expr_get_n_arg(stmt->body); for (i = 0; i < n; ++i) { isl_map *map_i; - isl_space *space; pet_expr *arg; arg = pet_expr_get_arg(stmt->body, i); - space = pet_stmt_get_space(stmt); - map_i = expr_extract_map(arg, space); - isl_space_free(space); + map_i = expr_extract_map(arg, pc); pet_expr_free(arg); call = isl_map_flat_range_product(call, map_i); } + pet_context_free(pc); name = pet_expr_call_get_name(stmt->body); call = isl_map_set_tuple_name(call, isl_dim_out, name); -- 2.11.4.GIT