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