public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Convert more incremental hash users to inchash
@ 2014-07-27 19:37 Andi Kleen
  2014-07-27 19:38 ` [PATCH 1/6] RTL & dwarf2out changes Andi Kleen
  0 siblings, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2014-07-27 19:37 UTC (permalink / raw)
  To: gcc-patches

This patchkit converts more incremental hash users to the new 
inchash class. The only larger change is for rtl hashing,
which I had to move to a new file to avoid problems
with the generator program. All changes should only
minimally change behavior.

Bootstrapped and tested on x86_64-linux. Ok to commit?

-Andi

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/6] Convert tree-ssa-dom to inchash
  2014-07-27 19:38     ` [PATCH 3/6] Convert ipa-devirt " Andi Kleen
@ 2014-07-27 19:38       ` Andi Kleen
  2014-07-27 19:45         ` [PATCH 5/6] Convert tree-ssa-sccvn " Andi Kleen
  0 siblings, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2014-07-27 19:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

gcc/:

2014-07-25  Andi Kleen  <ak@linux.intel.com>

	* tree-ssa-dom.c (iterative_hash_exprs_commutative): Convert to inchash.
	(iterative_hash_hashable_expr): Dito.
	(avail_expr_hash): Dito.
---
 gcc/tree-ssa-dom.c | 79 +++++++++++++++++++++++++-----------------------------
 1 file changed, 36 insertions(+), 43 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 08fd2fa..abf2b2e4 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "params.h"
 #include "tree-ssa-threadedge.h"
 #include "tree-ssa-dom.h"
+#include "inchash.h"
 
 /* This file implements optimizations on the dominator tree.  */
 
@@ -557,45 +558,40 @@ hashable_expr_equal_p (const struct hashable_expr *expr0,
 }
 
 /* Generate a hash value for a pair of expressions.  This can be used
-   iteratively by passing a previous result as the VAL argument.
+   iteratively by passing a previous result in HSTATE.
 
    The same hash value is always returned for a given pair of expressions,
    regardless of the order in which they are presented.  This is useful in
    hashing the operands of commutative functions.  */
 
-static hashval_t
+static void
 iterative_hash_exprs_commutative (const_tree t1,
-                                  const_tree t2, hashval_t val)
+                                  const_tree t2, inchash &hstate)
 {
-  hashval_t one = iterative_hash_expr (t1, 0);
-  hashval_t two = iterative_hash_expr (t2, 0);
-  hashval_t t;
-
-  if (one > two)
-    t = one, one = two, two = t;
-  val = iterative_hash_hashval_t (one, val);
-  val = iterative_hash_hashval_t (two, val);
+  inchash one, two;
 
-  return val;
+  iterative_hstate_expr (t1, one);
+  iterative_hstate_expr (t2, two);
+  hstate.add_commutative (one, two);
 }
 
 /* Compute a hash value for a hashable_expr value EXPR and a
    previously accumulated hash value VAL.  If two hashable_expr
    values compare equal with hashable_expr_equal_p, they must
    hash to the same value, given an identical value of VAL.
-   The logic is intended to follow iterative_hash_expr in tree.c.  */
+   The logic is intended to follow iterative_hstate_expr in tree.c.  */
 
-static hashval_t
-iterative_hash_hashable_expr (const struct hashable_expr *expr, hashval_t val)
+static void
+iterative_hash_hashable_expr (const struct hashable_expr *expr, inchash &hstate)
 {
   switch (expr->kind)
     {
     case EXPR_SINGLE:
-      val = iterative_hash_expr (expr->ops.single.rhs, val);
+      iterative_hstate_expr (expr->ops.single.rhs, hstate);
       break;
 
     case EXPR_UNARY:
-      val = iterative_hash_object (expr->ops.unary.op, val);
+      hstate.add_object (expr->ops.unary.op);
 
       /* Make sure to include signedness in the hash computation.
          Don't hash the type, that can lead to having nodes which
@@ -603,34 +599,34 @@ iterative_hash_hashable_expr (const struct hashable_expr *expr, hashval_t val)
          have different hash codes.  */
       if (CONVERT_EXPR_CODE_P (expr->ops.unary.op)
           || expr->ops.unary.op == NON_LVALUE_EXPR)
-        val += TYPE_UNSIGNED (expr->type);
+        hstate.add_int (TYPE_UNSIGNED (expr->type));
 
-      val = iterative_hash_expr (expr->ops.unary.opnd, val);
+      iterative_hstate_expr (expr->ops.unary.opnd, hstate);
       break;
 
     case EXPR_BINARY:
-      val = iterative_hash_object (expr->ops.binary.op, val);
+      hstate.add_object (expr->ops.binary.op);
       if (commutative_tree_code (expr->ops.binary.op))
-	val = iterative_hash_exprs_commutative (expr->ops.binary.opnd0,
-						expr->ops.binary.opnd1, val);
+	iterative_hash_exprs_commutative (expr->ops.binary.opnd0,
+					  expr->ops.binary.opnd1, hstate);
       else
         {
-          val = iterative_hash_expr (expr->ops.binary.opnd0, val);
-          val = iterative_hash_expr (expr->ops.binary.opnd1, val);
+          iterative_hstate_expr (expr->ops.binary.opnd0, hstate);
+          iterative_hstate_expr (expr->ops.binary.opnd1, hstate);
         }
       break;
 
     case EXPR_TERNARY:
-      val = iterative_hash_object (expr->ops.ternary.op, val);
+      hstate.add_object (expr->ops.ternary.op);
       if (commutative_ternary_tree_code (expr->ops.ternary.op))
-	val = iterative_hash_exprs_commutative (expr->ops.ternary.opnd0,
-						expr->ops.ternary.opnd1, val);
+	iterative_hash_exprs_commutative (expr->ops.ternary.opnd0,
+					  expr->ops.ternary.opnd1, hstate);
       else
         {
-          val = iterative_hash_expr (expr->ops.ternary.opnd0, val);
-          val = iterative_hash_expr (expr->ops.ternary.opnd1, val);
+          iterative_hstate_expr (expr->ops.ternary.opnd0, hstate);
+          iterative_hstate_expr (expr->ops.ternary.opnd1, hstate);
         }
-      val = iterative_hash_expr (expr->ops.ternary.opnd2, val);
+      iterative_hstate_expr (expr->ops.ternary.opnd2, hstate);
       break;
 
     case EXPR_CALL:
@@ -639,15 +635,14 @@ iterative_hash_hashable_expr (const struct hashable_expr *expr, hashval_t val)
         enum tree_code code = CALL_EXPR;
         gimple fn_from;
 
-        val = iterative_hash_object (code, val);
+        hstate.add_object (code);
         fn_from = expr->ops.call.fn_from;
         if (gimple_call_internal_p (fn_from))
-          val = iterative_hash_hashval_t
-            ((hashval_t) gimple_call_internal_fn (fn_from), val);
+          hstate.merge_hash ((hashval_t) gimple_call_internal_fn (fn_from));
         else
-          val = iterative_hash_expr (gimple_call_fn (fn_from), val);
+          iterative_hstate_expr (gimple_call_fn (fn_from), hstate);
         for (i = 0; i < expr->ops.call.nargs; i++)
-          val = iterative_hash_expr (expr->ops.call.args[i], val);
+          iterative_hstate_expr (expr->ops.call.args[i], hstate);
       }
       break;
 
@@ -656,15 +651,13 @@ iterative_hash_hashable_expr (const struct hashable_expr *expr, hashval_t val)
         size_t i;
 
         for (i = 0; i < expr->ops.phi.nargs; i++)
-          val = iterative_hash_expr (expr->ops.phi.args[i], val);
+          iterative_hstate_expr (expr->ops.phi.args[i], hstate);
       }
       break;
 
     default:
       gcc_unreachable ();
     }
-
-  return val;
 }
 
 /* Print a diagnostic dump of an expression hash table entry.  */
@@ -2599,24 +2592,24 @@ avail_expr_hash (const void *p)
   gimple stmt = ((const struct expr_hash_elt *)p)->stmt;
   const struct hashable_expr *expr = &((const struct expr_hash_elt *)p)->expr;
   tree vuse;
-  hashval_t val = 0;
+  inchash hstate;
 
-  val = iterative_hash_hashable_expr (expr, val);
+  iterative_hash_hashable_expr (expr, hstate);
 
   /* If the hash table entry is not associated with a statement, then we
      can just hash the expression and not worry about virtual operands
      and such.  */
   if (!stmt)
-    return val;
+    return hstate.end ();
 
   /* Add the SSA version numbers of the vuse operand.  This is important
      because compound variables like arrays are not renamed in the
      operands.  Rather, the rename is done on the virtual variable
      representing all the elements of the array.  */
   if ((vuse = gimple_vuse (stmt)))
-    val = iterative_hash_expr (vuse, val);
+    iterative_hstate_expr (vuse, hstate);
 
-  return val;
+  return hstate.end ();
 }
 
 /* PHI-ONLY copy and constant propagation.  This pass is meant to clean
-- 
2.0.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/6] Convert ipa-devirt to inchash
  2014-07-27 19:38   ` [PATCH 2/6] Convert asan.c to inchash Andi Kleen
@ 2014-07-27 19:38     ` Andi Kleen
  2014-07-27 19:38       ` [PATCH 4/6] Convert tree-ssa-dom " Andi Kleen
  2014-07-28  8:23     ` [PATCH 2/6] Convert asan.c " Richard Biener
  1 sibling, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2014-07-27 19:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

gcc/:

2014-07-25  Andi Kleen  <ak@linux.intel.com>

	* ipa-devirt.c (polymorphic_call_target_hasher::hash):
	Convert to inchash.
---
 gcc/ipa-devirt.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index 127d58d..5f529a9 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -1633,17 +1633,15 @@ struct polymorphic_call_target_hasher
 inline hashval_t
 polymorphic_call_target_hasher::hash (const value_type *odr_query)
 {
-  hashval_t hash;
-
-  hash = iterative_hash_host_wide_int
-	  (odr_query->otr_token,
-	   odr_query->type->id);
-  hash = iterative_hash_hashval_t (TYPE_UID (odr_query->context.outer_type),
-				   hash);
-  hash = iterative_hash_host_wide_int (odr_query->context.offset, hash);
-  return iterative_hash_hashval_t
-	    (((int)odr_query->context.maybe_in_construction << 1)
-	     | (int)odr_query->context.maybe_derived_type, hash);
+  inchash hstate (odr_query->otr_token);
+
+  hstate.add_wide_int (odr_query->type->id);
+  hstate.add_wide_int (TYPE_UID (odr_query->context.outer_type));
+  hstate.add_wide_int (odr_query->context.offset);
+  hstate.add_flag (odr_query->context.maybe_in_construction);
+  hstate.add_flag (odr_query->context.maybe_derived_type);
+  hstate.commit_flag ();
+  return hstate.end ();
 }
 
 /* Compare cache entries T1 and T2.  */
-- 
2.0.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 6/6] Convert tree-ssa-tail-merge to inchash
  2014-07-27 19:45         ` [PATCH 5/6] Convert tree-ssa-sccvn " Andi Kleen
@ 2014-07-27 19:38           ` Andi Kleen
  0 siblings, 0 replies; 11+ messages in thread
From: Andi Kleen @ 2014-07-27 19:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

gcc/:

2014-07-25  Andi Kleen  <ak@linux.intel.com>

	* tree-ssa-tail-merge.c (same_succ_hash): Convert to inchash.
---
 gcc/tree-ssa-tail-merge.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c
index 9600e28..a27af5b 100644
--- a/gcc/tree-ssa-tail-merge.c
+++ b/gcc/tree-ssa-tail-merge.c
@@ -451,7 +451,7 @@ stmt_update_dep_bb (gimple stmt)
 static hashval_t
 same_succ_hash (const_same_succ e)
 {
-  hashval_t hashval = bitmap_hash (e->succs);
+  inchash hstate (bitmap_hash (e->succs));
   int flags;
   unsigned int i;
   unsigned int first = bitmap_first_set_bit (e->bbs);
@@ -472,37 +472,35 @@ same_succ_hash (const_same_succ e)
 	continue;
       size++;
 
-      hashval = iterative_hash_hashval_t (gimple_code (stmt), hashval);
+      hstate.add_int (gimple_code (stmt));
       if (is_gimple_assign (stmt))
-	hashval = iterative_hash_hashval_t (gimple_assign_rhs_code (stmt),
-					    hashval);
+	hstate.add_int (gimple_assign_rhs_code (stmt));
       if (!is_gimple_call (stmt))
 	continue;
       if (gimple_call_internal_p (stmt))
-	hashval = iterative_hash_hashval_t
-	  ((hashval_t) gimple_call_internal_fn (stmt), hashval);
+        hstate.add_int (gimple_call_internal_fn (stmt));
       else
 	{
-	  hashval = iterative_hash_expr (gimple_call_fn (stmt), hashval);
+	  iterative_hstate_expr (gimple_call_fn (stmt), hstate);
 	  if (gimple_call_chain (stmt))
-	    hashval = iterative_hash_expr (gimple_call_chain (stmt), hashval);
+	    iterative_hstate_expr (gimple_call_chain (stmt), hstate);
 	}
       for (i = 0; i < gimple_call_num_args (stmt); i++)
 	{
 	  arg = gimple_call_arg (stmt, i);
 	  arg = vn_valueize (arg);
-	  hashval = iterative_hash_expr (arg, hashval);
+	  iterative_hstate_expr (arg, hstate);
 	}
     }
 
-  hashval = iterative_hash_hashval_t (size, hashval);
+  hstate.add_int (size);
   BB_SIZE (bb) = size;
 
   for (i = 0; i < e->succ_flags.length (); ++i)
     {
       flags = e->succ_flags[i];
       flags = flags & ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
-      hashval = iterative_hash_hashval_t (flags, hashval);
+      hstate.add_int (flags);
     }
 
   EXECUTE_IF_SET_IN_BITMAP (e->succs, 0, s, bs)
@@ -521,7 +519,7 @@ same_succ_hash (const_same_succ e)
 	}
     }
 
-  return hashval;
+  return hstate.end ();
 }
 
 /* Returns true if E1 and E2 have 2 successors, and if the successor flags
-- 
2.0.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/6] RTL & dwarf2out changes
  2014-07-27 19:37 Convert more incremental hash users to inchash Andi Kleen
@ 2014-07-27 19:38 ` Andi Kleen
  2014-07-27 19:38   ` [PATCH 2/6] Convert asan.c to inchash Andi Kleen
  2014-07-28 19:00   ` [PATCH 1/6] RTL & dwarf2out changes Cary Coutant
  0 siblings, 2 replies; 11+ messages in thread
From: Andi Kleen @ 2014-07-27 19:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

Convert dwarf2out and rtl.c to the new inchash interface.

I moved the rtl hash code to another file to avoid having to link
all the hash code into the generator functions.

gcc/:

2014-07-25  Andi Kleen  <ak@linux.intel.com>

	* Makefile.in (OBJS): Add rtlhash.o
	* dwarf2out.c (addr_table_entry_do_hash): Convert to inchash.
	(loc_checksum): Dito.
	(loc_checksum_ordered): Dito.
	(hash_loc_operands): Dito.
	(hash_locs): Dito.
	(hash_loc_list): Dito.
	* rtl.c (iterative_hash_rtx): Moved to rtlhash.c
	* rtl.h (iterative_hash_rtx): Moved to rtlhash.h
	* rtlhash.c: New file.
	* rtlhash.h: New file.
---
 gcc/Makefile.in |   1 +
 gcc/dwarf2out.c | 126 +++++++++++++++++++++++++++++---------------------------
 gcc/rtl.c       |  79 +----------------------------------
 gcc/rtl.h       |   1 -
 gcc/rtlhash.c   | 102 +++++++++++++++++++++++++++++++++++++++++++++
 gcc/rtlhash.h   |  27 ++++++++++++
 6 files changed, 197 insertions(+), 139 deletions(-)
 create mode 100644 gcc/rtlhash.c
 create mode 100644 gcc/rtlhash.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 4c578b3..a2fb5f5 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1350,6 +1350,7 @@ OBJS = \
 	resource.o \
 	rtl-error.o \
 	rtl.o \
+	rtlhash.o \
 	rtlanal.o \
 	rtlhooks.o \
 	sbitmap.o \
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 8fd1945..26fb34c 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -71,6 +71,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "flags.h"
 #include "hard-reg-set.h"
 #include "regs.h"
+#include "rtlhash.h"
 #include "insn-config.h"
 #include "reload.h"
 #include "function.h"
@@ -3277,7 +3278,7 @@ static void gen_scheduled_generic_parms_dies (void);
 
 static const char *comp_dir_string (void);
 
-static hashval_t hash_loc_operands (dw_loc_descr_ref, hashval_t);
+static void hash_loc_operands (dw_loc_descr_ref, inchash &);
 
 /* enum for tracking thread-local variables whose address is really an offset
    relative to the TLS pointer, which will need link-time relocation, but will
@@ -4190,17 +4191,22 @@ static hashval_t
 addr_table_entry_do_hash (const void *x)
 {
   const addr_table_entry *a = (const addr_table_entry *) x;
+  inchash hstate;
   switch (a->kind)
     {
       case ate_kind_rtx:
-        return iterative_hash_rtx (a->addr.rtl, 0);
+	hstate.add_int (0);
+	break;
       case ate_kind_rtx_dtprel:
-        return iterative_hash_rtx (a->addr.rtl, 1);
+	hstate.add_int (1);
+	break;
       case ate_kind_label:
         return htab_hash_string (a->addr.label);
       default:
         gcc_unreachable ();
     }
+  iterative_hstate_rtx (a->addr.rtl, hstate);
+  return hstate.end ();
 }
 
 /* Determine equality for two address_table_entries.  */
@@ -5544,11 +5550,14 @@ static inline void
 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
 {
   int tem;
-  hashval_t hash = 0;
+  inchash hstate;
+  hashval_t hash;
 
   tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
   CHECKSUM (tem);
-  hash = hash_loc_operands (loc, hash);
+  hash_loc_operands (loc, hstate);
+  /* ??? MD5 of another hash doesn't make a lot of sense... */
+  hash = hstate.end();
   CHECKSUM (hash);
 }
 
@@ -5758,11 +5767,13 @@ loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
   /* Otherwise, just checksum the raw location expression.  */
   while (loc != NULL)
     {
-      hashval_t hash = 0;
+      inchash hstate;
+      hashval_t hash;
 
       CHECKSUM_ULEB128 (loc->dtprel);
       CHECKSUM_ULEB128 (loc->dw_loc_opc);
-      hash = hash_loc_operands (loc, hash);
+      hash_loc_operands (loc, hstate);
+      hash = hstate.end ();
       CHECKSUM (hash);
       loc = loc->dw_loc_next;
     }
@@ -23619,10 +23630,10 @@ resolve_addr (dw_die_ref die)
    This pass tries to share identical local lists in .debug_loc
    section.  */
 
-/* Iteratively hash operands of LOC opcode.  */
+/* Iteratively hash operands of LOC opcode into HSTATE.  */
 
-static hashval_t
-hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
+static void
+hash_loc_operands (dw_loc_descr_ref loc, inchash &hstate)
 {
   dw_val_ref val1 = &loc->dw_loc_oprnd1;
   dw_val_ref val2 = &loc->dw_loc_oprnd2;
@@ -23681,7 +23692,7 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
     case DW_OP_piece:
     case DW_OP_deref_size:
     case DW_OP_xderef_size:
-      hash = iterative_hash_object (val1->v.val_int, hash);
+      hstate.add_object (val1->v.val_int);
       break;
     case DW_OP_skip:
     case DW_OP_bra:
@@ -23690,36 +23701,35 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
 
 	gcc_assert (val1->val_class == dw_val_class_loc);
 	offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
-	hash = iterative_hash_object (offset, hash);
+	hstate.add_object (offset);
       }
       break;
     case DW_OP_implicit_value:
-      hash = iterative_hash_object (val1->v.val_unsigned, hash);
+      hstate.add_object (val1->v.val_unsigned);
       switch (val2->val_class)
 	{
 	case dw_val_class_const:
-	  hash = iterative_hash_object (val2->v.val_int, hash);
+	  hstate.add_object (val2->v.val_int);
 	  break;
 	case dw_val_class_vec:
 	  {
 	    unsigned int elt_size = val2->v.val_vec.elt_size;
 	    unsigned int len = val2->v.val_vec.length;
 
-	    hash = iterative_hash_object (elt_size, hash);
-	    hash = iterative_hash_object (len, hash);
-	    hash = iterative_hash (val2->v.val_vec.array,
-				   len * elt_size, hash);
+	    hstate.add_int (elt_size);
+	    hstate.add_int (len);
+	    hstate.add (val2->v.val_vec.array, len * elt_size);
 	  }
 	  break;
 	case dw_val_class_const_double:
-	  hash = iterative_hash_object (val2->v.val_double.low, hash);
-	  hash = iterative_hash_object (val2->v.val_double.high, hash);
+	  hstate.add_object (val2->v.val_double.low);
+	  hstate.add_object (val2->v.val_double.high);
 	  break;
 	case dw_val_class_wide_int:
-	  hash = iterative_hash_object (*val2->v.val_wide, hash);
+	  hstate.add_object (*val2->v.val_wide);
 	  break;
-	case dw_val_class_addr:
-	  hash = iterative_hash_rtx (val2->v.val_addr, hash);
+	case dw_val_class_addr:	
+	  iterative_hstate_rtx (val2->v.val_addr, hstate);
 	  break;
 	default:
 	  gcc_unreachable ();
@@ -23727,17 +23737,17 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
       break;
     case DW_OP_bregx:
     case DW_OP_bit_piece:
-      hash = iterative_hash_object (val1->v.val_int, hash);
-      hash = iterative_hash_object (val2->v.val_int, hash);
+      hstate.add_object (val1->v.val_int);
+      hstate.add_object (val2->v.val_int);
       break;
     case DW_OP_addr:
     hash_addr:
       if (loc->dtprel)
 	{
 	  unsigned char dtprel = 0xd1;
-	  hash = iterative_hash_object (dtprel, hash);
+	  hstate.add_object (dtprel);
 	}
-      hash = iterative_hash_rtx (val1->v.val_addr, hash);
+      iterative_hstate_rtx (val1->v.val_addr, hstate);
       break;
     case DW_OP_GNU_addr_index:
     case DW_OP_GNU_const_index:
@@ -23745,16 +23755,16 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
         if (loc->dtprel)
           {
             unsigned char dtprel = 0xd1;
-            hash = iterative_hash_object (dtprel, hash);
+	    hstate.add_object (dtprel);
           }
-        hash = iterative_hash_rtx (val1->val_entry->addr.rtl, hash);
+        iterative_hstate_rtx (val1->val_entry->addr.rtl, hstate);
       }
       break;
     case DW_OP_GNU_implicit_pointer:
-      hash = iterative_hash_object (val2->v.val_int, hash);
+      hstate.add_int (val2->v.val_int);
       break;
     case DW_OP_GNU_entry_value:
-      hash = hash_loc_operands (val1->v.val_loc, hash);
+      hstate.add_object (val1->v.val_loc);
       break;
     case DW_OP_GNU_regval_type:
     case DW_OP_GNU_deref_type:
@@ -23763,16 +23773,16 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
 	  = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
 	unsigned int encoding
 	  = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
-	hash = iterative_hash_object (val1->v.val_int, hash);
-	hash = iterative_hash_object (byte_size, hash);
-	hash = iterative_hash_object (encoding, hash);
+	hstate.add_object (val1->v.val_int);
+	hstate.add_object (byte_size);
+	hstate.add_object (encoding);
       }
       break;
     case DW_OP_GNU_convert:
     case DW_OP_GNU_reinterpret:
       if (val1->val_class == dw_val_class_unsigned_const)
 	{
-	  hash = iterative_hash_object (val1->v.val_unsigned, hash);
+	  hstate.add_object (val1->v.val_unsigned);
 	  break;
 	}
       /* FALLTHRU */
@@ -23782,33 +23792,32 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
 	  = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
 	unsigned int encoding
 	  = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
-	hash = iterative_hash_object (byte_size, hash);
-	hash = iterative_hash_object (encoding, hash);
+	hstate.add_object (byte_size);
+	hstate.add_object (encoding);
 	if (loc->dw_loc_opc != DW_OP_GNU_const_type)
 	  break;
-	hash = iterative_hash_object (val2->val_class, hash);
+	hstate.add_object (val2->val_class);
 	switch (val2->val_class)
 	  {
 	  case dw_val_class_const:
-	    hash = iterative_hash_object (val2->v.val_int, hash);
+	    hstate.add_object (val2->v.val_int);
 	    break;
 	  case dw_val_class_vec:
 	    {
 	      unsigned int elt_size = val2->v.val_vec.elt_size;
 	      unsigned int len = val2->v.val_vec.length;
 
-	      hash = iterative_hash_object (elt_size, hash);
-	      hash = iterative_hash_object (len, hash);
-	      hash = iterative_hash (val2->v.val_vec.array,
-				     len * elt_size, hash);
+	      hstate.add_object (elt_size);
+	      hstate.add_object (len);
+	      hstate.add (val2->v.val_vec.array, len * elt_size);
 	    }
 	    break;
 	  case dw_val_class_const_double:
-	    hash = iterative_hash_object (val2->v.val_double.low, hash);
-	    hash = iterative_hash_object (val2->v.val_double.high, hash);
+	    hstate.add_object (val2->v.val_double.low);
+	    hstate.add_object (val2->v.val_double.high);
 	    break;
 	  case dw_val_class_wide_int:
-	    hash = iterative_hash_object (*val2->v.val_wide, hash);
+	    hstate.add_object (*val2->v.val_wide);
 	    break;
 	  default:
 	    gcc_unreachable ();
@@ -23820,13 +23829,12 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
       /* Other codes have no operands.  */
       break;
     }
-  return hash;
 }
 
-/* Iteratively hash the whole DWARF location expression LOC.  */
+/* Iteratively hash the whole DWARF location expression LOC into HSTATE.  */
 
-static inline hashval_t
-hash_locs (dw_loc_descr_ref loc, hashval_t hash)
+static inline void
+hash_locs (dw_loc_descr_ref loc, inchash &hstate)
 {
   dw_loc_descr_ref l;
   bool sizes_computed = false;
@@ -23836,15 +23844,14 @@ hash_locs (dw_loc_descr_ref loc, hashval_t hash)
   for (l = loc; l != NULL; l = l->dw_loc_next)
     {
       enum dwarf_location_atom opc = l->dw_loc_opc;
-      hash = iterative_hash_object (opc, hash);
+      hstate.add_object (opc);
       if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
 	{
 	  size_of_locs (loc);
 	  sizes_computed = true;
 	}
-      hash = hash_loc_operands (l, hash);
+      hash_loc_operands (l, hstate);
     }
-  return hash;
 }
 
 /* Compute hash of the whole location list LIST_HEAD.  */
@@ -23853,18 +23860,17 @@ static inline void
 hash_loc_list (dw_loc_list_ref list_head)
 {
   dw_loc_list_ref curr = list_head;
-  hashval_t hash = 0;
+  inchash hstate;
 
   for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
     {
-      hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
-      hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
+      hstate.add (curr->begin, strlen (curr->begin) + 1);
+      hstate.add (curr->end, strlen (curr->end) + 1);
       if (curr->section)
-	hash = iterative_hash (curr->section, strlen (curr->section) + 1,
-			       hash);
-      hash = hash_locs (curr->expr, hash);
+	hstate.add (curr->section, strlen (curr->section) + 1);
+      hash_locs (curr->expr, hstate);
     }
-  list_head->hash = hash;
+  list_head->hash = hstate.end ();
 }
 
 /* Return true if X and Y opcodes have the same operands.  */
diff --git a/gcc/rtl.c b/gcc/rtl.c
index 520f9a8..3363eeb 100644
--- a/gcc/rtl.c
+++ b/gcc/rtl.c
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifdef GENERATOR_FILE
 # include "errors.h"
 #else
+# include "rtlhash.h"
 # include "diagnostic-core.h"
 #endif
 
@@ -654,84 +655,6 @@ rtx_equal_p (const_rtx x, const_rtx y)
   return 1;
 }
 
-/* Iteratively hash rtx X.  */
-
-hashval_t
-iterative_hash_rtx (const_rtx x, hashval_t hash)
-{
-  enum rtx_code code;
-  enum machine_mode mode;
-  int i, j;
-  const char *fmt;
-
-  if (x == NULL_RTX)
-    return hash;
-  code = GET_CODE (x);
-  hash = iterative_hash_object (code, hash);
-  mode = GET_MODE (x);
-  hash = iterative_hash_object (mode, hash);
-  switch (code)
-    {
-    case REG:
-      i = REGNO (x);
-      return iterative_hash_object (i, hash);
-    case CONST_INT:
-      return iterative_hash_object (INTVAL (x), hash);
-    case CONST_WIDE_INT:
-      for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
-	hash = iterative_hash_object (CONST_WIDE_INT_ELT (x, i), hash);
-      return hash;
-    case SYMBOL_REF:
-      if (XSTR (x, 0))
-	return iterative_hash (XSTR (x, 0), strlen (XSTR (x, 0)) + 1,
-			       hash);
-      return hash;
-    case LABEL_REF:
-    case DEBUG_EXPR:
-    case VALUE:
-    case SCRATCH:
-    case CONST_DOUBLE:
-    case CONST_FIXED:
-    case DEBUG_IMPLICIT_PTR:
-    case DEBUG_PARAMETER_REF:
-      return hash;
-    default:
-      break;
-    }
-
-  fmt = GET_RTX_FORMAT (code);
-  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
-    switch (fmt[i])
-      {
-      case 'w':
-	hash = iterative_hash_object (XWINT (x, i), hash);
-	break;
-      case 'n':
-      case 'i':
-	hash = iterative_hash_object (XINT (x, i), hash);
-	break;
-      case 'V':
-      case 'E':
-	j = XVECLEN (x, i);
-	hash = iterative_hash_object (j, hash);
-	for (j = 0; j < XVECLEN (x, i); j++)
-	  hash = iterative_hash_rtx (XVECEXP (x, i, j), hash);
-	break;
-      case 'e':
-	hash = iterative_hash_rtx (XEXP (x, i), hash);
-	break;
-      case 'S':
-      case 's':
-	if (XSTR (x, i))
-	  hash = iterative_hash (XSTR (x, 0), strlen (XSTR (x, 0)) + 1,
-				 hash);
-	break;
-      default:
-	break;
-      }
-  return hash;
-}
-
 void
 dump_rtx_statistics (void)
 {
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 7f93f0a..7dc01b4 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -1983,7 +1983,6 @@ extern unsigned int rtx_size (const_rtx);
 extern rtx shallow_copy_rtx_stat (const_rtx MEM_STAT_DECL);
 #define shallow_copy_rtx(a) shallow_copy_rtx_stat (a MEM_STAT_INFO)
 extern int rtx_equal_p (const_rtx, const_rtx);
-extern hashval_t iterative_hash_rtx (const_rtx, hashval_t);
 
 /* In emit-rtl.c */
 extern rtvec gen_rtvec_v (int, rtx *);
diff --git a/gcc/rtlhash.c b/gcc/rtlhash.c
new file mode 100644
index 0000000..74c692c
--- /dev/null
+++ b/gcc/rtlhash.c
@@ -0,0 +1,102 @@
+/* RTL hash functions.
+   Copyright (C) 1987-2014 Free Software Foundation, Inc.
+
+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/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "ggc.h"
+#include "rtl.h"
+#include "rtlhash.h"
+
+/* Iteratively hash rtx X into HSTATE.  */
+
+void
+iterative_hstate_rtx (const_rtx x, inchash &hstate)
+{
+  enum rtx_code code;
+  enum machine_mode mode;
+  int i, j;
+  const char *fmt;
+
+  if (x == NULL_RTX)
+    return;
+  code = GET_CODE (x);
+  hstate.add_object (code);
+  mode = GET_MODE (x);
+  hstate.add_object (mode);
+  switch (code)
+    {
+    case REG:
+      hstate.add_int (REGNO (x));
+      return;
+    case CONST_INT:
+      hstate.add_object (INTVAL (x));
+      return;
+    case CONST_WIDE_INT:
+      for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
+	hstate.add_object (CONST_WIDE_INT_ELT (x, i));
+      return;
+    case SYMBOL_REF:
+      if (XSTR (x, 0))
+	hstate.add (XSTR (x, 0), strlen (XSTR (x, 0)) + 1);
+      return;
+    case LABEL_REF:
+    case DEBUG_EXPR:
+    case VALUE:
+    case SCRATCH:
+    case CONST_DOUBLE:
+    case CONST_FIXED:
+    case DEBUG_IMPLICIT_PTR:
+    case DEBUG_PARAMETER_REF:
+      return;
+    default:
+      break;
+    }
+
+  fmt = GET_RTX_FORMAT (code);
+  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
+    switch (fmt[i])
+      {
+      case 'w':
+	hstate.add_object (XWINT (x, i));
+	break;
+      case 'n':
+      case 'i':
+	hstate.add_object (XINT (x, i));
+	break;
+      case 'V':
+      case 'E':
+	j = XVECLEN (x, i);
+	hstate.add_int (j);
+	for (j = 0; j < XVECLEN (x, i); j++)
+	  iterative_hstate_rtx (XVECEXP (x, i, j), hstate);
+	break;
+      case 'e':
+	iterative_hstate_rtx (XEXP (x, i), hstate);
+	break;
+      case 'S':
+      case 's':
+	if (XSTR (x, i))
+	  hstate.add (XSTR (x, 0), strlen (XSTR (x, 0)) + 1);
+	break;
+      default:
+	break;
+      }
+}
diff --git a/gcc/rtlhash.h b/gcc/rtlhash.h
new file mode 100644
index 0000000..cd5c908
--- /dev/null
+++ b/gcc/rtlhash.h
@@ -0,0 +1,27 @@
+/* Register Transfer Language (RTL) hash functions.
+   Copyright (C) 1987-2014 Free Software Foundation, Inc.
+
+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 RTL_HASH_H
+#define RTL_HASH_H 1
+
+#include "inchash.h"
+
+extern void iterative_hstate_rtx (const_rtx, inchash &);
+
+#endif
-- 
2.0.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/6] Convert asan.c to inchash
  2014-07-27 19:38 ` [PATCH 1/6] RTL & dwarf2out changes Andi Kleen
@ 2014-07-27 19:38   ` Andi Kleen
  2014-07-27 19:38     ` [PATCH 3/6] Convert ipa-devirt " Andi Kleen
  2014-07-28  8:23     ` [PATCH 2/6] Convert asan.c " Richard Biener
  2014-07-28 19:00   ` [PATCH 1/6] RTL & dwarf2out changes Cary Coutant
  1 sibling, 2 replies; 11+ messages in thread
From: Andi Kleen @ 2014-07-27 19:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

gcc/:

2014-07-25  Andi Kleen  <ak@linux.intel.com>

	* asan.c (asan_mem_ref_hasher::hash): Convert to inchash.
---
 gcc/asan.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/asan.c b/gcc/asan.c
index 475dd82..f7fa55f 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -348,9 +348,10 @@ struct asan_mem_ref_hasher
 inline hashval_t
 asan_mem_ref_hasher::hash (const asan_mem_ref *mem_ref)
 {
-  hashval_t h = iterative_hash_expr (mem_ref->start, 0);
-  h = iterative_hash_host_wide_int (mem_ref->access_size, h);
-  return h;
+  inchash hstate;
+  iterative_hstate_expr (mem_ref->start, hstate);
+  hstate.add_wide_int (mem_ref->access_size);
+  return hstate.end ();
 }
 
 /* Compare two memory references.  We accept the length of either
-- 
2.0.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/6] Convert tree-ssa-sccvn to inchash
  2014-07-27 19:38       ` [PATCH 4/6] Convert tree-ssa-dom " Andi Kleen
@ 2014-07-27 19:45         ` Andi Kleen
  2014-07-27 19:38           ` [PATCH 6/6] Convert tree-ssa-tail-merge " Andi Kleen
  0 siblings, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2014-07-27 19:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

gcc/:

2014-07-25  Andi Kleen  <ak@linux.intel.com>

	* tree-ssa-sccvn.c (vn_reference_op_compute_hash):
	(vn_reference_compute_hash):
	(vn_nary_op_compute_hash):
	(vn_phi_compute_hash):
	* tree-ssa-sccvn.h (vn_hash_constant_with_type):
---
 gcc/tree-ssa-sccvn.c | 44 ++++++++++++++++++++++----------------------
 gcc/tree-ssa-sccvn.h |  6 ++++--
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 93314fc..160ca00 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -594,17 +594,16 @@ value_id_constant_p (unsigned int v)
 
 /* Compute the hash for a reference operand VRO1.  */
 
-static hashval_t
-vn_reference_op_compute_hash (const vn_reference_op_t vro1, hashval_t result)
+static void
+vn_reference_op_compute_hash (const vn_reference_op_t vro1, inchash &hstate)
 {
-  result = iterative_hash_hashval_t (vro1->opcode, result);
+  hstate.add_int (vro1->opcode);
   if (vro1->op0)
-    result = iterative_hash_expr (vro1->op0, result);
+    iterative_hstate_expr (vro1->op0, hstate);
   if (vro1->op1)
-    result = iterative_hash_expr (vro1->op1, result);
+    iterative_hstate_expr (vro1->op1, hstate);
   if (vro1->op2)
-    result = iterative_hash_expr (vro1->op2, result);
-  return result;
+    iterative_hstate_expr (vro1->op2, hstate);
 }
 
 /* Compute a hash for the reference operation VR1 and return it.  */
@@ -612,7 +611,8 @@ vn_reference_op_compute_hash (const vn_reference_op_t vro1, hashval_t result)
 hashval_t
 vn_reference_compute_hash (const vn_reference_t vr1)
 {
-  hashval_t result = 0;
+  inchash hstate;
+  hashval_t result;
   int i;
   vn_reference_op_t vro;
   HOST_WIDE_INT off = -1;
@@ -634,7 +634,7 @@ vn_reference_compute_hash (const vn_reference_t vr1)
 	{
 	  if (off != -1
 	      && off != 0)
-	    result = iterative_hash_hashval_t (off, result);
+	    hstate.add_int (off);
 	  off = -1;
 	  if (deref
 	      && vro->opcode == ADDR_EXPR)
@@ -642,14 +642,16 @@ vn_reference_compute_hash (const vn_reference_t vr1)
 	      if (vro->op0)
 		{
 		  tree op = TREE_OPERAND (vro->op0, 0);
-		  result = iterative_hash_hashval_t (TREE_CODE (op), result);
-		  result = iterative_hash_expr (op, result);
+		  hstate.add_int (TREE_CODE (op));
+		  iterative_hstate_expr (op, hstate);
 		}
 	    }
 	  else
-	    result = vn_reference_op_compute_hash (vro, result);
+	    vn_reference_op_compute_hash (vro, hstate);
 	}
     }
+  result = hstate.end ();
+  /* ??? We would ICE later if we hash instead of adding that in. */
   if (vr1->vuse)
     result += SSA_NAME_VERSION (vr1->vuse);
 
@@ -2236,7 +2238,7 @@ vn_reference_insert_pieces (tree vuse, alias_set_type set, tree type,
 hashval_t
 vn_nary_op_compute_hash (const vn_nary_op_t vno1)
 {
-  hashval_t hash;
+  inchash hstate;
   unsigned i;
 
   for (i = 0; i < vno1->length; ++i)
@@ -2252,11 +2254,11 @@ vn_nary_op_compute_hash (const vn_nary_op_t vno1)
       vno1->op[1] = temp;
     }
 
-  hash = iterative_hash_hashval_t (vno1->opcode, 0);
+  hstate.add_int (vno1->opcode);
   for (i = 0; i < vno1->length; ++i)
-    hash = iterative_hash_expr (vno1->op[i], hash);
+    iterative_hstate_expr (vno1->op[i], hstate);
 
-  return hash;
+  return hstate.end ();
 }
 
 /* Compare nary operations VNO1 and VNO2 and return true if they are
@@ -2536,26 +2538,24 @@ vn_nary_op_insert_stmt (gimple stmt, tree result)
 static inline hashval_t
 vn_phi_compute_hash (vn_phi_t vp1)
 {
-  hashval_t result;
+  inchash hstate (vp1->block->index);
   int i;
   tree phi1op;
   tree type;
 
-  result = vp1->block->index;
-
   /* If all PHI arguments are constants we need to distinguish
      the PHI node via its type.  */
   type = vp1->type;
-  result += vn_hash_type (type);
+  hstate.merge_hash (vn_hash_type (type));
 
   FOR_EACH_VEC_ELT (vp1->phiargs, i, phi1op)
     {
       if (phi1op == VN_TOP)
 	continue;
-      result = iterative_hash_expr (phi1op, result);
+      iterative_hstate_expr (phi1op, hstate);
     }
 
-  return result;
+  return hstate.end ();
 }
 
 /* Compare two phi entries for equality, ignoring VN_TOP arguments.  */
diff --git a/gcc/tree-ssa-sccvn.h b/gcc/tree-ssa-sccvn.h
index f52783a..f420656 100644
--- a/gcc/tree-ssa-sccvn.h
+++ b/gcc/tree-ssa-sccvn.h
@@ -140,8 +140,10 @@ vn_hash_type (tree type)
 static inline hashval_t
 vn_hash_constant_with_type (tree constant)
 {
-  return (iterative_hash_expr (constant, 0)
-	  + vn_hash_type (TREE_TYPE (constant)));
+  inchash hstate;
+  iterative_hstate_expr (constant, hstate);
+  hstate.merge_hash (vn_hash_type (TREE_TYPE (constant)));
+  return hstate.end ();
 }
 
 /* Compare the constants C1 and C2 with distinguishing type incompatible
-- 
2.0.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/6] Convert asan.c to inchash
  2014-07-27 19:38   ` [PATCH 2/6] Convert asan.c to inchash Andi Kleen
  2014-07-27 19:38     ` [PATCH 3/6] Convert ipa-devirt " Andi Kleen
@ 2014-07-28  8:23     ` Richard Biener
  1 sibling, 0 replies; 11+ messages in thread
From: Richard Biener @ 2014-07-28  8:23 UTC (permalink / raw)
  To: Andi Kleen; +Cc: GCC Patches, Andi Kleen

On Sun, Jul 27, 2014 at 9:37 PM, Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> gcc/:
>
> 2014-07-25  Andi Kleen  <ak@linux.intel.com>
>
>         * asan.c (asan_mem_ref_hasher::hash): Convert to inchash.
> ---
>  gcc/asan.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/asan.c b/gcc/asan.c
> index 475dd82..f7fa55f 100644
> --- a/gcc/asan.c
> +++ b/gcc/asan.c
> @@ -348,9 +348,10 @@ struct asan_mem_ref_hasher
>  inline hashval_t
>  asan_mem_ref_hasher::hash (const asan_mem_ref *mem_ref)
>  {
> -  hashval_t h = iterative_hash_expr (mem_ref->start, 0);
> -  h = iterative_hash_host_wide_int (mem_ref->access_size, h);
> -  return h;
> +  inchash hstate;
> +  iterative_hstate_expr (mem_ref->start, hstate);

Btw, this is what I mentioned with using a namespace instead of a class.
With a namespace you could have extended it with an API like

inchash::add_expr (hstate, mem_ref->start);

which would look the same API-wise as

> +  hstate.add_wide_int (mem_ref->access_size);

inchash::add_wide_int (hstate, mem_ref->access_size);

It would of course mean not using member functions but at least
it would have had a consistent API.

Richard.

> +  return hstate.end ();
>  }
>
>  /* Compare two memory references.  We accept the length of either
> --
> 2.0.1
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/6] RTL & dwarf2out changes
  2014-07-27 19:38 ` [PATCH 1/6] RTL & dwarf2out changes Andi Kleen
  2014-07-27 19:38   ` [PATCH 2/6] Convert asan.c to inchash Andi Kleen
@ 2014-07-28 19:00   ` Cary Coutant
  2014-07-28 19:42     ` Andi Kleen
  1 sibling, 1 reply; 11+ messages in thread
From: Cary Coutant @ 2014-07-28 19:00 UTC (permalink / raw)
  To: Andi Kleen; +Cc: gcc-patches, Andi Kleen

> +  /* ??? MD5 of another hash doesn't make a lot of sense... */
> +  hash = hstate.end();
>    CHECKSUM (hash);

[citation needed] I don't see why you think that. Maybe it'd be nicer
if we could use hash_loc_operands() to feed its input directly into
the MD5 checksum, but I think in this case it's perfectly fine to use
the hash instead, in order to avoid reimplementing a rather
substantial function that already exists.

Maybe we could make hash_loc_operands() a template that can be used as
part of either inchash or MD5?

In the case of loc_checksum(), we're tied to MD5 by the DWARF
standard. Otherwise, we could just rewrite it to use inchash
throughout.

-cary

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/6] RTL & dwarf2out changes
  2014-07-28 19:00   ` [PATCH 1/6] RTL & dwarf2out changes Cary Coutant
@ 2014-07-28 19:42     ` Andi Kleen
  2014-07-28 21:30       ` Cary Coutant
  0 siblings, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2014-07-28 19:42 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Andi Kleen, gcc-patches

On Mon, Jul 28, 2014 at 11:48:58AM -0700, Cary Coutant wrote:
> > +  /* ??? MD5 of another hash doesn't make a lot of sense... */
> > +  hash = hstate.end();
> >    CHECKSUM (hash);
> 
> [citation needed] I don't see why you think that. Maybe it'd be nicer
> if we could use hash_loc_operands() to feed its input directly into
> the MD5 checksum, but I think in this case it's perfectly fine to use
> the hash instead, in order to avoid reimplementing a rather
> substantial function that already exists.

Well you're dropping information at least, and it's slower
than it could be.

> Maybe we could make hash_loc_operands() a template that can be used as
> part of either inchash or MD5?
> 
> In the case of loc_checksum(), we're tied to MD5 by the DWARF
> standard. Otherwise, we could just rewrite it to use inchash
> throughout.

I'm not sure I understand the motivation. If gcc hashes in
gcc specific stuff (and this hash, even before my changes is)
then the output can never be re-created by anything but gcc.

If the standard just wants a well hashed number at the end
then any good hash should do.

I haven't checked it for this case, but if the hashing shows
up in profiles it may be worth using a faster but non secure
hash.

Anyways I can drop the comment if you don't agree with it.

-Andi

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/6] RTL & dwarf2out changes
  2014-07-28 19:42     ` Andi Kleen
@ 2014-07-28 21:30       ` Cary Coutant
  0 siblings, 0 replies; 11+ messages in thread
From: Cary Coutant @ 2014-07-28 21:30 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Andi Kleen, gcc-patches

>> In the case of loc_checksum(), we're tied to MD5 by the DWARF
>> standard. Otherwise, we could just rewrite it to use inchash
>> throughout.
>
> I'm not sure I understand the motivation. If gcc hashes in
> gcc specific stuff (and this hash, even before my changes is)
> then the output can never be re-created by anything but gcc.
>
> If the standard just wants a well hashed number at the end
> then any good hash should do.

It's complicated. The DWARF standard specifies how the signature for a
type unit (-fdebug-types-section) is computed, using MD5. There are
occasional location expressions in a type unit, but the only ones we
should see when computing a type signature are special-cased, and we
should never actually get to where hash_loc_operands() is called. If
one does slip through, it's not fatal -- we'll just generate a type
signature that doesn't conform to the standard, and we may miss an
opportunity for link-time type de-duplication.

For both -feliminate-dwarf2-dups and -gsplit-dwarf, though, we also
compute DIE signatures using the same code, and in these cases, we may
see location expressions that need hash_loc_operands(). These
signatures are not specified by the DWARF standard, so it's reasonable
(IMO) to reuse the existing hashing routine in that case. These
signatures are used for de-duplication, for fast lookup, and for
disambiguation where two CUs have the same DW_AT_name, so the loss of
information is not critical.

> I haven't checked it for this case, but if the hashing shows
> up in profiles it may be worth using a faster but non secure
> hash.
>
> Anyways I can drop the comment if you don't agree with it.

Thanks, please do. It does make sense, even if there's a theoretically
better way to do it.

-cary

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-07-28 21:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-27 19:37 Convert more incremental hash users to inchash Andi Kleen
2014-07-27 19:38 ` [PATCH 1/6] RTL & dwarf2out changes Andi Kleen
2014-07-27 19:38   ` [PATCH 2/6] Convert asan.c to inchash Andi Kleen
2014-07-27 19:38     ` [PATCH 3/6] Convert ipa-devirt " Andi Kleen
2014-07-27 19:38       ` [PATCH 4/6] Convert tree-ssa-dom " Andi Kleen
2014-07-27 19:45         ` [PATCH 5/6] Convert tree-ssa-sccvn " Andi Kleen
2014-07-27 19:38           ` [PATCH 6/6] Convert tree-ssa-tail-merge " Andi Kleen
2014-07-28  8:23     ` [PATCH 2/6] Convert asan.c " Richard Biener
2014-07-28 19:00   ` [PATCH 1/6] RTL & dwarf2out changes Cary Coutant
2014-07-28 19:42     ` Andi Kleen
2014-07-28 21:30       ` Cary Coutant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).