Refactor graphite-isl-ast-to-gimple.c

Refactor graphite-isl-ast-to-gimple.c:
Refactor so that each function can access 'region'. This will help
maintain a parameter rename_map within a region. No functional change intended.
This patch will be followed by another set of patches
where translate_isl_ast_to_gimple::region is used to keep parameters which need
renaming. Since we are planning to remove limit_scops, we now have to maintain a
set of parameters which needs renaming. This refactoring helps avoid passing
`region' to all the functions in this file.

It passes bootstrap and regtest.

gcc/ChangeLog:

2015-07-19  Aditya Kumar  <hiraditya@msn.com>

        * graphite-isl-ast-to-gimple.c:
	Refactor so that each function can access 'region'. This will help
	maintain a parameter rename_map within a region.

From-SVN: r226014
This commit is contained in:
Aditya Kumar 2015-07-20 18:02:49 +00:00 committed by Sebastian Pop
parent a051317b73
commit 050e1371a1
1 changed files with 180 additions and 32 deletions

View File

@ -125,9 +125,142 @@ void ivs_params_clear (ivs_params &ip)
}
}
static tree
gcc_expression_from_isl_expression (tree type, __isl_take isl_ast_expr *,
ivs_params &ip);
class translate_isl_ast_to_gimple
{
public:
translate_isl_ast_to_gimple (sese r)
: region (r)
{ }
/* Translates an ISL AST node NODE to GCC representation in the
context of a SESE. */
edge translate_isl_ast (loop_p context_loop, __isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip);
/* Translates an isl_ast_node_for to Gimple. */
edge translate_isl_ast_node_for (loop_p context_loop,
__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip);
/* Create the loop for a isl_ast_node_for.
- NEXT_E is the edge where new generated code should be attached. */
edge translate_isl_ast_for_loop (loop_p context_loop,
__isl_keep isl_ast_node *node_for,
edge next_e,
tree type, tree lb, tree ub,
ivs_params &ip);
/* Translates an isl_ast_node_if to Gimple. */
edge translate_isl_ast_node_if (loop_p context_loop,
__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip);
/* Translates an isl_ast_node_user to Gimple.
FIXME: We should remove iv_map.create (loop->num + 1), if it is
possible. */
edge translate_isl_ast_node_user (__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip);
/* Translates an isl_ast_node_block to Gimple. */
edge translate_isl_ast_node_block (loop_p context_loop,
__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip);
/* Converts a unary isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
tree unary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
ivs_params &ip);
/* Converts a binary isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
tree binary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
ivs_params &ip);
/* Converts a ternary isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
tree ternary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
ivs_params &ip);
/* Converts an isl_ast_expr_op expression E with unknown number of arguments
to a GCC expression tree of type TYPE. */
tree nary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
ivs_params &ip);
/* Converts an ISL AST expression E back to a GCC expression tree of
type TYPE. */
tree gcc_expression_from_isl_expression (tree type,
__isl_take isl_ast_expr *,
ivs_params &ip);
/* Return the tree variable that corresponds to the given isl ast identifier
expression (an isl_ast_expr of type isl_ast_expr_id).
FIXME: We should replace blind conversation of id's type with derivation
of the optimal type when we get the corresponding isl support. Blindly
converting type sizes may be problematic when we switch to smaller
types. */
tree gcc_expression_from_isl_ast_expr_id (tree type,
__isl_keep isl_ast_expr *expr_id,
ivs_params &ip);
/* Converts an isl_ast_expr_int expression E to a GCC expression tree of
type TYPE. */
tree gcc_expression_from_isl_expr_int (tree type,
__isl_take isl_ast_expr *expr);
/* Converts an isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
tree gcc_expression_from_isl_expr_op (tree type,
__isl_take isl_ast_expr *expr,
ivs_params &ip);
/* Creates a new LOOP corresponding to isl_ast_node_for. Inserts an
induction variable for the new LOOP. New LOOP is attached to CFG
starting at ENTRY_EDGE. LOOP is inserted into the loop tree and
becomes the child loop of the OUTER_LOOP. NEWIVS_INDEX binds
ISL's scattering name to the induction variable created for the
loop of STMT. The new induction variable is inserted in the NEWIVS
vector and is of type TYPE. */
struct loop *graphite_create_new_loop (edge entry_edge,
__isl_keep isl_ast_node *node_for,
loop_p outer, tree type,
tree lb, tree ub, ivs_params &ip);
/* All loops generated by create_empty_loop_on_edge have the form of
a post-test loop:
do
{
body of the loop;
} while (lower bound < upper bound);
We create a new if region protecting the loop to be executed, if
the execution count is zero (lower bound > upper bound). */
edge graphite_create_new_loop_guard (edge entry_edge,
__isl_keep isl_ast_node *node_for,
tree *type,
tree *lb, tree *ub, ivs_params &ip);
/* Creates a new if region corresponding to ISL's cond. */
edge graphite_create_new_guard (edge entry_edge,
__isl_take isl_ast_expr *if_cond,
ivs_params &ip);
/* Inserts in iv_map a tuple (OLD_LOOP->num, NEW_NAME) for the induction
variables of the loops around GBB in SESE.
FIXME: Instead of using a vec<tree> that maps each loop id to a possible
chrec, we could consider using a map<int, tree> that maps loop ids to the
corresponding tree expressions. */
void build_iv_mapping (vec<tree> iv_map, gimple_bb_p gbb,
__isl_keep isl_ast_expr *user_expr, ivs_params &ip,
sese region);
private:
sese region;
};
/* Return the tree variable that corresponds to the given isl ast identifier
expression (an isl_ast_expr of type isl_ast_expr_id).
@ -137,7 +270,8 @@ gcc_expression_from_isl_expression (tree type, __isl_take isl_ast_expr *,
converting type sizes may be problematic when we switch to smaller
types. */
static tree
tree
translate_isl_ast_to_gimple::
gcc_expression_from_isl_ast_expr_id (tree type,
__isl_keep isl_ast_expr *expr_id,
ivs_params &ip)
@ -148,7 +282,7 @@ gcc_expression_from_isl_ast_expr_id (tree type,
res = ip.find (tmp_isl_id);
isl_id_free (tmp_isl_id);
gcc_assert (res != ip.end () &&
"Could not map isl_id to tree expression");
"Could not map isl_id to tree expression");
isl_ast_expr_free (expr_id);
return fold_convert (type, res->second);
}
@ -156,7 +290,8 @@ gcc_expression_from_isl_ast_expr_id (tree type,
/* Converts an isl_ast_expr_int expression E to a GCC expression tree of
type TYPE. */
static tree
tree
translate_isl_ast_to_gimple::
gcc_expression_from_isl_expr_int (tree type, __isl_take isl_ast_expr *expr)
{
gcc_assert (isl_ast_expr_get_type (expr) == isl_ast_expr_int);
@ -177,7 +312,8 @@ gcc_expression_from_isl_expr_int (tree type, __isl_take isl_ast_expr *expr)
/* Converts a binary isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
static tree
tree
translate_isl_ast_to_gimple::
binary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
{
isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
@ -239,7 +375,8 @@ binary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
/* Converts a ternary isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
static tree
tree
translate_isl_ast_to_gimple::
ternary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
{
gcc_assert (isl_ast_expr_get_op_type (expr) == isl_ast_op_minus);
@ -260,7 +397,8 @@ ternary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
/* Converts a unary isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
static tree
tree
translate_isl_ast_to_gimple::
unary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
{
gcc_assert (isl_ast_expr_get_op_type (expr) == isl_ast_op_minus);
@ -273,7 +411,8 @@ unary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
/* Converts an isl_ast_expr_op expression E with unknown number of arguments
to a GCC expression tree of type TYPE. */
static tree
tree
translate_isl_ast_to_gimple::
nary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
{
enum tree_code op_code;
@ -303,11 +442,11 @@ nary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
return res;
}
/* Converts an isl_ast_expr_op expression E to a GCC expression tree of
type TYPE. */
static tree
tree
translate_isl_ast_to_gimple::
gcc_expression_from_isl_expr_op (tree type, __isl_take isl_ast_expr *expr,
ivs_params &ip)
{
@ -358,7 +497,8 @@ gcc_expression_from_isl_expr_op (tree type, __isl_take isl_ast_expr *expr,
/* Converts an ISL AST expression E back to a GCC expression tree of
type TYPE. */
static tree
tree
translate_isl_ast_to_gimple::
gcc_expression_from_isl_expression (tree type, __isl_take isl_ast_expr *expr,
ivs_params &ip)
{
@ -388,7 +528,8 @@ gcc_expression_from_isl_expression (tree type, __isl_take isl_ast_expr *expr,
loop of STMT. The new induction variable is inserted in the NEWIVS
vector and is of type TYPE. */
static struct loop *
struct loop *
translate_isl_ast_to_gimple::
graphite_create_new_loop (edge entry_edge, __isl_keep isl_ast_node *node_for,
loop_p outer, tree type, tree lb, tree ub,
ivs_params &ip)
@ -412,15 +553,12 @@ graphite_create_new_loop (edge entry_edge, __isl_keep isl_ast_node *node_for,
return loop;
}
static edge
translate_isl_ast (loop_p context_loop, __isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip);
/* Create the loop for a isl_ast_node_for.
- NEXT_E is the edge where new generated code should be attached. */
static edge
edge
translate_isl_ast_to_gimple::
translate_isl_ast_for_loop (loop_p context_loop,
__isl_keep isl_ast_node *node_for, edge next_e,
tree type, tree lb, tree ub,
@ -524,7 +662,8 @@ get_upper_bound (__isl_keep isl_ast_node *node_for)
We create a new if region protecting the loop to be executed, if
the execution count is zero (lower bound > upper bound). */
static edge
edge
translate_isl_ast_to_gimple::
graphite_create_new_loop_guard (edge entry_edge,
__isl_keep isl_ast_node *node_for, tree *type,
tree *lb, tree *ub, ivs_params &ip)
@ -566,7 +705,8 @@ graphite_create_new_loop_guard (edge entry_edge,
/* Translates an isl_ast_node_for to Gimple. */
static edge
edge
translate_isl_ast_to_gimple::
translate_isl_ast_node_for (loop_p context_loop, __isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip)
{
@ -588,20 +728,21 @@ translate_isl_ast_node_for (loop_p context_loop, __isl_keep isl_ast_node *node,
chrec, we could consider using a map<int, tree> that maps loop ids to the
corresponding tree expressions. */
static void
void
translate_isl_ast_to_gimple::
build_iv_mapping (vec<tree> iv_map, gimple_bb_p gbb,
__isl_keep isl_ast_expr *user_expr, ivs_params &ip,
sese region)
{
gcc_assert (isl_ast_expr_get_type (user_expr) == isl_ast_expr_op &&
isl_ast_expr_get_op_type (user_expr) == isl_ast_op_call);
isl_ast_expr_get_op_type (user_expr) == isl_ast_op_call);
int i;
isl_ast_expr *arg_expr;
for (i = 1; i < isl_ast_expr_get_op_n_arg (user_expr); i++)
{
arg_expr = isl_ast_expr_get_op_arg (user_expr, i);
tree type =
build_nonstandard_integer_type (graphite_expression_type_precision, 0);
build_nonstandard_integer_type (graphite_expression_type_precision, 0);
tree t = gcc_expression_from_isl_expression (type, arg_expr, ip);
loop_p old_loop = gbb_loop_at_index (gbb, region, i - 1);
iv_map[old_loop->num] = t;
@ -613,7 +754,8 @@ build_iv_mapping (vec<tree> iv_map, gimple_bb_p gbb,
FIXME: We should remove iv_map.create (loop->num + 1), if it is possible. */
static edge
edge
translate_isl_ast_to_gimple::
translate_isl_ast_node_user (__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip)
{
@ -650,7 +792,8 @@ translate_isl_ast_node_user (__isl_keep isl_ast_node *node,
/* Translates an isl_ast_node_block to Gimple. */
static edge
edge
translate_isl_ast_to_gimple::
translate_isl_ast_node_block (loop_p context_loop,
__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip)
@ -670,7 +813,8 @@ translate_isl_ast_node_block (loop_p context_loop,
/* Creates a new if region corresponding to ISL's cond. */
static edge
edge
translate_isl_ast_to_gimple::
graphite_create_new_guard (edge entry_edge, __isl_take isl_ast_expr *if_cond,
ivs_params &ip)
{
@ -683,7 +827,8 @@ graphite_create_new_guard (edge entry_edge, __isl_take isl_ast_expr *if_cond,
/* Translates an isl_ast_node_if to Gimple. */
static edge
edge
translate_isl_ast_to_gimple::
translate_isl_ast_node_if (loop_p context_loop,
__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip)
@ -708,9 +853,10 @@ translate_isl_ast_node_if (loop_p context_loop,
/* Translates an ISL AST node NODE to GCC representation in the
context of a SESE. */
static edge
translate_isl_ast (loop_p context_loop, __isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip)
edge
translate_isl_ast_to_gimple::translate_isl_ast (loop_p context_loop,
__isl_keep isl_ast_node *node,
edge next_e, ivs_params &ip)
{
switch (isl_ast_node_get_type (node))
{
@ -1050,7 +1196,9 @@ graphite_regenerate_ast_isl (scop_p scop)
context_loop = SESE_ENTRY (region)->src->loop_father;
translate_isl_ast (context_loop, root_node, if_region->true_region->entry,
translate_isl_ast_to_gimple t (region);
t.translate_isl_ast (context_loop, root_node, if_region->true_region->entry,
ip);
mark_virtual_operands_for_renaming (cfun);