bbs[i]->count = bbs[i]->count.apply_probability (p);
}
-/* Helper types for hash tables. */
-
-struct htab_bb_copy_original_entry
-{
- /* Block we are attaching info to. */
- int index1;
- /* Index of original or copy (depending on the hashtable) */
- int index2;
-};
-
-struct bb_copy_hasher : nofree_ptr_hash <htab_bb_copy_original_entry>
-{
- static inline hashval_t hash (const htab_bb_copy_original_entry *);
- static inline bool equal (const htab_bb_copy_original_entry *existing,
- const htab_bb_copy_original_entry * candidate);
-};
-
-inline hashval_t
-bb_copy_hasher::hash (const htab_bb_copy_original_entry *data)
-{
- return data->index1;
-}
-
-inline bool
-bb_copy_hasher::equal (const htab_bb_copy_original_entry *data,
- const htab_bb_copy_original_entry *data2)
-{
- return data->index1 == data2->index1;
-}
-
/* Data structures used to maintain mapping between basic blocks and
copies. */
-static hash_table<bb_copy_hasher> *bb_original;
-static hash_table<bb_copy_hasher> *bb_copy;
+typedef hash_map<int_hash<int, -1, -2>, int> copy_map_t;
+static copy_map_t *bb_original;
+static copy_map_t *bb_copy;
/* And between loops and copies. */
-static hash_table<bb_copy_hasher> *loop_copy;
-static object_allocator<htab_bb_copy_original_entry> *original_copy_bb_pool;
+static copy_map_t *loop_copy;
/* Initialize the data structures to maintain mapping between blocks
and its copies. */
void
initialize_original_copy_tables (void)
{
- original_copy_bb_pool = new object_allocator<htab_bb_copy_original_entry>
- ("original_copy");
- bb_original = new hash_table<bb_copy_hasher> (10);
- bb_copy = new hash_table<bb_copy_hasher> (10);
- loop_copy = new hash_table<bb_copy_hasher> (10);
+ bb_original = new copy_map_t (10);
+ bb_copy = new copy_map_t (10);
+ loop_copy = new copy_map_t (10);
}
/* Reset the data structures to maintain mapping between blocks and
void
reset_original_copy_tables (void)
{
- gcc_assert (original_copy_bb_pool);
bb_original->empty ();
bb_copy->empty ();
loop_copy->empty ();
void
free_original_copy_tables (void)
{
- gcc_assert (original_copy_bb_pool);
delete bb_copy;
bb_copy = NULL;
delete bb_original;
bb_original = NULL;
delete loop_copy;
loop_copy = NULL;
- delete original_copy_bb_pool;
- original_copy_bb_pool = NULL;
}
/* Return true iff we have had a call to initialize_original_copy_tables
bool
original_copy_tables_initialized_p (void)
{
- return original_copy_bb_pool != NULL;
+ return bb_copy != NULL;
}
/* Removes the value associated with OBJ from table TAB. */
static void
-copy_original_table_clear (hash_table<bb_copy_hasher> *tab, unsigned obj)
+copy_original_table_clear (copy_map_t *tab, unsigned obj)
{
- htab_bb_copy_original_entry **slot;
- struct htab_bb_copy_original_entry key, *elt;
-
- if (!original_copy_bb_pool)
+ if (!original_copy_tables_initialized_p ())
return;
- key.index1 = obj;
- slot = tab->find_slot (&key, NO_INSERT);
- if (!slot)
- return;
-
- elt = *slot;
- tab->clear_slot (slot);
- original_copy_bb_pool->remove (elt);
+ tab->remove (obj);
}
/* Sets the value associated with OBJ in table TAB to VAL.
Do nothing when data structures are not initialized. */
static void
-copy_original_table_set (hash_table<bb_copy_hasher> *tab,
+copy_original_table_set (copy_map_t *tab,
unsigned obj, unsigned val)
{
- struct htab_bb_copy_original_entry **slot;
- struct htab_bb_copy_original_entry key;
-
- if (!original_copy_bb_pool)
+ if (!original_copy_tables_initialized_p ())
return;
- key.index1 = obj;
- slot = tab->find_slot (&key, INSERT);
- if (!*slot)
- {
- *slot = original_copy_bb_pool->allocate ();
- (*slot)->index1 = obj;
- }
- (*slot)->index2 = val;
+ tab->put (obj, val);
}
/* Set original for basic block. Do nothing when data structures are not
basic_block
get_bb_original (basic_block bb)
{
- struct htab_bb_copy_original_entry *entry;
- struct htab_bb_copy_original_entry key;
-
- gcc_assert (original_copy_bb_pool);
+ gcc_assert (original_copy_tables_initialized_p ());
- key.index1 = bb->index;
- entry = bb_original->find (&key);
+ int *entry = bb_original->get (bb->index);
if (entry)
- return BASIC_BLOCK_FOR_FN (cfun, entry->index2);
+ return BASIC_BLOCK_FOR_FN (cfun, *entry);
else
return NULL;
}
basic_block
get_bb_copy (basic_block bb)
{
- struct htab_bb_copy_original_entry *entry;
- struct htab_bb_copy_original_entry key;
+ gcc_assert (original_copy_tables_initialized_p ());
- gcc_assert (original_copy_bb_pool);
-
- key.index1 = bb->index;
- entry = bb_copy->find (&key);
+ int *entry = bb_copy->get (bb->index);
if (entry)
- return BASIC_BLOCK_FOR_FN (cfun, entry->index2);
+ return BASIC_BLOCK_FOR_FN (cfun, *entry);
else
return NULL;
}
class loop *
get_loop_copy (class loop *loop)
{
- struct htab_bb_copy_original_entry *entry;
- struct htab_bb_copy_original_entry key;
-
- gcc_assert (original_copy_bb_pool);
+ gcc_assert (original_copy_tables_initialized_p ());
- key.index1 = loop->num;
- entry = loop_copy->find (&key);
+ int *entry = loop_copy->get (loop->num);
if (entry)
- return get_loop (cfun, entry->index2);
+ return get_loop (cfun, *entry);
else
return NULL;
}