From 803835ded7f4ed4bbfcf0bbb427c7cf1f23203ac Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 24 Jul 2015 12:39:08 +0000 Subject: [PATCH] genmatch.c (struct dt_node): Add statistic fields. 2015-07-24 Richard Biener * genmatch.c (struct dt_node): Add statistic fields. (dt_node::analyze): New method. (decision_tree::gen_gimple): Call analyze on the root node and print statistics to stderr. (decision_tree::gen_generic): Likewise. From-SVN: r226154 --- gcc/ChangeLog | 8 ++++++++ gcc/genmatch.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d7f6ca5c77c..0e18f35fe66 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-07-24 Richard Biener + + * genmatch.c (struct dt_node): Add statistic fields. + (dt_node::analyze): New method. + (decision_tree::gen_gimple): Call analyze on the root node + and print statistics to stderr. + (decision_tree::gen_generic): Likewise. + 2015-07-24 Richard Biener * fold-const.c (fold_binary_loc): Move simplifying of comparisons diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 83e66c6acc5..ce90a74a195 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -1212,6 +1212,11 @@ struct dt_node unsigned level; vec kids; + /* Statistics. */ + unsigned num_leafs; + unsigned total_size; + unsigned max_level; + dt_node (enum dt_type type_): type (type_), level (0), kids (vNULL) {} dt_node *append_node (dt_node *); @@ -1226,6 +1231,8 @@ struct dt_node void gen_kids_1 (FILE *, int, bool, vec, vec, vec, vec, vec, vec); + + void analyze (); }; /* Generic decision tree node used for DT_OPERAND and DT_MATCH. */ @@ -1428,6 +1435,30 @@ dt_node::append_simplify (simplify *s, unsigned pattern_no, return append_node (n); } +/* Analyze the node and its children. */ + +void +dt_node::analyze () +{ + num_leafs = 0; + total_size = 1; + max_level = level; + + if (type == DT_SIMPLIFY) + { + num_leafs = 1; + return; + } + + for (unsigned i = 0; i < kids.length (); ++i) + { + kids[i]->analyze (); + num_leafs += kids[i]->num_leafs; + total_size += kids[i]->total_size; + max_level = MAX (max_level, kids[i]->max_level); + } +} + /* Insert O into the decision tree and return the decision tree node found or created. */ @@ -2912,6 +2943,12 @@ dt_simplify::gen (FILE *f, int indent, bool gimple) void decision_tree::gen_gimple (FILE *f) { + root->analyze (); + + fprintf (stderr, "GIMPLE decision tree has %u leafs, maximum depth %u and " + "a total number of %u nodes\n", root->num_leafs, root->max_level, + root->total_size); + for (unsigned n = 1; n <= 3; ++n) { fprintf (f, "\nstatic bool\n" @@ -2958,6 +2995,12 @@ decision_tree::gen_gimple (FILE *f) void decision_tree::gen_generic (FILE *f) { + root->analyze (); + + fprintf (stderr, "GENERIC decision tree has %u leafs, maximum depth %u and " + "a total number of %u nodes\n", root->num_leafs, root->max_level, + root->total_size); + for (unsigned n = 1; n <= 3; ++n) { fprintf (f, "\ntree\n" -- 2.30.2