Commit 3d9784cb by Sebastian Pop Committed by Sebastian Pop

Compute once and cache the LB and UB for each clast_name.

2011-07-21  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite-clast-to-gimple.c (struct clast_name_index): Add lb
	and ub fields.
	(new_clast_name_index): Add lb and ub parameters.
	(free_clast_name_index): New.
	(clast_name_to_lb_ub): New.
	(save_clast_name_index): Add lb and ub parameters.
	(compute_bounds_for_param): New.
	(type_for_level): Removed.
	(type_for_clast_for): Removed level parameter.  Do not call
	type_for_level.
	(graphite_create_new_loop): Store the lb and ub for the clast_name
	of the iterator of the loop that has been generated.
	(graphite_create_new_loop_guard): Remove parameter level.
	(create_params_index): Store the lb and ub of each parameter.
	(gloog): Use free_clast_name_index.  Pass to create_params_index
	the current scop.

From-SVN: r176603
parent 12b30e6d
2011-07-21 Sebastian Pop <sebastian.pop@amd.com> 2011-07-21 Sebastian Pop <sebastian.pop@amd.com>
* graphite-clast-to-gimple.c (struct clast_name_index): Add lb
and ub fields.
(new_clast_name_index): Add lb and ub parameters.
(free_clast_name_index): New.
(clast_name_to_lb_ub): New.
(save_clast_name_index): Add lb and ub parameters.
(compute_bounds_for_param): New.
(type_for_level): Removed.
(type_for_clast_for): Removed level parameter. Do not call
type_for_level.
(graphite_create_new_loop): Store the lb and ub for the clast_name
of the iterator of the loop that has been generated.
(graphite_create_new_loop_guard): Remove parameter level.
(create_params_index): Store the lb and ub of each parameter.
(gloog): Use free_clast_name_index. Pass to create_params_index
the current scop.
2011-07-21 Sebastian Pop <sebastian.pop@amd.com>
* graphite-clast-to-gimple.c (max_signed_precision_type): Removed. * graphite-clast-to-gimple.c (max_signed_precision_type): Removed.
(max_precision_type): Inline max_signed_precision_type. (max_precision_type): Inline max_signed_precision_type.
(type_for_clast_red): Use max_precision_type. (type_for_clast_red): Use max_precision_type.
......
...@@ -57,28 +57,46 @@ graphite_verify (void) ...@@ -57,28 +57,46 @@ graphite_verify (void)
} }
/* Stores the INDEX in a vector and the loop nesting LEVEL for a given /* Stores the INDEX in a vector and the loop nesting LEVEL for a given
clast NAME. */ clast NAME. LB and UB represent the exact lower and upper bounds
that can be inferred from the polyhedral representation. */
typedef struct clast_name_index { typedef struct clast_name_index {
int index; int index;
int level; int level;
mpz_t lb, ub;
const char *name; const char *name;
} *clast_name_index_p; } *clast_name_index_p;
/* Returns a pointer to a new element of type clast_name_index_p built /* Returns a pointer to a new element of type clast_name_index_p built
from NAME, LEVEL, and INDEX. */ from NAME, INDEX, LEVEL, LB, and UB. */
static inline clast_name_index_p static inline clast_name_index_p
new_clast_name_index (const char *name, int index, int level) new_clast_name_index (const char *name, int index, int level,
mpz_t lb, mpz_t ub)
{ {
clast_name_index_p res = XNEW (struct clast_name_index); clast_name_index_p res = XNEW (struct clast_name_index);
res->name = name; res->name = name;
res->level = level; res->level = level;
res->index = index; res->index = index;
mpz_init (res->lb);
mpz_init (res->ub);
mpz_set (res->lb, lb);
mpz_set (res->ub, ub);
return res; return res;
} }
/* Free the memory taken by a clast_name_index struct. */
static void
free_clast_name_index (void *ptr)
{
struct clast_name_index *c = (struct clast_name_index *) ptr;
mpz_clear (c->lb);
mpz_clear (c->ub);
free (ptr);
}
/* For a given clast NAME, returns -1 if NAME is not in the /* For a given clast NAME, returns -1 if NAME is not in the
INDEX_TABLE, otherwise returns the loop level for the induction INDEX_TABLE, otherwise returns the loop level for the induction
variable NAME, or if it is a parameter, the parameter number in the variable NAME, or if it is a parameter, the parameter number in the
...@@ -130,11 +148,40 @@ clast_name_to_index (clast_name_p name, htab_t index_table) ...@@ -130,11 +148,40 @@ clast_name_to_index (clast_name_p name, htab_t index_table)
return -1; return -1;
} }
/* For a given clast NAME, initializes the lower and upper bounds LB
and UB stored in the INDEX_TABLE. Returns true when NAME has been
found in the INDEX_TABLE, false otherwise. */
static inline bool
clast_name_to_lb_ub (clast_name_p name, htab_t index_table, mpz_t lb, mpz_t ub)
{
struct clast_name_index tmp;
PTR *slot;
#ifdef CLOOG_ORG
gcc_assert (name->type == clast_expr_name);
tmp.name = ((const struct clast_name *) name)->name;
#else
tmp.name = name;
#endif
slot = htab_find_slot (index_table, &tmp, NO_INSERT);
if (slot && *slot)
{
mpz_set (lb, ((struct clast_name_index *) *slot)->lb);
mpz_set (ub, ((struct clast_name_index *) *slot)->ub);
return true;
}
return false;
}
/* Records in INDEX_TABLE the INDEX and LEVEL for NAME. */ /* Records in INDEX_TABLE the INDEX and LEVEL for NAME. */
static inline void static inline void
save_clast_name_index (htab_t index_table, const char *name, save_clast_name_index (htab_t index_table, const char *name,
int index, int level) int index, int level, mpz_t lb, mpz_t ub)
{ {
struct clast_name_index tmp; struct clast_name_index tmp;
PTR *slot; PTR *slot;
...@@ -146,7 +193,7 @@ save_clast_name_index (htab_t index_table, const char *name, ...@@ -146,7 +193,7 @@ save_clast_name_index (htab_t index_table, const char *name,
{ {
free (*slot); free (*slot);
*slot = new_clast_name_index (name, index, level); *slot = new_clast_name_index (name, index, level, lb, ub);
} }
} }
...@@ -579,6 +626,24 @@ graphite_create_new_guard (edge entry_edge, struct clast_guard *stmt, ...@@ -579,6 +626,24 @@ graphite_create_new_guard (edge entry_edge, struct clast_guard *stmt,
return exit_edge; return exit_edge;
} }
/* Compute the lower bound LOW and upper bound UP for the parameter
PARAM in scop SCOP based on the constraints in the context. */
static void
compute_bounds_for_param (scop_p scop, int param, mpz_t low, mpz_t up)
{
ppl_Linear_Expression_t le;
/* Prepare the linear expression corresponding to the parameter that
we want to maximize/minimize. */
ppl_new_Linear_Expression_with_dimension (&le, scop_nb_params (scop));
ppl_set_coef (le, param, 1);
ppl_max_for_le_pointset (SCOP_CONTEXT (scop), le, up);
ppl_min_for_le_pointset (SCOP_CONTEXT (scop), le, low);
ppl_delete_Linear_Expression (le);
}
/* Compute the lower bound LOW and upper bound UP for the induction /* Compute the lower bound LOW and upper bound UP for the induction
variable at LEVEL for the statement PBB, based on the transformed variable at LEVEL for the statement PBB, based on the transformed
scattering of PBB: T|I|G|Cst, with T the scattering transform, I scattering of PBB: T|I|G|Cst, with T the scattering transform, I
...@@ -608,26 +673,6 @@ compute_bounds_for_level (poly_bb_p pbb, int level, mpz_t low, mpz_t up) ...@@ -608,26 +673,6 @@ compute_bounds_for_level (poly_bb_p pbb, int level, mpz_t low, mpz_t up)
ppl_delete_Pointset_Powerset_C_Polyhedron (ps); ppl_delete_Pointset_Powerset_C_Polyhedron (ps);
} }
/* Compute the type for the induction variable at LEVEL for the
statement PBB, based on the transformed schedule of PBB. */
static tree
type_for_level (poly_bb_p pbb, int level)
{
mpz_t low, up;
tree type;
mpz_init (low);
mpz_init (up);
compute_bounds_for_level (pbb, level, low, up);
type = type_for_interval (low, up);
mpz_clear (low);
mpz_clear (up);
return type;
}
/* Walks a CLAST and returns the first statement in the body of a /* Walks a CLAST and returns the first statement in the body of a
loop. loop.
...@@ -671,18 +716,12 @@ clast_get_body_of_loop (struct clast_stmt *stmt) ...@@ -671,18 +716,12 @@ clast_get_body_of_loop (struct clast_stmt *stmt)
from STMT_FOR. */ from STMT_FOR. */
static tree static tree
type_for_clast_for (struct clast_for *stmt_for, int level, type_for_clast_for (struct clast_for *stmt_for, ivs_params_p ip)
ivs_params_p ip)
{ {
struct clast_stmt *stmt = (struct clast_stmt *) stmt_for;
struct clast_user_stmt *body = clast_get_body_of_loop (stmt);
CloogStatement *cs = body->statement;
poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (cs);
tree lb_type = type_for_clast_expr (stmt_for->LB, ip); tree lb_type = type_for_clast_expr (stmt_for->LB, ip);
tree ub_type = type_for_clast_expr (stmt_for->UB, ip); tree ub_type = type_for_clast_expr (stmt_for->UB, ip);
return max_precision_type return max_precision_type (lb_type, ub_type);
(lb_type, max_precision_type (ub_type, type_for_level (pbb, level)));
} }
/* Creates a new LOOP corresponding to Cloog's STMT. Inserts an /* Creates a new LOOP corresponding to Cloog's STMT. Inserts an
...@@ -698,6 +737,12 @@ graphite_create_new_loop (edge entry_edge, struct clast_for *stmt, ...@@ -698,6 +737,12 @@ graphite_create_new_loop (edge entry_edge, struct clast_for *stmt,
loop_p outer, tree type, tree lb, tree ub, loop_p outer, tree type, tree lb, tree ub,
int level, ivs_params_p ip) int level, ivs_params_p ip)
{ {
mpz_t low, up;
struct clast_user_stmt *body
= clast_get_body_of_loop ((struct clast_stmt *) stmt);
poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (body->statement);
tree stride = gmp_cst_to_tree (type, stmt->stride); tree stride = gmp_cst_to_tree (type, stmt->stride);
tree ivvar = create_tmp_var (type, "graphite_IV"); tree ivvar = create_tmp_var (type, "graphite_IV");
tree iv, iv_after_increment; tree iv, iv_after_increment;
...@@ -707,8 +752,13 @@ graphite_create_new_loop (edge entry_edge, struct clast_for *stmt, ...@@ -707,8 +752,13 @@ graphite_create_new_loop (edge entry_edge, struct clast_for *stmt,
add_referenced_var (ivvar); add_referenced_var (ivvar);
mpz_init (low);
mpz_init (up);
compute_bounds_for_level (pbb, level, low, up);
save_clast_name_index (ip->newivs_index, stmt->iterator, save_clast_name_index (ip->newivs_index, stmt->iterator,
VEC_length (tree, *(ip->newivs)), level); VEC_length (tree, *(ip->newivs)), level, low, up);
mpz_clear (low);
mpz_clear (up);
VEC_safe_push (tree, heap, *(ip->newivs), iv); VEC_safe_push (tree, heap, *(ip->newivs), iv);
return loop; return loop;
} }
...@@ -862,13 +912,13 @@ translate_clast_user (struct clast_user_stmt *stmt, edge next_e, ...@@ -862,13 +912,13 @@ translate_clast_user (struct clast_user_stmt *stmt, edge next_e,
static edge static edge
graphite_create_new_loop_guard (edge entry_edge, struct clast_for *stmt, graphite_create_new_loop_guard (edge entry_edge, struct clast_for *stmt,
int level, tree *type, tree *lb, tree *ub, tree *type, tree *lb, tree *ub,
ivs_params_p ip) ivs_params_p ip)
{ {
tree cond_expr; tree cond_expr;
edge exit_edge; edge exit_edge;
*type = type_for_clast_for (stmt, level, ip); *type = type_for_clast_for (stmt, ip);
*lb = clast_to_gcc_expression (*type, stmt->LB, ip); *lb = clast_to_gcc_expression (*type, stmt->LB, ip);
*ub = clast_to_gcc_expression (*type, stmt->UB, ip); *ub = clast_to_gcc_expression (*type, stmt->UB, ip);
...@@ -943,7 +993,7 @@ translate_clast_for (loop_p context_loop, struct clast_for *stmt, edge next_e, ...@@ -943,7 +993,7 @@ translate_clast_for (loop_p context_loop, struct clast_for *stmt, edge next_e,
htab_t bb_pbb_mapping, int level, ivs_params_p ip) htab_t bb_pbb_mapping, int level, ivs_params_p ip)
{ {
tree type, lb, ub; tree type, lb, ub;
edge last_e = graphite_create_new_loop_guard (next_e, stmt, level, &type, edge last_e = graphite_create_new_loop_guard (next_e, stmt, &type,
&lb, &ub, ip); &lb, &ub, ip);
edge true_e = get_true_edge_from_guard_bb (next_e->dest); edge true_e = get_true_edge_from_guard_bb (next_e->dest);
...@@ -1361,14 +1411,24 @@ debug_generated_program (scop_p scop) ...@@ -1361,14 +1411,24 @@ debug_generated_program (scop_p scop)
back from CLooG names to GCC trees. */ back from CLooG names to GCC trees. */
static void static void
create_params_index (htab_t index_table, CloogProgram *prog) { create_params_index (scop_p scop, htab_t index_table, CloogProgram *prog) {
CloogNames* names = cloog_program_names (prog); CloogNames* names = cloog_program_names (prog);
int nb_parameters = cloog_names_nb_parameters (names); int nb_parameters = cloog_names_nb_parameters (names);
char **parameters = cloog_names_parameters (names); char **parameters = cloog_names_parameters (names);
int i; int i;
mpz_t lb, ub;
mpz_init (lb);
mpz_init (ub);
for (i = 0; i < nb_parameters; i++) for (i = 0; i < nb_parameters; i++)
save_clast_name_index (index_table, parameters[i], i, i); {
compute_bounds_for_param (scop, i, lb, ub);
save_clast_name_index (index_table, parameters[i], i, i, lb, ub);
}
mpz_clear (lb);
mpz_clear (ub);
} }
/* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for /* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for
...@@ -1412,11 +1472,11 @@ gloog (scop_p scop, htab_t bb_pbb_mapping) ...@@ -1412,11 +1472,11 @@ gloog (scop_p scop, htab_t bb_pbb_mapping)
context_loop = SESE_ENTRY (region)->src->loop_father; context_loop = SESE_ENTRY (region)->src->loop_father;
newivs_index = htab_create (10, clast_name_index_elt_info, newivs_index = htab_create (10, clast_name_index_elt_info,
eq_clast_name_indexes, free); eq_clast_name_indexes, free_clast_name_index);
params_index = htab_create (10, clast_name_index_elt_info, params_index = htab_create (10, clast_name_index_elt_info,
eq_clast_name_indexes, free); eq_clast_name_indexes, free_clast_name_index);
create_params_index (params_index, pc.prog); create_params_index (scop, params_index, pc.prog);
ip.newivs = &newivs; ip.newivs = &newivs;
ip.newivs_index = newivs_index; ip.newivs_index = newivs_index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment