Patchwork [cxx-conversion] tree-related hash tables

login
register
mail settings
Submitter Lawrence Crowl
Date Dec. 2, 2012, 1:45 a.m.
Message ID <CAGqM8fYAkWK4FD-PdfSuVxeCCZGo15jMRo_UV6fy46iYXSKmYw@mail.gmail.com>
Download mbox | patch
Permalink /patch/203171/
State New
Headers show

Comments

Lawrence Crowl - Dec. 2, 2012, 1:45 a.m.
Change tree-related hash tables from htab_t to hash_table:

tree-complex.c complex_variable_components
tree-parloops.c eliminate_local_variables_stmt::decl_address
tree-parloops.c separate_decls_in_region::decl_copies

Move hash table declarations to a new tree-hasher.h, to resolve
compilation dependences and because they are used in few places.


Tested on x86-64.

Okay for branch?
Diego Novillo - Dec. 3, 2012, 7:57 p.m.
On 2012-12-01 20:45 , Lawrence Crowl wrote:

> Index: gcc/tree-hasher.h
> ===================================================================
> --- gcc/tree-hasher.h	(revision 0)
> +++ gcc/tree-hasher.h	(revision 0)
> @@ -0,0 +1,56 @@
> +/* Data and Control Flow Analysis for Trees.

This is the wrong description for this file.

> +   Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
> +   2012 Free Software Foundation, Inc.
> +   Contributed by Diego Novillo <dnovillo@redhat.com>

Only mention year 2012 and don't blame me for sins I never committed ;)


OK otherwise.


Diego.
Lawrence Crowl - Dec. 3, 2012, 8:01 p.m.
On 12/3/12, Diego Novillo <dnovillo@google.com> wrote:
> On 2012-12-01 20:45 , Lawrence Crowl wrote:
>> Index: gcc/tree-hasher.h
>> ===================================================================
>> --- gcc/tree-hasher.h	(revision 0)
>> +++ gcc/tree-hasher.h	(revision 0)
>> @@ -0,0 +1,56 @@
>> +/* Data and Control Flow Analysis for Trees.
>
> This is the wrong description for this file.
>
>> +   Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
>> 2011,
>> +   2012 Free Software Foundation, Inc.
>> +   Contributed by Diego Novillo <dnovillo@redhat.com>
>
> Only mention year 2012 and don't blame me for sins I never committed ;)

The dreaded "copy and fail to fully edit".

Fixed.

> OK otherwise.

Thanks.

Patch

Index: gcc/ChangeLog

2012-11-30  Lawrence Crowl  <crowl@google.com>

	* tree-hasher.h: New.
	(struct int_tree_hasher): New.
	(typedef int_tree_htab_type): New.

	* tree-flow.h (extern int_tree_map_hash): Moved into tree-hasher
	struct int_tree_hasher.
	(extern int_tree_map_eq): Likewise.

	* tree-complex.c: Include tree-hasher.h
	(htab_t complex_variable_components):
	Change type to hash_table.  Update dependent calls and types.

	* tree-parloops.c: Include tree-hasher.h.
	(htab_t eliminate_local_variables_stmt::decl_address):
	Change type to hash_table.  Update dependent calls and types.
	(htab_t separate_decls_in_region::decl_copies): Likewise.

	* tree-ssa.c (int_tree_map_eq): Moved into struct int_tree_hasher
	in tree-flow.h.
	(int_tree_map_hash): Likewise.

	* Makefile.in: Update to changes above.

Index: gcc/tree-complex.c
===================================================================
--- gcc/tree-complex.c	(revision 193902)
+++ gcc/tree-complex.c	(working copy)
@@ -29,6 +29,7 @@  along with GCC; see the file COPYING3.
 #include "tree-iterator.h"
 #include "tree-pass.h"
 #include "tree-ssa-propagate.h"
+#include "tree-hasher.h"


 /* For each complex ssa name, a lattice value.  We're interested in finding
@@ -54,7 +55,7 @@  static vec<complex_lattice_t> complex_la

 /* For each complex variable, a pair of variables for the components exists in
    the hashtable.  */
-static htab_t complex_variable_components;
+static int_tree_htab_type complex_variable_components;

 /* For each complex SSA_NAME, a pair of ssa names for the components.  */
 static vec<tree> complex_ssa_name_components;
@@ -66,7 +67,7 @@  cvc_lookup (unsigned int uid)
 {
   struct int_tree_map *h, in;
   in.uid = uid;
-  h = (struct int_tree_map *) htab_find_with_hash
(complex_variable_components, &in, uid);
+  h = complex_variable_components.find_with_hash (&in, uid);
   return h ? h->to : NULL;
 }

@@ -76,14 +77,13 @@  static void
 cvc_insert (unsigned int uid, tree to)
 {
   struct int_tree_map *h;
-  void **loc;
+  int_tree_map **loc;

   h = XNEW (struct int_tree_map);
   h->uid = uid;
   h->to = to;
-  loc = htab_find_slot_with_hash (complex_variable_components, h,
-				  uid, INSERT);
-  *(struct int_tree_map **) loc = h;
+  loc = complex_variable_components.find_slot_with_hash (h, uid, INSERT);
+  *loc = h;
 }

 /* Return true if T is not a zero constant.  In the case of real values,
@@ -1569,8 +1569,7 @@  tree_lower_complex (void)
   init_parameter_lattice_values ();
   ssa_propagate (complex_visit_stmt, complex_visit_phi);

-  complex_variable_components = htab_create (10,  int_tree_map_hash,
-					     int_tree_map_eq, free);
+  complex_variable_components.create (10);

   complex_ssa_name_components.create (2 * num_ssa_names);
   complex_ssa_name_components.safe_grow_cleared (2 * num_ssa_names);
@@ -1591,7 +1590,7 @@  tree_lower_complex (void)

   gsi_commit_edge_inserts ();

-  htab_delete (complex_variable_components);
+  complex_variable_components.dispose ();
   complex_ssa_name_components.release ();
   complex_lattice_values.release ();
   return 0;
Index: gcc/tree-hasher.h
===================================================================
--- gcc/tree-hasher.h	(revision 0)
+++ gcc/tree-hasher.h	(revision 0)
@@ -0,0 +1,56 @@ 
+/* Data and Control Flow Analysis for Trees.
+   Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
+   2012 Free Software Foundation, Inc.
+   Contributed by Diego Novillo <dnovillo@redhat.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_TREE_HASHER_H
+#define GCC_TREE_HASHER_H 1
+
+#include "hash-table.h"
+#include "tree-flow.h"
+
+/* Hashtable helpers.  */
+
+struct int_tree_hasher : typed_free_remove <int_tree_map>
+{
+  typedef int_tree_map value_type;
+  typedef int_tree_map compare_type;
+  static inline hashval_t hash (const value_type *);
+  static inline bool equal (const value_type *, const compare_type *);
+};
+
+/* Hash a UID in a int_tree_map.  */
+
+inline hashval_t
+int_tree_hasher::hash (const value_type *item)
+{
+  return item->uid;
+}
+
+/* Return true if the uid in both int tree maps are equal.  */
+
+inline bool
+int_tree_hasher::equal (const value_type *a, const compare_type *b)
+{
+  return (a->uid == b->uid);
+}
+
+typedef hash_table <int_tree_hasher> int_tree_htab_type;
+
+#endif /* GCC_TREE_HASHER_H  */
Index: gcc/tree-parloops.c
===================================================================
--- gcc/tree-parloops.c	(revision 193902)
+++ gcc/tree-parloops.c	(working copy)
@@ -31,6 +31,7 @@  along with GCC; see the file COPYING3.
 #include "tree-pass.h"
 #include "langhooks.h"
 #include "tree-vectorizer.h"
+#include "tree-hasher.h"

 /* This pass tries to distribute iterations of loops into several threads.
    The implementation is straightforward -- for each loop we test whether its
@@ -446,11 +447,11 @@  loop_has_blocks_with_irreducible_flag (s
    right before GSI.  */

 static tree
-take_address_of (tree obj, tree type, edge entry, htab_t decl_address,
-		 gimple_stmt_iterator *gsi)
+take_address_of (tree obj, tree type, edge entry,
+		 int_tree_htab_type decl_address, gimple_stmt_iterator *gsi)
 {
   int uid;
-  void **dslot;
+  int_tree_map **dslot;
   struct int_tree_map ielt, *nielt;
   tree *var_p, name, addr;
   gimple stmt;
@@ -473,7 +474,7 @@  take_address_of (tree obj, tree type, ed
      on it.  */
   uid = DECL_UID (TREE_OPERAND (TREE_OPERAND (*var_p, 0), 0));
   ielt.uid = uid;
-  dslot = htab_find_slot_with_hash (decl_address, &ielt, uid, INSERT);
+  dslot = decl_address.find_slot_with_hash (&ielt, uid, INSERT);
   if (!*dslot)
     {
       if (gsi == NULL)
@@ -491,7 +492,7 @@  take_address_of (tree obj, tree type, ed
       *dslot = nielt;
     }
   else
-    name = ((struct int_tree_map *) *dslot)->to;
+    name = (*dslot)->to;

   /* Express the address in terms of the canonical SSA name.  */
   TREE_OPERAND (*var_p, 0) = name;
@@ -568,7 +569,7 @@  struct elv_data
 {
   struct walk_stmt_info info;
   edge entry;
-  htab_t decl_address;
+  int_tree_htab_type decl_address;
   gimple_stmt_iterator *gsi;
   bool changed;
   bool reset;
@@ -658,7 +659,7 @@  eliminate_local_variables_1 (tree *tp, i

 static void
 eliminate_local_variables_stmt (edge entry, gimple_stmt_iterator *gsi,
-				htab_t decl_address)
+				int_tree_htab_type decl_address)
 {
   struct elv_data dta;
   gimple stmt = gsi_stmt (*gsi);
@@ -710,8 +711,8 @@  eliminate_local_variables (edge entry, e
   unsigned i;
   gimple_stmt_iterator gsi;
   bool has_debug_stmt = false;
-  htab_t decl_address = htab_create (10, int_tree_map_hash, int_tree_map_eq,
-				     free);
+  int_tree_htab_type decl_address;
+  decl_address.create (10);
   basic_block entry_bb = entry->src;
   basic_block exit_bb = exit->dest;

@@ -735,7 +736,7 @@  eliminate_local_variables (edge entry, e
 	  if (gimple_debug_bind_p (gsi_stmt (gsi)))
 	    eliminate_local_variables_stmt (entry, &gsi, decl_address);

-  htab_delete (decl_address);
+  decl_address.dispose ();
   body.release ();
 }

@@ -774,15 +775,15 @@  expr_invariant_in_region_p (edge entry,
    duplicated, storing the copies in DECL_COPIES.  */

 static tree
-separate_decls_in_region_name (tree name,
-			       htab_t name_copies, htab_t decl_copies,
-			       bool copy_name_p)
+separate_decls_in_region_name (tree name, htab_t name_copies,
+			       int_tree_htab_type decl_copies, bool copy_name_p)
 {
   tree copy, var, var_copy;
   unsigned idx, uid, nuid;
   struct int_tree_map ielt, *nielt;
   struct name_to_copy_elt elt, *nelt;
-  void **slot, **dslot;
+  void **slot;
+  int_tree_map **dslot;

   if (TREE_CODE (name) != SSA_NAME)
     return name;
@@ -815,7 +816,7 @@  separate_decls_in_region_name (tree name

   uid = DECL_UID (var);
   ielt.uid = uid;
-  dslot = htab_find_slot_with_hash (decl_copies, &ielt, uid, INSERT);
+  dslot = decl_copies.find_slot_with_hash (&ielt, uid, INSERT);
   if (!*dslot)
     {
       var_copy = create_tmp_var (TREE_TYPE (var), get_name (var));
@@ -829,7 +830,7 @@  separate_decls_in_region_name (tree name
          it again.  */
       nuid = DECL_UID (var_copy);
       ielt.uid = nuid;
-      dslot = htab_find_slot_with_hash (decl_copies, &ielt, nuid, INSERT);
+      dslot = decl_copies.find_slot_with_hash (&ielt, nuid, INSERT);
       gcc_assert (!*dslot);
       nielt = XNEW (struct int_tree_map);
       nielt->uid = nuid;
@@ -852,7 +853,8 @@  separate_decls_in_region_name (tree name

 static void
 separate_decls_in_region_stmt (edge entry, edge exit, gimple stmt,
-			       htab_t name_copies, htab_t decl_copies)
+			       htab_t name_copies,
+			       int_tree_htab_type decl_copies)
 {
   use_operand_p use;
   def_operand_p def;
@@ -891,14 +893,15 @@  separate_decls_in_region_stmt (edge entr

 static bool
 separate_decls_in_region_debug (gimple stmt, htab_t name_copies,
-				htab_t decl_copies)
+				int_tree_htab_type decl_copies)
 {
   use_operand_p use;
   ssa_op_iter oi;
   tree var, name;
   struct int_tree_map ielt;
   struct name_to_copy_elt elt;
-  void **slot, **dslot;
+  void **slot;
+  int_tree_map **dslot;

   if (gimple_debug_bind_p (stmt))
     var = gimple_debug_bind_get_var (stmt);
@@ -910,7 +913,7 @@  separate_decls_in_region_debug (gimple s
     return true;
   gcc_assert (DECL_P (var) && SSA_VAR_P (var));
   ielt.uid = DECL_UID (var);
-  dslot = htab_find_slot_with_hash (decl_copies, &ielt, ielt.uid, NO_INSERT);
+  dslot = decl_copies.find_slot_with_hash (&ielt, ielt.uid, NO_INSERT);
   if (!dslot)
     return true;
   if (gimple_debug_bind_p (stmt))
@@ -1254,8 +1257,8 @@  separate_decls_in_region (edge entry, ed
   basic_block bb0 = single_pred (bb1);
   htab_t name_copies = htab_create (10, name_to_copy_elt_hash,
 				    name_to_copy_elt_eq, free);
-  htab_t decl_copies = htab_create (10, int_tree_map_hash, int_tree_map_eq,
-				    free);
+  int_tree_htab_type decl_copies;
+  decl_copies.create (10);
   unsigned i;
   tree type, type_name, nvar;
   gimple_stmt_iterator gsi;
@@ -1372,7 +1375,7 @@  separate_decls_in_region (edge entry, ed
 	}
     }

-  htab_delete (decl_copies);
+  decl_copies.dispose ();
   htab_delete (name_copies);
 }

Index: gcc/tree-ssa.c
===================================================================
--- gcc/tree-ssa.c	(revision 193902)
+++ gcc/tree-ssa.c	(working copy)
@@ -1050,24 +1050,6 @@  err:
   internal_error ("verify_ssa failed");
 }

-/* Return true if the uid in both int tree maps are equal.  */
-
-int
-int_tree_map_eq (const void *va, const void *vb)
-{
-  const struct int_tree_map *a = (const struct int_tree_map *) va;
-  const struct int_tree_map *b = (const struct int_tree_map *) vb;
-  return (a->uid == b->uid);
-}
-
-/* Hash a UID in a int_tree_map.  */
-
-unsigned int
-int_tree_map_hash (const void *item)
-{
-  return ((const struct int_tree_map *)item)->uid;
-}
-
 /* Return true if the DECL_UID in both trees are equal.  */

 int
Index: gcc/tree-flow.h
===================================================================
--- gcc/tree-flow.h	(revision 193902)
+++ gcc/tree-flow.h	(working copy)
@@ -283,9 +283,6 @@  struct int_tree_map {
   tree to;
 };

-extern unsigned int int_tree_map_hash (const void *);
-extern int int_tree_map_eq (const void *, const void *);
-
 extern unsigned int uid_decl_map_hash (const void *);
 extern int uid_decl_map_eq (const void *, const void *);

Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 193902)
+++ gcc/Makefile.in	(working copy)
@@ -939,6 +939,7 @@  TREE_FLOW_H = tree-flow.h tree-flow-inli
 		$(BITMAP_H) sbitmap.h $(BASIC_BLOCK_H) $(GIMPLE_H) \
 		$(HASHTAB_H) $(CGRAPH_H) $(IPA_REFERENCE_H) \
 		tree-ssa-alias.h
+TREE_HASHER_H = tree-hasher.h $(HASH_TABLE_H) $(TREE_FLOW_H)
 TREE_SSA_LIVE_H = tree-ssa-live.h $(PARTITION_H)
 SSAEXPAND_H = ssaexpand.h $(TREE_SSA_LIVE_H)
 PRETTY_PRINT_H = pretty-print.h $(INPUT_H) $(OBSTACK_H)
@@ -2615,7 +2616,8 @@  tree-vectorizer.o: tree-vectorizer.c $(C
 tree-loop-distribution.o: tree-loop-distribution.c $(CONFIG_H) $(SYSTEM_H) \
    coretypes.h $(TREE_FLOW_H) $(CFGLOOP_H) $(TREE_DATA_REF_H) $(TREE_PASS_H)
 tree-parloops.o: tree-parloops.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
-   $(TREE_FLOW_H) $(CFGLOOP_H) $(TREE_DATA_REF_H) $(GIMPLE_PRETTY_PRINT_H) \
+   $(TREE_FLOW_H) $(TREE_HASHER_H) $(CFGLOOP_H) $(TREE_DATA_REF_H) \
+   $(GIMPLE_PRETTY_PRINT_H) \
    $(TREE_PASS_H) langhooks.h gt-tree-parloops.h $(TREE_VECTORIZER_H)
 tree-stdarg.o: tree-stdarg.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(TREE_H) $(FUNCTION_H) $(TREE_FLOW_H) $(TREE_PASS_H) \
@@ -3036,7 +3038,7 @@  tree-switch-conversion.o : tree-switch-c
     $(GGC_H) $(OBSTACK_H) $(PARAMS_H) $(CPPLIB_H) $(PARAMS_H) \
     $(GIMPLE_PRETTY_PRINT_H) langhooks.h
 tree-complex.o : tree-complex.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \
-    $(TM_H) $(FLAGS_H) $(TREE_FLOW_H) $(GIMPLE_H) \
+    $(TM_H) $(FLAGS_H) $(TREE_FLOW_H) $(TREE_HASHER_H) $(GIMPLE_H) \
     tree-iterator.h $(TREE_PASS_H) tree-ssa-propagate.h
 tree-emutls.o : tree-emutls.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \
     $(GIMPLE_H) $(TREE_PASS_H) $(TREE_FLOW_H) $(CGRAPH_H) langhooks.h \