This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Speed up G++


This patch improves the compile-time performance of G++ substantially
on some input test cases.  On the test case I was examining, comptypes
was at the top of the profile, with 12.7M calls; after this patch,
that figure is 1.7M -- i.e., an 80%+ reduction.  The number of calls to
ggc_alloc_stat dropped by about 8%.  That's worth about 10% of compile
time on the particular test case I was using.  I'd be interested in
hearing what kinds of effects people see on other code.

We maintain a cache of class-level bindings so that if we re-enter the
class we just left we can do so quickly.  Unfortunately, restoring the
cache was much more expensive than it should have been.

Nathan, I broke the vector abstraction barrier in push_binding, where
I calculate "need_fixup".  You will want to go back and adjust that
code after you add the additional vector API function we dicussed
today.

Tested on i866-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-07-07  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (saved_scope): Remove x_previous_class_type and
	x_previous_class_values; add x_previous_class_level.
	(previous_class_type): Remove.
	(previous_class_values): Remove.
	(previous_class_level): New macro.
	* class.c (pushclass): Restore the identifier cache more
	expeditiously.
	(invalidate_class_lookup_cache): Use vector for class_shadowed and
	previous_class_values.
	* decl.c (poplevel): Likewise.
	* name-lookup.c (cxx_binding_init): New function.
	(cxx_binding_make): Use it.
	(push_binding): For a binding in a class level, use a vector of
	cp_class_binding nodes.
	(push_binding_level): New function.
	(begin_scope): Use it.
	(leave_scope): Do not put class binding levels on the free list.
	(print_binding_level): Adjust for the fact that class_shadowed is
	a vector.
	(poplevel_class): Likewise.
	(clear_identifier_class_values): Likewise.
	(push_class_level_binding): Likewise.
	(set_class_shadows): Remove.
	(store_binding): New function.
	(store_class_bindings): New function.
	(push_to_top_level): Use store_class_bindings as appropriate.
	(pop_from_top_level): Use previous_class_level, not
	previous_class_type.
	* name-lookup.h (cp_class_binding): New type.
	(cp_binding_level): Use a vector object for class_shadowed.
	(push_binding_level): Declare.
	(set_class_shadows): Remove.

Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.624
diff -c -5 -p -r1.624 class.c
*** class.c	7 Jul 2004 10:20:20 -0000	1.624
--- class.c	8 Jul 2004 04:31:10 -0000
*************** pushclass (tree type)
*** 5484,5496 ****
       structures or unions are public.  */
    current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type) 
  			      ? access_private_node 
  			      : access_public_node);
  
!   if (previous_class_type != NULL_TREE
!       && (type != previous_class_type 
! 	  || !COMPLETE_TYPE_P (previous_class_type))
        && current_class_depth == 1)
      {
        /* Forcibly remove any old class remnants.  */
        invalidate_class_lookup_cache ();
      }
--- 5484,5495 ----
       structures or unions are public.  */
    current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type) 
  			      ? access_private_node 
  			      : access_public_node);
  
!   if (previous_class_level
!       && type != previous_class_level->this_entity
        && current_class_depth == 1)
      {
        /* Forcibly remove any old class remnants.  */
        invalidate_class_lookup_cache ();
      }
*************** pushclass (tree type)
*** 5498,5511 ****
    /* If we're about to enter a nested class, clear
       IDENTIFIER_CLASS_VALUE for the enclosing classes.  */
    if (current_class_depth > 1)
      clear_identifier_class_values ();
  
!   pushlevel_class ();
! 
!   if (type != previous_class_type || current_class_depth > 1)
      {
        push_class_decls (type);
        if (CLASSTYPE_TEMPLATE_INFO (type) && !CLASSTYPE_USE_TEMPLATE (type))
  	{
  	  /* If we are entering the scope of a template declaration (not a
  	     specialization), we need to push all the using decls with
--- 5497,5511 ----
    /* If we're about to enter a nested class, clear
       IDENTIFIER_CLASS_VALUE for the enclosing classes.  */
    if (current_class_depth > 1)
      clear_identifier_class_values ();
  
!   if (!previous_class_level 
!       || type != previous_class_level->this_entity
!       || current_class_depth > 1)
      {
+       pushlevel_class ();
        push_class_decls (type);
        if (CLASSTYPE_TEMPLATE_INFO (type) && !CLASSTYPE_USE_TEMPLATE (type))
  	{
  	  /* If we are entering the scope of a template declaration (not a
  	     specialization), we need to push all the using decls with
*************** pushclass (tree type)
*** 5518,5543 ****
  	      pushdecl_class_level (fields);
  	}
      }
    else
      {
!       tree item;
  
        /* We are re-entering the same class we just left, so we don't
  	 have to search the whole inheritance matrix to find all the
  	 decls to bind again.  Instead, we install the cached
  	 class_shadowed list, and walk through it binding names and
  	 setting up IDENTIFIER_TYPE_VALUEs.  */
!       set_class_shadows (previous_class_values);
!       for (item = previous_class_values; item; item = TREE_CHAIN (item))
! 	{
! 	  tree id = TREE_PURPOSE (item);
! 	  tree decl = TREE_TYPE (item);
! 	  
! 	  push_class_binding (id, decl);
! 	  if (TREE_CODE (decl) == TYPE_DECL)
! 	    set_identifier_type_value (id, decl);
  	}
        unuse_fields (type);
      }
    
    cxx_remember_type_decls (CLASSTYPE_NESTED_UTDS (type));
--- 5518,5554 ----
  	      pushdecl_class_level (fields);
  	}
      }
    else
      {
!       cp_class_binding *cb;
!       size_t i;
  
        /* We are re-entering the same class we just left, so we don't
  	 have to search the whole inheritance matrix to find all the
  	 decls to bind again.  Instead, we install the cached
  	 class_shadowed list, and walk through it binding names and
  	 setting up IDENTIFIER_TYPE_VALUEs.  */
!       push_binding_level (previous_class_level);
!       class_binding_level = previous_class_level;
!       for (i = 0; 
! 	   (cb = VEC_iterate (cp_class_binding, 
! 			      previous_class_level->class_shadowed,
! 			      i));
! 	   ++i)
! 	{
! 	  tree id;
! 	  tree type_decl;
! 
! 	  id = cb->identifier;
! 	  cb->base.previous = IDENTIFIER_BINDING (id);
! 	  IDENTIFIER_BINDING (id) = &cb->base;
! 	  type_decl = cb->base.value;
! 	  if (!type_decl || TREE_CODE (type_decl) != TYPE_DECL)
! 	    type_decl = cb->base.type;
! 	  if (type_decl && TREE_CODE (type_decl) == TYPE_DECL)
! 	    set_identifier_type_value (id, type_decl);
  	}
        unuse_fields (type);
      }
    
    cxx_remember_type_decls (CLASSTYPE_NESTED_UTDS (type));
*************** pushclass (tree type)
*** 5549,5566 ****
     must invalidate our cache.  */
  
  void
  invalidate_class_lookup_cache (void)
  {
!   tree t;
    
    /* The IDENTIFIER_CLASS_VALUEs are no longer valid.  */
!   for (t = previous_class_values; t; t = TREE_CHAIN (t))
!     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
  
!   previous_class_values = NULL_TREE;
!   previous_class_type = NULL_TREE;
  }
   
  /* Get out of the current class scope. If we were in a class scope
     previously, that is the one popped to.  */
  
--- 5560,5580 ----
     must invalidate our cache.  */
  
  void
  invalidate_class_lookup_cache (void)
  {
!   size_t i;
!   cp_class_binding *cb;
    
    /* The IDENTIFIER_CLASS_VALUEs are no longer valid.  */
!   for (i = 0;
!        (cb = VEC_iterate (cp_class_binding, 
! 			  previous_class_level->class_shadowed, i));
!        ++i)
!     IDENTIFIER_CLASS_VALUE (cb->identifier) = NULL_TREE;
  
!   previous_class_level = NULL;
  }
   
  /* Get out of the current class scope. If we were in a class scope
     previously, that is the one popped to.  */
  
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.997
diff -c -5 -p -r1.997 cp-tree.h
*** cp-tree.h	7 Jul 2004 10:20:24 -0000	1.997
--- cp-tree.h	8 Jul 2004 04:31:10 -0000
*************** struct saved_scope GTY(())
*** 638,649 ****
    tree access_specifier;
    tree function_decl;
    varray_type lang_base;
    tree lang_name;
    tree template_parms;
!   tree x_previous_class_type;
!   tree x_previous_class_values;
    tree x_saved_tree;
  
    HOST_WIDE_INT x_processing_template_decl;
    int x_processing_specialization;
    bool x_processing_explicit_instantiation;
--- 638,648 ----
    tree access_specifier;
    tree function_decl;
    varray_type lang_base;
    tree lang_name;
    tree template_parms;
!   struct cp_binding_level *x_previous_class_level;
    tree x_saved_tree;
  
    HOST_WIDE_INT x_processing_template_decl;
    int x_processing_specialization;
    bool x_processing_explicit_instantiation;
*************** struct saved_scope GTY(())
*** 692,711 ****
  
  #define processing_template_decl scope_chain->x_processing_template_decl
  #define processing_specialization scope_chain->x_processing_specialization
  #define processing_explicit_instantiation scope_chain->x_processing_explicit_instantiation
  
! /* _TYPE: the previous type that was a class */
  
! #define previous_class_type scope_chain->x_previous_class_type
! 
! /* This is a copy of the class_shadowed list of the previous class
!    binding contour when at global scope.  It's used to reset
!    IDENTIFIER_CLASS_VALUEs when entering another class scope (i.e. a
!    cache miss).  */
! 
! #define previous_class_values scope_chain->x_previous_class_values
  
  /* A list of private types mentioned, for deferred access checking.  */
  
  extern GTY(()) struct saved_scope *scope_chain;
  
--- 691,704 ----
  
  #define processing_template_decl scope_chain->x_processing_template_decl
  #define processing_specialization scope_chain->x_processing_specialization
  #define processing_explicit_instantiation scope_chain->x_processing_explicit_instantiation
  
! /* The cached class binding level, from the most recently exited
!    class, or NULL if none.  */
  
! #define previous_class_level scope_chain->x_previous_class_level
  
  /* A list of private types mentioned, for deferred access checking.  */
  
  extern GTY(()) struct saved_scope *scope_chain;
  
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1239
diff -c -5 -p -r1.1239 decl.c
*** decl.c	7 Jul 2004 10:20:27 -0000	1.1239
--- decl.c	8 Jul 2004 04:31:10 -0000
*************** poplevel (int keep, int reverse, int fun
*** 441,451 ****
  
    real_functionbody = (current_binding_level->kind == sk_cleanup
  		       ? ((functionbody = 0), tmp) : functionbody);
    subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  
!   my_friendly_assert (!current_binding_level->class_shadowed,
  		      19990414);
  
    /* We used to use KEEP == 2 to indicate that the new block should go
       at the beginning of the list of blocks at this binding level,
       rather than the end.  This hack is no longer used.  */
--- 441,452 ----
  
    real_functionbody = (current_binding_level->kind == sk_cleanup
  		       ? ((functionbody = 0), tmp) : functionbody);
    subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  
!   my_friendly_assert (VEC_length(cp_class_binding, 
! 				 current_binding_level->class_shadowed) == 0,
  		      19990414);
  
    /* We used to use KEEP == 2 to indicate that the new block should go
       at the beginning of the list of blocks at this binding level,
       rather than the end.  This hack is no longer used.  */
Index: name-lookup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.66
diff -c -5 -p -r1.66 name-lookup.c
*** name-lookup.c	7 Jul 2004 10:20:37 -0000	1.66
--- name-lookup.c	8 Jul 2004 04:31:10 -0000
*************** binding_table_foreach (binding_table tab
*** 326,335 ****
--- 326,346 ----
  
  /* A free list of "cxx_binding"s, connected by their PREVIOUS.  */
  
  static GTY((deletable)) cxx_binding *free_bindings;
  
+ /* Initialize VALUE and TYPE field for BINDING, and set the PREVIOUS
+    field to NULL.  */
+ 
+ static inline void
+ cxx_binding_init (cxx_binding *binding, tree value, tree type)
+ {
+   binding->value = value;
+   binding->type = type;
+   binding->previous = NULL;
+ }
+ 
  /* (GC)-allocate a binding object with VALUE and TYPE member initialized.  */
  
  static cxx_binding *
  cxx_binding_make (tree value, tree type)
  {
*************** cxx_binding_make (tree value, tree type)
*** 340,352 ****
        free_bindings = binding->previous;
      }
    else
      binding = ggc_alloc (sizeof (cxx_binding));
  
!   binding->value = value;
!   binding->type = type;
!   binding->previous = NULL;
  
    return binding;
  }
  
  /* Put BINDING back on the free list.  */
--- 351,361 ----
        free_bindings = binding->previous;
      }
    else
      binding = ggc_alloc (sizeof (cxx_binding));
  
!   cxx_binding_init (binding, value, type);
  
    return binding;
  }
  
  /* Put BINDING back on the free list.  */
*************** cxx_binding_free (cxx_binding *binding)
*** 363,374 ****
     level at which this declaration is being bound.  */
  
  static void
  push_binding (tree id, tree decl, cxx_scope* level)
  {
!    cxx_binding *binding = cxx_binding_make (decl, NULL);
  
    /* Now, fill in the binding information.  */
    binding->previous = IDENTIFIER_BINDING (id);
    binding->scope = level;
    INHERITED_VALUE_BINDING_P (binding) = 0;
    LOCAL_BINDING_P (binding) = (level != class_binding_level);
--- 372,406 ----
     level at which this declaration is being bound.  */
  
  static void
  push_binding (tree id, tree decl, cxx_scope* level)
  {
!   cxx_binding *binding;
  
+   if (level != class_binding_level)
+     binding = cxx_binding_make (decl, NULL_TREE);
+   else
+     {
+       cp_class_binding *cb;
+       size_t length;
+       size_t i;
+       bool need_fixup;
+ 
+       length = VEC_length (cp_class_binding, level->class_shadowed);
+       need_fixup = (length && length == level->class_shadowed->alloc);
+       cb = VEC_safe_push (cp_class_binding, level->class_shadowed, NULL);
+       cb->identifier = id;
+       binding = &cb->base;
+       cxx_binding_init (binding, decl, NULL_TREE);
+       if (need_fixup)
+ 	for (i = 0; i < length; ++i)
+ 	  {
+ 	    cb = VEC_index (cp_class_binding, level->class_shadowed, i);
+ 	    IDENTIFIER_BINDING (cb->identifier) = &cb->base;
+ 	  }
+     }
+ 			      
    /* Now, fill in the binding information.  */
    binding->previous = IDENTIFIER_BINDING (id);
    binding->scope = level;
    INHERITED_VALUE_BINDING_P (binding) = 0;
    LOCAL_BINDING_P (binding) = (level != class_binding_level);
*************** namespace_scope_ht_size (tree ns)
*** 1259,1268 ****
--- 1291,1320 ----
  
  /* A chain of binding_level structures awaiting reuse.  */
  
  static GTY((deletable)) struct cp_binding_level *free_binding_level;
  
+ /* Insert SCOPE as the innermost binding level.  */
+ 
+ void
+ push_binding_level (struct cp_binding_level *scope)
+ {
+   /* Add it to the front of currently active scopes stack.  */
+   scope->level_chain = current_binding_level;
+   current_binding_level = scope;
+   keep_next_level_flag = false;
+ 
+   if (ENABLE_SCOPE_CHECKING)
+     {
+       scope->binding_depth = binding_depth;
+       indent (binding_depth);
+       cxx_scope_debug (scope, input_line, "push");
+       is_class_level = 0;
+       binding_depth++;
+     }
+ }
+ 
  /* Create a new KIND scope and make it the top of the active scopes stack.
     ENTITY is the scope of the associated C++ entity (namespace, class,
     function); it is NULL otherwise.  */
  
  cxx_scope *
*************** begin_scope (scope_kind kind, tree entit
*** 1317,1339 ****
        my_friendly_assert (false, 20030922);
        break;
      }
    scope->kind = kind;
  
!   /* Add it to the front of currently active scopes stack.  */
!   scope->level_chain = current_binding_level;
!   current_binding_level = scope;
!   keep_next_level_flag = false;
! 
!   if (ENABLE_SCOPE_CHECKING)
!     {
!       scope->binding_depth = binding_depth;
!       indent (binding_depth);
!       cxx_scope_debug (scope, input_line, "push");
!       is_class_level = 0;
!       binding_depth++;
!     }
  
    return scope;
  }
  
  /* We're about to leave current scope.  Pop the top of the stack of
--- 1369,1379 ----
        my_friendly_assert (false, 20030922);
        break;
      }
    scope->kind = kind;
  
!   push_binding_level (scope);
  
    return scope;
  }
  
  /* We're about to leave current scope.  Pop the top of the stack of
*************** leave_scope (void)
*** 1364,1378 ****
      }
  
    /* Move one nesting level up.  */
    current_binding_level = scope->level_chain;
  
!   /* Namespace-scopes are left most probably temporarily, not completely;
!      they can be reopen later, e.g. in namespace-extension or any name
!      binding activity that requires us to resume a namespace.  For other
       scopes, we just make the structure available for reuse.  */
!   if (scope->kind != sk_namespace)
      {
        scope->level_chain = free_binding_level;
        if (scope->kind == sk_class)
          scope->type_decls = NULL;
        else
--- 1404,1420 ----
      }
  
    /* Move one nesting level up.  */
    current_binding_level = scope->level_chain;
  
!   /* Namespace-scopes are left most probably temporarily, not
!      completely; they can be reopen later, e.g. in namespace-extension
!      or any name binding activity that requires us to resume a
!      namespace.  For classes, we cache some binding levels.  For other
       scopes, we just make the structure available for reuse.  */
!   if (scope->kind != sk_namespace
!       && scope->kind != sk_class)
      {
        scope->level_chain = free_binding_level;
        if (scope->kind == sk_class)
          scope->type_decls = NULL;
        else
*************** print_binding_level (struct cp_binding_l
*** 1626,1642 ****
        i = 0;
        binding_table_foreach (lvl->type_decls, bt_print_entry, &i);
        if (i)
  	fprintf (stderr, "\n");
      }
!   if (lvl->class_shadowed)
      {
        fprintf (stderr, " class-shadowed:");
!       for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
! 	{
! 	  fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
! 	}
        fprintf (stderr, "\n");
      }
    if (lvl->type_shadowed)
      {
        fprintf (stderr, " type-shadowed:");
--- 1668,1688 ----
        i = 0;
        binding_table_foreach (lvl->type_decls, bt_print_entry, &i);
        if (i)
  	fprintf (stderr, "\n");
      }
!   if (VEC_length (cp_class_binding, lvl->class_shadowed))
      {
+       size_t i;
+       cp_class_binding *b;
        fprintf (stderr, " class-shadowed:");
!       for (i = 0; 
! 	   (b = VEC_iterate(cp_class_binding, 
! 			    lvl->class_shadowed,
! 			    i));
! 	   ++i) 
! 	fprintf (stderr, " %s ", IDENTIFIER_POINTER (b->identifier));
        fprintf (stderr, "\n");
      }
    if (lvl->type_shadowed)
      {
        fprintf (stderr, " type-shadowed:");
*************** pushlevel_class (void)
*** 2574,2583 ****
--- 2620,2631 ----
  
  void
  poplevel_class (void)
  {
    struct cp_binding_level *level = class_binding_level;
+   cp_class_binding *cb;
+   size_t i;
    tree shadowed;
  
    timevar_push (TV_NAME_LOOKUP);
    my_friendly_assert (level != 0, 354);
  
*************** poplevel_class (void)
*** 2587,2642 ****
       if we don't touch it here, we're able to use the cache effect if the
       next time we're entering a class scope, it is the same class.  */
    if (current_class_depth != 1)
      {
        struct cp_binding_level* b;
  
        /* Clear out our IDENTIFIER_CLASS_VALUEs.  */
!       for (shadowed = level->class_shadowed;
! 	   shadowed;
! 	   shadowed = TREE_CHAIN (shadowed))
! 	IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = NULL_TREE;
  
        /* Find the next enclosing class, and recreate
  	 IDENTIFIER_CLASS_VALUEs appropriate for that class.  */
        b = level->level_chain;
        while (b && b->kind != sk_class)
  	b = b->level_chain;
  
        if (b)
! 	for (shadowed = b->class_shadowed;
! 	     shadowed;
! 	     shadowed = TREE_CHAIN (shadowed))
  	  {
  	    cxx_binding *binding;
              
! 	    binding = IDENTIFIER_BINDING (TREE_PURPOSE (shadowed));
  	    while (binding && binding->scope != b)
  	      binding = binding->previous;
  
  	    if (binding)
! 	      IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed))
! 		= binding->value;
  	  }
      }
    else
      /* Remember to save what IDENTIFIER's were bound in this scope so we
         can recover from cache misses.  */
!     {
!       previous_class_type = current_class_type;
!       previous_class_values = class_binding_level->class_shadowed;
!     }
    for (shadowed = level->type_shadowed;
         shadowed;
         shadowed = TREE_CHAIN (shadowed))
      SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed));
  
    /* Remove the bindings for all of the class-level declarations.  */
!   for (shadowed = level->class_shadowed;
!        shadowed;
!        shadowed = TREE_CHAIN (shadowed))
!     pop_binding (TREE_PURPOSE (shadowed), TREE_TYPE (shadowed));
  
    /* Now, pop out of the binding level which we created up in the
       `pushlevel_class' routine.  */
    if (ENABLE_SCOPE_CHECKING)
      is_class_level = 1;
--- 2635,2687 ----
       if we don't touch it here, we're able to use the cache effect if the
       next time we're entering a class scope, it is the same class.  */
    if (current_class_depth != 1)
      {
        struct cp_binding_level* b;
+       cp_class_binding* cb;
+       size_t i;
  
        /* Clear out our IDENTIFIER_CLASS_VALUEs.  */
!       clear_identifier_class_values ();
  
        /* Find the next enclosing class, and recreate
  	 IDENTIFIER_CLASS_VALUEs appropriate for that class.  */
        b = level->level_chain;
        while (b && b->kind != sk_class)
  	b = b->level_chain;
  
        if (b)
! 	for (i = 0;
! 	     (cb = VEC_iterate (cp_class_binding, 
! 				b->class_shadowed, 
! 				i));
! 	     ++i)
  	  {
  	    cxx_binding *binding;
              
! 	    binding = IDENTIFIER_BINDING (cb->identifier);
  	    while (binding && binding->scope != b)
  	      binding = binding->previous;
  
  	    if (binding)
! 	      IDENTIFIER_CLASS_VALUE (cb->identifier) = binding->value;
  	  }
      }
    else
      /* Remember to save what IDENTIFIER's were bound in this scope so we
         can recover from cache misses.  */
!     previous_class_level = level;
    for (shadowed = level->type_shadowed;
         shadowed;
         shadowed = TREE_CHAIN (shadowed))
      SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed));
  
    /* Remove the bindings for all of the class-level declarations.  */
!   for (i = 0;
!        (cb = VEC_iterate (cp_class_binding, level->class_shadowed, i));
!        ++i)
!     IDENTIFIER_BINDING (cb->identifier) = cb->base.previous;
  
    /* Now, pop out of the binding level which we created up in the
       `pushlevel_class' routine.  */
    if (ENABLE_SCOPE_CHECKING)
      is_class_level = 1;
*************** push_class_binding (tree id, tree decl)
*** 2705,2723 ****
     for any names in enclosing classes.  */
  
  void
  clear_identifier_class_values (void)
  {
!   tree t;
! 
!   if (!class_binding_level)
!     return;
  
!   for (t = class_binding_level->class_shadowed;
!        t;
!        t = TREE_CHAIN (t))
!     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
  }
  
  /* Make the declaration of X appear in CLASS scope.  */
  
  bool
--- 2750,2769 ----
     for any names in enclosing classes.  */
  
  void
  clear_identifier_class_values (void)
  {
!   size_t i;
!   cp_class_binding *cb;
  
!   if (class_binding_level)
!     for (i = 0;
! 	 (cb = VEC_iterate (cp_class_binding, 
! 			    class_binding_level->class_shadowed, 
! 			    i));
! 	 ++i)
!       IDENTIFIER_CLASS_VALUE (cb->identifier) = NULL_TREE;
  }
  
  /* Make the declaration of X appear in CLASS scope.  */
  
  bool
*************** push_class_level_binding (tree name, tre
*** 2857,2900 ****
  	POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
        else if (TREE_CODE (x) == USING_DECL && is_overloaded_fn (bval))
  	old_decl = bval;
        else if (TREE_CODE (bval) == USING_DECL && is_overloaded_fn (x))
  	POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
!       
        if (old_decl)
  	{
! 	  tree shadow;
! 	  
  	  /* Find the previous binding of name on the class-shadowed
               list, and update it.  */
! 	  for (shadow = class_binding_level->class_shadowed;
! 	       shadow;
! 	       shadow = TREE_CHAIN (shadow))
! 	    if (TREE_PURPOSE (shadow) == name
! 		&& TREE_TYPE (shadow) == old_decl)
  	      {
  		binding->value = x;
  		INHERITED_VALUE_BINDING_P (binding) = 0;
- 		TREE_TYPE (shadow) = x;
  		IDENTIFIER_CLASS_VALUE (name) = x;
  		POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
  	      }
  	}
      }
  
    /* If we didn't replace an existing binding, put the binding on the
       stack of bindings for the identifier, and update the shadowed list.  */
    if (push_class_binding (name, x))
!     {
!       class_binding_level->class_shadowed
! 	= tree_cons (name, NULL,
! 		     class_binding_level->class_shadowed);
!       /* Record the value we are binding NAME to so that we can know
! 	 what to pop later.  */
!       TREE_TYPE (class_binding_level->class_shadowed) = x;
!       POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
!     }
  
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, false);
  }
  
  tree
--- 2903,2941 ----
  	POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
        else if (TREE_CODE (x) == USING_DECL && is_overloaded_fn (bval))
  	old_decl = bval;
        else if (TREE_CODE (bval) == USING_DECL && is_overloaded_fn (x))
  	POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
! 
        if (old_decl)
  	{
! 	  cp_class_binding *cb;
! 	  size_t i;
! 
  	  /* Find the previous binding of name on the class-shadowed
               list, and update it.  */
! 	  for (i = 0; 
! 	       (cb = VEC_iterate (cp_class_binding,
! 				  class_binding_level->class_shadowed,
! 				  i));
! 	       ++i)
! 	    if (cb->identifier == name
! 		&& (cb->base.value == old_decl
! 		    || cb->base.type == old_decl))
  	      {
  		binding->value = x;
  		INHERITED_VALUE_BINDING_P (binding) = 0;
  		IDENTIFIER_CLASS_VALUE (name) = x;
  		POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
  	      }
  	}
      }
  
    /* If we didn't replace an existing binding, put the binding on the
       stack of bindings for the identifier, and update the shadowed list.  */
    if (push_class_binding (name, x))
!     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
  
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, false);
  }
  
  tree
*************** do_class_using_decl (tree decl)
*** 2943,2957 ****
  	cp_emit_debug_info_for_using (r, scope);
      }
    return value;
  }
  
- void
- set_class_shadows (tree shadows)
- {
-   class_binding_level->class_shadowed = shadows;
- }
  
  /* Return the binding value for name in scope.  */
  
  tree
  namespace_binding (tree name, tree scope)
--- 2984,2993 ----
*************** struct cxx_saved_binding GTY(())
*** 4794,4848 ****
     local-value slots of all identifiers, so that only the global values
     are at all visible.  Simply setting current_binding_level to the global
     scope isn't enough, because more binding levels may be pushed.  */
  struct saved_scope *scope_chain;
  
  static cxx_saved_binding *
  store_bindings (tree names, cxx_saved_binding *old_bindings)
  {
    tree t;
    cxx_saved_binding *search_bindings = old_bindings;
  
    timevar_push (TV_NAME_LOOKUP);
    for (t = names; t; t = TREE_CHAIN (t))
      {
        tree id;
-       cxx_saved_binding *saved;
-       cxx_saved_binding *t1;
  
        if (TREE_CODE (t) == TREE_LIST)
  	id = TREE_PURPOSE (t);
        else
  	id = DECL_NAME (t);
  
!       if (!id
! 	  /* Note that we may have an IDENTIFIER_CLASS_VALUE even when
! 	     we have no IDENTIFIER_BINDING if we have left the class
! 	     scope, but cached the class-level declarations.  */
! 	  || !(IDENTIFIER_BINDING (id) || IDENTIFIER_CLASS_VALUE (id)))
! 	continue;
! 
!       for (t1 = search_bindings; t1; t1 = t1->previous)
! 	if (t1->identifier == id)
! 	  goto skip_it;
! 
!       my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
!       saved = cxx_saved_binding_make ();
!       saved->previous = old_bindings;
!       saved->identifier = id;
!       saved->binding = IDENTIFIER_BINDING (id);
!       saved->class_value = IDENTIFIER_CLASS_VALUE (id);;
!       saved->real_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
!       IDENTIFIER_BINDING (id) = NULL;
!       IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
!       old_bindings = saved;
!     skip_it:
!       ;
      }
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, old_bindings);
  }
  
  void
  push_to_top_level (void)
  {
    struct saved_scope *s;
    struct cp_binding_level *b;
--- 4830,4916 ----
     local-value slots of all identifiers, so that only the global values
     are at all visible.  Simply setting current_binding_level to the global
     scope isn't enough, because more binding levels may be pushed.  */
  struct saved_scope *scope_chain;
  
+ /* If ID is not already in the SEARCH_BINDINGS, prepend its binding
+    information to OLD_BINDINGS.  Returns the new OLD_BINDINGS
+    list.  */
+ 
+ static cxx_saved_binding *
+ store_binding (tree id,
+ 	       cxx_saved_binding *old_bindings,
+ 	       cxx_saved_binding *search_bindings)
+ {
+   cxx_saved_binding *saved;
+   cxx_saved_binding *t1;
+ 
+   if (!id
+       /* Note that we may have an IDENTIFIER_CLASS_VALUE even when
+ 	 we have no IDENTIFIER_BINDING if we have left the class
+ 	 scope, but cached the class-level declarations.  */
+       || !(IDENTIFIER_BINDING (id) || IDENTIFIER_CLASS_VALUE (id)))
+      return old_bindings;
+ 
+   for (t1 = search_bindings; t1; t1 = t1->previous)
+     if (t1->identifier == id)
+      return old_bindings;
+ 
+   my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
+   saved = cxx_saved_binding_make ();
+   saved->previous = old_bindings;
+   saved->identifier = id;
+   saved->binding = IDENTIFIER_BINDING (id);
+   saved->class_value = IDENTIFIER_CLASS_VALUE (id);;
+   saved->real_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
+   IDENTIFIER_BINDING (id) = NULL;
+   IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
+   return saved;
+ }
+ 
  static cxx_saved_binding *
  store_bindings (tree names, cxx_saved_binding *old_bindings)
  {
    tree t;
    cxx_saved_binding *search_bindings = old_bindings;
  
    timevar_push (TV_NAME_LOOKUP);
    for (t = names; t; t = TREE_CHAIN (t))
      {
        tree id;
  
        if (TREE_CODE (t) == TREE_LIST)
  	id = TREE_PURPOSE (t);
        else
  	id = DECL_NAME (t);
  
!       old_bindings 
! 	= store_binding (id, old_bindings, search_bindings);
      }
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, old_bindings);
  }
  
+ /* Like store_bindings, but NAMES is a vector of cp_class_binding
+    objects, rather than a TREE_LIST.  */
+ 
+ static cxx_saved_binding *
+ store_class_bindings (VEC(cp_class_binding) *names, 
+ 		      cxx_saved_binding *old_bindings)
+ {
+   size_t i;
+   cp_class_binding *cb;
+   cxx_saved_binding *search_bindings = old_bindings;
+ 
+   timevar_push (TV_NAME_LOOKUP);
+   for (i = 0; 
+        (cb = VEC_iterate(cp_class_binding, names, i));
+        ++i)
+     old_bindings 
+       = store_binding (cb->identifier, old_bindings, search_bindings);
+   POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, old_bindings);
+ }
+ 
  void
  push_to_top_level (void)
  {
    struct saved_scope *s;
    struct cp_binding_level *b;
*************** push_to_top_level (void)
*** 4862,4873 ****
      }
    else
      need_pop = 0;
  
    old_bindings = NULL;
!   if (scope_chain && previous_class_type)
!     old_bindings = store_bindings (previous_class_values, old_bindings);
  
    /* Have to include the global scope, because class-scope decls
       aren't listed anywhere useful.  */
    for (; b; b = b->level_chain)
      {
--- 4930,4942 ----
      }
    else
      need_pop = 0;
  
    old_bindings = NULL;
!   if (scope_chain && previous_class_level)
!     old_bindings = store_class_bindings (previous_class_level->class_shadowed,
! 					 old_bindings);
  
    /* Have to include the global scope, because class-scope decls
       aren't listed anywhere useful.  */
    for (; b; b = b->level_chain)
      {
*************** push_to_top_level (void)
*** 4882,4892 ****
  
        old_bindings = store_bindings (b->names, old_bindings);
        /* We also need to check class_shadowed to save class-level type
  	 bindings, since pushclass doesn't fill in b->names.  */
        if (b->kind == sk_class)
! 	old_bindings = store_bindings (b->class_shadowed, old_bindings);
  
        /* Unwind type-value slots back to top level.  */
        for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
  	SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
      }
--- 4951,4961 ----
  
        old_bindings = store_bindings (b->names, old_bindings);
        /* We also need to check class_shadowed to save class-level type
  	 bindings, since pushclass doesn't fill in b->names.  */
        if (b->kind == sk_class)
! 	old_bindings = store_class_bindings (b->class_shadowed, old_bindings);
  
        /* Unwind type-value slots back to top level.  */
        for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
  	SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
      }
*************** pop_from_top_level (void)
*** 4910,4920 ****
    struct saved_scope *s = scope_chain;
    cxx_saved_binding *saved;
  
    timevar_push (TV_NAME_LOOKUP); 
    /* Clear out class-level bindings cache.  */
!   if (previous_class_type)
      invalidate_class_lookup_cache ();
  
    current_lang_base = 0;
  
    scope_chain = s->prev;
--- 4979,4989 ----
    struct saved_scope *s = scope_chain;
    cxx_saved_binding *saved;
  
    timevar_push (TV_NAME_LOOKUP); 
    /* Clear out class-level bindings cache.  */
!   if (previous_class_level)
      invalidate_class_lookup_cache ();
  
    current_lang_base = 0;
  
    scope_chain = s->prev;
Index: name-lookup.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.h,v
retrieving revision 1.21
diff -c -5 -p -r1.21 name-lookup.h
*** name-lookup.h	16 Jun 2004 01:21:31 -0000	1.21
--- name-lookup.h	8 Jul 2004 04:31:10 -0000
*************** typedef enum scope_kind {
*** 115,124 ****
--- 115,133 ----
  			specialization.  Since, by definition, an
  			explicit specialization is introduced by
  			"template <>", this scope is always empty.  */
  } scope_kind;
  
+ typedef struct cp_class_binding GTY(())
+ {
+   cxx_binding base;
+   /* The bound name.  */
+   tree identifier;
+ } cp_class_binding;
+ 
+ DEF_VEC_O(cp_class_binding);
+ 
  /* For each binding contour we allocate a binding_level structure
     which records the names defined in that contour.
     Contours include:
      0) the global one
      1) one for each function definition,
*************** struct cp_binding_level GTY(())
*** 173,183 ****
  
      /* If this binding level is the binding level for a class, then
         class_shadowed is a TREE_LIST.  The TREE_PURPOSE of each node
         is the name of an entity bound in the class.  The TREE_TYPE is
         the DECL bound by this name in the class.  */
!     tree class_shadowed;
  
      /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and
         is used for all binding levels. In addition the TREE_VALUE is the
         IDENTIFIER_TYPE_VALUE before we entered the class.  */
      tree type_shadowed;
--- 182,192 ----
  
      /* If this binding level is the binding level for a class, then
         class_shadowed is a TREE_LIST.  The TREE_PURPOSE of each node
         is the name of an entity bound in the class.  The TREE_TYPE is
         the DECL bound by this name in the class.  */
!     VEC(cp_class_binding) *class_shadowed;
  
      /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and
         is used for all binding levels. In addition the TREE_VALUE is the
         IDENTIFIER_TYPE_VALUE before we entered the class.  */
      tree type_shadowed;
*************** extern void pop_from_top_level (void);
*** 271,280 ****
--- 280,290 ----
  extern void pop_everything (void);
  extern void keep_next_level (bool);
  extern bool is_ancestor (tree, tree);
  extern bool push_scope (tree);
  extern void pop_scope (tree);
+ extern void push_binding_level (struct cp_binding_level *);
  
  extern void push_namespace (tree);
  extern void pop_namespace (void);
  extern void push_nested_namespace (tree);
  extern void pop_nested_namespace (tree);
*************** extern bool pushdecl_class_level (tree);
*** 297,307 ****
  extern tree pushdecl_namespace_level (tree);
  extern bool push_class_level_binding (tree, tree);
  extern void storetags (tree);
  extern tree getdecls (void);
  extern tree cp_namespace_decls (tree);
- extern void set_class_shadows (tree);
  extern void set_decl_namespace (tree, tree, bool);
  extern tree current_decl_namespace (void);
  extern void push_decl_namespace (tree);
  extern void pop_decl_namespace (void);
  extern void do_namespace_alias (tree, tree);
--- 307,316 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]