Make all VEC_* functions, member functions of vec_t.

This patch is the first step towards making the API for VEC use
member functions.

There are no user code modifications in this patch.  Everything
is still using the VEC_* macros, but this time they expand into
member function calls.

Because of the way VECs are used, this required some trickery.
The API allows VECs to be NULL.  This means that services like
VEC_length(V) will return 0 when V is a NULL pointer.  This is,
of course, not possible to do if we call V->length().

For functions that either need to allocate/re-allocate the
vector, or they need to handle NULL vectors, I implemented them
as static member functions or free functions.

Another wart that I did not address in this patch is the fact
that vectors of pointers and vectors of objects have slightly
different semantics when handling elements in the vector.  In
vector of pointers, we pass them around by value, but in vectors
of objects, they are passed around via pointers.  That's why we
need TYPE * and TYPE ** overloads for some functions (e.g.,
vec_t::iterate).

I will fix these two warts in a subsequent patch.  The idea is to
make vec_t a single-word structure, which acts as a handler for
the structure containing the actual vector.  Something like this:

template<typename T>
struct vec_t
{
  struct vec_internal<T> *vec_;
};

This has the advantage that we can now declare the actual vector
instances as regular variables, instead of pointers.  They will
use the same amount of memory when embedded in other structures,
and we will be able to allocate and reallocate the actual data
without having to mutate the vector instance.

All the functions that are now static members in vec_t, will
become instance members in the new vec_t.  This will mean that
all the callers will need to be changed, of course.

Tested on x86_64 and ppc64 with all languages plus ada, go and obj-c++.

	Rewrite VEC_* functions as member functions of vec_t.

	* vec.h: Update documentation.
	(ALONE_VEC_CHECK_INFO): Define.
	(ALONE_VEC_CHECK_DECL): Define.
	(ALONE_VEC_CHECK_PASS): Define.
	(struct vec_prefix): Rename field NUM to NUM_.
	Rename field ALLOC to ALLOC_.
	Update all users.
	(struct vec_t): Rename field PREFIX to PREFIX_.
	Rename field VEC to VEC_.
	Update all users.
	(vec_t::length): Rename from VEC_length_1.  Update all users.
	(vec_t::empty): Rename from VEC_empty_1.  Update all users.
	(vec_t::address): Rename from VEC_address_1.  Update all users.
	(vec_address): New.
	(vec_t::last): Rename from VEC_last_1.  Update all users.
	(vec_t::operator[]): Rename from VEC_index_1.  Update all users.
	(vec_t::iterate): Rename from VEC_iterate_1.  Update all users.
	(vec_t::embedded_size): Rename from VEC_embedded_size_1.
	Update all users.
	(vec_t::embedded_init): Rename from VEC_embedded_init_1.
	Update all users.
	(vec_t::alloc): Rename from VEC_alloc_1.  Update all users.
	(vec_t::free): Rename from VEC_free_1.  Update all users.
	(vec_t::copy): Rename from VEC_copy_1.  Update all users.
	(vec_t::space): Rename from VEC_space_1.  Update all users.
	(vec_t::reserve): Rename from VEC_reserve_1.  Update all users.
	(vec_t::reserve_exact): Rename from VEC_reserve_exact_1.
	Update all users.
	(vec_t::splice): Rename from VEC_splice_1.  Update all users.
	(vec_t::safe_splice): Rename from VEC_safe_splice_1.  Update all users.
	(vec_t::quick_push): Rename from VEC_quick_push_1.  Update all users.
	(vec_t::safe_push): Rename from VEC_safe_push_1.  Update all users.
	(vec_t::pop): Rename from VEC_pop_1.  Update all users.
	(vec_t::truncate): Rename from VEC_truncate_1.  Update all users.
	(vec_t::safe_grow): Rename from VEC_safe_grow_1.  Update all users.
	(vec_t::safe_grow_cleared): Rename from VEC_safe_grow_cleared_1.
	Update all users.
	(vec_t::replace): Rename from VEC_replace_1.  Update all users.
	(vec_t::quick_insert): Rename from VEC_quick_insert_1.
	Update all users.
	(vec_t::safe_insert): Rename from VEC_safe_insert_1.  Update all users.
	(vec_t::ordered_remove): Rename from VEC_ordered_remove_1.
	Update all users.
	(vec_t::unordered_remove): Rename from VEC_unordered_remove_1.
	Update all users.
	(vec_t::block_remove): Rename from VEC_block_remove_1. Update all users.
	(vec_t::lower_bound): Rename from VEC_lower_bound_1. Update all users.

From-SVN: r190927
This commit is contained in:
Diego Novillo 2012-09-04 09:22:54 -04:00 committed by Diego Novillo
parent fd8d363e25
commit bd0c3bfdd7
3 changed files with 749 additions and 674 deletions

View File

@ -1,3 +1,55 @@
2012-09-04 Diego Novillo <dnovillo@google.com>
Rewrite VEC_* functions as member functions of vec_t.
* vec.h: Update documentation.
(ALONE_VEC_CHECK_INFO): Define.
(ALONE_VEC_CHECK_DECL): Define.
(ALONE_VEC_CHECK_PASS): Define.
(struct vec_prefix): Rename field NUM to NUM_.
Rename field ALLOC to ALLOC_.
Update all users.
(struct vec_t): Rename field PREFIX to PREFIX_.
Rename field VEC to VEC_.
Update all users.
(vec_t::length): Rename from VEC_length_1. Update all users.
(vec_t::empty): Rename from VEC_empty_1. Update all users.
(vec_t::address): Rename from VEC_address_1. Update all users.
(vec_address): New.
(vec_t::last): Rename from VEC_last_1. Update all users.
(vec_t::operator[]): Rename from VEC_index_1. Update all users.
(vec_t::iterate): Rename from VEC_iterate_1. Update all users.
(vec_t::embedded_size): Rename from VEC_embedded_size_1.
Update all users.
(vec_t::embedded_init): Rename from VEC_embedded_init_1.
Update all users.
(vec_t::alloc): Rename from VEC_alloc_1. Update all users.
(vec_t::free): Rename from VEC_free_1. Update all users.
(vec_t::copy): Rename from VEC_copy_1. Update all users.
(vec_t::space): Rename from VEC_space_1. Update all users.
(vec_t::reserve): Rename from VEC_reserve_1. Update all users.
(vec_t::reserve_exact): Rename from VEC_reserve_exact_1.
Update all users.
(vec_t::splice): Rename from VEC_splice_1. Update all users.
(vec_t::safe_splice): Rename from VEC_safe_splice_1. Update all users.
(vec_t::quick_push): Rename from VEC_quick_push_1. Update all users.
(vec_t::safe_push): Rename from VEC_safe_push_1. Update all users.
(vec_t::pop): Rename from VEC_pop_1. Update all users.
(vec_t::truncate): Rename from VEC_truncate_1. Update all users.
(vec_t::safe_grow): Rename from VEC_safe_grow_1. Update all users.
(vec_t::safe_grow_cleared): Rename from VEC_safe_grow_cleared_1.
Update all users.
(vec_t::replace): Rename from VEC_replace_1. Update all users.
(vec_t::quick_insert): Rename from VEC_quick_insert_1.
Update all users.
(vec_t::safe_insert): Rename from VEC_safe_insert_1. Update all users.
(vec_t::ordered_remove): Rename from VEC_ordered_remove_1.
Update all users.
(vec_t::unordered_remove): Rename from VEC_unordered_remove_1.
Update all users.
(vec_t::block_remove): Rename from VEC_block_remove_1. Update all users.
(vec_t::lower_bound): Rename from VEC_lower_bound_1. Update all users.
2012-09-04 Steven Bosscher <steven@gcc.gnu.org>
* gimple.h (gimple_build_switch): Remove.

View File

@ -175,8 +175,8 @@ calculate_allocation (const struct vec_prefix *pfx, int reserve, bool exact)
if (pfx)
{
alloc = pfx->alloc;
num = pfx->num;
alloc = pfx->alloc_;
num = pfx->num_;
}
else if (!reserve)
/* If there's no prefix, and we've not requested anything, then we
@ -240,9 +240,9 @@ vec_gc_o_reserve_1 (void *vec, int reserve, size_t vec_offset, size_t elt_size,
vec = ggc_realloc_stat (vec, size PASS_MEM_STAT);
((struct vec_prefix *)vec)->alloc = alloc;
((struct vec_prefix *)vec)->alloc_ = alloc;
if (!pfx)
((struct vec_prefix *)vec)->num = 0;
((struct vec_prefix *)vec)->num_ = 0;
return vec;
}
@ -268,9 +268,9 @@ vec_heap_o_reserve_1 (void *vec, int reserve, size_t vec_offset,
free_overhead (pfx);
vec = xrealloc (vec, vec_offset + alloc * elt_size);
((struct vec_prefix *)vec)->alloc = alloc;
((struct vec_prefix *)vec)->alloc_ = alloc;
if (!pfx)
((struct vec_prefix *)vec)->num = 0;
((struct vec_prefix *)vec)->num_ = 0;
if (GATHER_STATISTICS && vec)
register_overhead ((struct vec_prefix *)vec,
vec_offset + alloc * elt_size FINAL_PASS_MEM_STAT);
@ -306,8 +306,8 @@ vec_stack_p_reserve_exact_1 (int alloc, void *space)
VEC_safe_push (void_p, heap, stack_vecs, space);
pfx->num = 0;
pfx->alloc = alloc;
pfx->num_ = 0;
pfx->alloc_ = alloc;
return space;
}
@ -343,15 +343,15 @@ vec_stack_o_reserve_1 (void *vec, int reserve, size_t vec_offset,
}
/* Move VEC to the heap. */
reserve += ((struct vec_prefix *) vec)->num;
reserve += ((struct vec_prefix *) vec)->num_;
newvec = vec_heap_o_reserve_1 (NULL, reserve, vec_offset, elt_size,
exact PASS_MEM_STAT);
if (newvec && vec)
{
((struct vec_prefix *) newvec)->num = ((struct vec_prefix *) vec)->num;
((struct vec_prefix *) newvec)->num_ = ((struct vec_prefix *) vec)->num_;
memcpy (((struct vec_prefix *) newvec)+1,
((struct vec_prefix *) vec)+1,
((struct vec_prefix *) vec)->num * elt_size);
((struct vec_prefix *) vec)->num_ * elt_size);
}
return newvec;
}

1349
gcc/vec.h

File diff suppressed because it is too large Load Diff