Commit 50de5793 by Andi Kleen Committed by Andi Kleen

Change inchash to name space.

Change class inchash to move into a inchash namespace as requested.
The class is now inchash::hash

Rename iterative_hstate_expr to inchash::add_expr
... and convert existing users. It wasn't possible to use hash::,
because that lead to name space conflicts with cp and objc.

So class inchash is now inchash::hash and iterative_hstate_expr
is now inchash::add_expr.

gcc/:

2014-07-31  Andi Kleen  <ak@linux.intel.com>

	* inchash.h (inchash): Change inchash class to namespace.
	(class hash): ... Rename from inchash.
	(add_object): Move from macro to class template.
	* lto-streamer-out.c (hash_tree): Change inchash
	to inchash::hash.
	* tree.c (build_type_attribute_qual_variant): Dito.
	(type_hash_list): Dito.
	(attribute_hash_list): Dito.
	(iterative_hstate_expr): Rename to inchash::add_expr
	(build_range_type_1): Change inchash to inchash::hash
	and use hash::add_expr.
	(build_array_type_1): Dito.
	(build_function_type): Dito
	(build_method_type_directly): Dito.
	(build_offset_type): Dito.
	(build_complex_type): Dito.
	(make_vector_type): Dito.
	* tree.h (iterative_hash_expr): Dito.

gcc/lto/:

2014-07-31  Andi Kleen  <ak@linux.intel.com>

	* lto.c (hash_canonical_type): Use inchash::hash
	and use inchash::add_expr.
	(iterative_hash_canonical_type): Dito.

From-SVN: r213394
parent 79ce6d77
2014-07-31 Andi Kleen <ak@linux.intel.com>
* inchash.h (inchash): Change inchash class to namespace.
(class hash): ... Rename from inchash.
(add_object): Move from macro to class template.
* lto-streamer-out.c (hash_tree): Change inchash
to inchash::hash.
* tree.c (build_type_attribute_qual_variant): Dito.
(type_hash_list): Dito.
(attribute_hash_list): Dito.
(iterative_hstate_expr): Rename to inchash::add_expr
(build_range_type_1): Change inchash to inchash::hash
and use hash::add_expr.
(build_array_type_1): Dito.
(build_function_type): Dito
(build_method_type_directly): Dito.
(build_offset_type): Dito.
(build_complex_type): Dito.
(make_vector_type): Dito.
* tree.h (iterative_hash_expr): Dito.
2014-07-31 Chen Gang <gang.chen.5i5j@gmail.com> 2014-07-31 Chen Gang <gang.chen.5i5j@gmail.com>
* gcc.c (do_spec_1): Allocate enough space for saved_suffix. * gcc.c (do_spec_1): Allocate enough space for saved_suffix.
......
...@@ -35,12 +35,15 @@ along with GCC; see the file COPYING3. If not see ...@@ -35,12 +35,15 @@ along with GCC; see the file COPYING3. If not see
extern hashval_t iterative_hash_host_wide_int (HOST_WIDE_INT, hashval_t); extern hashval_t iterative_hash_host_wide_int (HOST_WIDE_INT, hashval_t);
extern hashval_t iterative_hash_hashval_t (hashval_t, hashval_t); extern hashval_t iterative_hash_hashval_t (hashval_t, hashval_t);
class inchash namespace inchash
{
class hash
{ {
public: public:
/* Start incremential hashing, optionally with SEED. */ /* Start incremential hashing, optionally with SEED. */
inchash (hashval_t seed = 0) hash (hashval_t seed = 0)
{ {
val = seed; val = seed;
bits = 0; bits = 0;
...@@ -83,11 +86,16 @@ class inchash ...@@ -83,11 +86,16 @@ class inchash
} }
/* Hash in state from other inchash OTHER. */ /* Hash in state from other inchash OTHER. */
void merge (inchash &other) void merge (hash &other)
{ {
merge_hash (other.val); merge_hash (other.val);
} }
template<class T> void add_object(T &obj)
{
add (&obj, sizeof(T));
}
/* Support for accumulating boolean flags */ /* Support for accumulating boolean flags */
void add_flag (bool flag) void add_flag (bool flag)
...@@ -105,7 +113,7 @@ class inchash ...@@ -105,7 +113,7 @@ class inchash
based on their value. This is useful for hashing commutative based on their value. This is useful for hashing commutative
expressions, so that A+B and B+A get the same hash. */ expressions, so that A+B and B+A get the same hash. */
void add_commutative (inchash &a, inchash &b) void add_commutative (hash &a, hash &b)
{ {
if (a.end() > b.end()) if (a.end() > b.end())
{ {
...@@ -124,6 +132,6 @@ class inchash ...@@ -124,6 +132,6 @@ class inchash
unsigned bits; unsigned bits;
}; };
#define add_object(o) add (&(o), sizeof (o)) }
#endif #endif
...@@ -732,7 +732,7 @@ DFS::DFS_write_tree_body (struct output_block *ob, ...@@ -732,7 +732,7 @@ DFS::DFS_write_tree_body (struct output_block *ob,
static hashval_t static hashval_t
hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, tree t) hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, tree t)
{ {
inchash hstate; inchash::hash hstate;
#define visit(SIBLING) \ #define visit(SIBLING) \
do { \ do { \
......
2014-07-31 Andi Kleen <ak@linux.intel.com>
* lto.c (hash_canonical_type): Use inchash::hash
and use inchash::add_expr.
(iterative_hash_canonical_type): Dito.
2014-07-30 Richard Biener <rguenther@suse.de> 2014-07-30 Richard Biener <rguenther@suse.de>
* lto-streamer.h (lto_write_data): New function. * lto-streamer.h (lto_write_data): New function.
......
...@@ -267,7 +267,7 @@ static hash_map<const_tree, hashval_t> *canonical_type_hash_cache; ...@@ -267,7 +267,7 @@ static hash_map<const_tree, hashval_t> *canonical_type_hash_cache;
static unsigned long num_canonical_type_hash_entries; static unsigned long num_canonical_type_hash_entries;
static unsigned long num_canonical_type_hash_queries; static unsigned long num_canonical_type_hash_queries;
static void iterative_hash_canonical_type (tree type, inchash &hstate); static void iterative_hash_canonical_type (tree type, inchash::hash &hstate);
static hashval_t gimple_canonical_type_hash (const void *p); static hashval_t gimple_canonical_type_hash (const void *p);
static void gimple_register_canonical_type_1 (tree t, hashval_t hash); static void gimple_register_canonical_type_1 (tree t, hashval_t hash);
...@@ -279,7 +279,7 @@ static void gimple_register_canonical_type_1 (tree t, hashval_t hash); ...@@ -279,7 +279,7 @@ static void gimple_register_canonical_type_1 (tree t, hashval_t hash);
static hashval_t static hashval_t
hash_canonical_type (tree type) hash_canonical_type (tree type)
{ {
inchash hstate; inchash::hash hstate;
/* Combine a few common features of types so that types are grouped into /* Combine a few common features of types so that types are grouped into
smaller sets; when searching for existing matching types to merge, smaller sets; when searching for existing matching types to merge,
...@@ -327,9 +327,9 @@ hash_canonical_type (tree type) ...@@ -327,9 +327,9 @@ hash_canonical_type (tree type)
/* OMP lowering can introduce error_mark_node in place of /* OMP lowering can introduce error_mark_node in place of
random local decls in types. */ random local decls in types. */
if (TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != error_mark_node) if (TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
iterative_hstate_expr (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), hstate); inchash::add_expr (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), hstate);
if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node) if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
iterative_hstate_expr (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), hstate); inchash::add_expr (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), hstate);
} }
/* Recurse for aggregates with a single element type. */ /* Recurse for aggregates with a single element type. */
...@@ -380,7 +380,7 @@ hash_canonical_type (tree type) ...@@ -380,7 +380,7 @@ hash_canonical_type (tree type)
/* Returning a hash value for gimple type TYPE combined with VAL. */ /* Returning a hash value for gimple type TYPE combined with VAL. */
static void static void
iterative_hash_canonical_type (tree type, inchash &hstate) iterative_hash_canonical_type (tree type, inchash::hash &hstate)
{ {
hashval_t v; hashval_t v;
/* An already processed type. */ /* An already processed type. */
......
...@@ -231,8 +231,8 @@ static void print_type_hash_statistics (void); ...@@ -231,8 +231,8 @@ static void print_type_hash_statistics (void);
static void print_debug_expr_statistics (void); static void print_debug_expr_statistics (void);
static void print_value_expr_statistics (void); static void print_value_expr_statistics (void);
static int type_hash_marked_p (const void *); static int type_hash_marked_p (const void *);
static void type_hash_list (const_tree, inchash &); static void type_hash_list (const_tree, inchash::hash &);
static void attribute_hash_list (const_tree, inchash &); static void attribute_hash_list (const_tree, inchash::hash &);
tree global_trees[TI_MAX]; tree global_trees[TI_MAX];
tree integer_types[itk_none]; tree integer_types[itk_none];
...@@ -4593,7 +4593,7 @@ build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) ...@@ -4593,7 +4593,7 @@ build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
{ {
if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
{ {
inchash hstate; inchash::hash hstate;
tree ntype; tree ntype;
int i; int i;
tree t; tree t;
...@@ -6631,7 +6631,7 @@ decl_debug_args_insert (tree from) ...@@ -6631,7 +6631,7 @@ decl_debug_args_insert (tree from)
of the individual types. */ of the individual types. */
static void static void
type_hash_list (const_tree list, inchash &hstate) type_hash_list (const_tree list, inchash::hash &hstate)
{ {
const_tree tail; const_tree tail;
...@@ -6866,7 +6866,7 @@ print_type_hash_statistics (void) ...@@ -6866,7 +6866,7 @@ print_type_hash_statistics (void)
by adding the hash codes of the individual attributes. */ by adding the hash codes of the individual attributes. */
static void static void
attribute_hash_list (const_tree list, inchash &hstate) attribute_hash_list (const_tree list, inchash::hash &hstate)
{ {
const_tree tail; const_tree tail;
...@@ -7384,13 +7384,16 @@ commutative_ternary_tree_code (enum tree_code code) ...@@ -7384,13 +7384,16 @@ commutative_ternary_tree_code (enum tree_code code)
return false; return false;
} }
namespace inchash
{
/* Generate a hash value for an expression. This can be used iteratively /* Generate a hash value for an expression. This can be used iteratively
by passing a previous result as the HSTATE argument. by passing a previous result as the HSTATE argument.
This function is intended to produce the same hash for expressions which This function is intended to produce the same hash for expressions which
would compare equal using operand_equal_p. */ would compare equal using operand_equal_p. */
void void
iterative_hstate_expr (const_tree t, inchash &hstate) add_expr (const_tree t, inchash::hash &hstate)
{ {
int i; int i;
enum tree_code code; enum tree_code code;
...@@ -7431,14 +7434,14 @@ iterative_hstate_expr (const_tree t, inchash &hstate) ...@@ -7431,14 +7434,14 @@ iterative_hstate_expr (const_tree t, inchash &hstate)
hstate.add ((const void *) TREE_STRING_POINTER (t), TREE_STRING_LENGTH (t)); hstate.add ((const void *) TREE_STRING_POINTER (t), TREE_STRING_LENGTH (t));
return; return;
case COMPLEX_CST: case COMPLEX_CST:
iterative_hstate_expr (TREE_REALPART (t), hstate); inchash::add_expr (TREE_REALPART (t), hstate);
iterative_hstate_expr (TREE_IMAGPART (t), hstate); inchash::add_expr (TREE_IMAGPART (t), hstate);
return; return;
case VECTOR_CST: case VECTOR_CST:
{ {
unsigned i; unsigned i;
for (i = 0; i < VECTOR_CST_NELTS (t); ++i) for (i = 0; i < VECTOR_CST_NELTS (t); ++i)
iterative_hstate_expr (VECTOR_CST_ELT (t, i), hstate); inchash::add_expr (VECTOR_CST_ELT (t, i), hstate);
return; return;
} }
case SSA_NAME: case SSA_NAME:
...@@ -7452,7 +7455,7 @@ iterative_hstate_expr (const_tree t, inchash &hstate) ...@@ -7452,7 +7455,7 @@ iterative_hstate_expr (const_tree t, inchash &hstate)
/* A list of expressions, for a CALL_EXPR or as the elements of a /* A list of expressions, for a CALL_EXPR or as the elements of a
VECTOR_CST. */ VECTOR_CST. */
for (; t; t = TREE_CHAIN (t)) for (; t; t = TREE_CHAIN (t))
iterative_hstate_expr (TREE_VALUE (t), hstate); inchash::add_expr (TREE_VALUE (t), hstate);
return; return;
case CONSTRUCTOR: case CONSTRUCTOR:
{ {
...@@ -7460,8 +7463,8 @@ iterative_hstate_expr (const_tree t, inchash &hstate) ...@@ -7460,8 +7463,8 @@ iterative_hstate_expr (const_tree t, inchash &hstate)
tree field, value; tree field, value;
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value) FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
{ {
iterative_hstate_expr (field, hstate); inchash::add_expr (field, hstate);
iterative_hstate_expr (value, hstate); inchash::add_expr (value, hstate);
} }
return; return;
} }
...@@ -7500,7 +7503,7 @@ iterative_hstate_expr (const_tree t, inchash &hstate) ...@@ -7500,7 +7503,7 @@ iterative_hstate_expr (const_tree t, inchash &hstate)
{ {
/* Make sure to include signness in the hash computation. */ /* Make sure to include signness in the hash computation. */
hstate.add_int (TYPE_UNSIGNED (TREE_TYPE (t))); hstate.add_int (TYPE_UNSIGNED (TREE_TYPE (t)));
iterative_hstate_expr (TREE_OPERAND (t, 0), hstate); inchash::add_expr (TREE_OPERAND (t, 0), hstate);
} }
else if (commutative_tree_code (code)) else if (commutative_tree_code (code))
...@@ -7509,19 +7512,21 @@ iterative_hstate_expr (const_tree t, inchash &hstate) ...@@ -7509,19 +7512,21 @@ iterative_hstate_expr (const_tree t, inchash &hstate)
however it appears. We do this by first hashing both operands however it appears. We do this by first hashing both operands
and then rehashing based on the order of their independent and then rehashing based on the order of their independent
hashes. */ hashes. */
inchash one, two; inchash::hash one, two;
iterative_hstate_expr (TREE_OPERAND (t, 0), one); inchash::add_expr (TREE_OPERAND (t, 0), one);
iterative_hstate_expr (TREE_OPERAND (t, 1), two); inchash::add_expr (TREE_OPERAND (t, 1), two);
hstate.add_commutative (one, two); hstate.add_commutative (one, two);
} }
else else
for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i) for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
iterative_hstate_expr (TREE_OPERAND (t, i), hstate); inchash::add_expr (TREE_OPERAND (t, i), hstate);
} }
return; return;
} }
} }
}
/* Constructors for pointer, array and function types. /* Constructors for pointer, array and function types.
(RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
constructed by language-dependent code, not here.) */ constructed by language-dependent code, not here.) */
...@@ -7711,7 +7716,7 @@ static tree ...@@ -7711,7 +7716,7 @@ static tree
build_range_type_1 (tree type, tree lowval, tree highval, bool shared) build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
{ {
tree itype = make_node (INTEGER_TYPE); tree itype = make_node (INTEGER_TYPE);
inchash hstate; inchash::hash hstate;
TREE_TYPE (itype) = type; TREE_TYPE (itype) = type;
...@@ -7739,8 +7744,8 @@ build_range_type_1 (tree type, tree lowval, tree highval, bool shared) ...@@ -7739,8 +7744,8 @@ build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
return itype; return itype;
} }
iterative_hstate_expr (TYPE_MIN_VALUE (itype), hstate); inchash::add_expr (TYPE_MIN_VALUE (itype), hstate);
iterative_hstate_expr (TYPE_MAX_VALUE (itype), hstate); inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
hstate.merge_hash (TYPE_HASH (type)); hstate.merge_hash (TYPE_HASH (type));
itype = type_hash_canon (hstate.end (), itype); itype = type_hash_canon (hstate.end (), itype);
...@@ -7847,7 +7852,7 @@ build_array_type_1 (tree elt_type, tree index_type, bool shared) ...@@ -7847,7 +7852,7 @@ build_array_type_1 (tree elt_type, tree index_type, bool shared)
if (shared) if (shared)
{ {
inchash hstate; inchash::hash hstate;
hstate.add_object (TYPE_HASH (elt_type)); hstate.add_object (TYPE_HASH (elt_type));
if (index_type) if (index_type)
hstate.add_object (TYPE_HASH (index_type)); hstate.add_object (TYPE_HASH (index_type));
...@@ -7991,7 +7996,7 @@ tree ...@@ -7991,7 +7996,7 @@ tree
build_function_type (tree value_type, tree arg_types) build_function_type (tree value_type, tree arg_types)
{ {
tree t; tree t;
inchash hstate; inchash::hash hstate;
bool any_structural_p, any_noncanonical_p; bool any_structural_p, any_noncanonical_p;
tree canon_argtypes; tree canon_argtypes;
...@@ -8146,7 +8151,7 @@ build_method_type_directly (tree basetype, ...@@ -8146,7 +8151,7 @@ build_method_type_directly (tree basetype,
{ {
tree t; tree t;
tree ptype; tree ptype;
inchash hstate; inchash::hash hstate;
bool any_structural_p, any_noncanonical_p; bool any_structural_p, any_noncanonical_p;
tree canon_argtypes; tree canon_argtypes;
...@@ -8214,7 +8219,7 @@ tree ...@@ -8214,7 +8219,7 @@ tree
build_offset_type (tree basetype, tree type) build_offset_type (tree basetype, tree type)
{ {
tree t; tree t;
inchash hstate; inchash::hash hstate;
/* Make a node of the sort we want. */ /* Make a node of the sort we want. */
t = make_node (OFFSET_TYPE); t = make_node (OFFSET_TYPE);
...@@ -8251,7 +8256,7 @@ tree ...@@ -8251,7 +8256,7 @@ tree
build_complex_type (tree component_type) build_complex_type (tree component_type)
{ {
tree t; tree t;
inchash hstate; inchash::hash hstate;
gcc_assert (INTEGRAL_TYPE_P (component_type) gcc_assert (INTEGRAL_TYPE_P (component_type)
|| SCALAR_FLOAT_TYPE_P (component_type) || SCALAR_FLOAT_TYPE_P (component_type)
...@@ -9403,7 +9408,7 @@ static tree ...@@ -9403,7 +9408,7 @@ static tree
make_vector_type (tree innertype, int nunits, enum machine_mode mode) make_vector_type (tree innertype, int nunits, enum machine_mode mode)
{ {
tree t; tree t;
inchash hstate; inchash::hash hstate;
t = make_node (VECTOR_TYPE); t = make_node (VECTOR_TYPE);
TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype); TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
......
...@@ -4284,14 +4284,20 @@ extern int tree_log2 (const_tree); ...@@ -4284,14 +4284,20 @@ extern int tree_log2 (const_tree);
extern int tree_floor_log2 (const_tree); extern int tree_floor_log2 (const_tree);
extern unsigned int tree_ctz (const_tree); extern unsigned int tree_ctz (const_tree);
extern int simple_cst_equal (const_tree, const_tree); extern int simple_cst_equal (const_tree, const_tree);
extern void iterative_hstate_expr (const_tree, inchash &);
namespace inchash
{
extern void add_expr (const_tree, hash &);
}
/* Compat version until all callers are converted. Return hash for /* Compat version until all callers are converted. Return hash for
TREE with SEED. */ TREE with SEED. */
static inline hashval_t iterative_hash_expr(const_tree tree, hashval_t seed) static inline hashval_t iterative_hash_expr(const_tree tree, hashval_t seed)
{ {
inchash hstate (seed); inchash::hash hstate (seed);
iterative_hstate_expr (tree, hstate); inchash::add_expr (tree, hstate);
return hstate.end (); return hstate.end ();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment