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]

Reduce function deferral in g++


G++ was deferring a very large number of functions in some cases, in
particular, when there were a large number of structures, as happens
when a MacOS program includes <Carbon/Carbon.h>, which virtually all
of them do.  This was slowing down PCH; for instance, this patch
gives a 25% speed improvement for using a PCH with a nearly-empty
source file.  (I figure it can't help in other circumstances, either.)

With that PCH, the number of deferred functions is reduced from about
16,000 to 73.

The patch itself is nearly trivial, and in fact is overly
conservative; most of the remaining functions in the list are inline
functions, and unless they are actually used they don't need to be
there either.

Bootstrapped & tested on powerpc-darwin, with enable-languages=c++.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-lessdefer.patch=======================
2004-05-24  Geoffrey Keating  <geoffk@apple.com>

	* method.c (implicitly_declare_fn): Don't call defer_fn; abort
	if it might be needed.
	* pt.c (mark_decl_instantiated): Only call defer_fn if
	the function actually needs processing in finish_file.
	* decl2.c (finish_file): Add check that elements in
	deferred_fns_used are really needed there.  Remove unnecessary
	test of DECL_SAVED_TREE.

Index: decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.708
diff -u -p -u -p -r1.708 decl2.c
--- decl2.c	19 May 2004 01:28:56 -0000	1.708
+++ decl2.c	24 May 2004 20:47:13 -0000
@@ -2749,9 +2749,14 @@ finish_file (void)
 	     calling import_export_decl will make an inline template
 	     instantiation "static", which will result in errors about
 	     the use of undefined functions if there is no body for
-	     the function.  */
+	     the function.  In fact, all the functions in this list
+	     *should* have a body.  */
 	  if (!DECL_SAVED_TREE (decl))
-	    continue;
+	    {
+	      if (! DECL_DECLARED_INLINE_P (decl) || ! TREE_USED (decl))
+		abort ();
+	      continue;
+	    }
 
 	  import_export_decl (decl);
 
@@ -2776,7 +2781,6 @@ finish_file (void)
 	     gotten around to synthesizing yet.)  */
 	  if (!DECL_EXTERNAL (decl)
 	      && DECL_NEEDED_P (decl)
-	      && DECL_SAVED_TREE (decl)
 	      && !TREE_ASM_WRITTEN (decl)
 	      && (!flag_unit_at_a_time 
 		  || !cgraph_node (decl)->local.finalized))
Index: method.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/method.c,v
retrieving revision 1.282
diff -u -p -u -p -r1.282 method.c
--- method.c	19 May 2004 01:28:56 -0000	1.282
+++ method.c	24 May 2004 20:47:13 -0000
@@ -1027,7 +1027,8 @@ implicitly_declare_fn (special_function_
   DECL_NOT_REALLY_EXTERN (fn) = 1;
   DECL_DECLARED_INLINE_P (fn) = 1;
   DECL_INLINE (fn) = 1;
-  defer_fn (fn);
+  if (TREE_USED (fn))
+    abort ();
   
   return fn;
 }
Index: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.854
diff -u -p -u -p -r1.854 pt.c
--- pt.c	23 May 2004 22:48:37 -0000	1.854
+++ pt.c	24 May 2004 20:47:14 -0000
@@ -10161,7 +10161,9 @@ mark_decl_instantiated (tree result, int
 	maybe_make_one_only (result);
     }
 
-  if (TREE_CODE (result) == FUNCTION_DECL)
+  if (TREE_CODE (result) == FUNCTION_DECL 
+      && (DECL_ARTIFICIAL (result) 
+	  || (DECL_DECLARED_INLINE_P (result) && TREE_USED (result))))
     defer_fn (result);
 }
 
============================================================


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