1 /* RTL hash functions.
2    Copyright (C) 1987-2018 Free Software Foundation, Inc.
3 
4 This file is part of GCC.
5 
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10 
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3.  If not see
18 <http://www.gnu.org/licenses/>.  */
19 
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "rtl.h"
25 #include "rtlhash.h"
26 
27 namespace inchash
28 {
29 
30 /* Iteratively hash rtx X into HSTATE.  */
31 
32 void
add_rtx(const_rtx x,hash & hstate)33 add_rtx (const_rtx x, hash &hstate)
34 {
35   enum rtx_code code;
36   machine_mode mode;
37   int i, j;
38   const char *fmt;
39 
40   if (x == NULL_RTX)
41     return;
42   code = GET_CODE (x);
43   hstate.add_object (code);
44   mode = GET_MODE (x);
45   hstate.add_object (mode);
46   switch (code)
47     {
48     case REG:
49       hstate.add_int (REGNO (x));
50       return;
51     case CONST_INT:
52       hstate.add_object (INTVAL (x));
53       return;
54     case CONST_WIDE_INT:
55       for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
56 	hstate.add_object (CONST_WIDE_INT_ELT (x, i));
57       return;
58     case CONST_POLY_INT:
59       for (i = 0; i < NUM_POLY_INT_COEFFS; ++i)
60 	hstate.add_wide_int (CONST_POLY_INT_COEFFS (x)[i]);
61       break;
62     case SYMBOL_REF:
63       if (XSTR (x, 0))
64 	hstate.add (XSTR (x, 0), strlen (XSTR (x, 0)) + 1);
65       return;
66     case LABEL_REF:
67     case DEBUG_EXPR:
68     case VALUE:
69     case SCRATCH:
70     case CONST_DOUBLE:
71     case CONST_FIXED:
72     case DEBUG_IMPLICIT_PTR:
73     case DEBUG_PARAMETER_REF:
74       return;
75     default:
76       break;
77     }
78 
79   fmt = GET_RTX_FORMAT (code);
80   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
81     switch (fmt[i])
82       {
83       case 'w':
84 	hstate.add_hwi (XWINT (x, i));
85 	break;
86       case 'n':
87       case 'i':
88 	hstate.add_int (XINT (x, i));
89 	break;
90       case 'p':
91 	hstate.add_poly_int (SUBREG_BYTE (x));
92 	break;
93       case 'V':
94       case 'E':
95 	j = XVECLEN (x, i);
96 	hstate.add_int (j);
97 	for (j = 0; j < XVECLEN (x, i); j++)
98 	  inchash::add_rtx (XVECEXP (x, i, j), hstate);
99 	break;
100       case 'e':
101 	inchash::add_rtx (XEXP (x, i), hstate);
102 	break;
103       case 'S':
104       case 's':
105 	if (XSTR (x, i))
106 	  hstate.add (XSTR (x, 0), strlen (XSTR (x, 0)) + 1);
107 	break;
108       default:
109 	break;
110       }
111 }
112 
113 }
114