Skip to content

Commit

Permalink
Remove unnecessary VEC function overloads.
Browse files Browse the repository at this point in the history
Several VEC member functions that accept an element 'T' used to have
two overloads: one taking 'T', the second taking 'T *'.

This used to be needed because of the interface dichotomy between
vectors of objects and vectors of pointers.  In the past, vectors of
pointers would use pass-by-value semantics, but vectors of objects
would use pass-by-reference semantics.  This is no longer necessary,
but the distinction had remained.

The main side-effect of this change is some code reduction in code
that manipulates vectors of objects.  For instance,

-  struct iterator_use *iuse;
-
-  iuse = VEC_safe_push (iterator_use, heap, iterator_uses, NULL);
-  iuse->iterator = iterator;
-  iuse->ptr = ptr;
+  struct iterator_use iuse = {iterator, ptr};
+  VEC_safe_push (iterator_use, heap, iterator_uses, iuse);

Compile time performance was not affected.

Tested on x86_64 and ppc64.

Also built all-gcc on all targets using VEC routines: arm, bfin, c6x,
epiphany, ia64, mips, sh, spu, and vms.

2012-09-10  Diego Novillo  <dnovillo@google.com>

	* vec.h (vec_t::quick_push): Remove overload that accepts 'T *'.
	Update all users.
	(vec_t::safe_push): Likewise.
	(vec_t::quick_insert): Likewise.
	(vec_t::lower_bound): Likewise.
	(vec_t::safe_insert): Likewise.
	(vec_t::replace): Change second argument to 'T &'.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@191165 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
dnovillo committed Sep 11, 2012
1 parent 85c0e76 commit e82e4eb
Show file tree
Hide file tree
Showing 71 changed files with 410 additions and 580 deletions.
10 changes: 10 additions & 0 deletions gcc/ChangeLog
@@ -1,3 +1,13 @@
2012-09-10 Diego Novillo <dnovillo@google.com>

* vec.h (vec_t::quick_push): Remove overload that accepts 'T *'.
Update all users.
(vec_t::safe_push): Likewise.
(vec_t::quick_insert): Likewise.
(vec_t::lower_bound): Likewise.
(vec_t::safe_insert): Likewise.
(vec_t::replace): Change second argument to 'T &'.

2012-09-10 Maciej W. Rozycki <macro@codesourcery.com>

* config/rs6000/rs6000.md: Move a splitter next to its insn.
Expand Down
13 changes: 4 additions & 9 deletions gcc/ada/gcc-interface/decl.c
Expand Up @@ -7507,9 +7507,8 @@ build_subst_list (Entity_Id gnat_subtype, Entity_Id gnat_type, bool definition)
(Node (gnat_value), gnat_subtype,
get_entity_name (gnat_discrim),
definition, true, false));
subst_pair *s = VEC_safe_push (subst_pair, heap, gnu_list, NULL);
s->discriminant = gnu_field;
s->replacement = replacement;
subst_pair s = {gnu_field, replacement};
VEC_safe_push (subst_pair, heap, gnu_list, s);
}

return gnu_list;
Expand Down Expand Up @@ -7541,14 +7540,10 @@ build_variant_list (tree qual_union_type, VEC(subst_pair,heap) *subst_list,
still be accessed. */
if (!integer_zerop (qual))
{
variant_desc *v;
tree variant_type = TREE_TYPE (gnu_field), variant_subpart;
variant_desc v = {variant_type, gnu_field, qual, NULL_TREE};

v = VEC_safe_push (variant_desc, heap, gnu_list, NULL);
v->type = variant_type;
v->field = gnu_field;
v->qual = qual;
v->new_type = NULL_TREE;
VEC_safe_push (variant_desc, heap, gnu_list, v);

/* Recurse on the variant subpart of the variant, if any. */
variant_subpart = get_variant_part (variant_type);
Expand Down
11 changes: 4 additions & 7 deletions gcc/ada/gcc-interface/utils.c
Expand Up @@ -4615,16 +4615,14 @@ convert (tree type, tree expr)

FOR_EACH_CONSTRUCTOR_ELT(e, idx, index, value)
{
constructor_elt *elt;
/* We expect only simple constructors. */
if (!SAME_FIELD_P (index, efield))
break;
/* The field must be the same. */
if (!SAME_FIELD_P (efield, field))
break;
elt = VEC_quick_push (constructor_elt, v, NULL);
elt->index = field;
elt->value = convert (TREE_TYPE (field), value);
constructor_elt elt = {field, convert (TREE_TYPE (field), value)};
VEC_quick_push (constructor_elt, v, elt);

/* If packing has made this field a bitfield and the input
value couldn't be emitted statically any more, we need to
Expand Down Expand Up @@ -4690,9 +4688,8 @@ convert (tree type, tree expr)
v = VEC_alloc (constructor_elt, gc, len);
FOR_EACH_CONSTRUCTOR_VALUE (e, ix, value)
{
constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
elt->index = NULL_TREE;
elt->value = value;
constructor_elt elt = {NULL_TREE, value};
VEC_quick_push (constructor_elt, v, elt);
}
expr = copy_node (expr);
TREE_TYPE (expr) = type;
Expand Down
4 changes: 2 additions & 2 deletions gcc/alias.c
Expand Up @@ -855,8 +855,8 @@ new_alias_set (void)
if (flag_strict_aliasing)
{
if (alias_sets == 0)
VEC_safe_push (alias_set_entry, gc, alias_sets, (alias_set_entry) 0);
VEC_safe_push (alias_set_entry, gc, alias_sets, (alias_set_entry) 0);
VEC_safe_push (alias_set_entry, gc, alias_sets, 0);
VEC_safe_push (alias_set_entry, gc, alias_sets, 0);
return VEC_length (alias_set_entry, alias_sets) - 1;
}
else
Expand Down
2 changes: 1 addition & 1 deletion gcc/c-family/c-common.c
Expand Up @@ -8535,7 +8535,7 @@ parse_optimize_options (tree args, bool attr_p)
/* Build up argv vector. Just in case the string is stored away, use garbage
collected strings. */
VEC_truncate (const_char_p, optimize_args, 0);
VEC_safe_push (const_char_p, gc, optimize_args, (const_char_p)NULL);
VEC_safe_push (const_char_p, gc, optimize_args, NULL);

for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap))
{
Expand Down
15 changes: 6 additions & 9 deletions gcc/c-family/c-pragma.c
Expand Up @@ -372,10 +372,8 @@ handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
}
else
{
pending_weak *pe;
pe = VEC_safe_push (pending_weak, gc, pending_weaks, NULL);
pe->name = name;
pe->value = value;
pending_weak pe = {name, value};
VEC_safe_push (pending_weak, gc, pending_weaks, pe);
}
}

Expand Down Expand Up @@ -499,9 +497,8 @@ add_to_renaming_pragma_list (tree oldname, tree newname)
return;
}

p = VEC_safe_push (pending_redefinition, gc, pending_redefine_extname, NULL);
p->oldname = oldname;
p->newname = newname;
pending_redefinition e = {oldname, newname};
VEC_safe_push (pending_redefinition, gc, pending_redefine_extname, e);
}

/* The current prefix set by #pragma extern_prefix. */
Expand Down Expand Up @@ -1236,14 +1233,14 @@ c_register_pragma_1 (const char *space, const char *name,

ns_name.space = space;
ns_name.name = name;
VEC_safe_push (pragma_ns_name, heap, registered_pp_pragmas, &ns_name);
VEC_safe_push (pragma_ns_name, heap, registered_pp_pragmas, ns_name);
id = VEC_length (pragma_ns_name, registered_pp_pragmas);
id += PRAGMA_FIRST_EXTERNAL - 1;
}
else
{
VEC_safe_push (internal_pragma_handler, heap, registered_pragmas,
&ihandler);
ihandler);
id = VEC_length (internal_pragma_handler, registered_pragmas);
id += PRAGMA_FIRST_EXTERNAL - 1;

Expand Down
8 changes: 4 additions & 4 deletions gcc/c/c-decl.c
Expand Up @@ -6437,7 +6437,7 @@ get_parm_info (bool ellipsis, tree expr)
{
tree decl = b->decl;
tree type = TREE_TYPE (decl);
c_arg_tag *tag;
c_arg_tag tag;
const char *keyword;

switch (TREE_CODE (decl))
Expand Down Expand Up @@ -6511,9 +6511,9 @@ get_parm_info (bool ellipsis, tree expr)
}
}

tag = VEC_safe_push (c_arg_tag, gc, tags, NULL);
tag->id = b->id;
tag->type = decl;
tag.id = b->id;
tag.type = decl;
VEC_safe_push (c_arg_tag, gc, tags, tag);
break;

case CONST_DECL:
Expand Down
4 changes: 2 additions & 2 deletions gcc/c/c-tree.h
Expand Up @@ -142,8 +142,8 @@ DEF_VEC_ALLOC_O (c_expr_t, heap);
/* Append a new c_expr_t element to V. */
#define C_EXPR_APPEND(V, ELEM) \
do { \
c_expr_t *__elem_p = VEC_safe_push (c_expr_t, gc, V, NULL); \
*__elem_p = (ELEM); \
c_expr_t __elem = (ELEM); \
VEC_safe_push (c_expr_t, gc, V, __elem); \
} while (0)

/* A kind of type specifier. Note that this information is currently
Expand Down
6 changes: 2 additions & 4 deletions gcc/c/c-typeck.c
Expand Up @@ -7709,7 +7709,6 @@ output_init_element (tree value, tree origtype, bool strict_string, tree type,
struct obstack * braced_init_obstack)
{
tree semantic_type = NULL_TREE;
constructor_elt *celt;
bool maybe_const = true;
bool npc;

Expand Down Expand Up @@ -7876,9 +7875,8 @@ output_init_element (tree value, tree origtype, bool strict_string, tree type,
/* Otherwise, output this element either to
constructor_elements or to the assembler file. */

celt = VEC_safe_push (constructor_elt, gc, constructor_elements, NULL);
celt->index = field;
celt->value = value;
constructor_elt celt = {field, value};
VEC_safe_push (constructor_elt, gc, constructor_elements, celt);

/* Advance the variable that indicates sequential elements output. */
if (TREE_CODE (constructor_type) == ARRAY_TYPE)
Expand Down
4 changes: 2 additions & 2 deletions gcc/config/mips/mips.c
Expand Up @@ -3989,8 +3989,8 @@ mips_multi_start (void)
static struct mips_multi_member *
mips_multi_add (void)
{
return VEC_safe_push (mips_multi_member, heap, mips_multi_members,
(struct mips_multi_member *) 0);
mips_multi_member empty;
return VEC_safe_push (mips_multi_member, heap, mips_multi_members, empty);
}

/* Add a normal insn with the given asm format to the current multi-insn
Expand Down
6 changes: 2 additions & 4 deletions gcc/config/pa/pa.c
Expand Up @@ -9948,11 +9948,9 @@ static GTY(()) VEC(extern_symbol,gc) *extern_symbols;
void
pa_hpux_asm_output_external (FILE *file, tree decl, const char *name)
{
extern_symbol * p = VEC_safe_push (extern_symbol, gc, extern_symbols, NULL);

gcc_assert (file == asm_out_file);
p->decl = decl;
p->name = name;
extern_symbol p = {decl, name};
VEC_safe_push (extern_symbol, gc, extern_symbols, p);
}

/* Output text required at the end of an assembler file.
Expand Down
7 changes: 2 additions & 5 deletions gcc/config/rs6000/rs6000-c.c
Expand Up @@ -3582,11 +3582,8 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
vec = VEC_alloc (constructor_elt, gc, size);
for(i = 0; i < size; i++)
{
constructor_elt *elt;

elt = VEC_quick_push (constructor_elt, vec, NULL);
elt->index = NULL_TREE;
elt->value = arg;
constructor_elt elt = {NULL_TREE, arg};
VEC_quick_push (constructor_elt, vec, elt);
}
return build_constructor (type, vec);
}
Expand Down
7 changes: 2 additions & 5 deletions gcc/config/rs6000/rs6000.c
Expand Up @@ -24901,11 +24901,8 @@ static void
add_compiler_branch_island (tree label_name, tree function_name,
int line_number)
{
branch_island *bi = VEC_safe_push (branch_island, gc, branch_islands, NULL);

bi->function_name = function_name;
bi->label_name = label_name;
bi->line_number = line_number;
branch_island bi = {function_name, label_name, line_number};
VEC_safe_push (branch_island, gc, branch_islands, bi);
}

/* Generate far-jump branch islands for everything recorded in
Expand Down
8 changes: 3 additions & 5 deletions gcc/cp/class.c
Expand Up @@ -8835,11 +8835,9 @@ add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
offset. */
if (vid->binfo == TYPE_BINFO (vid->derived))
{
tree_pair_p elt = VEC_safe_push (tree_pair_s, gc,
CLASSTYPE_VCALL_INDICES (vid->derived),
NULL);
elt->purpose = orig_fn;
elt->value = vid->index;
tree_pair_s elt = {orig_fn, vid->index};
VEC_safe_push (tree_pair_s, gc, CLASSTYPE_VCALL_INDICES (vid->derived),
elt);
}

/* The next vcall offset will be found at a more negative
Expand Down
16 changes: 7 additions & 9 deletions gcc/cp/decl.c
Expand Up @@ -2639,16 +2639,16 @@ tree
declare_local_label (tree id)
{
tree decl;
cp_label_binding *bind;
cp_label_binding bind;

/* Add a new entry to the SHADOWED_LABELS list so that when we leave
this scope we can restore the old value of IDENTIFIER_TYPE_VALUE. */
bind = VEC_safe_push (cp_label_binding, gc,
current_binding_level->shadowed_labels, NULL);
bind->prev_value = IDENTIFIER_LABEL_VALUE (id);
bind.prev_value = IDENTIFIER_LABEL_VALUE (id);

decl = make_label_decl (id, /*local_p=*/1);
bind->label = decl;
bind.label = decl;
VEC_safe_push (cp_label_binding, gc, current_binding_level->shadowed_labels,
bind);

return decl;
}
Expand Down Expand Up @@ -13782,10 +13782,8 @@ maybe_register_incomplete_var (tree var)
|| (TYPE_LANG_SPECIFIC (inner_type)
&& TYPE_BEING_DEFINED (inner_type)))
{
incomplete_var *iv
= VEC_safe_push (incomplete_var, gc, incomplete_vars, NULL);
iv->decl = var;
iv->incomplete_type = inner_type;
incomplete_var iv = {var, inner_type};
VEC_safe_push (incomplete_var, gc, incomplete_vars, iv);
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions gcc/cp/except.c
Expand Up @@ -1249,11 +1249,8 @@ expr_noexcept_p (tree expr, tsubst_flags_t complain)
if (!DECL_INITIAL (fn))
{
/* Not defined yet; check again at EOF. */
pending_noexcept *p
= VEC_safe_push (pending_noexcept, gc,
pending_noexcept_checks, NULL);
p->fn = fn;
p->loc = input_location;
pending_noexcept p = {fn, input_location};
VEC_safe_push (pending_noexcept, gc, pending_noexcept_checks, p);
}
else
maybe_noexcept_warning (fn);
Expand Down
27 changes: 13 additions & 14 deletions gcc/cp/init.c
Expand Up @@ -253,21 +253,21 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
have an upper bound of -1. */
if (!tree_int_cst_equal (max_index, integer_minus_one_node))
{
constructor_elt *ce;
constructor_elt ce;

v = VEC_alloc (constructor_elt, gc, 1);
ce = VEC_quick_push (constructor_elt, v, NULL);

/* If this is a one element array, we just use a regular init. */
if (tree_int_cst_equal (size_zero_node, max_index))
ce->index = size_zero_node;
ce.index = size_zero_node;
else
ce->index = build2 (RANGE_EXPR, sizetype, size_zero_node,
ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node,
max_index);

ce->value = build_zero_init_1 (TREE_TYPE (type),
ce.value = build_zero_init_1 (TREE_TYPE (type),
/*nelts=*/NULL_TREE,
static_storage_p, NULL_TREE);
VEC_quick_push (constructor_elt, v, ce);
}

/* Build a constructor to contain the initializations. */
Expand Down Expand Up @@ -448,28 +448,27 @@ build_value_init_noctor (tree type, tsubst_flags_t complain)
have an upper bound of -1. */
if (!tree_int_cst_equal (max_index, integer_minus_one_node))
{
constructor_elt *ce;
constructor_elt ce;

v = VEC_alloc (constructor_elt, gc, 1);
ce = VEC_quick_push (constructor_elt, v, NULL);

/* If this is a one element array, we just use a regular init. */
if (tree_int_cst_equal (size_zero_node, max_index))
ce->index = size_zero_node;
ce.index = size_zero_node;
else
ce->index = build2 (RANGE_EXPR, sizetype, size_zero_node,
max_index);
ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node, max_index);

ce->value = build_value_init (TREE_TYPE (type), complain);
ce.value = build_value_init (TREE_TYPE (type), complain);
VEC_quick_push (constructor_elt, v, ce);

if (ce->value == error_mark_node)
if (ce.value == error_mark_node)
return error_mark_node;

/* We shouldn't have gotten here for anything that would need
non-trivial initialization, and gimplify_init_ctor_preeval
would need to be fixed to allow it. */
gcc_assert (TREE_CODE (ce->value) != TARGET_EXPR
&& TREE_CODE (ce->value) != AGGR_INIT_EXPR);
gcc_assert (TREE_CODE (ce.value) != TARGET_EXPR
&& TREE_CODE (ce.value) != AGGR_INIT_EXPR);
}

/* Build a constructor to contain the initializations. */
Expand Down

0 comments on commit e82e4eb

Please sign in to comment.