From patchwork Tue Jun 16 08:43:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 484848 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 27CDB1402A5 for ; Tue, 16 Jun 2015 18:44:34 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=HF4lnn01; dkim-atps=neutral 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:subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=jbY VEnoZot0byNvau1S+ERyQfpXkdPsdyz62D3XBPbWhPJpnNgZOvd3cttqzpCeYbgp 4kk4e9UOEzJQ3HIec/IMo+FkOZVbQ33cyfToEUTwkzsU1oTgC/gv1irPDAJYMVoX uK3ZncYl03VFzK0HG0IYs8b2/sxzZ6XWGBcNYvZo= 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:subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=default; bh=eT/cZ9ez9 hvI2Wh9Z0Lcx5+CL58=; b=HF4lnn01Sse7uaV4vSkwrMPxZTx582IID7ta/OhrA +qV5j/pHaf8ng9cF3XIcsXhMXxhu/lFSox5hjp5F4R4zQ3mqugshvue1vzzMlsOM aR54+568VTb+7ZN/wKRycOt/ryTWIRRzAeo7xs1TyhOUNAiuMPJUeFTN5SFSpsi7 2o= Received: (qmail 93702 invoked by alias); 16 Jun 2015 08:44:04 -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 93621 invoked by uid 89); 16 Jun 2015 08:44:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=no version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jun 2015 08:44:01 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by uk-mta-28.uk.mimecast.lan; Tue, 16 Jun 2015 09:43:58 +0100 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 16 Jun 2015 09:43:58 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [01/13] Move hash traits to their own header file References: <87fv5s2gej.fsf@e105548-lin.cambridge.arm.com> Date: Tue, 16 Jun 2015 09:43:58 +0100 In-Reply-To: <87fv5s2gej.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Tue, 16 Jun 2015 09:42:28 +0100") Message-ID: <87bngg2gc1.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: 44DzlGmLQYyXEDoaVijG3Q-1 This patch just moves the traits classes to their own header file, hash-traits.h. gcc/ * hash-table.h: Include hash-traits.h. (typed_free_remove, typed_noop_remove, pointer_hash, ggc_hasher) (ggc_cache_hasher): Move to... * hash-traits.h: ...this new file. Index: gcc/hash-table.h =================================================================== --- gcc/hash-table.h 2015-06-15 16:04:44.775663659 +0100 +++ gcc/hash-table.h 2015-06-15 16:04:44.771663705 +0100 @@ -81,7 +81,7 @@ Software Foundation; either version 3, o We compose this into a few steps. 1. Decide on a removal policy for values stored in the table. - This header provides class templates for the two most common + hash-traits.h provides class templates for the two most common policies. * typed_free_remove implements the static 'remove' member function @@ -202,6 +202,7 @@ #define TYPED_HASHTAB_H #include "hashtab.h" #include "inchash.h" #include "mem-stats-traits.h" +#include "hash-traits.h" #include "hash-map-traits.h" template class hash_map; @@ -238,143 +239,6 @@ xcallocator ::data_free (Type *mem } -/* Helpful type for removing with free. */ - -template -struct typed_free_remove -{ - static inline void remove (Type *p); -}; - - -/* Remove with free. */ - -template -inline void -typed_free_remove ::remove (Type *p) -{ - free (p); -} - - -/* Helpful type for a no-op remove. */ - -template -struct typed_noop_remove -{ - static inline void remove (Type *p); -}; - - -/* Remove doing nothing. */ - -template -inline void -typed_noop_remove ::remove (Type *p ATTRIBUTE_UNUSED) -{ -} - - -/* Pointer hash with a no-op remove method. */ - -template -struct pointer_hash : typed_noop_remove -{ - typedef Type *value_type; - typedef Type *compare_type; - - static inline hashval_t hash (const value_type &); - - static inline bool equal (const value_type &existing, - const compare_type &candidate); -}; - -template -inline hashval_t -pointer_hash ::hash (const value_type &candidate) -{ - /* This is a really poor hash function, but it is what the current code uses, - so I am reusing it to avoid an additional axis in testing. */ - return (hashval_t) ((intptr_t)candidate >> 3); -} - -template -inline bool -pointer_hash ::equal (const value_type &existing, - const compare_type &candidate) -{ - return existing == candidate; -} - -/* Hasher for entry in gc memory. */ - -template -struct ggc_hasher -{ - typedef T value_type; - typedef T compare_type; - - static void remove (T) {} - - static void - ggc_mx (T p) - { - extern void gt_ggc_mx (T &); - gt_ggc_mx (p); - } - - static void - pch_nx (T &p) - { - extern void gt_pch_nx (T &); - gt_pch_nx (p); - } - - static void - pch_nx (T &p, gt_pointer_operator op, void *cookie) - { - op (&p, cookie); - } -}; - -/* Hasher for cache entry in gc memory. */ - -template -struct ggc_cache_hasher -{ - typedef T value_type; - typedef T compare_type; - - static void remove (T &) {} - - /* Entries are weakly held because this is for caches. */ - - static void ggc_mx (T &) {} - - static void - pch_nx (T &p) - { - extern void gt_pch_nx (T &); - gt_pch_nx (p); - } - - static void - pch_nx (T &p, gt_pointer_operator op, void *cookie) - { - op (&p, cookie); - } - - /* Clear out entries if they are about to be gc'd. */ - - static void - handle_cache_entry (T &e) - { - if (e != HTAB_EMPTY_ENTRY && e != HTAB_DELETED_ENTRY && !ggc_marked_p (e)) - e = static_cast (HTAB_DELETED_ENTRY); - } -}; - - /* Table of primes and their inversion information. */ struct prime_ent Index: gcc/hash-traits.h =================================================================== --- /dev/null 2015-06-02 17:27:28.541944012 +0100 +++ gcc/hash-traits.h 2015-06-15 16:04:44.771663705 +0100 @@ -0,0 +1,159 @@ +/* Traits for hashable types. + Copyright (C) 2014-2015 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 hash_traits_h +#define hash_traits_h + +/* Helpful type for removing with free. */ + +template +struct typed_free_remove +{ + static inline void remove (Type *p); +}; + + +/* Remove with free. */ + +template +inline void +typed_free_remove ::remove (Type *p) +{ + free (p); +} + + +/* Helpful type for a no-op remove. */ + +template +struct typed_noop_remove +{ + static inline void remove (Type *p); +}; + + +/* Remove doing nothing. */ + +template +inline void +typed_noop_remove ::remove (Type *p ATTRIBUTE_UNUSED) +{ +} + + +/* Pointer hash with a no-op remove method. */ + +template +struct pointer_hash : typed_noop_remove +{ + typedef Type *value_type; + typedef Type *compare_type; + + static inline hashval_t hash (const value_type &); + + static inline bool equal (const value_type &existing, + const compare_type &candidate); +}; + +template +inline hashval_t +pointer_hash ::hash (const value_type &candidate) +{ + /* This is a really poor hash function, but it is what the current code uses, + so I am reusing it to avoid an additional axis in testing. */ + return (hashval_t) ((intptr_t)candidate >> 3); +} + +template +inline bool +pointer_hash ::equal (const value_type &existing, + const compare_type &candidate) +{ + return existing == candidate; +} + +/* Hasher for entry in gc memory. */ + +template +struct ggc_hasher +{ + typedef T value_type; + typedef T compare_type; + + static void remove (T) {} + + static void + ggc_mx (T p) + { + extern void gt_ggc_mx (T &); + gt_ggc_mx (p); + } + + static void + pch_nx (T &p) + { + extern void gt_pch_nx (T &); + gt_pch_nx (p); + } + + static void + pch_nx (T &p, gt_pointer_operator op, void *cookie) + { + op (&p, cookie); + } +}; + +/* Hasher for cache entry in gc memory. */ + +template +struct ggc_cache_hasher +{ + typedef T value_type; + typedef T compare_type; + + static void remove (T &) {} + + /* Entries are weakly held because this is for caches. */ + + static void ggc_mx (T &) {} + + static void + pch_nx (T &p) + { + extern void gt_pch_nx (T &); + gt_pch_nx (p); + } + + static void + pch_nx (T &p, gt_pointer_operator op, void *cookie) + { + op (&p, cookie); + } + + /* Clear out entries if they are about to be gc'd. */ + + static void + handle_cache_entry (T &e) + { + if (e != HTAB_EMPTY_ENTRY && e != HTAB_DELETED_ENTRY && !ggc_marked_p (e)) + e = static_cast (HTAB_DELETED_ENTRY); + } +}; + +#endif