From 62da9f7d15c681636ffd8c5a03df630df56abd58 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 27 Sep 2010 18:50:03 +0200 Subject: [PATCH] optionally store domains of scattering dimensions in clast user statements It is sometimes useful to know for a given instance of a user statement in a clast for which scattering dimension values it is executed. This information is difficult if not impossible to retrieve from the clast because some dimensions may have been removed if they attain exactly one value. Signed-off-by: Sven Verdoolaege --- doc/cloog.texi | 18 ++++++++++++++++-- include/cloog/clast.h | 5 +++-- include/cloog/loop.h | 4 +++- include/cloog/options.h | 2 ++ source/clast.c | 16 +++++++++------- source/loop.c | 18 +++++++++++++----- source/options.c | 1 + source/program.c | 2 +- 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/doc/cloog.texi b/doc/cloog.texi index c3a4e8a..13f58d6 100644 --- a/doc/cloog.texi +++ b/doc/cloog.texi @@ -1803,6 +1803,7 @@ struct cloogoptions int cpp ; /* -cpp option. */ int compilable ; /* -compilable option. */ int language; /* LANGUAGE_C or LANGUAGE_FORTRAN */ + int save_domains; /* Save unsimplified copy of domain. */ @} ; typedef struct cloogoptions CloogOptions ; @@ -1828,6 +1829,12 @@ As a reminder, the default values are: @item @math{compilable = 0} (do not generate a compilable code). @end itemize +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. + @node CloogInput @subsection CloogInput @@ -1910,11 +1917,12 @@ struct clast_block *new_clast_block(void); struct clast_user_stmt @{ struct clast_stmt stmt; + CloogDomain * domain; CloogStatement * statement; struct clast_stmt * substitutions; @}; -struct clast_user_stmt *new_clast_user_stmt(CloogStatement *stmt, - struct clast_stmt *subs); +struct clast_user_stmt *new_clast_user_stmt(CloogDomain *domain, + CloogStatement *stmt, struct clast_stmt *subs); struct clast_for @{ struct clast_stmt stmt; @@ -1957,6 +1965,12 @@ by the user, @pxref{CloogStatement}. assigning an expression in terms of the scattering dimensions to each of the original iterators in the original order. The @code{LHS}s of these assignments are left blank (@code{NULL}). +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 this instance of the user statement is executed. +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_for} represents a for loop, iterating @code{body} for each diff --git a/include/cloog/clast.h b/include/cloog/clast.h index 9150c69..436c5ae 100644 --- a/include/cloog/clast.h +++ b/include/cloog/clast.h @@ -85,6 +85,7 @@ struct clast_block { struct clast_user_stmt { struct clast_stmt stmt; + CloogDomain * domain; CloogStatement * statement; struct clast_stmt * substitutions; }; @@ -126,8 +127,8 @@ struct clast_reduction *new_clast_reduction(enum clast_red_type t, int n); struct clast_root *new_clast_root(CloogNames *names); struct clast_assignment *new_clast_assignment(const char *lhs, struct clast_expr *rhs); -struct clast_user_stmt *new_clast_user_stmt(CloogStatement *stmt, - struct clast_stmt *subs); +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); diff --git a/include/cloog/loop.h b/include/cloog/loop.h index 1d87e5b..a871410 100644 --- a/include/cloog/loop.h +++ b/include/cloog/loop.h @@ -63,6 +63,7 @@ struct cloogloop { CloogState *state; /**< State. */ CloogDomain * domain ; /**< The iteration domain. */ + CloogDomain *unsimplified; /**< Unsimplified version of domain. */ int otl; /**< Loop is executed at most once. */ CloogStride *stride; /**< If not NULL, stride information on iterator * (filled only after loop generation). @@ -108,7 +109,8 @@ CloogLoop * cloog_loop_malloc(CloogState *state); 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); +CloogLoop *cloog_loop_simplify(CloogLoop *loop, CloogDomain *context, int level, + CloogOptions *options); void cloog_loop_scatter(CloogLoop *, CloogScattering *); diff --git a/include/cloog/options.h b/include/cloog/options.h index a610f32..c42245a 100644 --- a/include/cloog/options.h +++ b/include/cloog/options.h @@ -88,6 +88,8 @@ struct cloogoptions */ int language; /* 1 to generate FORTRAN, 0 for C otherwise. */ + int save_domains;/* Save unsimplified copy of domain. */ + /* MISC OPTIONS */ char * name ; /* Name of the input file. */ float time ; /* Time spent for code generation in seconds. */ diff --git a/source/clast.c b/source/clast.c index b8dea97..b3973a4 100644 --- a/source/clast.c +++ b/source/clast.c @@ -55,8 +55,8 @@ 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 void insert_block(CloogBlock *block, int level, - 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, struct clast_stmt ***next, CloogInfos *infos); @@ -156,17 +156,19 @@ static void free_clast_user_stmt(struct clast_stmt *s) { struct clast_user_stmt *u = (struct clast_user_stmt *)s; assert(CLAST_STMT_IS_A(s, stmt_user)); + cloog_domain_free(u->domain); cloog_statement_free(u->statement); cloog_clast_free(u->substitutions); free(u); } -struct clast_user_stmt *new_clast_user_stmt(CloogStatement *stmt, - struct clast_stmt *subs) +struct clast_user_stmt *new_clast_user_stmt(CloogDomain *domain, + CloogStatement *stmt, struct clast_stmt *subs) { struct clast_user_stmt *u = malloc(sizeof(struct clast_user_stmt)); u->stmt.op = &stmt_user; u->stmt.next = NULL; + u->domain = cloog_domain_copy(domain); u->statement = cloog_statement_copy(stmt); u->substitutions = subs; return u; @@ -1652,7 +1654,7 @@ static int insert_for(CloogConstraintSet *constraints, int level, int otl, ** * - September 21th 2003: first version (pick from pprint function). */ -static void insert_block(CloogBlock *block, int level, +static void insert_block(CloogDomain *domain, CloogBlock *block, int level, struct clast_stmt ***next, CloogInfos *infos) { CloogStatement * statement ; @@ -1667,7 +1669,7 @@ static void insert_block(CloogBlock *block, int level, subs = clast_equal(level,infos); statement->next = NULL; - **next = &new_clast_user_stmt(statement, subs)->stmt; + **next = &new_clast_user_stmt(domain, statement, subs)->stmt; statement->next = s_next; *next = &(**next)->next; } @@ -1758,7 +1760,7 @@ static void insert_loop(CloogLoop * loop, int level, if (!empty_loop) { /* Finally, if there is an included statement block, print it. */ - insert_block(loop->block, level+equality, next, infos); + insert_block(loop->unsimplified, loop->block, level+equality, next, infos); /* Go to the next level. */ if (loop->inner != NULL) diff --git a/source/loop.c b/source/loop.c index 926aad5..6d82aaa 100644 --- a/source/loop.c +++ b/source/loop.c @@ -208,6 +208,7 @@ void cloog_loop_free(CloogLoop * loop) next = loop->next ; cloog_domain_free(loop->domain) ; + cloog_domain_free(loop->unsimplified); cloog_block_free(loop->block) ; if (loop->inner != NULL) cloog_loop_free(loop->inner) ; @@ -345,6 +346,7 @@ CloogLoop *cloog_loop_malloc(CloogState *state) /* We set the various fields with default values. */ loop->state = state; loop->domain = NULL ; + loop->unsimplified = NULL; loop->block = NULL ; loop->usr = NULL; loop->inner = NULL ; @@ -2279,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) + int level, CloogOptions *options) { int domain_dim; CloogBlock * new_block ; @@ -2305,10 +2307,10 @@ static CloogLoop *loop_simplify(CloogLoop *loop, CloogDomain *context, return NULL; } - inner = cloog_loop_simplify(loop->inner, inter, level+1); - cloog_domain_free(inter) ; + inner = cloog_loop_simplify(loop->inner, inter, level+1, options); if ((inner == NULL) && (loop->block == NULL)) { + cloog_domain_free(inter); cloog_domain_free(simp); return NULL; } @@ -2318,6 +2320,11 @@ 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) + simplified->unsimplified = inter; + else + cloog_domain_free(inter); + return(simplified) ; } @@ -2343,14 +2350,15 @@ static CloogLoop *loop_simplify(CloogLoop *loop, CloogDomain *context, * simplifying gives a union of polyhedra (before, it * was under the responsibility of the pretty printer). */ -CloogLoop *cloog_loop_simplify(CloogLoop *loop, CloogDomain *context, int level) +CloogLoop *cloog_loop_simplify(CloogLoop *loop, CloogDomain *context, int level, + CloogOptions *options) { CloogLoop *now; CloogLoop *res = NULL; CloogLoop **next = &res; for (now = loop; now; now = now->next) { - *next = loop_simplify(now, context, level); + *next = loop_simplify(now, context, level, options); now->inner = NULL; /* For loop integrity. */ cloog_domain_free(now->domain); diff --git a/source/options.c b/source/options.c index d862bd8..75d44a9 100644 --- a/source/options.c +++ b/source/options.c @@ -309,6 +309,7 @@ CloogOptions *cloog_options_malloc(CloogState *state) options->callable = 0 ; /* No callable code. */ options->quiet = 0; /* Do print informational messages. */ options->language = LANGUAGE_C; /* The default output language is C. */ + options->save_domains = 0; /* Don't save domains. */ /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */ options->leaks = 0 ; /* I don't want to print allocation statistics.*/ options->backtrack = 0; /* Perform backtrack in Quillere's algorithm.*/ diff --git a/source/program.c b/source/program.c index 1076deb..d597c8f 100644 --- a/source/program.c +++ b/source/program.c @@ -781,7 +781,7 @@ CloogOptions * options ; #endif if ((!options->nosimplify) && (program->loop != NULL)) - loop = cloog_loop_simplify(loop, program->context, 1); + loop = cloog_loop_simplify(loop, program->context, 1, options); program->loop = loop ; } -- 2.11.4.GIT