8sa1-gcc/gcc/vec.c
Kaveh R. Ghazi 3d9a9f947f ggc.h (GGC_RESIZEVAR): New, reorder macros.
* ggc.h (GGC_RESIZEVAR): New, reorder macros.
	* tracer.c (tail_duplicate): Fix for -Wc++-compat.
	* tree-affine.c (aff_combination_expand, free_name_expansion):
	Likewise.
	* tree-cfg.c (replace_by_duplicate_decl, replace_ssa_name,
	move_stmt_r, new_label_mapper): Likewise.
	* tree-complex.c (cvc_lookup): Likewise.
	* tree-dfa.c (create_function_ann): Likewise.
	* tree-dump.c (dump_register): Likewise.
	* tree-if-conv.c (tree_if_conversion, add_to_predicate_list,
	find_phi_replacement_condition): Likewise.
	* tree-inline.c (copy_phis_for_bb, estimate_num_insns_1,
	tree_function_versioning): Likewise.
	* tree-into-ssa.c (cmp_dfsnum): Likewise.
	* tree-iterator.c (tsi_link_before, tsi_link_after): Likewise.
	* tree-nested.c (lookup_field_for_decl, lookup_tramp_for_decl,
	get_nonlocal_debug_decl, convert_nonlocal_reference,
	convert_nonlocal_omp_clauses, get_local_debug_decl,
	convert_local_reference, convert_local_omp_clauses,
	convert_nl_goto_reference, convert_nl_goto_receiver,
	convert_tramp_reference, convert_call_expr): Likewise.
	* tree-outof-ssa.c (contains_tree_r): Likewise.
	* tree-parloops.c (reduction_phi, initialize_reductions,
	eliminate_local_variables_1, add_field_for_reduction,
	add_field_for_name, create_phi_for_local_result,
	create_call_for_reduction_1, create_loads_for_reductions,
	create_stores_for_reduction, create_loads_and_stores_for_name):
	Likewise.
	* tree-phinodes.c (allocate_phi_node): Likewise.
	* tree-predcom.c (order_drefs, execute_pred_commoning_cbck):
	Likewise.
	* tree-sra.c (sra_elt_hash, sra_elt_eq, lookup_element):
	Likewise.
	* tree-ssa-alias.c (get_mem_sym_stats_for): Likewise.
	* tree-ssa-coalesce.c (compare_pairs): Likewise.
	* tree-ssa-loop-im.c (mem_ref_in_stmt, memref_hash, memref_eq,
	memref_free, gather_mem_refs_stmt, vtoe_hash, vtoe_eq, vtoe_free,
	record_vop_access, get_vop_accesses, get_vop_stores): Likewise.
	* tree-ssa-loop-prefetch.c (determine_loop_nest_reuse): Likewise. 
	* tree-ssa-sccvn.c (VN_INFO_GET, free_phi, free_reference,
	vn_nary_op_insert): Likewise.
	* tree-ssa.c (redirect_edge_var_map_add,
	redirect_edge_var_map_clear, redirect_edge_var_map_dup): Likewise.
	* tree-vectorizer.c (vectorize_loops): Likewise.
	* tree.c (make_node_stat, copy_node_stat, build_int_cst_wide,
	build_fixed, build_real, make_tree_binfo_stat, make_tree_vec_stat,
	tree_cons_stat, build1_stat, build_variant_type_copy,
	decl_init_priority_lookup, decl_fini_priority_lookup,
	decl_priority_info, decl_restrict_base_lookup,
	decl_restrict_base_insert, decl_debug_expr_lookup,
	decl_debug_expr_insert, decl_value_expr_lookup,
	decl_value_expr_insert, type_hash_eq, type_hash_lookup,
	type_hash_add, get_file_function_name, tree_check_failed,
	tree_not_check_failed, tree_range_check_failed,
	omp_clause_range_check_failed, build_omp_clause,
	build_vl_exp_stat): Likewise.
	* value-prof.c (gimple_histogram_value,
	gimple_duplicate_stmt_histograms): Likewise.
	* var-tracking.c (attrs_list_insert, attrs_list_copy,
	unshare_variable, variable_union_info_cmp_pos, variable_union,
	dataflow_set_different_1, dataflow_set_different_2,
	vt_find_locations, variable_was_changed, set_variable_part,
	emit_notes_for_differences_1, emit_notes_for_differences_2):
	Likewise.
	* varasm.c (prefix_name, emutls_decl, section_entry_eq,
	section_entry_hash, object_block_entry_eq,
	object_block_entry_hash, create_block_symbol,
	initialize_cold_section_name, default_function_rodata_section,
	strip_reg_name, set_user_assembler_name, const_desc_eq,
	build_constant_desc, output_constant_def, lookup_constant_def,
	const_desc_rtx_hash, const_desc_rtx_eq, const_rtx_hash_1,
	create_constant_pool, force_const_mem, compute_reloc_for_rtx_1,
	default_internal_label): Likewise.
	* varray.c (varray_init, varray_grow): Likewise.
	* vec.c (vec_gc_o_reserve_1, vec_heap_o_reserve_1): Likewise.

From-SVN: r136992
2008-06-20 18:34:07 +00:00

237 lines
6.4 KiB
C

/* Vector API for GNU compiler.
Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Contributed by Nathan Sidwell <nathan@codesourcery.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/* This file is compiled twice: once for the generator programs
once for the compiler. */
#ifdef GENERATOR_FILE
#include "bconfig.h"
#else
#include "config.h"
#endif
#include "system.h"
#include "ggc.h"
#include "vec.h"
#include "coretypes.h"
#include "toplev.h"
struct vec_prefix
{
unsigned num;
unsigned alloc;
void *vec[1];
};
/* Calculate the new ALLOC value, making sure that RESERVE slots are
free. If EXACT grow exactly, otherwise grow exponentially. */
static inline unsigned
calculate_allocation (const struct vec_prefix *pfx, int reserve, bool exact)
{
unsigned alloc = 0;
unsigned num = 0;
gcc_assert (reserve >= 0);
if (pfx)
{
alloc = pfx->alloc;
num = pfx->num;
}
else if (!reserve)
/* If there's no prefix, and we've not requested anything, then we
will create a NULL vector. */
return 0;
/* We must have run out of room. */
gcc_assert (alloc - num < (unsigned) reserve);
if (exact)
/* Exact size. */
alloc = num + reserve;
else
{
/* Exponential growth. */
if (!alloc)
alloc = 4;
else if (alloc < 16)
/* Double when small. */
alloc = alloc * 2;
else
/* Grow slower when large. */
alloc = (alloc * 3 / 2);
/* If this is still too small, set it to the right size. */
if (alloc < num + reserve)
alloc = num + reserve;
}
return alloc;
}
/* Ensure there are at least RESERVE free slots in VEC. If EXACT grow
exactly, else grow exponentially. As a special case, if VEC is
NULL and RESERVE is 0, no vector will be created. The vector's
trailing array is at VEC_OFFSET offset and consists of ELT_SIZE
sized elements. */
static void *
vec_gc_o_reserve_1 (void *vec, int reserve, size_t vec_offset, size_t elt_size,
bool exact MEM_STAT_DECL)
{
struct vec_prefix *pfx = (struct vec_prefix *) vec;
unsigned alloc = alloc = calculate_allocation (pfx, reserve, exact);
if (!alloc)
return NULL;
vec = ggc_realloc_stat (vec, vec_offset + alloc * elt_size PASS_MEM_STAT);
((struct vec_prefix *)vec)->alloc = alloc;
if (!pfx)
((struct vec_prefix *)vec)->num = 0;
return vec;
}
/* Ensure there are at least RESERVE free slots in VEC, growing
exponentially. If RESERVE < 0 grow exactly, else grow
exponentially. As a special case, if VEC is NULL, and RESERVE is
0, no vector will be created. */
void *
vec_gc_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), false
PASS_MEM_STAT);
}
/* Ensure there are at least RESERVE free slots in VEC, growing
exactly. If RESERVE < 0 grow exactly, else grow exponentially. As
a special case, if VEC is NULL, and RESERVE is 0, no vector will be
created. */
void *
vec_gc_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), true
PASS_MEM_STAT);
}
/* As for vec_gc_p_reserve, but for object vectors. The vector's
trailing array is at VEC_OFFSET offset and consists of ELT_SIZE
sized elements. */
void *
vec_gc_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve, vec_offset, elt_size, false
PASS_MEM_STAT);
}
/* As for vec_gc_p_reserve_exact, but for object vectors. The
vector's trailing array is at VEC_OFFSET offset and consists of
ELT_SIZE sized elements. */
void *
vec_gc_o_reserve_exact (void *vec, int reserve, size_t vec_offset,
size_t elt_size MEM_STAT_DECL)
{
return vec_gc_o_reserve_1 (vec, reserve, vec_offset, elt_size, true
PASS_MEM_STAT);
}
/* As for vec_gc_o_reserve_1, but for heap allocated vectors. */
static void *
vec_heap_o_reserve_1 (void *vec, int reserve, size_t vec_offset,
size_t elt_size, bool exact MEM_STAT_DECL)
{
struct vec_prefix *pfx = (struct vec_prefix *) vec;
unsigned alloc = calculate_allocation (pfx, reserve, exact);
if (!alloc)
return NULL;
vec = xrealloc (vec, vec_offset + alloc * elt_size);
((struct vec_prefix *)vec)->alloc = alloc;
if (!pfx)
((struct vec_prefix *)vec)->num = 0;
return vec;
}
/* As for vec_gc_p_reserve, but for heap allocated vectors. */
void *
vec_heap_p_reserve (void *vec, int reserve MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), false
PASS_MEM_STAT);
}
/* As for vec_gc_p_reserve_exact, but for heap allocated vectors. */
void *
vec_heap_p_reserve_exact (void *vec, int reserve MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve,
offsetof (struct vec_prefix, vec),
sizeof (void *), true
PASS_MEM_STAT);
}
/* As for vec_gc_o_reserve, but for heap allocated vectors. */
void *
vec_heap_o_reserve (void *vec, int reserve, size_t vec_offset, size_t elt_size
MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve, vec_offset, elt_size, false
PASS_MEM_STAT);
}
/* As for vec_gc_o_reserve_exact, but for heap allocated vectors. */
void *
vec_heap_o_reserve_exact (void *vec, int reserve, size_t vec_offset,
size_t elt_size MEM_STAT_DECL)
{
return vec_heap_o_reserve_1 (vec, reserve, vec_offset, elt_size, true
PASS_MEM_STAT);
}
#if ENABLE_CHECKING
/* Issue a vector domain error, and then fall over. */
void
vec_assert_fail (const char *op, const char *struct_name,
const char *file, unsigned int line, const char *function)
{
internal_error ("vector %s %s domain error, in %s at %s:%u",
struct_name, op, function, trim_filename (file), line);
}
#endif