This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix tree statistics with -fmem-report.
- From: Martin Liška <mliska at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Richard Biener <richard dot guenther at gmail dot com>
- Date: Wed, 14 Mar 2018 10:51:54 +0100
- Subject: [PATCH] Fix tree statistics with -fmem-report.
- Authentication-results: sourceware.org; auth=none
Hi.
Current code that tracks memory statistics wrongly decremented a counter
based on t_kind, which is an enum value and thus a constant:
- tree_node_counts[(int) t_kind]--;
That's obviously a mistake.
May I install the patch after reg tests&bootstrap?
Thanks,
Martin
gcc/ChangeLog:
2018-03-14 Martin Liska <mliska@suse.cz>
* tree.c (record_node_allocation_statistics): Use
get_stats_node_kind.
(get_stats_node_kind): New function extracted from
record_node_allocation_statistics.
(free_node): Use get_stats_node_kind.
---
gcc/tree.c | 94 +++++++++++++++++++++++++-------------------------------------
1 file changed, 38 insertions(+), 56 deletions(-)
diff --git a/gcc/tree.c b/gcc/tree.c
index 1e1a1be1f20..ce52f0af0b7 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -933,92 +933,68 @@ tree_size (const_tree node)
}
}
-/* Record interesting allocation statistics for a tree node with CODE
- and LENGTH. */
+/* Return tree node kind based on tree CODE. */
-static void
-record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED,
- size_t length ATTRIBUTE_UNUSED)
+static tree_node_kind
+get_stats_node_kind (enum tree_code code)
{
enum tree_code_class type = TREE_CODE_CLASS (code);
- tree_node_kind kind;
-
- if (!GATHER_STATISTICS)
- return;
switch (type)
{
case tcc_declaration: /* A decl node */
- kind = d_kind;
- break;
-
+ return d_kind;
case tcc_type: /* a type node */
- kind = t_kind;
- break;
-
+ return t_kind;
case tcc_statement: /* an expression with side effects */
- kind = s_kind;
- break;
-
+ return s_kind;
case tcc_reference: /* a reference */
- kind = r_kind;
- break;
-
+ return r_kind;
case tcc_expression: /* an expression */
case tcc_comparison: /* a comparison expression */
case tcc_unary: /* a unary arithmetic expression */
case tcc_binary: /* a binary arithmetic expression */
- kind = e_kind;
- break;
-
+ return e_kind;
case tcc_constant: /* a constant */
- kind = c_kind;
- break;
-
+ return c_kind;
case tcc_exceptional: /* something random, like an identifier. */
switch (code)
{
case IDENTIFIER_NODE:
- kind = id_kind;
- break;
-
+ return id_kind;
case TREE_VEC:
- kind = vec_kind;
- break;
-
+ return vec_kind;
case TREE_BINFO:
- kind = binfo_kind;
- break;
-
+ return binfo_kind;
case SSA_NAME:
- kind = ssa_name_kind;
- break;
-
+ return ssa_name_kind;
case BLOCK:
- kind = b_kind;
- break;
-
+ return b_kind;
case CONSTRUCTOR:
- kind = constr_kind;
- break;
-
+ return constr_kind;
case OMP_CLAUSE:
- kind = omp_clause_kind;
- break;
-
+ return omp_clause_kind;
default:
- kind = x_kind;
- break;
+ return x_kind;
}
break;
-
case tcc_vl_exp:
- kind = e_kind;
- break;
-
+ return e_kind;
default:
gcc_unreachable ();
}
+}
+
+/* Record interesting allocation statistics for a tree node with CODE
+ and LENGTH. */
+
+static void
+record_node_allocation_statistics (enum tree_code code, size_t length)
+{
+ if (!GATHER_STATISTICS)
+ return;
+
+ tree_node_kind kind = get_stats_node_kind (code);
tree_code_counts[(int) code]++;
tree_node_counts[(int) kind]++;
@@ -1157,9 +1133,15 @@ free_node (tree node)
enum tree_code code = TREE_CODE (node);
if (GATHER_STATISTICS)
{
+ enum tree_node_kind kind = get_stats_node_kind (code);
+
+ gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
+ gcc_checking_assert (tree_node_counts[(int) kind] != 0);
+ gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
+
tree_code_counts[(int) TREE_CODE (node)]--;
- tree_node_counts[(int) t_kind]--;
- tree_node_sizes[(int) t_kind] -= tree_size (node);
+ tree_node_counts[(int) kind]--;
+ tree_node_sizes[(int) kind] -= tree_size (node);
}
if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
vec_free (CONSTRUCTOR_ELTS (node));