On Thu, Jun 26, 2014 at 10:11 AM, Prathamesh Kulkarni <bilbotheelffri...@gmail.com> wrote: > This patch factors expression checking for GIMPLE. > > Generates code as: > if (TREE_CODE (opname) == SSA_NAME) > { > gimple def_stmt = SSA_NAME_DEF_STMT (opname); > if (is_gimple_assign (def_stmt)) > { > if (gimple_assign_rhs_code (def_stmt) == <expr-code1>) > { > .... > } > if (gimple_assign_rhs_code (def_stmt) == <expr-code2>) > { > .... > } > } > } > > We cannot use switch-case, for convert/nop since > we use CONVERT_EXPR_CODE_P, so i used if stmt.
Actually we can by using case NOP_EXPR: case CONVERT_EXPR: for it. Note that currently you still do if (is_gimple_assign (def_stmt)) { if (gimple_assign_rhs_code (def_stmt) == PLUS_EXPR) { } if (gimple_assign_rhs_code (def_stmt) == MINUS_EXPR) { } thus not use else if (). Of course in the end we want switch (gimple_assign_rhs_code (def_stmt)) { case PLUS_EXPR; ... case MINUS_EXPR: ... > Unfortunately, back-tracking is still done. I shall look into that. Note that we need to backtrack to the next parent with a 'true' kid (and from there to its next parent with a 'true' kid). Possibly with using a switch-case or proper if-else-if there isn't anything special to do as the backtracking would work naturally then. So I suggest to concentrate on getting the code to use if (TREE_CODE (op0) == SSA_NAME) { gimple def_stmt = SSA_NAME_DEF_STMT (op0); if (is_gimple_assign (def_stmt)) { switch (gimple_assign_rhs_code ()) { case PLUS_EXPR: ... } else if (gimple_call_builtin_p (def_stmt, BUILT_IN_NORMAL)) { switch (DECL_FUNCTION_CODE (gimple_call_fndecl (def_stmt))) { case BUILT_IN_ABS: ... } } else if (TREE_CODE (op0) == REALPART_EXPR) ... other GENERIC cases <true> match (not in else {}) that would backtrack through the <true> cases by means of them not short-circuited by an else but everything else short-circuited by proper use of switch () and if - else-if code. Thanks, Richard. > * genmatch.c (dt_node::get_expr_code): New member function. > (dt_node::is_gimple_expr): Likewise. > (dt_node::is_gimple_fn): Likewise. > (dt_operand::kids_type): New struct. > (dt_operand::gen_gimple_expr): Remove. > (dt_operand::gen_gimple_expr_expr): Remove 2nd argument and > change return type to unsigned. Adjust code-gen for > expressions. > (dt_operand::gen_gimple_expr_fn): Remove 2nd argument and change > return type to unsigned. > (dt_operand::grok_kids): New member function. > (dt_operand::gen_gimple_kids): Likewise. > (dt_operand::gen_gimple): Adjust code-gen for gimple expressions. > Call dt_operand::gen_gimple_kids. > (decision_tree::gen_gimple): Call dt_operand::gen_gimple_kids. > > Thanks and Regards, > Prathamesh