From bc067a8a6078111287812230ca7d06400180602f Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 18 Sep 2013 13:02:11 +0200 Subject: [PATCH] isl_ast_build_expr.c: extract out isl_ast_build_with_arguments This new function will be useful for constructing member accesses. Signed-off-by: Sven Verdoolaege --- isl_ast_build_expr.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/isl_ast_build_expr.c b/isl_ast_build_expr.c index bf670db7..a57dd514 100644 --- a/isl_ast_build_expr.c +++ b/isl_ast_build_expr.c @@ -1338,6 +1338,37 @@ static __isl_give isl_multi_pw_aff *set_iterator_names( return mpa; } +/* Construct an isl_ast_expr of type "type" with as first argument "arg0" and + * the remaining arguments derived from "mpa". + * That is, construct a call or access expression that calls/accesses "arg0" + * with arguments/indices specified by "mpa". + */ +static __isl_give isl_ast_expr *isl_ast_build_with_arguments( + __isl_keep isl_ast_build *build, enum isl_ast_op_type type, + __isl_take isl_ast_expr *arg0, __isl_take isl_multi_pw_aff *mpa) +{ + int i, n; + isl_ctx *ctx; + isl_ast_expr *expr; + + ctx = isl_ast_build_get_ctx(build); + + n = isl_multi_pw_aff_dim(mpa, isl_dim_out); + expr = isl_ast_expr_alloc_op(ctx, type, 1 + n); + expr = isl_ast_expr_set_op_arg(expr, 0, arg0); + for (i = 0; i < n; ++i) { + isl_pw_aff *pa; + isl_ast_expr *arg; + + pa = isl_multi_pw_aff_get_pw_aff(mpa, i); + arg = isl_ast_build_expr_from_pw_aff_internal(build, pa); + expr = isl_ast_expr_set_op_arg(expr, 1 + i, arg); + } + + isl_multi_pw_aff_free(mpa); + return expr; +} + /* Construct an isl_ast_expr of type "type" that calls or accesses * the element specified by "mpa". * The first argument is obtained from the output tuple name. @@ -1349,7 +1380,6 @@ static __isl_give isl_ast_expr *isl_ast_build_from_multi_pw_aff_internal( __isl_keep isl_ast_build *build, enum isl_ast_op_type type, __isl_take isl_multi_pw_aff *mpa) { - int i, n; isl_ctx *ctx; isl_id *id; isl_ast_expr *expr; @@ -1359,26 +1389,14 @@ static __isl_give isl_ast_expr *isl_ast_build_from_multi_pw_aff_internal( return isl_multi_pw_aff_free(mpa); ctx = isl_ast_build_get_ctx(build); - n = isl_multi_pw_aff_dim(mpa, isl_dim_out); - expr = isl_ast_expr_alloc_op(ctx, type, 1 + n); if (isl_multi_pw_aff_has_tuple_id(mpa, isl_dim_out)) id = isl_multi_pw_aff_get_tuple_id(mpa, isl_dim_out); else id = isl_id_alloc(ctx, "", NULL); - expr = isl_ast_expr_set_op_arg(expr, 0, isl_ast_expr_from_id(id)); - for (i = 0; i < n; ++i) { - isl_pw_aff *pa; - isl_ast_expr *arg; - - pa = isl_multi_pw_aff_get_pw_aff(mpa, i); - arg = isl_ast_build_expr_from_pw_aff_internal(build, pa); - expr = isl_ast_expr_set_op_arg(expr, 1 + i, arg); - } - - isl_multi_pw_aff_free(mpa); - return expr; + expr = isl_ast_expr_from_id(id); + return isl_ast_build_with_arguments(build, type, expr, mpa); } /* Construct an isl_ast_expr of type "type" that calls or accesses -- 2.11.4.GIT