Re: [cxx-conversion] LTO-related hash tables

2012-12-04 Thread Diego Novillo
On Mon, Dec 3, 2012 at 4:10 PM, Lawrence Crowl cr...@googlers.com wrote:

 Before the change, lto-streamer.h output_block::string_hash_table was
 an htab_t.  The element type was opaque, i.e. implicit in the void*
 casting in the hash functions provided at the htab_create call site.

 With the change to hash_table, the output_block::string_hash_table
 declaration needed string_slot_hasher which in turn needed
 string_slot.  But string_slot was defined in data-streamer.h after
 output_block in lto-streamer.h.  So, something had to move.

Ah, thanks.


Diego.


Re: [cxx-conversion] LTO-related hash tables

2012-12-03 Thread Diego Novillo

On 2012-12-01 20:40 , Lawrence Crowl wrote:

Change LTO-related hash tables from htab_t to hash_table:

lto-streamer.h output_block::string_hash_table
lto-streamer-in.c file_name_hash_table
lto-streamer.c tree_htab

The struct string_slot moves from data-streamer.h to lto-streamer.h to
resolve compilation dependences.


What compilation dependences?  If it was fine before in data-streamer.h 
why does it need to move to lto-streamer.h?  I'm missing that connection.



Diego.


Re: [cxx-conversion] LTO-related hash tables

2012-12-03 Thread Lawrence Crowl
On 12/3/12, Diego Novillo dnovi...@google.com wrote:
 On 2012-12-01 20:40 , Lawrence Crowl wrote:
  Change LTO-related hash tables from htab_t to hash_table:
 
  lto-streamer.h output_block::string_hash_table
  lto-streamer-in.c file_name_hash_table
  lto-streamer.c tree_htab
 
  The struct string_slot moves from data-streamer.h to
  lto-streamer.h to resolve compilation dependences.

 What compilation dependences?  If it was fine before in
 data-streamer.h why does it need to move to lto-streamer.h?
 I'm missing that connection.

Before the change, lto-streamer.h output_block::string_hash_table was
an htab_t.  The element type was opaque, i.e. implicit in the void*
casting in the hash functions provided at the htab_create call site.

With the change to hash_table, the output_block::string_hash_table
declaration needed string_slot_hasher which in turn needed
string_slot.  But string_slot was defined in data-streamer.h after
output_block in lto-streamer.h.  So, something had to move.

-- 
Lawrence Crowl


[cxx-conversion] LTO-related hash tables

2012-12-01 Thread Lawrence Crowl
Change LTO-related hash tables from htab_t to hash_table:

lto-streamer.h output_block::string_hash_table
lto-streamer-in.c file_name_hash_table
lto-streamer.c tree_htab

The struct string_slot moves from data-streamer.h to lto-streamer.h to
resolve compilation dependences.


Tested on x86-64.

Okay for branch?


Index: gcc/ChangeLog

2012-11-30  Lawrence Crowl  cr...@google.com

* data-streamer.h (struct string_slot): Move to lto-streamer.h.
(hash_string_slot_node): Move implementation into lto-streamer.h
struct string_slot_hasher.
(eq_string_slot_node): Likewise.

* data-streamer-out.c: Update output_block::string_hash_table
dependent calls and types.

* lto-streamer.h (struct string_slot): Move from data-streamer.h
(struct string_slot_hasher): New.
(htab_t output_block::string_hash_table):
Change type to hash_table.  Update dependent calls and types.

* lto-streamer-in.c (freeing_string_slot_hasher): New.
(htab_t file_name_hash_table):
Change type to hash_table.  Update dependent calls and types.

* lto-streamer-out.c: Update output_block::string_hash_table dependent
calls and types.

* lto-streamer.c (htab_t tree_htab):
Change type to hash_table.  Update dependent calls and types.

* Makefile.in: Update to changes above.

Index: gcc/data-streamer-out.c
===
--- gcc/data-streamer-out.c (revision 193902)
+++ gcc/data-streamer-out.c (working copy)
@@ -42,8 +42,7 @@ streamer_string_index (struct output_blo
   s_slot.len = len;
   s_slot.slot_num = 0;

-  slot = (struct string_slot **) htab_find_slot (ob-string_hash_table,
-s_slot, INSERT);
+  slot = ob-string_hash_table.find_slot (s_slot, INSERT);
   if (*slot == NULL)
 {
   struct lto_output_stream *string_stream = ob-string_stream;
Index: gcc/lto-streamer-out.c
===
--- gcc/lto-streamer-out.c  (revision 193902)
+++ gcc/lto-streamer-out.c  (working copy)
@@ -77,8 +77,7 @@ create_output_block (enum lto_section_ty

   clear_line_info (ob);

-  ob-string_hash_table = htab_create (37, hash_string_slot_node,
-  eq_string_slot_node, NULL);
+  ob-string_hash_table.create (37);
   gcc_obstack_init (ob-obstack);

   return ob;
@@ -92,7 +91,7 @@ destroy_output_block (struct output_bloc
 {
   enum lto_section_type section_type = ob-section_type;

-  htab_delete (ob-string_hash_table);
+  ob-string_hash_table.dispose ();

   free (ob-main_stream);
   free (ob-string_stream);
Index: gcc/lto-streamer-in.c
===
--- gcc/lto-streamer-in.c   (revision 193902)
+++ gcc/lto-streamer-in.c   (working copy)
@@ -49,8 +49,19 @@ along with GCC; see the file COPYING3.
 #include tree-pass.h
 #include streamer-hooks.h

+struct freeing_string_slot_hasher : string_slot_hasher
+{
+  static inline void remove (value_type *);
+};
+
+inline void
+freeing_string_slot_hasher::remove (value_type *v)
+{
+  free (v);
+}
+
 /* The table to hold the file names.  */
-static htab_t file_name_hash_table;
+static hash_table freeing_string_slot_hasher file_name_hash_table;


 /* Check that tag ACTUAL has one of the given values.  NUM_TAGS is the
@@ -94,14 +105,14 @@ lto_input_data_block (struct lto_input_b
 static const char *
 canon_file_name (const char *string)
 {
-  void **slot;
+  string_slot **slot;
   struct string_slot s_slot;
   size_t len = strlen (string);

   s_slot.s = string;
   s_slot.len = len;

-  slot = htab_find_slot (file_name_hash_table, s_slot, INSERT);
+  slot = file_name_hash_table.find_slot (s_slot, INSERT);
   if (*slot == NULL)
 {
   char *saved_string;
@@ -117,7 +128,7 @@ canon_file_name (const char *string)
 }
   else
 {
-  struct string_slot *old_slot = (struct string_slot *) *slot;
+  struct string_slot *old_slot = *slot;
   return old_slot-s;
 }
 }
@@ -1150,8 +1161,7 @@ void
 lto_reader_init (void)
 {
   lto_streamer_init ();
-  file_name_hash_table = htab_create (37, hash_string_slot_node,
- eq_string_slot_node, free);
+  file_name_hash_table.create (37);
 }


Index: gcc/data-streamer.h
===
--- gcc/data-streamer.h (revision 193902)
+++ gcc/data-streamer.h (working copy)
@@ -44,15 +44,6 @@ struct bitpack_d
   void *stream;
 };

-
-/* String hashing.  */
-struct string_slot
-{
-  const char *s;
-  int len;
-  unsigned int slot_num;
-};
-
 /* In data-streamer.c  */
 void bp_pack_var_len_unsigned (struct bitpack_d *, unsigned HOST_WIDE_INT);
 void bp_pack_var_len_int (struct bitpack_d *, HOST_WIDE_INT);
@@ -90,35 +81,6 @@ const char *bp_unpack_string (struct dat
 unsigned HOST_WIDE_INT