Commit 6032e9e8 authored by Matthias Braun's avatar Matthias Braun
Browse files

hashptr.h: use inline functions instead of #define

parent 68d6fda0
......@@ -34,7 +34,7 @@
/* Computing x * _FIRM_FNV_FNV_PRIME */
#define _FIRM_FNV_TIMES_PRIME(x) ((x) * _FIRM_FNV_FNV_PRIME)
static inline unsigned firm_fnv_hash(const unsigned char *data, size_t bytes)
static inline unsigned hash_data(const unsigned char *data, size_t bytes)
{
size_t i;
unsigned hash = _FIRM_FNV_OFFSET_BASIS;
......@@ -47,7 +47,13 @@ static inline unsigned firm_fnv_hash(const unsigned char *data, size_t bytes)
return hash;
}
static inline unsigned firm_fnv_hash_str(const char *data)
/**
* Returns a hash value for a string.
* @param str The string (can be const).
* @param len The length of the string.
* @return A hash value for the string.
*/
static inline unsigned hash_str(const char *data)
{
unsigned i;
unsigned hash = _FIRM_FNV_OFFSET_BASIS;
......@@ -61,29 +67,22 @@ static inline unsigned firm_fnv_hash_str(const char *data)
}
/**
* hash a pointer value: Pointer addresses are mostly aligned to 4
* or 8 bytes. So we remove the lowest 3 bits
* Returns a hash value for a pointer.
* Pointer addresses are mostly aligned to 4 or 8 bytes. So we remove the
* lowest 3 bits.
*/
#define HASH_PTR(ptr) ((unsigned)(((char *) (ptr) - (char *)0) >> 3))
static inline unsigned hash_ptr(const void *ptr)
{
return HASH_PTR(ptr);
return ((unsigned)(((char *) (ptr) - (char *)0) >> 3));
}
/**
* Hash a string.
* @param str The string (can be const).
* @param len The length of the string.
* @return A hash value for the string.
* Combines 2 hash values.
* @param a One hash value.
* @param b Another hash value.
* @return A hash value computed from both.
*/
#define HASH_STR(str,len) firm_fnv_hash((const unsigned char *) (str), (len))
#ifdef _MSC_VER
#pragma warning(disable:4307)
#endif /* _MSC_VER */
static inline unsigned _hash_combine(unsigned x, unsigned y)
static inline unsigned hash_combine(unsigned x, unsigned y)
{
unsigned hash = _FIRM_FNV_TIMES_PRIME(_FIRM_FNV_OFFSET_BASIS);
hash ^= x;
......@@ -92,18 +91,6 @@ static inline unsigned _hash_combine(unsigned x, unsigned y)
return hash;
}
#ifdef _MSC_VER
#pragma warning(default:4307)
#endif /* _MSC_VER */
/**
* Make one hash value out of two others.
* @param a One hash value.
* @param b Another hash value.
* @return A hash value computed from the both.
*/
#define HASH_COMBINE(a,b) _hash_combine(a, b)
#include "../end.h"
#endif
......@@ -52,14 +52,17 @@ FIRM_API int pset_default_ptr_cmp(const void *x, const void *y);
*/
typedef struct pset pset;
/*
* Define some convenience macros using the predefined hash function.
*/
#define pset_insert_ptr(set,key) pset_insert(set, key, HASH_PTR(key))
#define pset_hinsert_ptr(set,key) pset_hinsert(set, key, HASH_PTR(key))
#define pset_remove_ptr(set,key) pset_remove(set, key, HASH_PTR(key))
#define pset_find_ptr(set,key) pset_find(set, key, HASH_PTR(key))
/** Inserts into pointer set with default hash function. */
#define pset_insert_ptr(set,key) pset_insert(set, key, hash_ptr(key))
/** Inserts into pointer set with default hash function and return entry */
#define pset_hinsert_ptr(set,key) pset_hinsert(set, key, hash_ptr(key))
/** Removes pointer from pointer set with default hash function */
#define pset_remove_ptr(set,key) pset_remove(set, key, hash_ptr(key))
/** Finds pointer in pointer set with default hash function */
#define pset_find_ptr(set,key) pset_find(set, key, hash_ptr(key))
/** Creates new pointer set with default compare function */
#define pset_new_ptr(slots) new_pset(pset_default_ptr_cmp, slots)
/** Creates new pointer set with default compare function and default size */
#define pset_new_ptr_default() pset_new_ptr(64)
/** The entry of a pset, representing an element pointer in the set and its meta-information */
......
......@@ -77,14 +77,14 @@ size_t eset_count(eset *s)
void eset_insert(eset *s, void *p)
{
if (!eset_contains(s, p)) {
set_insert((set *)s, &p, sizeof(p), HASH_PTR(p));
set_insert((set *)s, &p, sizeof(p), hash_ptr(p));
}
}
int eset_contains(eset *s, void *p)
{
return set_find((set *)s, &p, sizeof(p), HASH_PTR(p)) != NULL;
return set_find((set *)s, &p, sizeof(p), hash_ptr(p)) != NULL;
}
......
......@@ -75,18 +75,18 @@ void pmap_insert(pmap *map, const void *key, void *value)
pmap_entry entry, *p;
entry.key = key;
p = (pmap_entry*) set_insert(M2S(map), &entry, sizeof(pmap_entry), HASH_PTR(key));
p = (pmap_entry*) set_insert(M2S(map), &entry, sizeof(pmap_entry), hash_ptr(key));
p->value = value;
}
int pmap_contains(pmap *map, const void *key)
{
return set_find(M2S(map), &key, sizeof(pmap_entry), HASH_PTR(key)) != NULL;
return set_find(M2S(map), &key, sizeof(pmap_entry), hash_ptr(key)) != NULL;
}
pmap_entry * pmap_find(pmap *map, const void *key)
{
return (pmap_entry *)set_find(M2S(map), &key, sizeof(pmap_entry), HASH_PTR(key));
return (pmap_entry *)set_find(M2S(map), &key, sizeof(pmap_entry), hash_ptr(key));
}
......
......@@ -208,8 +208,8 @@ static void ana_Call(ir_node *n, void *env)
buf.irg = callee;
pset_insert((pset *)callee->callers, irg, HASH_PTR(irg));
found = (cg_callee_entry*) pset_find((pset *)irg->callees, &buf, HASH_PTR(callee));
pset_insert((pset *)callee->callers, irg, hash_ptr(irg));
found = (cg_callee_entry*) pset_find((pset *)irg->callees, &buf, hash_ptr(callee));
if (found) { /* add Call node to list, compute new nesting. */
ir_node **arr = found->call_list;
ARR_APP1(ir_node *, arr, n);
......@@ -220,7 +220,7 @@ static void ana_Call(ir_node *n, void *env)
found->call_list = NEW_ARR_F(ir_node *, 1);
found->call_list[0] = n;
found->max_depth = 0;
pset_insert((pset *)irg->callees, found, HASH_PTR(callee));
pset_insert((pset *)irg->callees, found, hash_ptr(callee));
}
depth = get_loop_depth(get_irn_loop(get_nodes_block(n)));
found->max_depth = (depth > found->max_depth) ? depth : found->max_depth;
......
......@@ -61,7 +61,7 @@ static int cmp_node(const void *a, const void *b, size_t sz)
static dfs_edge_t *get_edge(const dfs_t *self, const void *src, const void *tgt)
{
unsigned hash = HASH_COMBINE(HASH_PTR(src), HASH_PTR(tgt));
unsigned hash = hash_combine(hash_ptr(src), hash_ptr(tgt));
dfs_edge_t templ;
templ.src = src;
......
......@@ -70,7 +70,7 @@ static dfs_node_t *_dfs_get_node(const dfs_t *self, const void *node)
dfs_node_t templ;
memset(&templ, 0, sizeof(templ));
templ.node = node;
return (dfs_node_t*) set_insert(self->nodes, &templ, sizeof(templ), HASH_PTR(node));
return (dfs_node_t*) set_insert(self->nodes, &templ, sizeof(templ), hash_ptr(node));
}
#define _dfs_int_is_ancestor(n, m) ((m)->pre_num >= (n)->pre_num && (m)->pre_num <= (n)->max_pre_num)
......
......@@ -96,7 +96,7 @@ static freq_t *set_find_freq(set *freqs, const ir_node *irn)
{
freq_t query;
query.irn = irn;
return (freq_t*) set_find(freqs, &query, sizeof(query), HASH_PTR(irn));
return (freq_t*) set_find(freqs, &query, sizeof(query), hash_ptr(irn));
}
static freq_t *set_insert_freq(set *freqs, const ir_node *irn)
......@@ -106,7 +106,7 @@ static freq_t *set_insert_freq(set *freqs, const ir_node *irn)
query.irn = irn;
query.freq = 0.0;
query.idx = -1;
return (freq_t*) set_insert(freqs, &query, sizeof(query), HASH_PTR(irn));
return (freq_t*) set_insert(freqs, &query, sizeof(query), hash_ptr(irn));
}
double get_block_execfreq(const ir_exec_freq *ef, const ir_node *irn)
......
......@@ -717,7 +717,7 @@ typedef struct mem_disambig_entry {
ir_alias_relation result; /**< The alias relation result. */
} mem_disambig_entry;
#define HASH_ENTRY(adr1, adr2) (HASH_PTR(adr1) ^ HASH_PTR(adr2))
#define HASH_ENTRY(adr1, adr2) (hash_ptr(adr1) ^ hash_ptr(adr2))
/**
* Compare two relation cache entries.
......
......@@ -134,7 +134,7 @@ static void emit_amd64_SymConst(const ir_node *irn)
key.u.id = get_entity_ld_ident(attr->entity);
key.is_ident = 1;
key.label = 0;
entry = (sym_or_tv_t *)set_insert(sym_or_tv, &key, sizeof(key), HASH_PTR(key.u.generic));
entry = (sym_or_tv_t *)set_insert(sym_or_tv, &key, sizeof(key), hash_ptr(key.u.generic));
if (entry->label == 0) {
/* allocate a label */
entry->label = get_unique_label();
......
......@@ -263,7 +263,7 @@ static void emit_arm_SymConst(const ir_node *irn)
key.u.entity = attr->entity;
key.is_entity = true;
key.label = 0;
entry = (sym_or_tv_t *)set_insert(sym_or_tv, &key, sizeof(key), HASH_PTR(key.u.generic));
entry = (sym_or_tv_t *)set_insert(sym_or_tv, &key, sizeof(key), hash_ptr(key.u.generic));
if (entry->label == 0) {
/* allocate a label */
entry->label = get_unique_label();
......@@ -301,7 +301,7 @@ static void emit_arm_fConst(const ir_node *irn)
key.u.tv = get_fConst_value(irn);
key.is_entity = false;
key.label = 0;
entry = (sym_or_tv_t *)set_insert(sym_or_tv, &key, sizeof(key), HASH_PTR(key.u.generic));
entry = (sym_or_tv_t *)set_insert(sym_or_tv, &key, sizeof(key), hash_ptr(key.u.generic));
if (entry->label == 0) {
/* allocate a label */
entry->label = get_unique_label();
......
......@@ -68,7 +68,7 @@ static arm_irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set)
templ.irn = irn;
templ.reg = NULL;
hash = HASH_PTR(irn);
hash = hash_ptr(irn);
return (arm_irn_reg_assoc*)set_insert(reg_set, &templ, sizeof(templ), hash);
}
......
......@@ -41,7 +41,7 @@
DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
#define HASH_LOOP_INFO(info) (HASH_PTR((info)->loop) ^ HASH_PTR((info)->cls))
#define HASH_LOOP_INFO(info) (hash_ptr((info)->loop) ^ hash_ptr((info)->cls))
typedef struct be_loop_info_t {
ir_loop *loop;
......
......@@ -98,7 +98,7 @@ static const be_use_t *get_or_set_use_block(be_uses_t *env,
const ir_node *block,
const ir_node *def)
{
unsigned hash = HASH_COMBINE(hash_irn(block), hash_irn(def));
unsigned hash = hash_combine(hash_irn(block), hash_irn(def));
be_use_t temp;
be_use_t* result;
......
......@@ -350,13 +350,13 @@ static spill_t *find_spill(be_verify_spillslots_env_t *env, ir_node *node)
spill_t spill;
spill.spill = node;
return (spill_t*)set_find(env->spills, &spill, sizeof(spill), HASH_PTR(node));
return (spill_t*)set_find(env->spills, &spill, sizeof(spill), hash_ptr(node));
}
static spill_t *get_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_entity *ent)
{
spill_t spill, *res;
int hash = HASH_PTR(node);
int hash = hash_ptr(node);
spill.spill = node;
res = (spill_t*)set_find(env->spills, &spill, sizeof(spill), hash);
......@@ -413,7 +413,7 @@ static void collect_memperm(be_verify_spillslots_env_t *env, ir_node *node, ir_n
{
int i, arity;
spill_t spill, *res;
int hash = HASH_PTR(node);
int hash = hash_ptr(node);
int out;
ir_node* memperm;
ir_entity *spillent;
......@@ -452,7 +452,7 @@ static void collect_memphi(be_verify_spillslots_env_t *env, ir_node *node, ir_no
{
int i, arity;
spill_t spill, *res;
int hash = HASH_PTR(node);
int hash = hash_ptr(node);
assert(is_Phi(node));
......
......@@ -1051,7 +1051,7 @@ static unsigned ia32_hash_Immediate(const ir_node *irn)
{
const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
return hash_ptr(a->symconst) + (a->sc_sign << 16) + a->offset;
}
/** Compare node attributes for Immediates. */
......
......@@ -80,7 +80,7 @@ firm_dbg_module_t *firm_dbg_register(const char *name)
if (!module_set)
firm_dbg_init();
return (firm_dbg_module_t*)set_insert(module_set, &mod, sizeof(mod), HASH_STR(name, strlen(name)));
return (firm_dbg_module_t*)set_insert(module_set, &mod, sizeof(mod), hash_str(name));
}
void firm_dbg_set_mask(firm_dbg_module_t *module, unsigned mask)
......
......@@ -118,7 +118,7 @@ typedef struct {
} bp_ident_t;
/** Calculate the hash value for an ident breakpoint. */
#define HASH_IDENT_BP(key) (HASH_PTR((key).id) ^ (key).bp.reason)
#define HASH_IDENT_BP(key) (hash_ptr((key).id) ^ (key).bp.reason)
/** The set containing the breakpoints on node numbers. */
static set *bp_numbers;
......
......@@ -46,7 +46,7 @@ void init_ident(void)
ident *new_id_from_chars(const char *str, size_t len)
{
unsigned hash = HASH_STR(str, len);
unsigned hash = hash_data((const unsigned char*)str, len);
ident *result = (ident*) set_hinsert0(id_set, str, len, hash);
return result;
}
......
......@@ -51,7 +51,7 @@
#define ValueType ir_edge_t*
#define NullValue NULL
#define DeletedValue ((ir_edge_t*)-1)
#define Hash(this,key) (HASH_PTR(key->src) ^ (key->pos * 40013))
#define Hash(this,key) (hash_ptr(key->src) ^ (key->pos * 40013))
#define KeysEqual(this,key1,key2) ((key1->src) == (key2->src) && (key1->pos == key2->pos))
#define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof((ptr)[0]))
......@@ -181,7 +181,7 @@ void edges_reset_private_data(ir_graph *irg, int offset, unsigned size)
#define get_irn_out_list_head(irn) (&get_irn_out_info(irn)->outs)
#define edge_hash(edge) (TIMES37((edge)->pos) + HASH_PTR((edge)->src))
#define edge_hash(edge) (TIMES37((edge)->pos) + hash_ptr((edge)->src))
void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind)
{
......
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