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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [varray.c] - Blame information for rev 363

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Virtual array support.
2
   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007
3
   Free Software Foundation, Inc.
4
   Contributed by Cygnus Solutions.
5
 
6
   This file is part of GCC.
7
 
8
   GCC is free software; you can redistribute it and/or modify it
9
   under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3, or (at your option)
11
   any later version.
12
 
13
   GCC is distributed in the hope that it will be useful, but WITHOUT
14
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
   License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with GCC; see the file COPYING3.  If not see
20
   <http://www.gnu.org/licenses/>.  */
21
 
22
#include "config.h"
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
#include "toplev.h"
27
#include "varray.h"
28
#include "ggc.h"
29
#include "hashtab.h"
30
 
31
#define VARRAY_HDR_SIZE (sizeof (struct varray_head_tag) - sizeof (varray_data))
32
 
33
#ifdef GATHER_STATISTICS
34
 
35
/* Store information about each particular varray.  */
36
struct varray_descriptor
37
{
38
  const char *name;
39
  int allocated;
40
  int created;
41
  int resized;
42
  int copied;
43
};
44
 
45
/* Hashtable mapping varray names to descriptors.  */
46
static htab_t varray_hash;
47
 
48
/* Hashtable helpers.  */
49
static hashval_t
50
hash_descriptor (const void *p)
51
{
52
  const struct varray_descriptor *d = p;
53
  return htab_hash_pointer (d->name);
54
}
55
static int
56
eq_descriptor (const void *p1, const void *p2)
57
{
58
  const struct varray_descriptor *d = p1;
59
  return d->name == p2;
60
}
61
 
62
/* For given name, return descriptor, create new if needed.  */
63
static struct varray_descriptor *
64
varray_descriptor (const char *name)
65
{
66
  struct varray_descriptor **slot;
67
 
68
  if (!varray_hash)
69
    varray_hash = htab_create (10, hash_descriptor, eq_descriptor, NULL);
70
 
71
  slot = (struct varray_descriptor **)
72
    htab_find_slot_with_hash (varray_hash, name,
73
                              htab_hash_pointer (name),
74
                              1);
75
  if (*slot)
76
    return *slot;
77
  *slot = xcalloc (sizeof (**slot), 1);
78
  (*slot)->name = name;
79
  return *slot;
80
}
81
#endif
82
 
83
/* Do not add any more non-GC items here.  Please either remove or GC
84
   those items that are not GCed.  */
85
 
86
static const struct {
87
  unsigned char size;
88
  bool uses_ggc;
89
} element[NUM_VARRAY_DATA] = {
90
  { sizeof (char), 1 },
91
  { sizeof (unsigned char), 1 },
92
  { sizeof (short), 1 },
93
  { sizeof (unsigned short), 1 },
94
  { sizeof (int), 1 },
95
  { sizeof (unsigned int), 1 },
96
  { sizeof (long), 1 },
97
  { sizeof (unsigned long), 1 },
98
  { sizeof (HOST_WIDE_INT), 1 },
99
  { sizeof (unsigned HOST_WIDE_INT), 1 },
100
  { sizeof (void *), 1 },
101
  { sizeof (void *), 0 },
102
  { sizeof (char *), 1 },
103
  { sizeof (struct rtx_def *), 1 },
104
  { sizeof (struct rtvec_def *), 1 },
105
  { sizeof (union tree_node *), 1 },
106
  { sizeof (struct bitmap_head_def *), 1 },
107
  { sizeof (struct reg_info_def *), 0 },
108
  { sizeof (struct basic_block_def *), 1 },
109
  { sizeof (struct elt_list *), 1 },
110
  { sizeof (struct edge_def *), 1 },
111
  { sizeof (tree *), 1 },
112
};
113
 
114
/* Allocate a virtual array with NUM_ELEMENT elements, each of which is
115
   ELEMENT_SIZE bytes long, named NAME.  Array elements are zeroed.  */
116
varray_type
117
varray_init (size_t num_elements, enum varray_data_enum element_kind,
118
             const char *name)
119
{
120
  size_t data_size = num_elements * element[element_kind].size;
121
  varray_type ptr;
122
#ifdef GATHER_STATISTICS
123
  struct varray_descriptor *desc = varray_descriptor (name);
124
 
125
  desc->created++;
126
  desc->allocated += data_size + VARRAY_HDR_SIZE;
127
#endif
128
  if (element[element_kind].uses_ggc)
129
    ptr = ggc_alloc_cleared (VARRAY_HDR_SIZE + data_size);
130
  else
131
    ptr = xcalloc (VARRAY_HDR_SIZE + data_size, 1);
132
 
133
  ptr->num_elements = num_elements;
134
  ptr->elements_used = 0;
135
  ptr->type = element_kind;
136
  ptr->name = name;
137
  return ptr;
138
}
139
 
140
/* Grow/shrink the virtual array VA to N elements.  Zero any new elements
141
   allocated.  */
142
varray_type
143
varray_grow (varray_type va, size_t n)
144
{
145
  size_t old_elements = va->num_elements;
146
  if (n != old_elements)
147
    {
148
      size_t elem_size = element[va->type].size;
149
      size_t old_data_size = old_elements * elem_size;
150
      size_t data_size = n * elem_size;
151
#ifdef GATHER_STATISTICS
152
      struct varray_descriptor *desc = varray_descriptor (va->name);
153
      varray_type oldva = va;
154
 
155
      if (data_size > old_data_size)
156
        desc->allocated += data_size - old_data_size;
157
      desc->resized ++;
158
#endif
159
 
160
 
161
      if (element[va->type].uses_ggc)
162
        va = ggc_realloc (va, VARRAY_HDR_SIZE + data_size);
163
      else
164
        va = xrealloc (va, VARRAY_HDR_SIZE + data_size);
165
      va->num_elements = n;
166
      if (n > old_elements)
167
        memset (&va->data.vdt_c[old_data_size], 0, data_size - old_data_size);
168
#ifdef GATHER_STATISTICS
169
      if (oldva != va)
170
        desc->copied++;
171
#endif
172
    }
173
 
174
  return va;
175
}
176
 
177
/* Reset a varray to its original state.  */
178
void
179
varray_clear (varray_type va)
180
{
181
  size_t data_size = element[va->type].size * va->num_elements;
182
 
183
  memset (va->data.vdt_c, 0, data_size);
184
  va->elements_used = 0;
185
}
186
 
187
/* Check the bounds of a varray access.  */
188
 
189
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
190
 
191
void
192
varray_check_failed (varray_type va, size_t n, const char *file, int line,
193
                     const char *function)
194
{
195
  internal_error ("virtual array %s[%lu]: element %lu out of bounds "
196
                  "in %s, at %s:%d",
197
                  va->name, (unsigned long) va->num_elements, (unsigned long) n,
198
                  function, trim_filename (file), line);
199
}
200
 
201
void
202
varray_underflow (varray_type va, const char *file, int line,
203
                  const char *function)
204
{
205
  internal_error ("underflowed virtual array %s in %s, at %s:%d",
206
                  va->name, function, trim_filename (file), line);
207
}
208
 
209
#endif
210
 
211
 
212
/* Output per-varray statistics.  */
213
#ifdef GATHER_STATISTICS
214
 
215
/* Used to accumulate statistics about varray sizes.  */
216
struct output_info
217
{
218
  int count;
219
  int size;
220
};
221
 
222
/* Called via htab_traverse.  Output varray descriptor pointed out by SLOT
223
   and update statistics.  */
224
static int
225
print_statistics (void **slot, void *b)
226
{
227
  struct varray_descriptor *d = (struct varray_descriptor *) *slot;
228
  struct output_info *i = (struct output_info *) b;
229
 
230
  if (d->allocated)
231
    {
232
      fprintf (stderr, "%-21s %6d %10d %7d %7d\n", d->name,
233
               d->created, d->allocated, d->resized, d->copied);
234
      i->size += d->allocated;
235
      i->count += d->created;
236
    }
237
  return 1;
238
}
239
#endif
240
 
241
/* Output per-varray memory usage statistics.  */
242
void
243
dump_varray_statistics (void)
244
{
245
#ifdef GATHER_STATISTICS
246
  struct output_info info;
247
 
248
  fprintf (stderr, "\nVARRAY Kind            Count      Bytes  Resized copied\n");
249
  fprintf (stderr, "-------------------------------------------------------\n");
250
  info.count = 0;
251
  info.size = 0;
252
  htab_traverse (varray_hash, print_statistics, &info);
253
  fprintf (stderr, "-------------------------------------------------------\n");
254
  fprintf (stderr, "%-20s %7d %10d\n",
255
           "Total", info.count, info.size);
256
  fprintf (stderr, "-------------------------------------------------------\n");
257
#endif
258
}

powered by: WebSVN 2.1.0

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