diff options
author | Richard Sandiford <richard.sandiford@linaro.org> | 2018-05-24 08:02:35 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2018-05-24 08:02:35 +0000 |
commit | 5d75ad95aa808d6767afc0cdadd3b62e831c5cdf (patch) | |
tree | 0cc9a5a00b0c8f56cb996dc8818b9bfa42ed5005 /gcc/genmatch.c | |
parent | e29ea4832560f961c00e19fca923f325a08761d6 (diff) | |
download | gcc-5d75ad95aa808d6767afc0cdadd3b62e831c5cdf.zip gcc-5d75ad95aa808d6767afc0cdadd3b62e831c5cdf.tar.gz gcc-5d75ad95aa808d6767afc0cdadd3b62e831c5cdf.tar.bz2 |
Add a class to represent a gimple match result
Gimple match results are represented by a code_helper for the operation,
a tree for the type, and an array of three trees for the operands.
This patch wraps them up in a class so that they don't need to be
passed around individually.
The main reason for doing this is to make it easier to increase the
number of operands (for calls) or to support more complicated kinds
of operation. But passing around fewer operands also helps to reduce
the size of gimple-match.o (about 7% for development builds and 4% for
release builds).
2018-05-24 Richard Sandiford <richard.sandiford@linaro.org>
gcc/
* gimple-match.h (gimple_match_op): New class.
(mprts_hook): Replace parameters with a gimple_match_op *.
(maybe_build_generic_op): Likewise.
(gimple_simplified_result_is_gimple_val): Replace parameters with
a const gimple_match_op *.
(gimple_simplify): Replace code_helper * and tree * parameters with
a gimple_match_op * parameter.
(gimple_resimplify1): Replace code_helper *, tree and tree *
parameters with a gimple_match_op * parameter.
(gimple_resimplify2): Likewise.
(gimple_resimplify3): Likewise.
(maybe_push_res_to_seq): Replace code_helper, tree and tree *
parameters with a gimple_match_op * parameter.
* gimple-match-head.c (gimple_simplify): Change prototypes of
auto-generated functions to take a gimple_match_op * instead of
separate code_helper * and tree * parameters. Make the same
change in the top-level overload and update calls to the
gimple_resimplify routines. Update calls to the auto-generated
functions and to maybe_push_res_to_seq in the publicly-facing
operation-specific gimple_simplify overloads.
(gimple_match_op::MAX_NUM_OPS): Define.
(gimple_resimplify1): Replace rcode and ops with a single res_op
parameter. Update call to gimple_simplify.
(gimple_resimplify2): Likewise.
(gimple_resimplify3): Likewise.
(mprts_hook): Replace parameters with a gimple_match_op *.
(maybe_build_generic_op): Likewise.
(build_call_internal): Replace type, nargs and ops with
a gimple_match_op *.
(maybe_push_res_to_seq): Replace res_code, type and ops parameters
with a single gimple_match_op *. Update calls to mprts_hook,
build_call_internal and gimple_simplified_result_is_gimple_val.
Factor out code that is common to the tree_code and combined_fn cases.
* genmatch.c (expr::gen_transform): Replace tem_code and
tem_ops with a gimple_match_op called tem_op. Update calls
to the gimple_resimplify functions and maybe_push_res_to_seq.
(dt_simplify::gen_1): Manipulate res_op instead of res_code and
res_ops. Update call to the gimple_resimplify functions.
(dt_simplify::gen): Pass res_op instead of res_code and res_ops.
(decision_tree::gen): Make the functions take a gimple_match_op *
called res_op instead of separate res_code and res_ops parameters.
Update call accordingly.
* gimple-fold.c (replace_stmt_with_simplification): Replace rcode
and ops with a single res_op parameter. Update calls to
maybe_build_generic_op and maybe_push_res_to_seq.
(fold_stmt_1): Update calls to gimple_simplify and
replace_stmt_with_simplification.
(gimple_fold_stmt_to_constant_1): Update calls to gimple_simplify
and gimple_simplified_result_is_gimple_val.
* tree-cfgcleanup.c (cleanup_control_expr_graph): Update call to
gimple_simplify.
* tree-ssa-sccvn.c (vn_lookup_simplify_result): Replace parameters
with a gimple_match_op *.
(vn_nary_build_or_lookup): Likewise. Update call to
vn_nary_build_or_lookup_1.
(vn_nary_build_or_lookup_1): Replace rcode, type and ops with a
gimple_match_op *. Update calls to the gimple_resimplify routines
and to gimple_simplified_result_is_gimple_val.
(vn_nary_simplify): Update call to vn_nary_build_or_lookup_1.
Use gimple_match_op::MAX_NUM_OPS instead of a hard-coded 3.
(vn_reference_lookup_3): Update call to vn_nary_build_or_lookup.
(visit_nary_op): Likewise.
(visit_reference_op_load): Likewise.
From-SVN: r260634
Diffstat (limited to 'gcc/genmatch.c')
-rw-r--r-- | gcc/genmatch.c | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/gcc/genmatch.c b/gcc/genmatch.c index c794e4d..5715dd1 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -2484,17 +2484,16 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, /* ??? Building a stmt can fail for various reasons here, seq being NULL or the stmt referencing SSA names occuring in abnormal PHIs. So if we fail here we should continue matching other patterns. */ - fprintf_indent (f, indent, "code_helper tem_code = %s;\n", opr_name); - fprintf_indent (f, indent, "tree tem_ops[3] = { "); + fprintf_indent (f, indent, "gimple_match_op tem_op (%s, %s", + opr_name, type); for (unsigned i = 0; i < ops.length (); ++i) - fprintf (f, "ops%d[%u]%s", depth, i, - i == ops.length () - 1 ? " };\n" : ", "); + fprintf (f, ", ops%d[%u]", depth, i); + fprintf (f, ");\n"); fprintf_indent (f, indent, - "gimple_resimplify%d (lseq, &tem_code, %s, tem_ops, valueize);\n", - ops.length (), type); + "gimple_resimplify%d (lseq, &tem_op, valueize);\n", + ops.length ()); fprintf_indent (f, indent, - "res = maybe_push_res_to_seq (tem_code, %s, tem_ops, lseq);\n", - type); + "res = maybe_push_res_to_seq (&tem_op, lseq);\n"); fprintf_indent (f, indent, "if (!res) return false;\n"); if (*opr == CONVERT_EXPR) @@ -3322,17 +3321,22 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) else if (is_a <predicate_id *> (opr)) is_predicate = true; if (!is_predicate) - fprintf_indent (f, indent, "*res_code = %s;\n", + fprintf_indent (f, indent, "res_op->set_op (%s, type, %d);\n", *e->operation == CONVERT_EXPR - ? "NOP_EXPR" : e->operation->id); + ? "NOP_EXPR" : e->operation->id, + e->ops.length ()); for (unsigned j = 0; j < e->ops.length (); ++j) { char dest[32]; - snprintf (dest, 32, "res_ops[%d]", j); + if (is_predicate) + snprintf (dest, 32, "res_ops[%d]", j); + else + snprintf (dest, 32, "res_op->ops[%d]", j); const char *optype = get_operand_type (opr, j, "type", e->expr_type, - j == 0 ? NULL : "TREE_TYPE (res_ops[0])"); + j == 0 ? NULL + : "TREE_TYPE (res_op->ops[0])"); /* We need to expand GENERIC conditions we captured from COND_EXPRs and we need to unshare them when substituting into COND_EXPRs. */ @@ -3348,30 +3352,29 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) gimple_build w/o actually building the stmt. */ if (!is_predicate) fprintf_indent (f, indent, - "gimple_resimplify%d (lseq, res_code, type, " - "res_ops, valueize);\n", e->ops.length ()); + "gimple_resimplify%d (lseq, res_op," + " valueize);\n", e->ops.length ()); } else if (result->type == operand::OP_CAPTURE || result->type == operand::OP_C_EXPR) { - result->gen_transform (f, indent, "res_ops[0]", true, 1, "type", + fprintf_indent (f, indent, "tree tem;\n"); + result->gen_transform (f, indent, "tem", true, 1, "type", &cinfo, indexes); - fprintf_indent (f, indent, "*res_code = TREE_CODE (res_ops[0]);\n"); + fprintf_indent (f, indent, "res_op->set_value (tem);\n"); if (is_a <capture *> (result) && cinfo.info[as_a <capture *> (result)->where].cond_expr_cond_p) { /* ??? Stupid tcc_comparison GENERIC trees in COND_EXPRs. Deal with substituting a capture of that. */ fprintf_indent (f, indent, - "if (COMPARISON_CLASS_P (res_ops[0]))\n"); + "if (COMPARISON_CLASS_P (tem))\n"); fprintf_indent (f, indent, " {\n"); fprintf_indent (f, indent, - " tree tem = res_ops[0];\n"); - fprintf_indent (f, indent, - " res_ops[0] = TREE_OPERAND (tem, 0);\n"); + " res_op->ops[0] = TREE_OPERAND (tem, 0);\n"); fprintf_indent (f, indent, - " res_ops[1] = TREE_OPERAND (tem, 1);\n"); + " res_op->ops[1] = TREE_OPERAND (tem, 1);\n"); fprintf_indent (f, indent, " }\n"); } @@ -3529,7 +3532,7 @@ dt_simplify::gen (FILE *f, int indent, bool gimple) { if (gimple) { - fprintf_indent (f, indent, "if (%s (res_code, res_ops, seq, " + fprintf_indent (f, indent, "if (%s (res_op, seq, " "valueize, type, captures", info->fname); for (unsigned i = 0; i < s->for_subst_vec.length (); ++i) if (s->for_subst_vec[i].first->used) @@ -3697,9 +3700,8 @@ decision_tree::gen (FILE *f, bool gimple) fcnt++); if (gimple) fprintf (f, "\nstatic bool\n" - "%s (code_helper *res_code, tree *res_ops,\n" - " gimple_seq *seq, tree (*valueize)(tree) " - "ATTRIBUTE_UNUSED,\n" + "%s (gimple_match_op *res_op, gimple_seq *seq,\n" + " tree (*valueize)(tree) ATTRIBUTE_UNUSED,\n" " const tree ARG_UNUSED (type), tree *ARG_UNUSED " "(captures)\n", s->fname); @@ -3753,8 +3755,9 @@ decision_tree::gen (FILE *f, bool gimple) if (gimple) fprintf (f, "\nstatic bool\n" - "gimple_simplify_%s (code_helper *res_code, tree *res_ops,\n" - " gimple_seq *seq, tree (*valueize)(tree) " + "gimple_simplify_%s (gimple_match_op *res_op," + " gimple_seq *seq,\n" + " tree (*valueize)(tree) " "ATTRIBUTE_UNUSED,\n" " code_helper ARG_UNUSED (code), tree " "ARG_UNUSED (type)\n", @@ -3780,8 +3783,8 @@ decision_tree::gen (FILE *f, bool gimple) tail-calls to the split-out functions. */ if (gimple) fprintf (f, "\nstatic bool\n" - "gimple_simplify (code_helper *res_code, tree *res_ops,\n" - " gimple_seq *seq, tree (*valueize)(tree),\n" + "gimple_simplify (gimple_match_op *res_op, gimple_seq *seq,\n" + " tree (*valueize)(tree) ATTRIBUTE_UNUSED,\n" " code_helper code, const tree type"); else fprintf (f, "\ntree\n" @@ -3819,7 +3822,7 @@ decision_tree::gen (FILE *f, bool gimple) is_a <fn_id *> (e->operation) ? "-" : "", e->operation->id); if (gimple) - fprintf (f, " return gimple_simplify_%s (res_code, res_ops, " + fprintf (f, " return gimple_simplify_%s (res_op, " "seq, valueize, code, type", e->operation->id); else fprintf (f, " return generic_simplify_%s (loc, code, type", |