From a9733e1858970f41ec49ad4676281292bdc14ed3 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 3 Jan 2011 18:30:10 +0100 Subject: [PATCH] clast construction: keep track of valid stride entries insert_modulo_guard_constraint tries to exploit strides of outer loops to simplify the constraint. However, insert_modulo_guard_constraint may have been called from within insert_extra_modulo_guards, in which case the "level" may be strictly greater than the current loop level, i.e., the number of valid entries in the strides array. We therefore need to explicitly keep track of the number of valid entries in that array. Signed-off-by: Sven Verdoolaege --- source/clast.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/clast.c b/source/clast.c index c12bac0..e335e90 100644 --- a/source/clast.c +++ b/source/clast.c @@ -17,6 +17,7 @@ struct clooginfos { CloogState *state; /**< State. */ CloogStride **stride; + int stride_level; /**< Number of valid entries in stride array. */ int nb_scattdims ; /**< Scattering dimension number. */ int * scaldims ; /**< Boolean array saying whether a given * scattering dimension is scalar or not. @@ -1303,7 +1304,10 @@ static int insert_modulo_guard_constraint(CloogConstraint *c, void *user) nb_elts = 0; /* First, the modulo guard : the iterators... */ - for (i = level - 1; i >= 1; --i) + i = level - 1; + if (i > infos->stride_level) + i = infos->stride_level; + for (; i >= 1; --i) eliminate_using_stride_constraint(line, len, nb_iter, infos->stride[i - 1], i, line[level]); for (i=1;i<=nb_iter;i++) { @@ -1743,8 +1747,10 @@ static void insert_loop(CloogLoop * loop, int level, constraints = cloog_constraint_set_simplify(temp,infos->equal,level, infos->names->nb_parameters); cloog_constraint_set_free(temp); - if (level) + if (level) { infos->stride[level - 1] = loop->stride; + infos->stride_level++; + } /* First of all we have to print the guard. */ insert_guard(constraints,level, next, infos); @@ -1779,8 +1785,10 @@ static void insert_loop(CloogLoop * loop, int level, insert_loop(loop->inner, level+1, next, infos); } - if (level) + if (level) { cloog_equal_del(infos->equal,level); + infos->stride_level--; + } cloog_constraint_set_free(constraints); /* Go to the next loop on the same level. */ @@ -1810,6 +1818,7 @@ struct clast_stmt *cloog_clast_create(CloogProgram *program, */ nb_levels = program->names->nb_scattering+program->names->nb_iterators+1; infos->stride = ALLOCN(CloogStride *, nb_levels); + infos->stride_level = 0; infos->equal = cloog_equal_alloc(nb_levels, nb_levels, program->names->nb_parameters); -- 2.11.4.GIT