From c25696045a8422510cc2bdea80cd68eabc16d25f Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor <iant@google.com>
Date: Wed, 10 Jun 2009 16:21:03 +0000
Subject: vec.h (DEF_VEC_ALLOC_I): Use DEF_VEC_NONALLOC_FUNCS_I.

	* vec.h (DEF_VEC_ALLOC_I): Use DEF_VEC_NONALLOC_FUNCS_I.
	(DEF_VEC_ALLOC_P): Use DEF_VEC_NONALLOC_FUNCS_P.
	(DEF_VEC_ALLOC_O): Use DEF_VEC_NONALLOC_FUNCS_O.
	(DEF_VEC_ALLOC_FUNC_P): Only define VEC_OP (T,A,alloc).
	(DEF_VEC_NONALLOC_FUNCS_P): New macro, broken out of old
	DEF_VEC_ALLOC_FUNC_P.
	(DEF_VEC_ALLOC_FUNC_O): Only define VEC_OP (T,A,alloc).
	(DEF_VEC_NONALLOC_FUNCS_O): New macro, broken out of old
	DEF_VEC_ALLOC_FUNC_O.
	(DEF_VEC_ALLOC_FUNC_I): Only define VEC_OP (T,A,alloc).
	(DEF_VEC_NONALLOC_FUNCS_I): New macro, broken out of old
	DEF_VEC_ALLOC_FUNC_I.
	(vec_stack_p_reserve, vec_stack_p_reserve_exact): Declare.
	(vec_stack_p_reserve_exact_1): Declare.
	(vec_stack_o_reserve, vec_stack_o_reserve_exact): Declare.
	(vec_stack_free): Declare.
	(VEC_stack_alloc): Define.
	(DEF_VEC_ALLOC_P_STACK, DEF_VEC_ALLOC_FUNC_P_STACK): Define.
	(DEF_VEC_ALLOC_O_STACK, DEF_VEC_ALLOC_FUNC_O_STACK): Define.
	(DEF_VEC_ALLOC_I_STACK, DEF_VEC_ALLOC_FUNC_I_STACK): Define.
	* vec.c (void_p): New type.  Call DEF_VEC_P and DEF_VEC_ALLOC_P
	for void_p.
	(stack_vecs): New static variable.
	(vec_stack_p_reserve_exact_1): New function.
	(vec_stack_o_reserve_1): New static function.
	(vec_stack_p_reserve, vec_stack_p_reserve_exact): New functions.
	(vec_stack_o_reserve, vec_stack_o_reserve_exact): New functions.
	(vec_stack_free): New function.
	* df-scan.c (df_ref): Use DEF_VEC_P and DEF_VEC_ALLOC_P_STACK.
	(VEC_df_ref_stack_alloc): Define.
	(df_mw_hardreg_ptr): New type.  Use DEF_VEC_P and
	DEF_VEC_ALLOC_P_STACK.
	(VEC_df_mw_hardreg_ptr_stack_alloc): Define.
	(struct df_collection_rec): Change _vec fields to VEC.  Remove
	_use fields.
	(df_free_collection_rec): Adjust for new fields.
	(df_insn_rescan): Use new df_collection_rec fields.
	(df_notes_rescan, df_canonize_collection_rec): Likewise.
	(df_ref_create_structure, df_ref_record): Likewise.
	(df_get_conditional_uses, df_get_call_refs): Likewise.
	(df_insn_refs_collect, df_bb_refs_collect): Likewise.
	(df_bb_refs_record, df_record_entry_block_defs): Likewise.
	(df_record_exit_block_uses, df_bb_verify): Likewise.
	(df_swap_refs): Change ref_vec parameter to VEC.  Change all
	callers.
	(df_sort_and_compress_refs): Change ref_vec parameter to VEC.
	Remove count parameter.  Change return type to void.  Change all
	callers.
	(df_sort_and_compress_mws): Change mw_vec parameter to VEC.
	Remove count parameter.  Change return type to void.  Change all
	callers.
	(df_install_refs): Change old_vec parameter to VEC.  Remove count
	parameter.  Change all callers.
	(df_install_mws): Change old_vec parameter to VEC.  Remove count
	parameter.  Change all callers.
	(df_refs_verify): Change new_rec parameter to VEC.  Change call
	callers.
	(df_mws_verify): Likewise.

From-SVN: r148347
---
 gcc/vec.h | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 83 insertions(+), 6 deletions(-)

(limited to 'gcc/vec.h')

diff --git a/gcc/vec.h b/gcc/vec.h
index 6c79df00885..d408c6d1a1a 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -508,6 +508,7 @@ struct vec_swallow_trailing_semi
 #define DEF_VEC_ALLOC_I(T,A)						  \
 VEC_TA(T,base,A);							  \
 DEF_VEC_ALLOC_FUNC_I(T,A)						  \
+DEF_VEC_NONALLOC_FUNCS_I(T,A)						  \
 struct vec_swallow_trailing_semi
 
 /* Vector of pointer to object.  */
@@ -524,6 +525,7 @@ struct vec_swallow_trailing_semi
 #define DEF_VEC_ALLOC_P(T,A)						  \
 VEC_TA(T,base,A);							  \
 DEF_VEC_ALLOC_FUNC_P(T,A)						  \
+DEF_VEC_NONALLOC_FUNCS_P(T,A)						  \
 struct vec_swallow_trailing_semi
 
 #define DEF_VEC_FUNC_P(T)						  \
@@ -716,8 +718,10 @@ static inline VEC(T,A) *VEC_OP (T,A,alloc)				  \
 {									  \
   return (VEC(T,A) *) vec_##A##_p_reserve_exact (NULL, alloc_		  \
 						 PASS_MEM_STAT);	  \
-}									  \
-									  \
+}
+
+
+#define DEF_VEC_NONALLOC_FUNCS_P(T,A)					  \
 static inline void VEC_OP (T,A,free)					  \
      (VEC(T,A) **vec_)							  \
 {									  \
@@ -814,6 +818,7 @@ struct vec_swallow_trailing_semi
 #define DEF_VEC_ALLOC_O(T,A)						  \
 VEC_TA(T,base,A);							  \
 DEF_VEC_ALLOC_FUNC_O(T,A)						  \
+DEF_VEC_NONALLOC_FUNCS_O(T,A)						  \
 struct vec_swallow_trailing_semi
 
 #define DEF_VEC_FUNC_O(T)						  \
@@ -995,8 +1000,9 @@ static inline VEC(T,A) *VEC_OP (T,A,alloc)      			  \
 						 offsetof (VEC(T,A),base.vec), \
 						 sizeof (T)		  \
 						 PASS_MEM_STAT);	  \
-}									  \
-									  \
+}
+
+#define DEF_VEC_NONALLOC_FUNCS_O(T,A)					  \
 static inline VEC(T,A) *VEC_OP (T,A,copy) (VEC(T,base) *vec_ MEM_STAT_DECL) \
 {									  \
   size_t len_ = vec_ ? vec_->num : 0;					  \
@@ -1099,8 +1105,9 @@ static inline VEC(T,A) *VEC_OP (T,A,alloc)      			  \
   return (VEC(T,A) *) vec_##A##_o_reserve_exact				  \
 		      (NULL, alloc_, offsetof (VEC(T,A),base.vec),	  \
 		       sizeof (T) PASS_MEM_STAT);			  \
-}									  \
-									  \
+}
+
+#define DEF_VEC_NONALLOC_FUNCS_I(T,A)					  \
 static inline VEC(T,A) *VEC_OP (T,A,copy) (VEC(T,base) *vec_ MEM_STAT_DECL) \
 {									  \
   size_t len_ = vec_ ? vec_->num : 0;					  \
@@ -1195,4 +1202,74 @@ static inline T *VEC_OP (T,A,safe_insert)		     	  	  \
 				       VEC_CHECK_PASS);			  \
 }
 
+/* We support a vector which starts out with space on the stack and
+   switches to heap space when forced to reallocate.  This works a
+   little differently.  Instead of DEF_VEC_ALLOC_P(TYPE, heap|gc), use
+   DEF_VEC_ALLOC_P_STACK(TYPE).  This uses alloca to get the initial
+   space; because alloca can not be usefully called in an inline
+   function, and because a macro can not define a macro, you must then
+   write a #define for each type:
+
+   #define VEC_{TYPE}_stack_alloc(alloc)                          \
+     VEC_stack_alloc({TYPE}, alloc)
+
+   This is really a hack and perhaps can be made better.  Note that
+   this macro will wind up evaluating the ALLOC parameter twice.
+
+   Only the initial allocation will be made using alloca, so pass a
+   reasonable estimate that doesn't use too much stack space; don't
+   pass zero.  Don't return a VEC(TYPE,stack) vector from the function
+   which allocated it.  */
+
+extern void *vec_stack_p_reserve (void *, int MEM_STAT_DECL);
+extern void *vec_stack_p_reserve_exact (void *, int MEM_STAT_DECL);
+extern void *vec_stack_p_reserve_exact_1 (int, void *);
+extern void *vec_stack_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL);
+extern void *vec_stack_o_reserve_exact (void *, int, size_t, size_t
+					 MEM_STAT_DECL);
+extern void vec_stack_free (void *);
+
+#define VEC_stack_alloc(T,alloc)					  \
+  (VEC_OP (T,stack,alloc1)						  \
+   (alloc, XALLOCAVAR (VEC(T,stack), VEC_embedded_size (T, alloc))))
+
+#define DEF_VEC_ALLOC_P_STACK(T)					  \
+VEC_TA(T,base,stack);							  \
+DEF_VEC_ALLOC_FUNC_P_STACK(T)						  \
+DEF_VEC_NONALLOC_FUNCS_P(T,stack)					  \
+struct vec_swallow_trailing_semi
+
+#define DEF_VEC_ALLOC_FUNC_P_STACK(T)					  \
+static inline VEC(T,stack) *VEC_OP (T,stack,alloc1)			  \
+     (int alloc_, VEC(T,stack)* space MEM_STAT_DECL)			  \
+{									  \
+   return (VEC(T,stack) *) vec_stack_p_reserve_exact_1 (alloc_, space); \
+}
+
+#define DEF_VEC_ALLOC_O_STACK(T)					  \
+VEC_TA(T,base,stack);							  \
+DEF_VEC_ALLOC_FUNC_O_STACK(T)						  \
+DEF_VEC_NONALLOC_FUNCS_O(T,stack)					  \
+struct vec_swallow_trailing_semi
+
+#define DEF_VEC_ALLOC_FUNC_O_STACK(T)					  \
+static inline VEC(T,stack) *VEC_OP (T,stack,alloc1)			  \
+     (int alloc_, VEC(T,stack)* space MEM_STAT_DECL)			  \
+{									  \
+  return ((VEC(T,stack) *) vec_stack_p_reserve_exact_1 (alloc_, space); \
+}
+
+#define DEF_VEC_ALLOC_I_STACK(T)					  \
+VEC_TA(T,base,stack);							  \
+DEF_VEC_ALLOC_FUNC_I_STACK(T)						  \
+DEF_VEC_NONALLOC_FUNCS_I(T,stack)					  \
+struct vec_swallow_trailing_semi
+
+#define DEF_VEC_ALLOC_FUNC_I_STACK(T)					  \
+static inline VEC(T,stack) *VEC_OP (T,stack,alloc1)			  \
+     (int alloc_, VEC(T,stack)* space MEM_STAT_DECL)			  \
+{									  \
+  return ((VEC(T,stack) *) vec_stack_p_reserve_exact_1 (alloc_, space); \
+}
+
 #endif /* GCC_VEC_H */
-- 
cgit v1.2.1