C++ PATCH: Don't push_to_top_level when we don't need to

Mark Mitchell mark@codesourcery.com
Fri Dec 29 01:23:00 GMT 2000


This patch chops another 5% off of Gerald's test case by not calling
push_to_top_level when we don't need to.

These two patches cut the number of calls to ggc_alloc from 7M to 6M,
which is responsible for much of the win.  I've got a few more of
these in the works; I think we can avoid a lot of the memory
allocation/collection we're doing now, which should help to speed
things up.

While I was at it, I removed some code that wasn't used any more.

Tested on i686-pc-linux-gnu.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-12-29  Mark Mitchell  <mark@codesourcery.com>

	* class.c (pushclass): Remove #if 0'd code.
	* cp-tree.h (overload_template_name): Remove.
	* decl.c (store_bindings): Simplify.
	(pop_from_top_level): Likewise.
	* pt.c (overload_template_name): Remove.
	(instantiate_decl): Don't call push_to_top_level if it's not 
	needed.

Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.347
diff -c -p -r1.347 class.c
*** class.c	2000/12/22 14:47:22	1.347
--- class.c	2000/12/29 07:43:39
*************** pushclass (type, modify)
*** 5603,5613 ****
  
    pushlevel_class ();
  
- #if 0
-   if (CLASSTYPE_TEMPLATE_INFO (type))
-     overload_template_name (type);
- #endif
- 
    if (modify)
      {
        if (type != previous_class_type || current_class_depth > 1)
--- 5603,5608 ----
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.550
diff -c -p -r1.550 cp-tree.h
*** cp-tree.h	2000/12/22 17:05:50	1.550
--- cp-tree.h	2000/12/29 07:43:42
*************** extern tree lookup_template_function    
*** 4186,4192 ****
  extern int uses_template_parms			PARAMS ((tree));
  extern tree instantiate_class_template		PARAMS ((tree));
  extern tree instantiate_template		PARAMS ((tree, tree));
- extern void overload_template_name		PARAMS ((tree));
  extern int fn_type_unification                  PARAMS ((tree, tree, tree, tree, tree, unification_kind_t, int));
  extern tree tinst_for_decl			PARAMS ((void));
  extern void mark_decl_instantiated		PARAMS ((tree, int));
--- 4186,4191 ----
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.726
diff -c -p -r1.726 decl.c
*** decl.c	2000/12/20 18:16:46	1.726
--- decl.c	2000/12/29 07:43:51
*************** store_bindings (names, old_bindings)
*** 2447,2464 ****
  	if (TREE_VEC_ELT (t1, 0) == id)
  	  goto skip_it;
  
        binding = make_tree_vec (4);
! 
!       if (id)
! 	{
! 	  my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
! 	  TREE_VEC_ELT (binding, 0) = id;
! 	  TREE_VEC_ELT (binding, 1) = REAL_IDENTIFIER_TYPE_VALUE (id);
! 	  TREE_VEC_ELT (binding, 2) = IDENTIFIER_BINDING (id);
! 	  TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
! 	  IDENTIFIER_BINDING (id) = NULL_TREE;
! 	  IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
! 	}
        TREE_CHAIN (binding) = old_bindings;
        old_bindings = binding;
      skip_it:
--- 2447,2460 ----
  	if (TREE_VEC_ELT (t1, 0) == id)
  	  goto skip_it;
  
+       my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
        binding = make_tree_vec (4);
!       TREE_VEC_ELT (binding, 0) = id;
!       TREE_VEC_ELT (binding, 1) = REAL_IDENTIFIER_TYPE_VALUE (id);
!       TREE_VEC_ELT (binding, 2) = IDENTIFIER_BINDING (id);
!       TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
!       IDENTIFIER_BINDING (id) = NULL_TREE;
!       IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
        TREE_CHAIN (binding) = old_bindings;
        old_bindings = binding;
      skip_it:
*************** pop_from_top_level ()
*** 2552,2563 ****
    for (t = s->old_bindings; t; t = TREE_CHAIN (t))
      {
        tree id = TREE_VEC_ELT (t, 0);
!       if (id)
! 	{
! 	  SET_IDENTIFIER_TYPE_VALUE (id, TREE_VEC_ELT (t, 1));
! 	  IDENTIFIER_BINDING (id) = TREE_VEC_ELT (t, 2);
! 	  IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
!  	}
      }
  
    /* If we were in the middle of compiling a function, restore our
--- 2548,2557 ----
    for (t = s->old_bindings; t; t = TREE_CHAIN (t))
      {
        tree id = TREE_VEC_ELT (t, 0);
! 
!       SET_IDENTIFIER_TYPE_VALUE (id, TREE_VEC_ELT (t, 1));
!       IDENTIFIER_BINDING (id) = TREE_VEC_ELT (t, 2);
!       IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
      }
  
    /* If we were in the middle of compiling a function, restore our
ndex: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.495
diff -c -p -r1.495 pt.c
*** pt.c	2000/12/29 06:09:44	1.495
--- pt.c	2000/12/29 07:43:57
*************** instantiate_template (tmpl, targ_ptr)
*** 7558,7581 ****
    return fndecl;
  }
  
- /* Push the name of the class template into the scope of the instantiation.  */
- 
- void
- overload_template_name (type)
-      tree type;
- {
-   tree id = DECL_NAME (CLASSTYPE_TI_TEMPLATE (type));
-   tree decl;
- 
-   if (IDENTIFIER_CLASS_VALUE (id)
-       && TREE_TYPE (IDENTIFIER_CLASS_VALUE (id)) == type)
-     return;
- 
-   decl = build_decl (TYPE_DECL, id, type);
-   DECL_ARTIFICIAL (decl) = 1;
-   pushdecl_class_level (decl);
- }
- 
  /* The FN is a TEMPLATE_DECL for a function.  The ARGS are the
     arguments that are being used when calling it.  TARGS is a vector
     into which the deduced template arguments are placed.  
--- 7558,7563 ----
*************** instantiate_decl (d, defer_ok)
*** 9621,9626 ****
--- 9603,9609 ----
    tree gen_tmpl;
    int pattern_defined;
    int line = lineno;
+   int need_push;
    const char *file = input_filename;
  
    /* This function should only be used to instantiate templates for
*************** instantiate_decl (d, defer_ok)
*** 9776,9782 ****
        goto out;
      }
  
!   push_to_top_level ();
  
    /* We're now committed to instantiating this template.  Mark it as
       instantiated so that recursive calls to instantiate_decl do not
--- 9759,9767 ----
        goto out;
      }
  
!   need_push = !global_bindings_p ();
!   if (need_push)
!     push_to_top_level ();
  
    /* We're now committed to instantiating this template.  Mark it as
       instantiated so that recursive calls to instantiate_decl do not
*************** instantiate_decl (d, defer_ok)
*** 9840,9846 ****
    /* We're not deferring instantiation any more.  */
    TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (d)) = 0;
  
!   pop_from_top_level ();
  
  out:
    lineno = line;
--- 9825,9832 ----
    /* We're not deferring instantiation any more.  */
    TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (d)) = 0;
  
!   if (need_push)
!     pop_from_top_level ();
  
  out:
    lineno = line;


More information about the Gcc-patches mailing list