austern 03/02/12 14:28:32 Modified: live/gcc3/gcc langhooks-def.h langhooks.h toplev.c live/gcc3/gcc/cp cp-lang.c decl.c Log: Reviewed by: Devang First steps toward improving wrapup_global_declarations performance. Changed an unconditional write to a conditional one (to improve performance in concert with PCH), and reorganized code so that I can change the C++ front end without having to worry about breaking the other front ends. These two changes together yield about a 2.5% improvement. Revision Changes Path 1.18 +10 -1 src/live/gcc3/gcc/langhooks-def.h Index: langhooks-def.h =================================================================== RCS file: /cvs/Darwin/src/live/gcc3/gcc/langhooks-def.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- langhooks-def.h 2002/12/08 00:37:50 1.17 +++ langhooks-def.h 2003/02/12 22:28:30 1.18 @@ -97,6 +97,11 @@ void lhd_tree_inlining_end_inlining PARAMS ((tree)); tree lhd_tree_inlining_convert_parm_for_inlining PARAMS ((tree, tree, tree)); +/* APPLE LOCAL begin improve wrapup_global_declarations performance */ +/* In toplev.c */ +void write_global_declarations PARAMS ((void)); +/* APPLE LOCAL end improve wrapup_global_declarations performance */ + #define LANG_HOOKS_NAME "GNU unknown" #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct lang_identifier) #define LANG_HOOKS_INIT lhd_do_nothing @@ -243,6 +248,9 @@ #define LANG_HOOKS_PUSHDECL pushdecl #define LANG_HOOKS_GETDECLS getdecls #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL lhd_warn_unused_global_decl +/* APPLE LOCAL begin improve wrapup_global_declarations performance */ +#define LANG_HOOKS_WRITE_GLOBALS write_global_declarations +/* APPLE LOCAL end improve wrapup_global_declarations performance */ #define LANG_HOOKS_DECLS { \ LANG_HOOKS_PUSHLEVEL, \ @@ -252,7 +260,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. */ 1.19 +6 -0 src/live/gcc3/gcc/langhooks.h Index: langhooks.h =================================================================== RCS file: /cvs/Darwin/src/live/gcc3/gcc/langhooks.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- langhooks.h 2002/12/08 00:37:50 1.18 +++ langhooks.h 2003/02/12 22:28:30 1.19 @@ -170,6 +170,12 @@ /* 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 */ +/* APPLE LOCAL begin improve wrapup_global_declarations performance */ + void (*final_write_globals) PARAMS ((void)); +/* APPLE LOCAL end improve wrapup_global_declarations performance */ }; /* Language-specific hooks. See langhooks-def.h for defaults. */ 1.174 +40 -27 src/live/gcc3/gcc/toplev.c Index: toplev.c =================================================================== RCS file: /cvs/Darwin/src/live/gcc3/gcc/toplev.c,v retrieving revision 1.173 retrieving revision 1.174 diff -u -r1.173 -r1.174 --- toplev.c 2003/02/12 17:54:34 1.173 +++ toplev.c 2003/02/12 22:28:30 1.174 @@ -2112,7 +2112,10 @@ decl = vec[i]; /* We're not deferring this any longer. */ - DECL_DEFER_OUTPUT (decl) = 0; + /* APPLE LOCAL begin improve wrapup_global_declarations performance */ + if (DECL_DEFER_OUTPUT (decl) != 0) + DECL_DEFER_OUTPUT (decl) = 0; + /* APPLE LOCAL end improve wrapup_global_declarations performance */ if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0) (*lang_hooks.finish_incomplete_decl) (decl); @@ -2325,7 +2328,9 @@ static void compile_file () { - tree globals; + /* APPLE LOCAL begin improve wrapup_global_declarations performance */ + /* Remove declaration of 'globals' */ + /* APPLE LOCAL end improve wrapup_global_declarations performance */ /* Initialize yet another pass. */ @@ -2354,26 +2359,9 @@ if (flag_syntax_only) return; - globals = (*lang_hooks.decls.getdecls) (); + /* APPLE LOCAL begin improve wrapup_global_declarations performance */ + (*lang_hooks.decls.final_write_globals)(); - /* 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); - /* This must occur after the loop to output deferred functions. Else the profiler initializer would not be emitted if all the functions in this compilation unit were deferred. @@ -2382,13 +2370,8 @@ data to need to be output, so it need not be in the deferred function loop above. */ output_func_start_profiler (); + /* APPLE LOCAL end improve wrapup_global_declarations performance */ - check_global_declarations (vec, len); - - /* Clean up. */ - free (vec); - } - /* Write out any pending weak symbol declarations. */ weak_finish (); @@ -2445,6 +2428,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, 1.25 +5 -0 src/live/gcc3/gcc/cp/cp-lang.c Index: cp-lang.c =================================================================== RCS file: /cvs/Darwin/src/live/gcc3/gcc/cp/cp-lang.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- cp-lang.c 2002/12/18 00:32:12 1.24 +++ cp-lang.c 2003/02/12 22:28:31 1.25 @@ -102,6 +102,11 @@ #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 +/* APPLE LOCAL begin improve wrapup_global_declarations performance */ +#undef LANG_HOOKS_WRITE_GLOBALS +#define LANG_HOOKS_WRITE_GLOBALS lhd_do_nothing +/* APPLE LOCAL end improve wrapup_global_declarations performance */ + #undef LANG_HOOKS_FUNCTION_INIT #define LANG_HOOKS_FUNCTION_INIT cxx_push_function_context 1.128 +3 -3 src/live/gcc3/gcc/cp/decl.c Index: decl.c =================================================================== RCS file: /cvs/Darwin/src/live/gcc3/gcc/cp/decl.c,v retrieving revision 1.127 retrieving revision 1.128 diff -u -r1.127 -r1.128 --- decl.c 2003/01/22 06:03:27 1.127 +++ decl.c 2003/02/12 22:28:31 1.128 @@ -1944,9 +1944,9 @@ tree decl; int last_time = (data != 0); - if (last_time && namespace == global_namespace) - /* Let compile_file handle the global namespace. */ - return 0; + /* APPLE LOCAL begin improve wrapup_global_declarations performance */ + /* Remove early return for the global namespace */ + /* APPLE LOCAL end improve wrapup_global_declarations performance */ /* Process the decls in reverse order--earliest first. Put them into VEC from back to front, then take out from front. */