On 09/04/14 03:42, Richard Biener wrote: > On Wed, Sep 3, 2014 at 7:54 PM, Aldy Hernandez wrote: > Flow-wise I still want to move hand-off to the cgraph code to toplev.c, > out from the FEs final_write_gloabals hook: > > /* This must also call finalize_compilation_unit. */ > lang_hooks.decls.final_write_globals (); > > that would make clearer how control flows. Neat. I like it. > I'd also rather split the hook into two ... (and call the 2nd non-early > phase hook from where we output the code). What does that phase > output for global decls anyway? This is also a very good idea, and it makes the intent clearer. > Otherwise looks like a good incremental improvement to me. Since we're pretty much on the same page, I've committed this revision you just looked at, so we can talk about the changes you mention above separately, namely: a) Divorcing final_write_globals and finalize_compilation. b) Splitting the global_decl hook into two. So this is what I have in mind (patch attached). I'd like to split LANG_HOOKS_WRITE_GLOBALS in favor of LANG_HOOKS_{EARLY,LATE}_WRITE_GLOBALS, as well as splitting the global_decl debug hook into {early,late}_global_decl. I've commented things throughout to make it very clear what we're getting at. I chose to dispense with the old names to make it very clear what the hook should do, and to make sure I didn't miss any places. Toplev will now look much cleaner: + /* Emit early debugging information as well as globals. */ + timevar_start (TV_PHASE_DEFERRED); + lang_hooks.decls.early_write_globals (); + timevar_stop (TV_PHASE_DEFERRED); + + /* We're done parsing; proceed to optimize and emit assembly. */ + timevar_start (TV_PHASE_OPT_GEN); + symtab->finalize_compilation_unit (); + timevar_stop (TV_PHASE_OPT_GEN); + + /* Amend any debugging information generated previously. */ + timevar_start (TV_PHASE_DBGINFO); + lang_hooks.decls.late_write_globals (); + timevar_stop (TV_PHASE_DBGINFO); Preeeeety... if I do say so myself. The attached patch is untested, and will fail miserably on anything but C (lto, c++, etc). But it shows how I'd like to approach this. Would you bless this approach, so I can continue with the other languages and LTO? As usual, thanks for your feedback. Aldy