From patchwork Wed Jul 30 14:23:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 374920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9DBC6140189 for ; Thu, 31 Jul 2014 00:25:09 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=NkIgZGGNjB2bkMoh927tmuaIFTRfaHC33A9D1LAZGNCLRMtANlI7A nB3ragEUJqO+zrONIKsHM+co09SmWE33t+fYIImJSOM++5tebhUkNjMf6UVgI11L Kt1oyIhKsJaFx086UMPxLqYZ8DddO9eXwwrY6Z94f9vzJdkCq6pF5Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=wZLj5cxaVUJII8gfg5zcgsXpMT4=; b=cJLBO27KhM5ZYQRIA2cD Xl3cMYmgIoHhxy3k2I/9We6yu+N4jhCWDL1s0Mf62FhrPIUcpPyQGE+qvObBaL9s /Uv7NKRXAqyZfOzNfQWjNtqVQFN7063yHQHLBkiN0ppsZONMc7yMZIhPXwEtKY8E NAwwkzq6/TfrHKHwIppzXzo= Received: (qmail 12063 invoked by alias); 30 Jul 2014 14:24:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 11989 invoked by uid 89); 30 Jul 2014 14:24:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: one.firstfloor.org Received: from one.firstfloor.org (HELO one.firstfloor.org) (193.170.194.197) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 30 Jul 2014 14:24:17 +0000 Received: from basil.firstfloor.org (184-100-237-164.ptld.qwest.net [184.100.237.164]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by one.firstfloor.org (Postfix) with ESMTPSA id 77558869BA; Wed, 30 Jul 2014 16:24:11 +0200 (CEST) Received: by basil.firstfloor.org (Postfix, from userid 1000) id 06F30A0A4E; Wed, 30 Jul 2014 07:23:50 -0700 (PDT) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 2/7] RTL & dwarf2out changes Date: Wed, 30 Jul 2014 07:23:40 -0700 Message-Id: <1406730225-25896-3-git-send-email-andi@firstfloor.org> In-Reply-To: <1406730225-25896-2-git-send-email-andi@firstfloor.org> References: <1406730225-25896-1-git-send-email-andi@firstfloor.org> <1406730225-25896-2-git-send-email-andi@firstfloor.org> From: Andi Kleen 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. v2: Removed ??? comment. gcc/: 2014-07-29 Andi Kleen * 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 | 125 +++++++++++++++++++++++++++++--------------------------- gcc/rtl.c | 79 +---------------------------------- gcc/rtl.h | 1 - gcc/rtlhash.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ gcc/rtlhash.h | 32 +++++++++++++++ 6 files changed, 206 insertions(+), 139 deletions(-) create mode 100644 gcc/rtlhash.c create mode 100644 gcc/rtlhash.h 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..f90329b 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::hash &); /* 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::hash 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 (); } + inchash::add_rtx (a->addr.rtl, hstate); + return hstate.end (); } /* Determine equality for two address_table_entries. */ @@ -5544,11 +5550,13 @@ static inline void loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx) { int tem; - hashval_t hash = 0; + inchash::hash 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); + hash = hstate.end(); CHECKSUM (hash); } @@ -5758,11 +5766,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::hash 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 +23629,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::hash &hstate) { dw_val_ref val1 = &loc->dw_loc_oprnd1; dw_val_ref val2 = &loc->dw_loc_oprnd2; @@ -23681,7 +23691,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 +23700,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: + inchash::add_rtx (val2->v.val_addr, hstate); break; default: gcc_unreachable (); @@ -23727,17 +23736,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); + inchash::add_rtx (val1->v.val_addr, hstate); break; case DW_OP_GNU_addr_index: case DW_OP_GNU_const_index: @@ -23745,16 +23754,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); + inchash::add_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 +23772,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 +23791,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 +23828,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::hash &hstate) { dw_loc_descr_ref l; bool sizes_computed = false; @@ -23836,15 +23843,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 +23859,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::hash 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 3ab45d2..2fb0c5c 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..ed4ee7a --- /dev/null +++ b/gcc/rtlhash.c @@ -0,0 +1,107 @@ +/* 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 +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "ggc.h" +#include "rtl.h" +#include "rtlhash.h" + +namespace inchash +{ + +/* Iteratively hash rtx X into HSTATE. */ + +void +add_rtx (const_rtx x, hash &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++) + inchash::add_rtx (XVECEXP (x, i, j), hstate); + break; + case 'e': + inchash::add_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..158a2c2 --- /dev/null +++ b/gcc/rtlhash.h @@ -0,0 +1,32 @@ +/* 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 +. */ + +#ifndef RTL_HASH_H +#define RTL_HASH_H 1 + +#include "inchash.h" + +namespace inchash +{ + +extern void add_rtx (const_rtx, hash &); + +} + +#endif