oops, didn't set plain text mode. sorry for re-post.
On Tue, Jun 24, 2014 at 4:59 PM, Prathamesh Kulkarni <bilbotheelffri...@gmail.com> wrote: > This patch factors out checking expression-code in gimple-match-head.c > > * gimple-match-head.c (check_gimple_assign): New function. > (check_gimple_assign_convert): Likewise. > (check_gimple_call_builtin): Likewise. > > * genmatch.c (dt_operand::gen_gimple_expr_expr): Add argument const char *. > Generate call to gimple_assign_check or check_gimple_assign_convert. > (dt_operand::gen_gimple_expr_fn): Add argument const char *. > Generate call to check_gimple_call_builtin. > (decision_tree::gen_gimple): Generate definition of def_stmt. > > Thanks and Regards, > Prathamesh.
Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 211932) +++ gcc/genmatch.c (working copy) @@ -341,8 +341,8 @@ struct dt_operand: public dt_node unsigned gen_gimple_match_op (FILE *, const char *); unsigned gen_gimple_expr (FILE *, const char *); - void gen_gimple_expr_expr (FILE *, expr *); - void gen_gimple_expr_fn (FILE *, expr *); + void gen_gimple_expr_expr (FILE *, expr *, const char *); + void gen_gimple_expr_fn (FILE *, expr *, const char *); unsigned gen_generic_expr (FILE *, const char *); void gen_generic_expr_expr (FILE *, expr *, const char *); @@ -898,12 +898,12 @@ dt_operand::gen_gimple_match_op (FILE *f } void -dt_operand::gen_gimple_expr_fn (FILE *f, expr *e) +dt_operand::gen_gimple_expr_fn (FILE *f, expr *e, const char *opname) { unsigned n_ops = e->ops.length (); fn_id *op = static_cast <fn_id *> (e->operation->op); - fprintf (f, "if (gimple_call_builtin_p (def_stmt, %s))\n", op->id); + fprintf (f, "if (check_gimple_call_builtin (%s, def_stmt, %s))\n", opname, op->id); fprintf (f, "{\n"); for (unsigned i = 0; i < n_ops; ++i) @@ -918,18 +918,16 @@ dt_operand::gen_gimple_expr_fn (FILE *f, } void -dt_operand::gen_gimple_expr_expr (FILE *f, expr *e) +dt_operand::gen_gimple_expr_expr (FILE *f, expr *e, const char *opname) { unsigned n_ops = e->ops.length (); operator_id *op_id = static_cast <operator_id *> (e->operation->op); if (op_id->code == NOP_EXPR || op_id->code == CONVERT_EXPR) - fprintf (f, "if (is_gimple_assign (def_stmt)\n" - " && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt)))"); + fprintf (f, "if (check_gimple_assign_convert (%s, def_stmt))\n", opname); else - fprintf (f, "if (is_gimple_assign (def_stmt) && gimple_assign_rhs_code (def_stmt) == %s)\n", op_id->id); - + fprintf (f, "if (check_gimple_assign (%s, def_stmt, %s))\n", opname, op_id->id); fprintf (f, "{\n"); for (unsigned i = 0; i < n_ops; ++i) @@ -948,13 +946,9 @@ dt_operand::gen_gimple_expr (FILE *f, co { expr *e = static_cast<expr *> (op); - fprintf (f, "if (TREE_CODE (%s) == SSA_NAME)\n", opname); - fprintf (f, "{\n"); - - fprintf (f, "gimple def_stmt = SSA_NAME_DEF_STMT (%s);\n", opname); - (e->operation->op->kind == id_base::CODE) ? gen_gimple_expr_expr (f, e) : gen_gimple_expr_fn (f, e); - - return e->ops.length () + 2; + (e->operation->op->kind == id_base::CODE) ? gen_gimple_expr_expr (f, e, opname) + : gen_gimple_expr_fn (f, e, opname); + return e->ops.length () + 1; } @@ -1140,6 +1134,7 @@ decision_tree::gen_gimple (FILE *f) write_fn_prototype (f, 3); fprintf (f, "{\n"); + fprintf (f, "gimple def_stmt;\n"); for (unsigned i = 0; i < root->kids.length (); i++) { Index: gcc/gimple-match-head.c =================================================================== --- gcc/gimple-match-head.c (revision 211932) +++ gcc/gimple-match-head.c (working copy) @@ -713,3 +713,33 @@ do_valueize (tree (*valueize)(tree), tre return valueize (op); return op; } + +static bool +check_gimple_assign (tree op, gimple& def_stmt, enum tree_code code) +{ + if (TREE_CODE (op) != SSA_NAME) + return false; + + def_stmt = SSA_NAME_DEF_STMT (op); + return is_gimple_assign (def_stmt) && gimple_assign_rhs_code (def_stmt) == code; +} + +static bool +check_gimple_assign_convert (tree op, gimple& def_stmt) +{ + if (TREE_CODE (op) != SSA_NAME) + return false; + + def_stmt = SSA_NAME_DEF_STMT (op); + return is_gimple_assign (def_stmt) && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt)); +} + +static bool +check_gimple_call_builtin (tree op, gimple& def_stmt, enum built_in_function fn) +{ + if (TREE_CODE (op) != SSA_NAME) + return false; + + def_stmt = SSA_NAME_DEF_STMT (op); + return gimple_call_builtin_p (def_stmt, fn); +}