This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Varray memory consumption strikes back
- From: Jan Hubicka <jh at suse dot cz>
- To: Jan Hubicka <jh at suse dot cz>, Jeffrey A Law <law at redhat dot com>,gcc at gcc dot gnu dot org, amacleod at redhat dot com
- Date: Wed, 6 Oct 2004 22:17:21 +0200
- Subject: Re: Varray memory consumption strikes back
- References: <20040904095915.GV1947@kam.mff.cuni.cz> <1094317419.2919.9.camel@localhost.localdomain> <20040904213324.GI15137@kam.mff.cuni.cz> <1095137295.10968.305.camel@localhost.localdomain> <20040914151414.GU10129@kam.mff.cuni.cz> <1095352487.10968.1594.camel@localhost.localdomain> <20040916220328.GZ3692@kam.mff.cuni.cz> <1095911109.11715.44.camel@localhost.localdomain> <20041006195934.GW10273@kam.mff.cuni.cz> <20041006200632.GA16973@nevyn.them.org>
>
> Eh? obstack_free is precisely a pop operation.
Well, for obstack_free you need to know the address of object you want
to pop off the stack, so it is not exactly what I need ;)
>
> > This is stack implementation that don't use resizing and ggc. I converted the
> > dom's stacks to it and it seems to be resonably fast. On Gerald's testcase it
> > redues compilation time from 1m14.581s to 1m14.025s (consistently) and memory
> > footprint from 89MB to 80.
> >
> > While measuring the bootstrap speed, the difference seems to be winthin noise.
>
> You didn't include the new files.
Oops...
Attached.
Honza
>
> --
> Daniel Jacobowitz
/* stack of pointers
Copyright (C) 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef GCC_PTRSTACK_H
#define GCC_PTRSTACK_H
struct ptrstack {
struct ptrstack *prev;
unsigned int size, used;
void *data[1];
};
typedef struct ptrstack *ptrstack;
ptrstack ptrstack_create (void);
void ptrstack_free (ptrstack);
ptrstack ptrstack_grow_internal (ptrstack);
/* Push VALUE to STACK_HEADER. */
static inline void
ptrstack_push (ptrstack stack_header, void *value)
{
ptrstack stack = stack_header->prev;
if (stack->size == stack->used)
stack = ptrstack_grow_internal (stack_header);
stack->data[stack->used++] = value;
}
/* Pop value out of STACK_HEADER and return it. */
static inline void *
ptrstack_pop (ptrstack stack_header)
{
ptrstack stack = stack_header->prev;
gcc_assert (stack->used || stack->prev != stack);
if (!stack->used)
{
ptrstack oldstack = stack->prev;
free (stack);
stack = stack_header->prev = oldstack;
}
return stack->data[--stack->used];
}
/* Return top value of STACK_HEADER. */
static inline void *
ptrstack_top (ptrstack stack_header)
{
ptrstack stack = stack_header->prev;
gcc_assert (stack->used || stack->prev != stack);
if (!stack->used)
{
ptrstack oldstack = stack->prev;
free (stack);
stack = stack_header->prev = oldstack;
}
return stack->data[stack->used - 1];
}
/* Return true IFF the stack is empty. */
static inline bool
ptrstack_empty_p (ptrstack stack)
{
return !stack->used;
}
#endif
/* stack of pointers
Copyright (C) 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "ptrstack.h"
#define DEFAULT_PTRSTACK_SIZE 256
/* Create empty stack. */
ptrstack
ptrstack_create (void)
{
ptrstack stack =
xmalloc (sizeof (struct ptrstack) +
(DEFAULT_PTRSTACK_SIZE - 1) * sizeof (void *));
stack->prev = stack;
stack->size = DEFAULT_PTRSTACK_SIZE;
stack->used = 0;
return stack;
}
/* Free empty stack. */
void
ptrstack_free (ptrstack stack)
{
gcc_assert (stack->prev && !stack->used && stack->prev == stack);
stack->prev = NULL;
free (stack);
}
/* Helper function for ptrstack_push - allocate new memory container. */
ptrstack
ptrstack_grow_internal (ptrstack stack_header)
{
ptrstack stack = stack_header->prev;
ptrstack newstack;
size_t newsize = (size_t) stack->size + (size_t) stack->size / 2;
if (newsize > 65536)
newsize = 65536;
newstack = xmalloc (sizeof (struct ptrstack) + (newsize - 1) * sizeof (void *));
newstack->prev = stack;
newstack->size = newsize;
newstack->used = 0;
stack_header->prev = newstack;
return newstack;
}