PATCH: Shrinking C++ front end data structures

Doug Gregor doug.gregor@gmail.com
Mon Mar 12 18:13:00 GMT 2007


[My apologies for the empty e-mails earlier; I'll try again]

The variadic templates patch introduced a significant compile-time
memory usage regression due to the addition to two boolean flags:

  http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00652.html

The attached patch uses existing bits for these two flags, to bring
our memory usage back where it was. In addition, this patch attacks
some low-hanging fruit in the C++ data structures, packing values into
single bits when possible and making some HOST_WIDE_INTs into smaller
ints (where the HOST_WIDE_INTs aren't needed).

On the tramp3d test on i686-pc-linux-gnu, total virtual memory drops
from 437001kB down to 432961kB.

Tested i686-pc-linux-gnu; no regressions.

Okay for mainline?

  Cheers,
  Doug


2007-03-12  Douglas Gregor  <doug.gregor@gmail.com>



        * ptree.c (cxx_print_type): Use formatting markup for integers
        when printing template parameter index/level/orig level.
        (cxx_print_xnode): Ditto.
        * cp-tree.h (TEMPLATE_PARM_PARAMETER_PACK): Use TREE_LANG_FLAG_0.
        (struct template_parm_index_s): Remove the PARAMETER_PACK member.
        Make INDEX, LEVEL, and ORIG_LEVEL integers instead of
        HOST_WIDE_INTs.
        (struct saved_scope): Make X_PROCESSING_TEMPLATE_DECL an int,
        rather than a HOST_WIDE_INT.
        Turn X_PROCESSING_EXPLICIT_INSTANTIATION, SKIP_EVALUATION, and
        NEED_POP_FUNCTION_CONTEXT into bool bitfields; reorder fields for
        better bit-packing.
        (struct language_function): Make RETURNS_VALUE, RETURNS_NULL,
        RETURNS_ABNORMALLY, IN_FUNCTION_TRY_HANDLER, and
        IN_BASE_INITIALIZER single-bit bitfields.
        (struct cp_declarator): Make KIND a 4-bit field. Move
        PARAMETER_PACK_P just after KIND.
        * name-lookup.c (push_to_top_level): Make need_pop a bool value.

Index: ptree.c
===================================================================
--- ptree.c     (revision 122840)
+++ ptree.c     (working copy)
@@ -68,8 +68,7 @@ cxx_print_type (FILE *file, tree node, i
     case TEMPLATE_TEMPLATE_PARM:
     case BOUND_TEMPLATE_TEMPLATE_PARM:
       indent_to (file, indent + 3);
-      fprintf (file, "index " HOST_WIDE_INT_PRINT_DEC " level "
-              HOST_WIDE_INT_PRINT_DEC " orig_level " HOST_WIDE_INT_PRINT_DEC,
+      fprintf (file, "index %d level %d orig_level %d",
               TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node),
               TEMPLATE_TYPE_ORIG_LEVEL (node));
       return;
@@ -181,8 +180,7 @@ cxx_print_xnode (FILE *file, tree node,
       break;
     case TEMPLATE_PARM_INDEX:
       indent_to (file, indent + 3);
-      fprintf (file, "index " HOST_WIDE_INT_PRINT_DEC " level "
-              HOST_WIDE_INT_PRINT_DEC " orig_level " HOST_WIDE_INT_PRINT_DEC,
+      fprintf (file, "index %d level %d orig_level %d",
               TEMPLATE_PARM_IDX (node), TEMPLATE_PARM_LEVEL (node),
               TEMPLATE_PARM_ORIG_LEVEL (node));
       break;
Index: cp-tree.h
===================================================================
--- cp-tree.h   (revision 122840)
+++ cp-tree.h   (working copy)
@@ -56,6 +56,7 @@ struct diagnostic_context;
       OMP_FOR_GIMPLIFYING_P (in OMP_FOR)
       BASELINK_QUALIFIED_P (in BASELINK)
       TARGET_EXPR_IMPLICIT_P (in TARGET_EXPR)
+      TEMPLATE_PARM_PARAMETER_PACK (in TEMPLATE_PARM_INDEX)
    1: IDENTIFIER_VIRTUAL_P (in IDENTIFIER_NODE)
       TI_PENDING_TEMPLATE_FLAG.
       TEMPLATE_PARMS_FOR_INLINE.
@@ -219,14 +220,10 @@ struct lang_identifier GTY(())
 struct template_parm_index_s GTY(())
 {
   struct tree_common common;
-  HOST_WIDE_INT index;
-  HOST_WIDE_INT level;
-  HOST_WIDE_INT orig_level;
+  int index;
+  int level;
+  int orig_level;
   tree decl;
-
-  /* When true, indicates that this parameter is actually a parameter
-     pack, for variadic templates.  */
-  BOOL_BITFIELD parameter_pack;
 };
 typedef struct template_parm_index_s template_parm_index;

@@ -703,11 +700,12 @@ struct saved_scope GTY(())
   struct cp_binding_level *x_previous_class_level;
   tree x_saved_tree;

-  HOST_WIDE_INT x_processing_template_decl;
+  int x_processing_template_decl;
   int x_processing_specialization;
-  bool x_processing_explicit_instantiation;
-  int need_pop_function_context;
-  bool skip_evaluation;
+
+  BOOL_BITFIELD need_pop_function_context;
+  BOOL_BITFIELD x_processing_explicit_instantiation;
+  BOOL_BITFIELD skip_evaluation;

   struct stmt_tree_s x_stmt_tree;

@@ -786,11 +784,11 @@ struct language_function GTY(())
   tree x_vtt_parm;
   tree x_return_value;

-  int returns_value;
-  int returns_null;
-  int returns_abnormally;
-  int in_function_try_handler;
-  int in_base_initializer;
+  unsigned returns_value : 1;
+  unsigned returns_null : 1;
+  unsigned returns_abnormally : 1;
+  unsigned in_function_try_handler : 1;
+  unsigned in_base_initializer : 1;

   /* True if this function can throw an exception.  */
   BOOL_BITFIELD can_throw : 1;
@@ -3705,7 +3703,7 @@ enum overload_flags { NO_SPECIAL = 0, DT
 #define TEMPLATE_PARM_DESCENDANTS(NODE) (TREE_CHAIN (NODE))
 #define TEMPLATE_PARM_ORIG_LEVEL(NODE) (TEMPLATE_PARM_INDEX_CAST
(NODE)->orig_level)
 #define TEMPLATE_PARM_DECL(NODE) (TEMPLATE_PARM_INDEX_CAST (NODE)->decl)
-#define TEMPLATE_PARM_PARAMETER_PACK(NODE) (TEMPLATE_PARM_INDEX_CAST
(NODE)->parameter_pack)
+#define TEMPLATE_PARM_PARAMETER_PACK(NODE) (TREE_LANG_FLAG_0
(TEMPLATE_PARM_INDEX_CHECK (NODE)))

 /* These macros are for accessing the fields of TEMPLATE_TYPE_PARM,
    TEMPLATE_TEMPLATE_PARM and BOUND_TEMPLATE_TEMPLATE_PARM nodes.  */
@@ -3901,16 +3899,18 @@ struct cp_parameter_declarator {
 /* A declarator.  */
 struct cp_declarator {
   /* The kind of declarator.  */
-  cp_declarator_kind kind;
+  ENUM_BITFIELD (cp_declarator_kind) kind : 4;
+  /* Whether we parsed an ellipsis (`...') just before the declarator,
+     to indicate this is a parameter pack.  */
+  BOOL_BITFIELD parameter_pack_p : 1;
+  /* Sparse bits to pad out a 32-bit word.  */
+  unsigned spare : 27;
   /* Attributes that apply to this declarator.  */
   tree attributes;
   /* For all but cdk_id and cdk_error, the contained declarator.  For
      cdk_id and cdk_error, guaranteed to be NULL.  */
   cp_declarator *declarator;
   location_t id_loc; /* Currently only set for cdk_id. */
-  /* Whether we parsed an ellipsis (`...') just before the declarator,
-     to indicate this is a parameter pack.  */
-  bool parameter_pack_p;
   union {
     /* For identifiers.  */
     struct {
Index: name-lookup.c
===================================================================
--- name-lookup.c       (revision 122840)
+++ name-lookup.c       (working copy)
@@ -5030,7 +5030,7 @@ push_to_top_level (void)
   struct cp_binding_level *b;
   cxx_saved_binding *sb;
   size_t i;
-  int need_pop;
+  bool need_pop;

   timevar_push (TV_NAME_LOOKUP);
   s = GGC_CNEW (struct saved_scope);
@@ -5040,11 +5040,11 @@ push_to_top_level (void)
   /* If we're in the middle of some function, save our state.  */
   if (cfun)
     {
-      need_pop = 1;
+      need_pop = true;
       push_function_context_to (NULL_TREE);
     }
   else
-    need_pop = 0;
+    need_pop = false;

   if (scope_chain && previous_class_level)
     store_class_bindings (previous_class_level->class_shadowed,



More information about the Gcc-patches mailing list