This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: first pass of wrapup_global_declarations performance improvements
- From: Matt Austern <austern at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 14 Feb 2003 13:08:22 -0800
- Subject: PATCH: first pass of wrapup_global_declarations performance improvements
This patch does two things.
First, it changes an unconditional write into a conditional write.
This is because, empirically, the unconditional write dirties pages
unnecessarily. This is a noticeable performance problem, especially
when using PCH.
Second, it introduces a new langhook so that the C++ front end no
longer relies on wrapup_global_declarations being called from toplev.c.
Instead it moves that responsibility to finish_file, in cp/decl2.c.
This results in a slight performance improvement, but the real reason
for doing this is so I can make changes to the C++ front end without
fear of breaking any other front ends.
This patch has been bootstrapped on Linux, dg-tested and timed on OS X.
For Apple's usual performance test (building Finder_FE at -O0 using
PCH), it gives about a 2.5% improvement.
OK to commit to mainline and gcc-3_3-branch?
--Matt
Index: gcc/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
retrieving revision 1.16739
diff -u -r1.16739 ChangeLog
--- gcc/ChangeLog 14 Feb 2003 17:50:29 -0000 1.16739
+++ gcc/ChangeLog 14 Feb 2003 21:04:59 -0000
@@ -1,3 +1,12 @@
+2003-02-14 Matt Austern <austern@apple.com>
+ * langhooks.h, langhooks-def.h: introduce new langhook,
+ final_write_globals, with write_global_declarations as default.
+ * toplev.c: Move invocation of wrapup_global_declarations from
+ compile_file to new function, write_global_declarations. Change
+ compile_file to use final_write_globals hook. Change
+ wrapup_global_declarations so writing to DECL_DEFER_OUTPUT is
+ conditional.
+
2003-02-14 Kazu Hirata <kazu@cs.umass.edu>
* simplify-rtx.c (simplify_binary_operation): Simplify ~y when
Index: gcc/langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.41
diff -u -r1.41 langhooks-def.h
--- gcc/langhooks-def.h 12 Feb 2003 21:48:57 -0000 1.41
+++ gcc/langhooks-def.h 14 Feb 2003 21:04:59 -0000
@@ -82,6 +82,9 @@
void lhd_tree_inlining_end_inlining PARAMS ((tree));
tree lhd_tree_inlining_convert_parm_for_inlining PARAMS ((tree, tree,
tree));
+/* In toplev.c */
+void write_global_declarations PARAMS ((void));
+
#define LANG_HOOKS_NAME "GNU unknown"
#define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct lang_identifier)
#define LANG_HOOKS_INIT lhd_do_nothing
@@ -217,6 +220,7 @@
#define LANG_HOOKS_PUSHDECL pushdecl
#define LANG_HOOKS_GETDECLS getdecls
#define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL lhd_warn_unused_global_decl
+#define LANG_HOOKS_WRITE_GLOBALS write_global_declarations
#define LANG_HOOKS_DECLS { \
LANG_HOOKS_PUSHLEVEL, \
@@ -226,7 +230,8 @@
LANG_HOOKS_SET_BLOCK, \
LANG_HOOKS_PUSHDECL, \
LANG_HOOKS_GETDECLS, \
- LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL \
+ LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL, \
+ LANG_HOOKS_WRITE_GLOBALS \
}
/* The whole thing. The structure is defined in langhooks.h. */
Index: gcc/langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.50
diff -u -r1.50 langhooks.h
--- gcc/langhooks.h 12 Feb 2003 21:48:57 -0000 1.50
+++ gcc/langhooks.h 14 Feb 2003 21:04:59 -0000
@@ -176,6 +176,10 @@
/* Returns true when we should warn for an unused global DECL.
We will already have checked that it has static binding. */
bool (*warn_unused_global) PARAMS ((tree));
+
+ /* Obtain a list of globals and do final output on them at end
+ of compilation */
+ void (*final_write_globals) PARAMS ((void));
};
/* Language-specific hooks. See langhooks-def.h for defaults. */
Index: gcc/toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.709
diff -u -r1.709 toplev.c
--- gcc/toplev.c 12 Feb 2003 21:48:57 -0000 1.709
+++ gcc/toplev.c 14 Feb 2003 21:04:59 -0000
@@ -1934,7 +1934,8 @@
decl = vec[i];
/* We're not deferring this any longer. */
- DECL_DEFER_OUTPUT (decl) = 0;
+ if (DECL_DEFER_OUTPUT (decl) != 0)
+ DECL_DEFER_OUTPUT (decl) = 0;
if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
(*lang_hooks.finish_incomplete_decl) (decl);
@@ -2141,8 +2142,6 @@
static void
compile_file ()
{
- tree globals;
-
/* Initialize yet another pass. */
init_final (main_input_filename);
@@ -2165,25 +2164,7 @@
if (flag_syntax_only)
return;
- globals = (*lang_hooks.decls.getdecls) ();
-
- /* Really define vars that have had only a tentative definition.
- Really output inline functions that must actually be callable
- and have not been output so far. */
-
- {
- int len = list_length (globals);
- tree *vec = (tree *) xmalloc (sizeof (tree) * len);
- int i;
- tree decl;
-
- /* Process the decls in reverse order--earliest first.
- Put them into VEC from back to front, then take out from front.
*/
-
- for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
- vec[len - i - 1] = decl;
-
- wrapup_global_declarations (vec, len);
+ (*lang_hooks.decls.final_write_globals)();
if (profile_arc_flag)
/* This must occur after the loop to output deferred functions.
@@ -2191,12 +2172,6 @@
functions in this compilation unit were deferred. */
create_profiler ();
- check_global_declarations (vec, len);
-
- /* Clean up. */
- free (vec);
- }
-
/* Write out any pending weak symbol declarations. */
weak_finish ();
@@ -2247,6 +2222,36 @@
close_dump_file (DFI_combine, NULL, NULL_RTX);
timevar_pop (TV_DUMP);
}
+}
+
+/* Default for lang_hooks.decls.final_write_globals */
+void write_global_declarations ()
+{
+ tree globals = (*lang_hooks.decls.getdecls) ();
+
+ /* Really define vars that have had only a tentative definition.
+ Really output inline functions that must actually be callable
+ and have not been output so far. */
+
+ {
+ int len = list_length (globals);
+ tree *vec = (tree *) xmalloc (sizeof (tree) * len);
+ int i;
+ tree decl;
+
+ /* Process the decls in reverse order--earliest first.
+ Put them into VEC from back to front, then take out from front.
*/
+
+ for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
+ vec[len - i - 1] = decl;
+
+ wrapup_global_declarations (vec, len);
+
+ check_global_declarations (vec, len);
+
+ /* Clean up. */
+ free (vec);
+ }
}
/* This is called from various places for FUNCTION_DECL, VAR_DECL,
Index: gcc/cp/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.3196
diff -u -r1.3196 ChangeLog
--- gcc/cp/ChangeLog 14 Feb 2003 06:04:39 -0000 1.3196
+++ gcc/cp/ChangeLog 14 Feb 2003 21:05:00 -0000
@@ -1,3 +1,9 @@
+2003-02-14 Matt Austern <austern@apple.com>
+ * cp/cp-lang.c: Change lang hooks so that final_write_globals does
+ nothing for C++.
+ * cp/decl.c (wrapup_globals_for_namespace): Remove special
+ handling of global namespace.
+
2003-02-13 Gabriel Dos Reis <gdr@integrable-solutions.net>
* decl2.c: Include "timevar.h".
Index: gcc/cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.46
diff -u -r1.46 cp-lang.c
--- gcc/cp/cp-lang.c 1 Jan 2003 11:58:57 -0000 1.46
+++ gcc/cp/cp-lang.c 14 Feb 2003 21:05:00 -0000
@@ -92,6 +92,9 @@
#define LANG_HOOKS_PRINT_ERROR_FUNCTION cxx_print_error_function
#undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
#define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL cxx_warn_unused_global_decl
+#undef LANG_HOOKS_WRITE_GLOBALS
+#define LANG_HOOKS_WRITE_GLOBALS lhd_do_nothing
+
#undef LANG_HOOKS_FUNCTION_INIT
#define LANG_HOOKS_FUNCTION_INIT cxx_push_function_context
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.997
diff -u -r1.997 decl.c
--- gcc/cp/decl.c 13 Feb 2003 08:10:27 -0000 1.997
+++ gcc/cp/decl.c 14 Feb 2003 21:05:00 -0000
@@ -1855,10 +1855,6 @@
tree decl;
int last_time = (data != 0);
- if (last_time && namespace == global_namespace)
- /* Let compile_file handle the global namespace. */
- return 0;
-
/* Process the decls in reverse order--earliest first.
Put them into VEC from back to front, then take out from front.
*/
for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))