From 5f6c7108b72b60ae0209b83eb6a1d8590af60594 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 29 Nov 2010 18:19:38 -0500 Subject: [PATCH] Optionally store domains of scattering dimensions in clast for For each clast_for the subset of the scattering space that is executed inside this for is stored. The domain of a user statement is now also only saved when the domain lies entirely in the scattering space, i.e., when the -stop option is used. Signed-off-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- doc/cloog.texi | 21 +++++++++++++++------ include/cloog/clast.h | 6 ++++-- include/cloog/loop.h | 2 +- source/clast.c | 48 ++++++++++++++++++++++++++++++------------------ source/loop.c | 12 +++++++----- source/program.c | 3 ++- 6 files changed, 59 insertions(+), 33 deletions(-) diff --git a/doc/cloog.texi b/doc/cloog.texi index 13f58d6..88669dc 100644 --- a/doc/cloog.texi +++ b/doc/cloog.texi @@ -1831,10 +1831,12 @@ As a reminder, the default values are: The @code{save_domains} option is only useful for users of the CLooG library. This option defaults to 0, but when it is set, the @code{domain} -field of each @code{clast_user_stmt} will be set to the set -of values for the scattering dimensions -for which this instance of the user statement is executed. - +field of each @code{clast_user_stmt} will be set to the set of values for the +scattering dimensions for which this instance of the user statement is executed. +The @code{domain} field of each @code{clast_for} contains the set of values for +the scattering dimensions for which an instance of a user statement is executed +inside the @code{clast_for}. It is only available if the @code{clast_for} +enumerates a scattering dimension. @node CloogInput @subsection CloogInput @@ -1926,14 +1928,16 @@ struct clast_user_stmt *new_clast_user_stmt(CloogDomain *domain, struct clast_for @{ struct clast_stmt stmt; + CloogDomain * domain; const char * iterator; struct clast_expr * LB; struct clast_expr * UB; cloog_int_t stride; struct clast_stmt * body; @}; -struct clast_for *new_clast_for(const char *it, struct clast_expr *LB, - struct clast_expr *UB, cloog_int_t stride); +struct clast_for *new_clast_for(CloogDomain *domain, const char *it, + struct clast_expr *LB, struct clast_expr *UB, + cloog_int_t stride); struct clast_guard @{ struct clast_stmt stmt; @@ -1976,6 +1980,11 @@ constant scattering dimensions may have been removed from this set. A @code{clast_for} represents a for loop, iterating @code{body} for each value of @code{iterator} between @code{LB} and @code{UB} in steps of size @code{stride}. +The @code{domain} is set to @code{NULL} if the @code{save_domains} option is not +set. Otherwise, it is set to the set of values for the scattering dimensions +for which a user statement is executed inside this @code{clast_for}. Note that +unless the @code{noscalars} option has been set, the constant scattering +dimensions may have been removed from this set. @noindent A @code{clast_guard} represents the guarded execution of the @code{then} diff --git a/include/cloog/clast.h b/include/cloog/clast.h index 436c5ae..b455369 100644 --- a/include/cloog/clast.h +++ b/include/cloog/clast.h @@ -92,6 +92,7 @@ struct clast_user_stmt { struct clast_for { struct clast_stmt stmt; + CloogDomain * domain; const char * iterator; struct clast_expr * LB; struct clast_expr * UB; @@ -130,8 +131,9 @@ struct clast_assignment *new_clast_assignment(const char *lhs, struct clast_user_stmt *new_clast_user_stmt(CloogDomain *domain, CloogStatement *stmt, struct clast_stmt *subs); struct clast_block *new_clast_block(void); -struct clast_for *new_clast_for(const char *it, struct clast_expr *LB, - struct clast_expr *UB, CloogStride *stride); +struct clast_for *new_clast_for(CloogDomain *domain, const char *it, + struct clast_expr *LB, struct clast_expr *UB, + CloogStride *stride); struct clast_guard *new_clast_guard(int n); void free_clast_name(struct clast_name *t); diff --git a/include/cloog/loop.h b/include/cloog/loop.h index a871410..b62a274 100644 --- a/include/cloog/loop.h +++ b/include/cloog/loop.h @@ -110,7 +110,7 @@ CloogLoop *cloog_loop_generate(CloogLoop *loop, CloogDomain *context, int level, int scalar, int *scaldims, int nb_scattdims, CloogOptions *options); CloogLoop *cloog_loop_simplify(CloogLoop *loop, CloogDomain *context, int level, - CloogOptions *options); + int nb_scattdims, CloogOptions *options); void cloog_loop_scatter(CloogLoop *, CloogScattering *); diff --git a/source/clast.c b/source/clast.c index b3973a4..c12bac0 100644 --- a/source/clast.c +++ b/source/clast.c @@ -51,10 +51,12 @@ static void insert_guard(CloogConstraintSet *constraints, int level, static int insert_modulo_guard(CloogConstraint *upper, CloogConstraint *lower, int level, struct clast_stmt ***next, CloogInfos *infos); -static int insert_equation(CloogConstraint *upper, CloogConstraint *lower, - int level, struct clast_stmt ***next, CloogInfos *infos); -static int insert_for(CloogConstraintSet *constraints, int level, int otl, - struct clast_stmt ***next, CloogInfos *infos); +static int insert_equation(CloogDomain *domain, CloogConstraint *upper, + CloogConstraint *lower, int level, + struct clast_stmt ***next, CloogInfos *infos); +static int insert_for(CloogDomain *domain, CloogConstraintSet *constraints, + int level, int otl, struct clast_stmt ***next, + CloogInfos *infos); static void insert_block(CloogDomain *domain, CloogBlock *block, int level, struct clast_stmt ***next, CloogInfos *infos); static void insert_loop(CloogLoop * loop, int level, @@ -203,6 +205,7 @@ static void free_clast_for(struct clast_stmt *s) { struct clast_for *f = (struct clast_for *)s; assert(CLAST_STMT_IS_A(s, stmt_for)); + cloog_domain_free(f->domain); free_clast_expr(f->LB); free_clast_expr(f->UB); cloog_int_clear(f->stride); @@ -210,12 +213,14 @@ static void free_clast_for(struct clast_stmt *s) free(f); } -struct clast_for *new_clast_for(const char *it, struct clast_expr *LB, - struct clast_expr *UB, CloogStride *stride) +struct clast_for *new_clast_for(CloogDomain *domain, const char *it, + struct clast_expr *LB, struct clast_expr *UB, + CloogStride *stride) { struct clast_for *f = malloc(sizeof(struct clast_for)); f->stmt.op = &stmt_for; f->stmt.next = NULL; + f->domain = cloog_domain_copy(domain); f->iterator = it; f->LB = LB; f->UB = UB; @@ -1412,7 +1417,7 @@ static int insert_modulo_guard(CloogConstraint *upper, * a loop with a single iteration, but the user wants us to generate * a loop anyway, so we do it here. */ -static int insert_equation_as_loop(CloogConstraint *upper, +static int insert_equation_as_loop(CloogDomain *domain, CloogConstraint *upper, CloogConstraint *lower, int level, struct clast_stmt ***next, CloogInfos *infos) { @@ -1425,7 +1430,8 @@ static int insert_equation_as_loop(CloogConstraint *upper, e1 = clast_expr_copy(e2); else e1 = clast_bound_from_constraint(lower, level, infos->names); - f = new_clast_for(iterator, e1, e2, infos->stride[level-1]); + + f = new_clast_for(domain, iterator, e1, e2, infos->stride[level-1]); **next = &f->stmt; *next = &f->body; @@ -1459,14 +1465,15 @@ static int insert_equation_as_loop(CloogConstraint *upper, * - July 14th 2003: (debug) no more print the constant in the modulo guard when * it was previously included in a stride calculation. */ -static int insert_equation(CloogConstraint *upper, CloogConstraint *lower, - int level, struct clast_stmt ***next, CloogInfos *infos) +static int insert_equation(CloogDomain *domain, CloogConstraint *upper, + CloogConstraint *lower, int level, struct clast_stmt + ***next, CloogInfos *infos) { struct clast_expr *e; struct clast_assignment *ass; if (!infos->options->otl) - return insert_equation_as_loop(upper, lower, level, next, infos); + return insert_equation_as_loop(domain, upper, lower, level, next, infos); if (!insert_modulo_guard(upper, lower, level, next, infos)) { cloog_constraint_release(lower); @@ -1606,8 +1613,9 @@ static void insert_guarded_otl_for(CloogConstraintSet *constraints, int level, * the number of parameters in matrix (nb_par), and the arrays of iterator * names and parameters (iters and params). */ -static int insert_for(CloogConstraintSet *constraints, int level, int otl, - struct clast_stmt ***next, CloogInfos *infos) +static int insert_for(CloogDomain *domain, CloogConstraintSet *constraints, + int level, int otl, struct clast_stmt ***next, + CloogInfos *infos) { const char *iterator; struct clast_expr *e1; @@ -1634,7 +1642,8 @@ static int insert_for(CloogConstraintSet *constraints, int level, int otl, } else { struct clast_for *f; iterator = cloog_names_name_at_level(infos->names, level); - f = new_clast_for(iterator, e1, e2, infos->stride[level-1]); + + f = new_clast_for(domain, iterator, e1, e2, infos->stride[level-1]); **next = &f->stmt; *next = &f->body; } @@ -1747,15 +1756,18 @@ static void insert_loop(CloogLoop * loop, int level, */ if (cloog_constraint_is_valid(i = cloog_constraint_set_defining_equality(constraints, level))) { - empty_loop = !insert_equation(i, cloog_constraint_invalid(), - level, next, infos); + empty_loop = !insert_equation(loop->unsimplified, i, + cloog_constraint_invalid(), level, next, + infos); equality = 1 ; } else if (cloog_constraint_is_valid(i = cloog_constraint_set_defining_inequalities(constraints, level, &j, infos->names->nb_parameters))) { - empty_loop = !insert_equation(i, j, level, next, infos); + empty_loop = !insert_equation(loop->unsimplified, i, j, level, next, + infos); } else - empty_loop = !insert_for(constraints, level, loop->otl, next, infos); + empty_loop = !insert_for(loop->unsimplified, constraints, level, + loop->otl, next, infos); } if (!empty_loop) { diff --git a/source/loop.c b/source/loop.c index 6d82aaa..ec5200a 100644 --- a/source/loop.c +++ b/source/loop.c @@ -2281,7 +2281,7 @@ CloogLoop *cloog_loop_generate(CloogLoop *loop, CloogDomain *context, * See cloog_loop_simplify. */ static CloogLoop *loop_simplify(CloogLoop *loop, CloogDomain *context, - int level, CloogOptions *options) + int level, int nb_scattdims, CloogOptions *options) { int domain_dim; CloogBlock * new_block ; @@ -2307,7 +2307,8 @@ static CloogLoop *loop_simplify(CloogLoop *loop, CloogDomain *context, return NULL; } - inner = cloog_loop_simplify(loop->inner, inter, level+1, options); + inner = cloog_loop_simplify(loop->inner, inter, level+1, nb_scattdims, + options); if ((inner == NULL) && (loop->block == NULL)) { cloog_domain_free(inter); @@ -2320,7 +2321,8 @@ static CloogLoop *loop_simplify(CloogLoop *loop, CloogDomain *context, simplified = cloog_loop_alloc(loop->state, simp, loop->otl, loop->stride, new_block, inner, NULL); - if (loop->block && options->save_domains) + /* Only save the domains, if their level is still a scattering level. */ + if (options->save_domains && level <= nb_scattdims) simplified->unsimplified = inter; else cloog_domain_free(inter); @@ -2351,14 +2353,14 @@ static CloogLoop *loop_simplify(CloogLoop *loop, CloogDomain *context, * was under the responsibility of the pretty printer). */ CloogLoop *cloog_loop_simplify(CloogLoop *loop, CloogDomain *context, int level, - CloogOptions *options) + int nb_scattdims, CloogOptions *options) { CloogLoop *now; CloogLoop *res = NULL; CloogLoop **next = &res; for (now = loop; now; now = now->next) { - *next = loop_simplify(now, context, level, options); + *next = loop_simplify(now, context, level, nb_scattdims, options); now->inner = NULL; /* For loop integrity. */ cloog_domain_free(now->domain); diff --git a/source/program.c b/source/program.c index d597c8f..45dfa0f 100644 --- a/source/program.c +++ b/source/program.c @@ -781,7 +781,8 @@ CloogOptions * options ; #endif if ((!options->nosimplify) && (program->loop != NULL)) - loop = cloog_loop_simplify(loop, program->context, 1, options); + loop = cloog_loop_simplify(loop, program->context, 1, + program->nb_scattdims, options); program->loop = loop ; } -- 2.11.4.GIT