OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [varray.c] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* Virtual array support.
/* Virtual array support.
   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007
   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Cygnus Solutions.
   Contributed by Cygnus Solutions.
 
 
   This file is part of GCC.
   This file is part of GCC.
 
 
   GCC is free software; you can redistribute it and/or modify it
   GCC is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
   any later version.
 
 
   GCC is distributed in the hope that it will be useful, but WITHOUT
   GCC is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   License for more details.
   License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with GCC; see the file COPYING3.  If not see
   along with GCC; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */
   <http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
#include "toplev.h"
#include "toplev.h"
#include "varray.h"
#include "varray.h"
#include "ggc.h"
#include "ggc.h"
#include "hashtab.h"
#include "hashtab.h"
 
 
#define VARRAY_HDR_SIZE (sizeof (struct varray_head_tag) - sizeof (varray_data))
#define VARRAY_HDR_SIZE (sizeof (struct varray_head_tag) - sizeof (varray_data))
 
 
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
 
 
/* Store information about each particular varray.  */
/* Store information about each particular varray.  */
struct varray_descriptor
struct varray_descriptor
{
{
  const char *name;
  const char *name;
  int allocated;
  int allocated;
  int created;
  int created;
  int resized;
  int resized;
  int copied;
  int copied;
};
};
 
 
/* Hashtable mapping varray names to descriptors.  */
/* Hashtable mapping varray names to descriptors.  */
static htab_t varray_hash;
static htab_t varray_hash;
 
 
/* Hashtable helpers.  */
/* Hashtable helpers.  */
static hashval_t
static hashval_t
hash_descriptor (const void *p)
hash_descriptor (const void *p)
{
{
  const struct varray_descriptor *d = p;
  const struct varray_descriptor *d = p;
  return htab_hash_pointer (d->name);
  return htab_hash_pointer (d->name);
}
}
static int
static int
eq_descriptor (const void *p1, const void *p2)
eq_descriptor (const void *p1, const void *p2)
{
{
  const struct varray_descriptor *d = p1;
  const struct varray_descriptor *d = p1;
  return d->name == p2;
  return d->name == p2;
}
}
 
 
/* For given name, return descriptor, create new if needed.  */
/* For given name, return descriptor, create new if needed.  */
static struct varray_descriptor *
static struct varray_descriptor *
varray_descriptor (const char *name)
varray_descriptor (const char *name)
{
{
  struct varray_descriptor **slot;
  struct varray_descriptor **slot;
 
 
  if (!varray_hash)
  if (!varray_hash)
    varray_hash = htab_create (10, hash_descriptor, eq_descriptor, NULL);
    varray_hash = htab_create (10, hash_descriptor, eq_descriptor, NULL);
 
 
  slot = (struct varray_descriptor **)
  slot = (struct varray_descriptor **)
    htab_find_slot_with_hash (varray_hash, name,
    htab_find_slot_with_hash (varray_hash, name,
                              htab_hash_pointer (name),
                              htab_hash_pointer (name),
                              1);
                              1);
  if (*slot)
  if (*slot)
    return *slot;
    return *slot;
  *slot = xcalloc (sizeof (**slot), 1);
  *slot = xcalloc (sizeof (**slot), 1);
  (*slot)->name = name;
  (*slot)->name = name;
  return *slot;
  return *slot;
}
}
#endif
#endif
 
 
/* Do not add any more non-GC items here.  Please either remove or GC
/* Do not add any more non-GC items here.  Please either remove or GC
   those items that are not GCed.  */
   those items that are not GCed.  */
 
 
static const struct {
static const struct {
  unsigned char size;
  unsigned char size;
  bool uses_ggc;
  bool uses_ggc;
} element[NUM_VARRAY_DATA] = {
} element[NUM_VARRAY_DATA] = {
  { sizeof (char), 1 },
  { sizeof (char), 1 },
  { sizeof (unsigned char), 1 },
  { sizeof (unsigned char), 1 },
  { sizeof (short), 1 },
  { sizeof (short), 1 },
  { sizeof (unsigned short), 1 },
  { sizeof (unsigned short), 1 },
  { sizeof (int), 1 },
  { sizeof (int), 1 },
  { sizeof (unsigned int), 1 },
  { sizeof (unsigned int), 1 },
  { sizeof (long), 1 },
  { sizeof (long), 1 },
  { sizeof (unsigned long), 1 },
  { sizeof (unsigned long), 1 },
  { sizeof (HOST_WIDE_INT), 1 },
  { sizeof (HOST_WIDE_INT), 1 },
  { sizeof (unsigned HOST_WIDE_INT), 1 },
  { sizeof (unsigned HOST_WIDE_INT), 1 },
  { sizeof (void *), 1 },
  { sizeof (void *), 1 },
  { sizeof (void *), 0 },
  { sizeof (void *), 0 },
  { sizeof (char *), 1 },
  { sizeof (char *), 1 },
  { sizeof (struct rtx_def *), 1 },
  { sizeof (struct rtx_def *), 1 },
  { sizeof (struct rtvec_def *), 1 },
  { sizeof (struct rtvec_def *), 1 },
  { sizeof (union tree_node *), 1 },
  { sizeof (union tree_node *), 1 },
  { sizeof (struct bitmap_head_def *), 1 },
  { sizeof (struct bitmap_head_def *), 1 },
  { sizeof (struct reg_info_def *), 0 },
  { sizeof (struct reg_info_def *), 0 },
  { sizeof (struct basic_block_def *), 1 },
  { sizeof (struct basic_block_def *), 1 },
  { sizeof (struct elt_list *), 1 },
  { sizeof (struct elt_list *), 1 },
  { sizeof (struct edge_def *), 1 },
  { sizeof (struct edge_def *), 1 },
  { sizeof (tree *), 1 },
  { sizeof (tree *), 1 },
};
};
 
 
/* Allocate a virtual array with NUM_ELEMENT elements, each of which is
/* Allocate a virtual array with NUM_ELEMENT elements, each of which is
   ELEMENT_SIZE bytes long, named NAME.  Array elements are zeroed.  */
   ELEMENT_SIZE bytes long, named NAME.  Array elements are zeroed.  */
varray_type
varray_type
varray_init (size_t num_elements, enum varray_data_enum element_kind,
varray_init (size_t num_elements, enum varray_data_enum element_kind,
             const char *name)
             const char *name)
{
{
  size_t data_size = num_elements * element[element_kind].size;
  size_t data_size = num_elements * element[element_kind].size;
  varray_type ptr;
  varray_type ptr;
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
  struct varray_descriptor *desc = varray_descriptor (name);
  struct varray_descriptor *desc = varray_descriptor (name);
 
 
  desc->created++;
  desc->created++;
  desc->allocated += data_size + VARRAY_HDR_SIZE;
  desc->allocated += data_size + VARRAY_HDR_SIZE;
#endif
#endif
  if (element[element_kind].uses_ggc)
  if (element[element_kind].uses_ggc)
    ptr = ggc_alloc_cleared (VARRAY_HDR_SIZE + data_size);
    ptr = ggc_alloc_cleared (VARRAY_HDR_SIZE + data_size);
  else
  else
    ptr = xcalloc (VARRAY_HDR_SIZE + data_size, 1);
    ptr = xcalloc (VARRAY_HDR_SIZE + data_size, 1);
 
 
  ptr->num_elements = num_elements;
  ptr->num_elements = num_elements;
  ptr->elements_used = 0;
  ptr->elements_used = 0;
  ptr->type = element_kind;
  ptr->type = element_kind;
  ptr->name = name;
  ptr->name = name;
  return ptr;
  return ptr;
}
}
 
 
/* Grow/shrink the virtual array VA to N elements.  Zero any new elements
/* Grow/shrink the virtual array VA to N elements.  Zero any new elements
   allocated.  */
   allocated.  */
varray_type
varray_type
varray_grow (varray_type va, size_t n)
varray_grow (varray_type va, size_t n)
{
{
  size_t old_elements = va->num_elements;
  size_t old_elements = va->num_elements;
  if (n != old_elements)
  if (n != old_elements)
    {
    {
      size_t elem_size = element[va->type].size;
      size_t elem_size = element[va->type].size;
      size_t old_data_size = old_elements * elem_size;
      size_t old_data_size = old_elements * elem_size;
      size_t data_size = n * elem_size;
      size_t data_size = n * elem_size;
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
      struct varray_descriptor *desc = varray_descriptor (va->name);
      struct varray_descriptor *desc = varray_descriptor (va->name);
      varray_type oldva = va;
      varray_type oldva = va;
 
 
      if (data_size > old_data_size)
      if (data_size > old_data_size)
        desc->allocated += data_size - old_data_size;
        desc->allocated += data_size - old_data_size;
      desc->resized ++;
      desc->resized ++;
#endif
#endif
 
 
 
 
      if (element[va->type].uses_ggc)
      if (element[va->type].uses_ggc)
        va = ggc_realloc (va, VARRAY_HDR_SIZE + data_size);
        va = ggc_realloc (va, VARRAY_HDR_SIZE + data_size);
      else
      else
        va = xrealloc (va, VARRAY_HDR_SIZE + data_size);
        va = xrealloc (va, VARRAY_HDR_SIZE + data_size);
      va->num_elements = n;
      va->num_elements = n;
      if (n > old_elements)
      if (n > old_elements)
        memset (&va->data.vdt_c[old_data_size], 0, data_size - old_data_size);
        memset (&va->data.vdt_c[old_data_size], 0, data_size - old_data_size);
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
      if (oldva != va)
      if (oldva != va)
        desc->copied++;
        desc->copied++;
#endif
#endif
    }
    }
 
 
  return va;
  return va;
}
}
 
 
/* Reset a varray to its original state.  */
/* Reset a varray to its original state.  */
void
void
varray_clear (varray_type va)
varray_clear (varray_type va)
{
{
  size_t data_size = element[va->type].size * va->num_elements;
  size_t data_size = element[va->type].size * va->num_elements;
 
 
  memset (va->data.vdt_c, 0, data_size);
  memset (va->data.vdt_c, 0, data_size);
  va->elements_used = 0;
  va->elements_used = 0;
}
}
 
 
/* Check the bounds of a varray access.  */
/* Check the bounds of a varray access.  */
 
 
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
 
 
void
void
varray_check_failed (varray_type va, size_t n, const char *file, int line,
varray_check_failed (varray_type va, size_t n, const char *file, int line,
                     const char *function)
                     const char *function)
{
{
  internal_error ("virtual array %s[%lu]: element %lu out of bounds "
  internal_error ("virtual array %s[%lu]: element %lu out of bounds "
                  "in %s, at %s:%d",
                  "in %s, at %s:%d",
                  va->name, (unsigned long) va->num_elements, (unsigned long) n,
                  va->name, (unsigned long) va->num_elements, (unsigned long) n,
                  function, trim_filename (file), line);
                  function, trim_filename (file), line);
}
}
 
 
void
void
varray_underflow (varray_type va, const char *file, int line,
varray_underflow (varray_type va, const char *file, int line,
                  const char *function)
                  const char *function)
{
{
  internal_error ("underflowed virtual array %s in %s, at %s:%d",
  internal_error ("underflowed virtual array %s in %s, at %s:%d",
                  va->name, function, trim_filename (file), line);
                  va->name, function, trim_filename (file), line);
}
}
 
 
#endif
#endif
 
 
 
 
/* Output per-varray statistics.  */
/* Output per-varray statistics.  */
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
 
 
/* Used to accumulate statistics about varray sizes.  */
/* Used to accumulate statistics about varray sizes.  */
struct output_info
struct output_info
{
{
  int count;
  int count;
  int size;
  int size;
};
};
 
 
/* Called via htab_traverse.  Output varray descriptor pointed out by SLOT
/* Called via htab_traverse.  Output varray descriptor pointed out by SLOT
   and update statistics.  */
   and update statistics.  */
static int
static int
print_statistics (void **slot, void *b)
print_statistics (void **slot, void *b)
{
{
  struct varray_descriptor *d = (struct varray_descriptor *) *slot;
  struct varray_descriptor *d = (struct varray_descriptor *) *slot;
  struct output_info *i = (struct output_info *) b;
  struct output_info *i = (struct output_info *) b;
 
 
  if (d->allocated)
  if (d->allocated)
    {
    {
      fprintf (stderr, "%-21s %6d %10d %7d %7d\n", d->name,
      fprintf (stderr, "%-21s %6d %10d %7d %7d\n", d->name,
               d->created, d->allocated, d->resized, d->copied);
               d->created, d->allocated, d->resized, d->copied);
      i->size += d->allocated;
      i->size += d->allocated;
      i->count += d->created;
      i->count += d->created;
    }
    }
  return 1;
  return 1;
}
}
#endif
#endif
 
 
/* Output per-varray memory usage statistics.  */
/* Output per-varray memory usage statistics.  */
void
void
dump_varray_statistics (void)
dump_varray_statistics (void)
{
{
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
  struct output_info info;
  struct output_info info;
 
 
  fprintf (stderr, "\nVARRAY Kind            Count      Bytes  Resized copied\n");
  fprintf (stderr, "\nVARRAY Kind            Count      Bytes  Resized copied\n");
  fprintf (stderr, "-------------------------------------------------------\n");
  fprintf (stderr, "-------------------------------------------------------\n");
  info.count = 0;
  info.count = 0;
  info.size = 0;
  info.size = 0;
  htab_traverse (varray_hash, print_statistics, &info);
  htab_traverse (varray_hash, print_statistics, &info);
  fprintf (stderr, "-------------------------------------------------------\n");
  fprintf (stderr, "-------------------------------------------------------\n");
  fprintf (stderr, "%-20s %7d %10d\n",
  fprintf (stderr, "%-20s %7d %10d\n",
           "Total", info.count, info.size);
           "Total", info.count, info.size);
  fprintf (stderr, "-------------------------------------------------------\n");
  fprintf (stderr, "-------------------------------------------------------\n");
#endif
#endif
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.