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]

[PATCH] Cleanup constant pool in varasm.c


Hi!

Whenever we allocate struct pool_constant, we allocate one struct pool_sym for it
as well and link them together (and pool_sym is never allocated without
corresponding pool_constant), which is why I came with this patch. It should
both save some memory (e.g. on 64bit host pool_constant used to have 48
bytes and pool_sym 24 bytes, now there is just pool_constant which has 60
bytes) and speed things up (there is no need to allocate/free/go through and
ggc mark pool_syms).
Bootstrapped on i386-*-linux, regression tested there as well.

2000-11-06  Jakub Jelinek  <jakub@redhat.com>

	* varasm.c (struct varasm_status): Change x_const_rtx_sym_hash_table
	to array of pool_constnat pointers.
	(struct pool_constant): Add next_sym and label members.
	(struct pool_sym): Remove.
	(init_varasm_status): Change pool_sym into pool_constant.
	(mark_pool_constant): Mark pc->label string as well.
	(mark_pool_sym_hash_table): Remove.
	(mark_varasm_status): Remove it from caller as well.
	(free_varasm_status): Don't free pool_sym structures.
	(force_const_mem): Don't allocate pool_sym structure, instead
	fill pool->label and chain it into rtx_sym hash table.
	(find_pool_constant, mark_constant_pool): Use pool_constant instead
	of pool_sym.

--- gcc/varasm.c.jj	Sun Nov  5 18:53:03 2000
+++ gcc/varasm.c	Mon Nov  6 13:51:51 2000
@@ -101,7 +101,7 @@ struct varasm_status
      so each function gets its own constants-pool that comes right before
      it.  */
   struct constant_descriptor **x_const_rtx_hash_table;
-  struct pool_sym **x_const_rtx_sym_hash_table;
+  struct pool_constant **x_const_rtx_sym_hash_table;
 
   /* Pointers to first and last constant in pool.  */
   struct pool_constant *x_first_pool, *x_last_pool;
@@ -184,7 +184,6 @@ static void asm_output_aligned_bss	PARAM
 #endif
 #endif /* BSS_SECTION_ASM_OP */
 static void mark_pool_constant          PARAMS ((struct pool_constant *));
-static void mark_pool_sym_hash_table	PARAMS ((struct pool_sym **));
 static void mark_const_hash_entry	PARAMS ((void *));
 static void asm_emit_uninitialised	PARAMS ((tree, const char*, int, int));
 
@@ -3211,25 +3210,16 @@ output_constant_def_contents (exp, reloc
 struct pool_constant
 {
   struct constant_descriptor *desc;
-  struct pool_constant *next;
-  enum machine_mode mode;
+  struct pool_constant *next, *next_sym;
+  char *label;
   rtx constant;
+  enum machine_mode mode;
   int labelno;
   int align;
   int offset;
   int mark;
 };
 
-/* Structure used to maintain hash table mapping symbols used to their
-   corresponding constants.  */
-
-struct pool_sym
-{
-  char *label;
-  struct pool_constant *pool;
-  struct pool_sym *next;
-};
-
 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
    The argument is XSTR (... , 0)  */
 
@@ -3249,8 +3239,8 @@ init_varasm_status (f)
     = ((struct constant_descriptor **)
        xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
   p->x_const_rtx_sym_hash_table
-    = ((struct pool_sym **)
-       xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_sym *)));
+    = ((struct pool_constant **)
+       xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
 
   p->x_first_pool = p->x_last_pool = 0;
   p->x_pool_offset = 0;
@@ -3267,24 +3257,11 @@ mark_pool_constant (pc)
     {
       ggc_mark (pc);
       ggc_mark_rtx (pc->constant);
+      ggc_mark_string (pc->label);
       pc = pc->next;
     }
 }
 
-/* Mark PPS for GC.  */
-
-static void
-mark_pool_sym_hash_table (pps)
-     struct pool_sym **pps;
-{
-  struct pool_sym *ps;
-  int i;
-
-  for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
-    for (ps = pps[i]; ps ; ps = ps->next)
-      ggc_mark_string (ps->label);
-}
-
 /* Mark P for GC.  */
 
 void
@@ -3295,7 +3272,6 @@ mark_varasm_status (p)
     return;
 
   mark_pool_constant (p->x_first_pool);
-  mark_pool_sym_hash_table (p->x_const_rtx_sym_hash_table);
   ggc_mark_rtx (p->x_const_double_chain);
 }
 
@@ -3316,7 +3292,6 @@ free_varasm_status (f)
   for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
     {
       struct constant_descriptor* cd;
-      struct pool_sym *ps;
 
       cd = p->x_const_rtx_hash_table[i];
       while (cd) {
@@ -3324,13 +3299,6 @@ free_varasm_status (f)
 	free (cd);
 	cd = next;
       }
-
-      ps = p->x_const_rtx_sym_hash_table[i];
-      while (ps) {
-	struct pool_sym *next = ps->next;
-	free (ps);
-	ps = next;
-      }
     }
 
   free (p->x_const_rtx_hash_table);
@@ -3554,7 +3522,6 @@ force_const_mem (mode, x)
   if (found == 0)
     {
       register struct pool_constant *pool;
-      register struct pool_sym *sym;
       int align;
 
       /* No constant equal to X is known to have been output.
@@ -3607,11 +3574,9 @@ force_const_mem (mode, x)
 
       /* Add label to symbol hash table.  */
       hash = SYMHASH (found);
-      sym = (struct pool_sym *) xmalloc (sizeof (struct pool_sym));
-      sym->label = found;
-      sym->pool = pool;
-      sym->next = const_rtx_sym_hash_table[hash];
-      const_rtx_sym_hash_table[hash] = sym;
+      pool->label = found;
+      pool->next_sym = const_rtx_sym_hash_table[hash];
+      const_rtx_sym_hash_table[hash] = pool;
     }
 
   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
@@ -3645,13 +3610,13 @@ find_pool_constant (f, addr)
      struct function *f;
      rtx addr;
 {
-  struct pool_sym *sym;
+  struct pool_constant *pool;
   const char *label = XSTR (addr, 0);
 
-  for (sym = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; sym;
-       sym = sym->next)
-    if (sym->label == label)
-      return sym->pool;
+  for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
+       pool = pool->next_sym)
+    if (pool->label == label)
+      return pool;
 
   abort ();
 }
@@ -3858,7 +3823,7 @@ mark_constant_pool ()
      not clear that 2'd level references can happen. */
   for (pool = first_pool; pool; pool = pool->next)
     {
-      struct pool_sym *sym;
+      struct pool_constant *tem;
       const char *label;
 
       /* skip unmarked entries; no insn refers to them. */
@@ -3871,10 +3836,10 @@ mark_constant_pool ()
       label = XSTR (pool->constant, 0);
 
       /* Be sure the symbol's value is marked. */
-      for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; 
-           sym = sym->next)
-	  if (sym->label == label)
-	    sym->pool->mark = 1;
+      for (tem = const_rtx_sym_hash_table[SYMHASH (label)]; tem; 
+           tem = tem->next)
+	  if (tem->label == label)
+	    tem->mark = 1;
       /* If we didn't find it, there's something truly wrong here, but it
 	 will be announced by the assembler. */
     }

	Jakub

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