When looking at PR60060, outputting the declaration debug info for
a local static variable twice (once via BLOCK_VARS and once via
calling the debug hook on all globals) I noticed that the
rest_of_decl_compilation call in materialize_cgraph always works
on the empty lto_global_var_decls vector (we only populate it
later).  That results in the opportunity to effectively remove it
and in lto_write_globals walk over the defined vars in the
varpool instead.

Eventually the fix for PR60060 is to not push TREE_ASM_WRITTEN
decls there (but I'm not sure of other side-effects of that ...).

Thus, this cleanup first.

LTO bootstrap / regtest running on x86_64-unknown-linux-gnu.

Ok?

Thanks,
Richard.

2014-02-05  Richard Biener  <rguent...@suse.de>

        lto/
        * lto.h (lto_global_var_decls): Remove.
        * lto-lang.c (lto_init): Do not allocate lto_global_var_decls.
        (lto_write_globals): Do nothing in WPA stage, gather globals from
        the varpool here ...
        * lto.c (lto_main): ... not here.
        (materialize_cgraph): Do not call rest_of_decl_compilation
        on the empty lto_global_var_decls vector.
        (lto_global_var_decls): Remove.

Index: gcc/lto/lto-lang.c
===================================================================
*** gcc/lto/lto-lang.c  (revision 207497)
--- gcc/lto/lto-lang.c  (working copy)
*************** lto_getdecls (void)
*** 1075,1085 ****
  static void
  lto_write_globals (void)
  {
!   tree *vec = lto_global_var_decls->address ();
!   int len = lto_global_var_decls->length ();
    wrapup_global_declarations (vec, len);
    emit_debug_global_declarations (vec, len);
!   vec_free (lto_global_var_decls);
  }
  
  static tree
--- 1075,1094 ----
  static void
  lto_write_globals (void)
  {
!   if (flag_wpa)
!     return;
! 
!   /* Record the global variables.  */
!   vec<tree> lto_global_var_decls = vNULL;
!   varpool_node *vnode;
!   FOR_EACH_DEFINED_VARIABLE (vnode)
!     lto_global_var_decls.safe_push (vnode->decl);
! 
!   tree *vec = lto_global_var_decls.address ();
!   int len = lto_global_var_decls.length ();
    wrapup_global_declarations (vec, len);
    emit_debug_global_declarations (vec, len);
!   lto_global_var_decls.release ();
  }
  
  static tree
*************** lto_init (void)
*** 1218,1224 ****
  #undef NAME_TYPE
  
    /* Initialize LTO-specific data structures.  */
-   vec_alloc (lto_global_var_decls, 256);
    in_lto_p = true;
  
    return true;
--- 1227,1232 ----
Index: gcc/lto/lto.c
===================================================================
*** gcc/lto/lto.c       (revision 207497)
--- gcc/lto/lto.c       (working copy)
*************** along with GCC; see the file COPYING3.
*** 50,57 ****
  #include "context.h"
  #include "pass_manager.h"
  
- /* Vector to keep track of external variables we've seen so far.  */
- vec<tree, va_gc> *lto_global_var_decls;
  
  static GTY(()) tree first_personality_decl;
  
--- 50,55 ----
*************** read_cgraph_and_symbols (unsigned nfiles
*** 3009,3017 ****
  static void
  materialize_cgraph (void)
  {
-   tree decl;
    struct cgraph_node *node; 
-   unsigned i;
    timevar_id_t lto_timer;
  
    if (!quiet_flag)
--- 3007,3013 ----
*************** materialize_cgraph (void)
*** 3043,3052 ****
    current_function_decl = NULL;
    set_cfun (NULL);
  
-   /* Inform the middle end about the global variables we have seen.  */
-   FOR_EACH_VEC_ELT (*lto_global_var_decls, i, decl)
-     rest_of_decl_compilation (decl, 1, 0);
- 
    if (!quiet_flag)
      fprintf (stderr, "\n");
  
--- 3039,3044 ----
*************** lto_main (void)
*** 3309,3316 ****
        do_whole_program_analysis ();
        else
        {
-         varpool_node *vnode;
- 
          timevar_start (TV_PHASE_OPT_GEN);
  
          materialize_cgraph ();
--- 3301,3306 ----
*************** lto_main (void)
*** 3330,3339 ****
             this.  */
          if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
            print_lto_report_1 ();
- 
-         /* Record the global variables.  */
-         FOR_EACH_DEFINED_VARIABLE (vnode)
-           vec_safe_push (lto_global_var_decls, vnode->decl);
        }
      }
  
--- 3320,3325 ----
Index: gcc/lto/lto.h
===================================================================
*** gcc/lto/lto.h       (revision 207497)
--- gcc/lto/lto.h       (working copy)
*************** extern tree lto_eh_personality (void);
*** 41,49 ****
  extern void lto_main (void);
  extern void lto_read_all_file_options (void);
  
- /* In lto-symtab.c  */
- extern GTY(()) vec<tree, va_gc> *lto_global_var_decls;
- 
  /* In lto-elf.c or lto-coff.c  */
  extern lto_file *lto_obj_file_open (const char *filename, bool writable);
  extern void lto_obj_file_close (lto_file *file);
--- 41,46 ----

Reply via email to