diff mbox

[1/6] RTL & dwarf2out changes

Message ID 1406489825-9561-2-git-send-email-andi@firstfloor.org
State New
Headers show

Commit Message

Andi Kleen July 27, 2014, 7:37 p.m. UTC
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

Comments

Cary Coutant July 28, 2014, 6:48 p.m. UTC | #1
> +  /* ??? 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
Andi Kleen July 28, 2014, 7:25 p.m. UTC | #2
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
Cary Coutant July 28, 2014, 9:06 p.m. UTC | #3
>> 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
diff mbox

Patch

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