This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PCH] cache memory for cselib_init
- From: Geoffrey Keating <geoffk at romulus dot sfbay dot redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 31 May 2002 02:02:06 -0700
- Subject: [PCH] cache memory for cselib_init
I didn't think cselib_init would get called hundreds of times
to allocate space for thousands of registers, but this happens
while building expr.o on the sparc bootstrap.
Bootstrapped & tested on i686-pc-linux.
--
Geoff Keating <geoffk@redhat.com>
===File ~/patches/pchbranch-csemingc.patch==================
2002-05-30 Geoffrey Keating <geoffk@redhat.com>
* varray.h (VARRAY_CLEAR): New.
(varray_clear): Prototype.
* varray.c (varray_clear): New.
* cselib.c (reg_values_old): New.
(used_regs_old): New.
(cselib_init): Use cached varrays if available to avoid
generating large amounts of garbage.
(cselib_finish): Don't throw away old varrays.
Index: varray.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varray.c,v
retrieving revision 1.14.2.2
diff -p -u -p -r1.14.2.2 varray.c
--- varray.c 23 May 2002 19:28:48 -0000 1.14.2.2
+++ varray.c 31 May 2002 08:10:36 -0000
@@ -106,6 +106,17 @@ varray_grow (va, n)
return va;
}
+/* Reset a varray to its original state. */
+void
+varray_clear (va)
+ varray_type va;
+{
+ size_t data_size = element_size[va->type] * va->num_elements;
+
+ memset (va->data.c, 0, data_size);
+ va->elements_used = 0;
+}
+
/* Check the bounds of a varray access. */
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
Index: varray.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varray.h,v
retrieving revision 1.24.12.5
diff -p -u -p -r1.24.12.5 varray.h
--- varray.h 23 May 2002 19:28:48 -0000 1.24.12.5
+++ varray.h 31 May 2002 08:10:36 -0000
@@ -217,6 +217,10 @@ extern varray_type varray_grow PARAMS ((
#define VARRAY_ACTIVE_SIZE(VA) ((VA)->elements_used)
#define VARRAY_POP_ALL(VA) ((VA)->elements_used = 0)
+#define VARRAY_CLEAR(VA) varray_clear(VA)
+
+extern void varray_clear PARAMS ((varray_type));
+
/* Check for VARRAY_xxx macros being in bound. */
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
extern void varray_check_failed PARAMS ((varray_type, size_t,
Index: cselib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cselib.c,v
retrieving revision 1.15.6.4
diff -p -u -p -r1.15.6.4 cselib.c
--- cselib.c 23 May 2002 19:28:42 -0000 1.15.6.4
+++ cselib.c 31 May 2002 08:10:36 -0000
@@ -101,11 +101,13 @@ static int n_useless_values;
pointers to cselib_val structures, but rather elt_lists. The purpose is
to be able to refer to the same register in different modes. */
static GTY(()) varray_type reg_values;
+static GTY((deletable (""))) varray_type reg_values_old;
#define REG_VALUES(I) VARRAY_ELT_LIST (reg_values, (I))
/* Here the set of indices I with REG_VALUES(I) != 0 is saved. This is used
in clear_table() for fast emptying. */
static GTY(()) varray_type used_regs;
+static GTY((deletable (""))) varray_type used_regs_old;
/* We pass this to cselib_invalidate_mem to invalidate all of
memory for a non-const call instruction. */
@@ -1358,8 +1360,18 @@ cselib_init ()
callmem = gen_rtx_MEM (BLKmode, const0_rtx);
cselib_nregs = max_reg_num ();
- VARRAY_ELT_LIST_INIT (reg_values, cselib_nregs, "reg_values");
- VARRAY_UINT_INIT (used_regs, cselib_nregs, "used_regs");
+ if (reg_values_old != NULL && VARRAY_SIZE (reg_values_old) >= cselib_nregs)
+ {
+ reg_values = reg_values_old;
+ used_regs = used_regs_old;
+ VARRAY_CLEAR (reg_values);
+ VARRAY_CLEAR (used_regs);
+ }
+ else
+ {
+ VARRAY_ELT_LIST_INIT (reg_values, cselib_nregs, "reg_values");
+ VARRAY_UINT_INIT (used_regs, cselib_nregs, "used_regs");
+ }
hash_table = htab_create_ggc (31, get_value_hash, entry_and_rtx_equal_p,
NULL);
clear_table (1);
@@ -1370,7 +1382,9 @@ cselib_init ()
void
cselib_finish ()
{
+ reg_values_old = reg_values;
reg_values = 0;
+ used_regs_old = used_regs;
used_regs = 0;
hash_table = 0;
n_useless_values = 0;
============================================================