Hi!

While type_hash_canon in case of reusing an already existing type
ggc_frees the freshly created type, we still waste one type uid
for each such case, this patch attempts to avoid that.
Furthermore, for INTEGER_TYPE we keep around the min and max value
INTEGER_CSTs and the cached values vector (until it is GCed).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-05-04  Jakub Jelinek  <ja...@redhat.com>

        * tree.c (next_type_uid): Change type to unsigned.
        (type_hash_canon): Decrement back next_type_uid if
        freeing a type node with the highest TYPE_UID.  For INTEGER_TYPEs
        also ggc_free TYPE_MIN_VALUE, TYPE_MAX_VALUE and TYPE_CACHED_VALUES
        if possible.

--- gcc/tree.c.jj       2017-05-03 16:55:39.688052581 +0200
+++ gcc/tree.c  2017-05-03 18:49:30.662185944 +0200
@@ -151,7 +151,7 @@ static const char * const tree_node_kind
 /* Unique id for next decl created.  */
 static GTY(()) int next_decl_uid;
 /* Unique id for next type created.  */
-static GTY(()) int next_type_uid = 1;
+static GTY(()) unsigned next_type_uid = 1;
 /* Unique id for next debug decl created.  Use negative numbers,
    to catch erroneous uses.  */
 static GTY(()) int next_debug_decl_uid;
@@ -7188,6 +7188,19 @@ type_hash_canon (unsigned int hashcode,
     {
       tree t1 = ((type_hash *) *loc)->type;
       gcc_assert (TYPE_MAIN_VARIANT (t1) == t1);
+      if (TYPE_UID (type) + 1 == next_type_uid)
+       --next_type_uid;
+      if (TREE_CODE (type) == INTEGER_TYPE)
+       {
+         if (TYPE_MIN_VALUE (type)
+             && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
+           ggc_free (TYPE_MIN_VALUE (type));
+         if (TYPE_MAX_VALUE (type)
+             && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
+           ggc_free (TYPE_MAX_VALUE (type));
+         if (TYPE_CACHED_VALUES_P (type))
+           ggc_free (TYPE_CACHED_VALUES (type));
+       }
       free_node (type);
       return t1;
     }

        Jakub

Reply via email to