From 028a407463ce341487103abc877032384e6427bf Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 21 Oct 2020 09:40:09 +0200 Subject: [PATCH] Simplify CFG copying tables This simplifies the maps between original and new basic blocks and loops as used for CFG copying. Instead of using a pointer hash table to allocated mapping entries use a hash_map with int_hash, removing the indirection and code duplication. We can use -1 and -2 as empty/deleted values as those are not valid basic-block indices or loop numbers. 2020-10-21 Richard Biener * cfg.c (htab_bb_copy_original_entry): Remove. (bb_copy_hasher): Likewise. (bb_original, bb_copy, loop_copy): Use hash_map, int>. (original_copy_bb_pool): Remove. (initialize_original_copy_tables): Adjust. (reset_original_copy_tables): Likewise. (free_original_copy_tables): Likewise. (original_copy_tables_initialized_p): Likewise. (copy_original_table_clear): Simplify. (copy_original_table_set): Likewise. (get_bb_original): Likewise. (get_bb_copy): Likewise. (get_loop_copy): Likewise. --- gcc/cfg.c | 114 +++++++++++------------------------------------------- 1 file changed, 23 insertions(+), 91 deletions(-) diff --git a/gcc/cfg.c b/gcc/cfg.c index 270a48f729a..d82324faf03 100644 --- a/gcc/cfg.c +++ b/gcc/cfg.c @@ -959,55 +959,23 @@ scale_bbs_frequencies (basic_block *bbs, int nbbs, 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 -{ - 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_original; -static hash_table *bb_copy; +typedef hash_map, int> copy_map_t; +static copy_map_t *bb_original; +static copy_map_t *bb_copy; /* And between loops and copies. */ -static hash_table *loop_copy; -static object_allocator *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 - ("original_copy"); - bb_original = new hash_table (10); - bb_copy = new hash_table (10); - loop_copy = new hash_table (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 @@ -1016,7 +984,6 @@ initialize_original_copy_tables (void) void reset_original_copy_tables (void) { - gcc_assert (original_copy_bb_pool); bb_original->empty (); bb_copy->empty (); loop_copy->empty (); @@ -1027,15 +994,12 @@ reset_original_copy_tables (void) 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 @@ -1044,51 +1008,31 @@ free_original_copy_tables (void) 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 *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 *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 @@ -1103,15 +1047,11 @@ set_bb_original (basic_block bb, basic_block original) 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; } @@ -1128,15 +1068,11 @@ set_bb_copy (basic_block bb, basic_block copy) 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; } @@ -1158,15 +1094,11 @@ set_loop_copy (class loop *loop, class loop *copy) 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; } -- 2.30.2