PR 66861 Fix null pointer crash on mingw.
[official-gcc.git] / gcc / rtlhash.c
blob62fe788d6439dc4c785e28e1c4d943389ecabe01
1 /* RTL hash functions.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "rtl.h"
25 #include "rtlhash.h"
27 namespace inchash
30 /* Iteratively hash rtx X into HSTATE. */
32 void
33 add_rtx (const_rtx x, hash &hstate)
35 enum rtx_code code;
36 machine_mode mode;
37 int i, j;
38 const char *fmt;
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)
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 SYMBOL_REF:
59 if (XSTR (x, 0))
60 hstate.add (XSTR (x, 0), strlen (XSTR (x, 0)) + 1);
61 return;
62 case LABEL_REF:
63 case DEBUG_EXPR:
64 case VALUE:
65 case SCRATCH:
66 case CONST_DOUBLE:
67 case CONST_FIXED:
68 case DEBUG_IMPLICIT_PTR:
69 case DEBUG_PARAMETER_REF:
70 return;
71 default:
72 break;
75 fmt = GET_RTX_FORMAT (code);
76 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
77 switch (fmt[i])
79 case 'w':
80 hstate.add_object (XWINT (x, i));
81 break;
82 case 'n':
83 case 'i':
84 hstate.add_object (XINT (x, i));
85 break;
86 case 'V':
87 case 'E':
88 j = XVECLEN (x, i);
89 hstate.add_int (j);
90 for (j = 0; j < XVECLEN (x, i); j++)
91 inchash::add_rtx (XVECEXP (x, i, j), hstate);
92 break;
93 case 'e':
94 inchash::add_rtx (XEXP (x, i), hstate);
95 break;
96 case 'S':
97 case 's':
98 if (XSTR (x, i))
99 hstate.add (XSTR (x, 0), strlen (XSTR (x, 0)) + 1);
100 break;
101 default:
102 break;