This is the mail archive of the gcc@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]

Re: Varray memory consumption strikes back


> 
> 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;
}

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