summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2004-09-08 08:08:56 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2004-09-08 08:08:56 +0000
commit07e8c04c5c9fd05187e0135a6c00b55daea82410 (patch)
tree82cf8d02cbdec1663fdfa61ae2f02250a8f504bc /gcc
parent611234b4a911bea129f06d829c2077155c3ed5ae (diff)
downloadgcc-07e8c04c5c9fd05187e0135a6c00b55daea82410.tar.gz
* vec.c (vec_p_reserve, vec_o_reserve): Rename to ...
(vec_gc_p_reserve, vec_gc_o_reserve): ... here. Clone to (vec_heap_p_reserve, vec_heap_o_reserve): ... here, adjust. (vec_gc_free, vec_heap_free): New. * vec.h (DEF_VEC_GC_P, DEF_VEC_MALLOC_P): New. (DEF_VEC_P): Add allocator argument. Adjust. (DEF_VEC_GC_O, DEF_VEC_MALLOC_O): New. (DEF_VEC_O): Add allocator argument. Adjust. (VEC(free)): New. * tree.h (tree): Define a GC'd vector. * lamba-code.c (lambda_loop): Likewise. * value-prof.h (histogram_value): Likewise. * cp/cp-tree.h (tree_pair_s): Likewise. * cp/name-lookup.h (cxx_saved_binding, cp_class_binding): Likewise. * cp/semantics.c (deferred_access): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@87179 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog19
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/name-lookup.h4
-rw-r--r--gcc/cp/semantics.c2
-rw-r--r--gcc/lambda-code.c2
-rw-r--r--gcc/tree.h4
-rw-r--r--gcc/value-prof.h2
-rw-r--r--gcc/vec.c71
-rw-r--r--gcc/vec.h68
9 files changed, 145 insertions, 29 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 88432812e4c..28fe88eb1c0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,24 @@
2004-09-08 Nathan Sidwell <nathan@codesourcery.com>
+ * vec.c (vec_p_reserve, vec_o_reserve): Rename to ...
+ (vec_gc_p_reserve, vec_gc_o_reserve): ... here. Clone to
+ (vec_heap_p_reserve, vec_heap_o_reserve): ... here, adjust.
+ (vec_gc_free, vec_heap_free): New.
+ * vec.h (DEF_VEC_GC_P, DEF_VEC_MALLOC_P): New.
+ (DEF_VEC_P): Add allocator argument. Adjust.
+ (DEF_VEC_GC_O, DEF_VEC_MALLOC_O): New.
+ (DEF_VEC_O): Add allocator argument. Adjust.
+ (VEC(free)): New.
+
+ * tree.h (tree): Define a GC'd vector.
+ * lamba-code.c (lambda_loop): Likewise.
+ * value-prof.h (histogram_value): Likewise.
+ * cp/cp-tree.h (tree_pair_s): Likewise.
+ * cp/name-lookup.h (cxx_saved_binding, cp_class_binding): Likewise.
+ * cp/semantics.c (deferred_access): Likewise.
+
+2004-09-08 Nathan Sidwell <nathan@codesourcery.com>
+
* emit-rtl.c (immed_double_const): Use gcc_assert and gcc_unreachable.
(gen_rtx_SUBREG, gen_reg_rtx, mark_user_reg, subreg_hard_regno,
gen_lowpart_common, gen_highpart, gen_highpart_mode,
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 35eb3a7766c..0204cc23ed7 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -955,7 +955,7 @@ typedef struct tree_pair_s GTY (())
tree value;
} tree_pair_s;
typedef tree_pair_s *tree_pair_p;
-DEF_VEC_O (tree_pair_s);
+DEF_VEC_GC_O (tree_pair_s);
/* This is a few header flags for 'struct lang_type'. Actually,
all but the first are used only for lang_type_class; they
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 892303b565f..e03f8ec9339 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -91,7 +91,7 @@ typedef struct cxx_saved_binding GTY(())
tree real_type_value;
} cxx_saved_binding;
-DEF_VEC_O(cxx_saved_binding);
+DEF_VEC_GC_O(cxx_saved_binding);
extern tree identifier_type_value (tree);
extern void set_identifier_type_value (tree, tree);
@@ -132,7 +132,7 @@ typedef struct cp_class_binding GTY(())
tree identifier;
} cp_class_binding;
-DEF_VEC_O(cp_class_binding);
+DEF_VEC_GC_O(cp_class_binding);
/* For each binding contour we allocate a binding_level structure
which records the names defined in that contour.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index dd35580067c..fe687a0f618 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -138,7 +138,7 @@ typedef struct deferred_access GTY(())
enum deferring_kind deferring_access_checks_kind;
} deferred_access;
-DEF_VEC_O (deferred_access);
+DEF_VEC_GC_O (deferred_access);
/* Data for deferred access checking. */
static GTY(()) VEC (deferred_access) *deferred_access_stack;
diff --git a/gcc/lambda-code.c b/gcc/lambda-code.c
index cdf04708bfb..be1195048cd 100644
--- a/gcc/lambda-code.c
+++ b/gcc/lambda-code.c
@@ -1406,7 +1406,7 @@ find_induction_var_from_exit_cond (struct loop *loop)
return TREE_OPERAND (test, 0);
}
-DEF_VEC_P(lambda_loop);
+DEF_VEC_GC_P(lambda_loop);
/* Generate a lambda loopnest from a gcc loopnest LOOP_NEST.
Return the new loop nest.
INDUCTIONVARS is a pointer to an array of induction variables for the
diff --git a/gcc/tree.h b/gcc/tree.h
index 7d6d87c0dee..c23ec7c769c 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -76,8 +76,8 @@ extern const unsigned char tree_code_length[];
extern const char *const tree_code_name[];
-/* A vector of trees. */
-DEF_VEC_P(tree);
+/* A garbage collected vector of trees. */
+DEF_VEC_GC_P(tree);
/* Classify which part of the compiler has defined a given builtin function.
diff --git a/gcc/value-prof.h b/gcc/value-prof.h
index 60215fde30d..312b8bc6226 100644
--- a/gcc/value-prof.h
+++ b/gcc/value-prof.h
@@ -66,7 +66,7 @@ struct histogram_value_t GTY(())
typedef struct histogram_value_t *histogram_value;
-DEF_VEC_P(histogram_value);
+DEF_VEC_GC_P(histogram_value);
typedef VEC(histogram_value) *histogram_values;
diff --git a/gcc/vec.c b/gcc/vec.c
index 1f9ac206282..72480dcd6fe 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -39,11 +39,11 @@ struct vec_prefix
VEC can be NULL, to create a new vector. */
void *
-vec_p_reserve (void *vec, int reserve MEM_STAT_DECL)
+vec_gc_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
- return vec_o_reserve (vec, reserve,
- offsetof (struct vec_prefix, vec), sizeof (void *)
- PASS_MEM_STAT);
+ return vec_gc_o_reserve (vec, reserve,
+ offsetof (struct vec_prefix, vec), sizeof (void *)
+ PASS_MEM_STAT);
}
/* Ensure there are at least RESERVE free slots in VEC, if RESERVE >=
@@ -53,8 +53,8 @@ vec_p_reserve (void *vec, int reserve MEM_STAT_DECL)
ELT_SIZE sized elements. */
void *
-vec_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
- MEM_STAT_DECL)
+vec_gc_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
+ MEM_STAT_DECL)
{
struct vec_prefix *pfx = vec;
unsigned alloc = pfx ? pfx->num : 0;
@@ -77,6 +77,65 @@ vec_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
return vec;
}
+/* Explicitly release a vector. */
+
+void
+vec_gc_free (void *vec)
+{
+ ggc_free (vec);
+}
+
+/* Ensure there are at least RESERVE free slots in VEC, if RESERVE >=
+ 0. If RESERVE < 0 increase the current allocation exponentially.
+ VEC can be NULL, to create a new vector. */
+
+void *
+vec_heap_p_reserve (void *vec, int reserve MEM_STAT_DECL)
+{
+ return vec_heap_o_reserve (vec, reserve,
+ offsetof (struct vec_prefix, vec), sizeof (void *)
+ PASS_MEM_STAT);
+}
+
+/* Ensure there are at least RESERVE free slots in VEC, if RESERVE >=
+ 0. If RESERVE < 0, increase the current allocation exponentially.
+ VEC can be NULL, in which case a new vector is created. The
+ vector's trailing array is at VEC_OFFSET offset and consists of
+ ELT_SIZE sized elements. */
+
+void *
+vec_heap_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
+ MEM_STAT_DECL)
+{
+ struct vec_prefix *pfx = vec;
+ unsigned alloc = pfx ? pfx->num : 0;
+
+ if (reserve >= 0)
+ alloc += reserve;
+ else if (alloc)
+ alloc *= 2;
+ else
+ alloc = 4;
+
+ if (pfx && pfx->alloc >= alloc)
+ abort ();
+
+ vec = xrealloc (vec, vec_offset + alloc * elt_size);
+ ((struct vec_prefix *)vec)->alloc = alloc;
+ if (!pfx)
+ ((struct vec_prefix *)vec)->num = 0;
+
+ return vec;
+}
+
+/* Explicitly release a vector. */
+
+void
+vec_heap_free (void *vec)
+{
+ free (vec);
+}
+
#if ENABLE_CHECKING
/* Issue a vector domain error, and then fall over. */
diff --git a/gcc/vec.h b/gcc/vec.h
index cbc5f81062a..d6fc8adfcea 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -78,19 +78,25 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
The 'lower_bound' function will determine where to place an item in the
array using insert that will maintain sorted order.
+ Both garbage collected and explicitly managed vector types are
+ creatable. The allocation mechanism is specified when the type is
+ defined, and is therefore part of the type.
+
If you need to directly manipulate a vector, then the 'address'
accessor will return the address of the start of the vector. Also
the 'space' predicate will tell you whether there is spare capacity
in the vector. You will not normally need to use these two functions.
- Vector types are defined using a DEF_VEC_{O,P}(TYPEDEF) macro, and
- variables of vector type are declared using a VEC(TYPEDEF)
- macro. The characters O and P indicate whether TYPEDEF is a pointer
- (P) or object (O) type.
+ Vector types are defined using a DEF_VEC_{GC,MALLOC}_{O,P}(TYPEDEF)
+ macro, and variables of vector type are declared using a
+ VEC(TYPEDEF) macro. The tags GC and MALLOC specify the allocation
+ method -- garbage collected or explicit malloc/free calls. The
+ characters O and P indicate whether TYPEDEF is a pointer (P) or
+ object (O) type.
An example of their use would be,
- DEF_VEC_P(tree); // define a vector of tree pointers. This must
+ DEF_VEC_GC_P(tree); // define a gc'd vector of tree pointers. This must
// appear at file scope.
struct my_struct {
@@ -158,6 +164,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#define VEC_alloc(TDEF,A) (VEC_OP(TDEF,alloc)(A MEM_STAT_INFO))
+/* Free a vector.
+ void VEC_T_alloc(VEC(T) *&);
+
+ Free a vector and set it to NULL. */
+
+#define VEC_free(TDEF,V) (VEC_OP(TDEF,free)(&V))
+
/* Use these to determine the required size and initialization of a
vector embedded within another structure (as the final member).
@@ -317,8 +330,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#if !IN_GENGTYPE
/* Reallocate an array of elements with prefix. */
-extern void *vec_p_reserve (void *, int MEM_STAT_DECL);
-extern void *vec_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL);
+extern void *vec_gc_p_reserve (void *, int MEM_STAT_DECL);
+extern void *vec_gc_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL);
+extern void vec_gc_free (void *);
+extern void *vec_heap_p_reserve (void *, int MEM_STAT_DECL);
+extern void *vec_heap_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL);
+extern void vec_heap_free (void *);
#if ENABLE_CHECKING
#define VEC_CHECK_INFO ,__FILE__,__LINE__,__FUNCTION__
@@ -359,10 +376,13 @@ typedef struct VEC (TDEF) GTY(()) \
/* Vector of pointer to object. */
#if IN_GENGTYPE
-{"DEF_VEC_P", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL},
+{"DEF_VEC_GC_P", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL},
+{"DEF_VEC_MALLOC_P", "", NULL},
#else
+#define DEF_VEC_GC_P(TDEF) DEF_VEC_P(TDEF,gc)
+#define DEF_VEC_MALLOC_P(TDEF) DEF_VEC_P(TDEF,heap)
-#define DEF_VEC_P(TDEF) \
+#define DEF_VEC_P(TDEF,a) \
VEC_TDEF (TDEF); \
\
static inline unsigned VEC_OP (TDEF,length) \
@@ -405,7 +425,14 @@ static inline int VEC_OP (TDEF,iterate) \
static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \
(int alloc_ MEM_STAT_DECL) \
{ \
- return (VEC (TDEF) *) vec_p_reserve (NULL, alloc_ - !alloc_ PASS_MEM_STAT);\
+ return (VEC (TDEF) *) vec_##a##_p_reserve (NULL, alloc_ - !alloc_ PASS_MEM_STAT);\
+} \
+ \
+static inline void VEC_OP (TDEF,free) \
+ (VEC (TDEF) **vec_) \
+{ \
+ vec_##a##_free (*vec_); \
+ *vec_ = NULL; \
} \
\
static inline size_t VEC_OP (TDEF,embedded_size) \
@@ -434,7 +461,7 @@ static inline int VEC_OP (TDEF,reserve) \
int extend = VEC_OP (TDEF,space) (*vec_, alloc_); \
\
if (extend) \
- *vec_ = (VEC (TDEF) *) vec_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \
+ *vec_ = (VEC (TDEF) *) vec_##a##_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \
\
return extend; \
} \
@@ -577,10 +604,14 @@ struct vec_swallow_trailing_semi
/* Vector of object. */
#if IN_GENGTYPE
-{"DEF_VEC_O", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL},
+{"DEF_VEC_GC_O", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL},
+{"DEF_VEC_MALLOC_O", "", NULL},
#else
-#define DEF_VEC_O(TDEF) \
+#define DEF_VEC_GC_O(TDEF) DEF_VEC_O(TDEF,gc)
+#define DEF_VEC_MALLOC_O(TDEF) DEF_VEC_O(TDEF,heap)
+
+#define DEF_VEC_O(TDEF,a) \
VEC_TDEF (TDEF); \
\
static inline unsigned VEC_OP (TDEF,length) \
@@ -623,11 +654,18 @@ static inline int VEC_OP (TDEF,iterate) \
static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \
(int alloc_ MEM_STAT_DECL) \
{ \
- return (VEC (TDEF) *) vec_o_reserve (NULL, alloc_ - !alloc_, \
+ return (VEC (TDEF) *) vec_##a##_o_reserve (NULL, alloc_ - !alloc_, \
offsetof (VEC(TDEF),vec), sizeof (TDEF)\
PASS_MEM_STAT); \
} \
\
+static inline void VEC_OP (TDEF,free) \
+ (VEC (TDEF) **vec_) \
+{ \
+ vec_##a##_free (*vec_); \
+ *vec_ = NULL; \
+} \
+ \
static inline size_t VEC_OP (TDEF,embedded_size) \
(int alloc_) \
{ \
@@ -654,7 +692,7 @@ static inline int VEC_OP (TDEF,reserve) \
int extend = VEC_OP (TDEF,space) (*vec_, alloc_); \
\
if (extend) \
- *vec_ = (VEC (TDEF) *) vec_o_reserve (*vec_, alloc_, \
+ *vec_ = (VEC (TDEF) *) vec_##a##_o_reserve (*vec_, alloc_, \
offsetof (VEC(TDEF),vec), sizeof (TDEF) \
PASS_MEM_STAT); \
\