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]

Cut down memory usage in dwarf2out.c


Hello,

decl_die_table is pretty sparse.
This patch changes it from simple array indexed by DECL_UID
to a hash table whose key is decl_uid.
It saves 2MB of 145 MB with "-g -O3" (~11 MB is caused by "-g") on Gerald's
testacse.

Bootstrapped/regtested x86-64.
OK for mainline and the branch?

Joe

2004-01-27  Josef Zlomek  <zlomekj@suse.cz>

	* dwarf2out.c (struct die_struct): Added field decl_id.
	(decl_die_table): Changed to hash table.
	(decl_die_table_allocated): Deleted.
	(decl_die_table_in_use): Deleted.
	(DECL_DIE_TABLE_INCREMENT): Deleted.
	(decl_die_table_hash): New function.
	(decl_die_table_eq): New function.
	(lookup_decl_die): Lookup in a hash table.
	(equate_decl_number_to_die): Insert into a hash table.
	(dwarf2out_init): Init hash table decl_die_table.

Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.480
diff -c -3 -p -r1.480 dwarf2out.c
*** dwarf2out.c	20 Jan 2004 22:29:20 -0000	1.480
--- dwarf2out.c	27 Jan 2004 21:15:42 -0000
*************** typedef struct die_struct GTY(())
*** 3351,3356 ****
--- 3351,3357 ----
    dw_offset die_offset;
    unsigned long die_abbrev;
    int die_mark;
+   unsigned int decl_id;
  }
  die_node;
  
*************** static GTY(()) varray_type file_table;
*** 3468,3487 ****
  static GTY(()) varray_type file_table_emitted;
  static GTY(()) size_t file_table_last_lookup_index;
  
! /* A pointer to the base of a table of references to DIE's that describe
!    declarations.  The table is indexed by DECL_UID() which is a unique
!    number identifying each decl.  */
! static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
! 
! /* Number of elements currently allocated for the decl_die_table.  */
! static GTY(()) unsigned decl_die_table_allocated;
! 
! /* Number of elements in decl_die_table currently in use.  */
! static GTY(()) unsigned decl_die_table_in_use;
! 
! /* Size (in elements) of increments by which we may expand the
!    decl_die_table.  */
! #define DECL_DIE_TABLE_INCREMENT 256
  
  /* A pointer to the base of a list of references to DIE's that
     are uniquely identified by their tag, presence/absence of
--- 3469,3477 ----
  static GTY(()) varray_type file_table_emitted;
  static GTY(()) size_t file_table_last_lookup_index;
  
! /* A hash table of references to DIE's that describe declarations.
!    The key is a DECL_UID() which is a unique number identifying each decl.  */
! static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
  
  /* A pointer to the base of a list of references to DIE's that
     are uniquely identified by their tag, presence/absence of
*************** static void add_child_die (dw_die_ref, d
*** 3653,3658 ****
--- 3643,3650 ----
  static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
  static dw_die_ref lookup_type_die (tree);
  static void equate_type_number_to_die (tree, dw_die_ref);
+ static hashval_t decl_die_table_hash (const void *);
+ static int decl_die_table_eq (const void *, const void *);
  static dw_die_ref lookup_decl_die (tree);
  static void equate_decl_number_to_die (tree, dw_die_ref);
  static void print_spaces (FILE *);
*************** equate_type_number_to_die (tree type, dw
*** 5177,5190 ****
    TYPE_SYMTAB_DIE (type) = type_die;
  }
  
  /* Return the DIE associated with a given declaration.  */
  
  static inline dw_die_ref
  lookup_decl_die (tree decl)
  {
!   unsigned decl_id = DECL_UID (decl);
! 
!   return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
  }
  
  /* Equate a DIE to a particular declaration.  */
--- 5169,5196 ----
    TYPE_SYMTAB_DIE (type) = type_die;
  }
  
+ /* Returns a hash value for X (which really is a die_struct).  */
+ 
+ static hashval_t
+ decl_die_table_hash (const void *x)
+ {
+   return (hashval_t) ((const dw_die_ref) x)->decl_id;
+ }
+ 
+ /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y.  */
+ 
+ static int
+ decl_die_table_eq (const void *x, const void *y)
+ {
+   return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y));
+ }
+ 
  /* Return the DIE associated with a given declaration.  */
  
  static inline dw_die_ref
  lookup_decl_die (tree decl)
  {
!   return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
  }
  
  /* Equate a DIE to a particular declaration.  */
*************** static void
*** 5193,5219 ****
  equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
  {
    unsigned int decl_id = DECL_UID (decl);
!   unsigned int num_allocated;
! 
!   if (decl_id >= decl_die_table_allocated)
!     {
!       num_allocated
! 	= ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
! 	   / DECL_DIE_TABLE_INCREMENT)
! 	  * DECL_DIE_TABLE_INCREMENT;
! 
!       decl_die_table = ggc_realloc (decl_die_table,
! 				    sizeof (dw_die_ref) * num_allocated);
! 
!       memset (&decl_die_table[decl_die_table_allocated], 0,
! 	     (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
!       decl_die_table_allocated = num_allocated;
!     }
! 
!   if (decl_id >= decl_die_table_in_use)
!     decl_die_table_in_use = (decl_id + 1);
  
!   decl_die_table[decl_id] = decl_die;
  }
  
  /* Keep track of the number of spaces used to indent the
--- 5199,5209 ----
  equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
  {
    unsigned int decl_id = DECL_UID (decl);
!   void **slot;
  
!   slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
!   *slot = decl_die;
!   decl_die->decl_id = decl_id;
  }
  
  /* Keep track of the number of spaces used to indent the
*************** dwarf2out_init (const char *filename ATT
*** 12554,12563 ****
    init_file_table ();
  
    /* Allocate the initial hunk of the decl_die_table.  */
!   decl_die_table = ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT
! 				      * sizeof (dw_die_ref));
!   decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
!   decl_die_table_in_use = 0;
  
    /* Allocate the initial hunk of the decl_scope_table.  */
    VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
--- 12544,12551 ----
    init_file_table ();
  
    /* Allocate the initial hunk of the decl_die_table.  */
!   decl_die_table = htab_create_ggc (10, decl_die_table_hash,
! 				    decl_die_table_eq, NULL);
  
    /* Allocate the initial hunk of the decl_scope_table.  */
    VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");


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