| 1 |
/* RTL hash functions. |
| 2 |
Copyright (C) 1987-2025 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 |
| 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 'L': |
| 91 |
hstate.add_hwi (XLOC (x, i)); |
| 92 |
break; |
| 93 |
case 'p': |
| 94 |
hstate.add_poly_int (SUBREG_BYTE (x)); |
| 95 |
break; |
| 96 |
case 'V': |
| 97 |
case 'E': |
| 98 |
j = XVECLEN (x, i); |
| 99 |
hstate.add_int (j); |
| 100 |
for (j = 0; j < XVECLEN (x, i); j++) |
| 101 |
inchash::add_rtx (XVECEXP (x, i, j), hstate); |
| 102 |
break; |
| 103 |
case 'e': |
| 104 |
inchash::add_rtx (XEXP (x, i), hstate); |
| 105 |
break; |
| 106 |
case 'S': |
| 107 |
case 's': |
| 108 |
if (XSTR (x, i)) |
| 109 |
hstate.add (XSTR (x, 0), strlen (XSTR (x, 0)) + 1); |
| 110 |
break; |
| 111 |
default: |
| 112 |
break; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
} |