From patchwork Tue Jun 16 09:14:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 484876 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 661B31402A5 for ; Tue, 16 Jun 2015 19:14: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=HuBQq0YM; 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=R0J gX6J6bsWbBGOybI8DreZMv3DjhyQn0Jr2mcL21osV3O9Ea1eZmzZjuHDglfp2Bor mRRELsxgKSwfSHLNOPYri6HHTLvov9YaUXu9oz7k/PgWNJewHnBWPZL2wUpdvWK3 2maVl1PXAryPvm5jP3VGroY1DL0mwn/nxkwAhq9s= 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=AnE0itDPr HNp8FFjr2vInh6C9l0=; b=HuBQq0YMqVr2/Q76Q2uXg3M4d20FaETzit/6hfBRV kkoP3cCkibzrlKWyiV5LyQFdfjN4R6uU1Die85t4/zOYOXaOv7qxu+Q/oznq1sV6 VjzU1Gmb0IiusmeM+oYq63WNyc7Yv5Hje+VTEK5xdrjI2HhD7XtNGL3lqMr+eZI3 E0= Received: (qmail 8251 invoked by alias); 16 Jun 2015 09:14:27 -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 8231 invoked by uid 89); 16 Jun 2015 09:14:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_05, 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) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jun 2015 09:14:24 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by uk-mta-25.uk.mimecast.lan; Tue, 16 Jun 2015 10:14:20 +0100 Received: from localhost ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 16 Jun 2015 10:14:20 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [12/13] Reuse hash_table traits for hash_set References: <87fv5s2gej.fsf@e105548-lin.cambridge.arm.com> Date: Tue, 16 Jun 2015 10:14:20 +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: <87y4jkypzn.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: dgqQSbEWRVC6M32g_vMsQA-1 This is the main patch, to reuse the hash_table traits for hash_set. The idea is to replace the untemplated default_hashset_traits with a templated default_hash_traits, which gives the default traits for a given type. This allows things like hash_set to continue to work. For now I've left default_hash_traits without a default implementation. It could instead be defined to inherit its argument, so that hash_set > would work. I didn't do that because I don't have a use case, but it seems like a reasonably clean approach if needed. gcc/ * hash-traits.h (default_hash_traits): New structure. * hash-set.h (default_hashset_traits): Delete. (hash_set): Use default_hash_traits instead of default_hashset_traits. Delete hash_entry type and use Key directly. * ipa-devirt.c (pair_traits): Delete. (default_hash_traits ): Override. (odr_subtypes_equivalent_p): Remove pair_types template parameter. (odr_types_equivalent_p, add_type_duplicate): Likewise. Index: gcc/hash-traits.h =================================================================== --- gcc/hash-traits.h 2015-06-16 10:12:56.580811647 +0100 +++ gcc/hash-traits.h 2015-06-16 10:12:56.576811695 +0100 @@ -190,4 +190,9 @@ struct ggc_ptr_hash : pointer_hash , template struct ggc_cache_ptr_hash : pointer_hash , ggc_cache_remove {}; +template struct default_hash_traits; + +template +struct default_hash_traits : ggc_ptr_hash {}; + #endif Index: gcc/hash-set.h =================================================================== --- gcc/hash-set.h 2015-06-16 10:12:56.580811647 +0100 +++ gcc/hash-set.h 2015-06-16 10:12:56.572811743 +0100 @@ -21,162 +21,9 @@ Software Foundation; either version 3, o #ifndef hash_set_h #define hash_set_h -/* implement default behavior for traits when types allow it. */ - -struct default_hashset_traits -{ - /* Hashes the passed in key. */ - - template - static hashval_t - hash (T *p) - { - return uintptr_t (p) >> 3; - } - - template static hashval_t hash(const T &v) { return v; } - - /* Return true if the two keys passed as arguments are equal. */ - - template - static bool - equal (const T &a, const T &b) - { - return a == b; - } - - /* Called to dispose of the key before marking the entry as deleted. */ - - template static void remove (T &v) { v.~T (); } - - /* Mark the passed in entry as being deleted. */ - - template - static void - mark_deleted (T *&e) - { - e = reinterpret_cast (1); - } - - /* Mark the passed in entry as being empty. */ - - template - static void - mark_empty (T *&e) - { - e = NULL; - } - - /* Return true if the passed in entry is marked as deleted. */ - - template - static bool - is_deleted (T *e) - { - return e == reinterpret_cast (1); - } - - /* Return true if the passed in entry is marked as empty. */ - - template static bool is_empty (T *e) { return e == NULL; } - - /* ggc walking routine, mark all objects refered to by this one. */ - - template - static void - ggc_mx (T &x) - { - extern void gt_ggc_mx (T &); - gt_ggc_mx (x); - } - - /* pch walking routine, note all objects refered to by this element. */ - - template - static void - pch_nx (T &x) - { - extern void gt_pch_nx (T &); - gt_pch_nx (x); - } -}; - -template +template > class hash_set { - struct hash_entry - { - Key m_key; - - typedef hash_entry value_type; - typedef Key compare_type; - - static hashval_t hash (const hash_entry &e) - { - return Traits::hash (e.m_key); - } - - static bool equal (const hash_entry &a, const Key &b) - { - return Traits::equal (a.m_key, b); - } - - static void remove (hash_entry &e) { Traits::remove (e.m_key); } - - static void - mark_deleted (hash_entry &e) - { - Traits::mark_deleted (e.m_key); - } - - static bool is_deleted (const hash_entry &e) - { - return Traits::is_deleted (e.m_key); - } - - static void - mark_empty (hash_entry &e) - { - Traits::mark_empty (e.m_key); - } - - static bool - is_empty (const hash_entry &e) - { - return Traits::is_empty (e.m_key); - } - - static void ggc_mx (hash_entry &e) - { - Traits::ggc_mx (e.m_key); - } - - static void pch_nx (hash_entry &e) - { - Traits::pch_nx (e.m_key); - } - - static void pch_nx (hash_entry &e, gt_pointer_operator op, void *c) - { - pch_nx_helper (e.m_key, op, c); - } - - private: - template - static void - pch_nx_helper (T &x, gt_pointer_operator op, void *cookie) - { - gt_pch_nx (&x, op, cookie); - } - - template - static void - pch_nx_helper (T *&x, gt_pointer_operator op, void *cookie) - { - op (&x, cookie); - } - }; - public: explicit hash_set (size_t n = 13, bool ggc = false CXX_MEM_STAT_INFO) : m_table (n, ggc, true, HASH_SET_ORIGIN PASS_MEM_STAT) {} @@ -196,11 +43,10 @@ templatem_key = k; + *e = k; return existed; } @@ -209,8 +55,8 @@ template void traverse (Arg a) const { - for (typename hash_table::iterator iter = m_table.begin (); + for (typename hash_table::iterator iter = m_table.begin (); iter != m_table.end (); ++iter) - f ((*iter).m_key, a); + f (*iter, a); } /* Return the number of elements in the set. */ @@ -234,7 +80,7 @@ template friend void gt_pch_nx (hash_set *); template friend void gt_pch_nx (hash_set *, gt_pointer_operator, void *); - hash_table m_table; + hash_table m_table; }; /* ggc marking routines. */ Index: gcc/ipa-devirt.c =================================================================== --- gcc/ipa-devirt.c 2015-06-16 10:12:56.580811647 +0100 +++ gcc/ipa-devirt.c 2015-06-16 10:12:56.576811695 +0100 @@ -164,8 +164,11 @@ typedef struct tree second; } type_pair; -struct pair_traits : default_hashset_traits +template <> +struct default_hash_traits : typed_noop_remove { + typedef type_pair value_type; + typedef type_pair compare_type; static hashval_t hash (type_pair p) { @@ -194,7 +197,7 @@ struct pair_traits : default_hashset_tra }; static bool odr_types_equivalent_p (tree, tree, bool, bool *, - hash_set *, + hash_set *, location_t, location_t); static bool odr_violation_reported = false; @@ -771,7 +774,7 @@ set_type_binfo (tree type, tree binfo) static bool odr_subtypes_equivalent_p (tree t1, tree t2, - hash_set *visited, + hash_set *visited, location_t loc1, location_t loc2) { @@ -1337,7 +1340,7 @@ warn_types_mismatch (tree t1, tree t2, l static bool odr_types_equivalent_p (tree t1, tree t2, bool warn, bool *warned, - hash_set *visited, + hash_set *visited, location_t loc1, location_t loc2) { /* Check first for the obvious case of pointer identity. */ @@ -1787,7 +1790,7 @@ odr_types_equivalent_p (tree t1, tree t2 bool odr_types_equivalent_p (tree type1, tree type2) { - hash_set visited; + hash_set visited; #ifdef ENABLE_CHECKING gcc_assert (odr_or_derived_type_p (type1) && odr_or_derived_type_p (type2)); @@ -1867,7 +1870,7 @@ add_type_duplicate (odr_type val, tree t bool base_mismatch = false; unsigned int i; bool warned = false; - hash_set visited; + hash_set visited; gcc_assert (in_lto_p); vec_safe_push (val->types, type);