]> gcc.gnu.org Git - gcc.git/commitdiff
vec.c (vec_p_reserve, [...]): Rename to ...
authorNathan Sidwell <nathan@codesourcery.com>
Wed, 8 Sep 2004 08:08:56 +0000 (08:08 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 8 Sep 2004 08:08:56 +0000 (08:08 +0000)
* 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.

From-SVN: r87179

gcc/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/name-lookup.h
gcc/cp/semantics.c
gcc/lambda-code.c
gcc/tree.h
gcc/value-prof.h
gcc/vec.c
gcc/vec.h

index 88432812e4c016aa0178ab73ea0e4270e074ada4..28fe88eb1c01f91d2392d95d5e4d9367f24af67d 100644 (file)
@@ -1,3 +1,22 @@
+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.
index 35eb3a7766cf3545815ca3a03dea5deb78aa16a8..0204cc23ed78c08cc0cb46b1d8f49746ce92f6c0 100644 (file)
@@ -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
index 892303b565f4022143e71fee577e128952566730..e03f8ec933980df14ab4298afd85614130fe9130 100644 (file)
@@ -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.
index dd35580067c673697708eb5926f69829fa309668..fe687a0f618e9d8bb62effcecf2472a253aeef15 100644 (file)
@@ -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;
index cdf04708bfb46fc16505781552a173e1ca47d03d..be1195048cd3c2499a4c6d9013d783686100a94f 100644 (file)
@@ -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
index 7d6d87c0dee54ea7b8a73ec04e470b1d3e0d3516..c23ec7c769ccd9ebf2291aba9ef5071b658df34d 100644 (file)
@@ -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);
 
 \f
 /* Classify which part of the compiler has defined a given builtin function.
index 60215fde30dc4dd9198f98214ea1fe6e9eee0163..312b8bc6226f3ce9a8e5f8ebbac78757078668eb 100644 (file)
@@ -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;
 
index 1f9ac2062822cd38ff555c044613696ff6eba6f5..72480dcd6fed864184c7b19464fe81080b801515 100644 (file)
--- 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.  */
 
index cbc5f81062a51d2041c8a3d18ff085b78855a67d..d6fc8adfcea822ca47449da836a222d7c4ece184 100644 (file)
--- 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);                                \
                                                                          \
This page took 0.10478 seconds and 5 git commands to generate.