From patchwork Tue Jun 23 14:42:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 487662 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 EAA8F140082 for ; Wed, 24 Jun 2015 00:43:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Efjkoeya; 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=CFB bp1gww44bi+4gvZhKLuv7bvSnchRX4IqvRGK0iHO4SSPi7mj9DDh7FxqBXfw5EPD hYbskDW4ez7hDIsku/yh0VMLfOewykOWAY0YkpN50xMMsUuGFlBYAoMEPJbefu2o fb/IsFyoKPAro+bJHlwRbirz1rPDyFqp8SDTISBM= 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=z/xY/DB6x 6tKANLMzmxFovbE5GY=; b=EfjkoeyaxY7JSRGConnPQi8XqvTaATbSLoOS7r5rB oX1R046SlIe+7Za5aIdT/LyErISnxdwZBTJpYYjADPLR4Xg0o9ri4Hm46Wpun3St YFS/10Vm91KgYGb/2vbH3sdJg64AfCFuvK6asv+y9wflr317+3h2/SEBeuybmh5U lY= Received: (qmail 2962 invoked by alias); 23 Jun 2015 14:43:02 -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 2942 invoked by uid 89); 23 Jun 2015 14:43:01 -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, 23 Jun 2015 14:43:00 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-30-s3aUgLGJRnCGIJpc-iDPZg-1 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 23 Jun 2015 15:42:56 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [01/12] Add hash_map traits that use existing hash_table-like traits References: <87egl2bicm.fsf@e105548-lin.cambridge.arm.com> Date: Tue, 23 Jun 2015 15:42:56 +0100 In-Reply-To: <87egl2bicm.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Tue, 23 Jun 2015 15:38:17 +0100") Message-ID: <87616ebi4v.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: s3aUgLGJRnCGIJpc-iDPZg-1 This patch defines a class that converts hash_table-style traits into hash_map traits. It can be used as the default traits for all hash_maps that don't specify their own traits (i.e. this patch does work on its own). By the end of the series this class replaces default_hashmap_traits. gcc/ * hash-map-traits.h: Include hash-traits.h. (simple_hashmap_traits): New class. * mem-stats.h (hash_map): Change the default traits to simple_hashmap_traits >. Index: gcc/hash-map-traits.h =================================================================== --- gcc/hash-map-traits.h 2015-06-23 15:42:24.132002236 +0100 +++ gcc/hash-map-traits.h 2015-06-23 15:42:24.128002280 +0100 @@ -23,6 +23,8 @@ #define HASH_MAP_TRAITS_H /* Bacause mem-stats.h uses default hashmap traits, we have to put the class to this separate header file. */ +#include "hash-traits.h" + /* implement default behavior for traits when types allow it. */ struct default_hashmap_traits @@ -101,4 +103,75 @@ struct default_hashmap_traits } }; +/* Implement hash_map traits for a key with hash traits H. Empty and + deleted map entries are represented as empty and deleted keys. */ + +template +struct simple_hashmap_traits +{ + static inline hashval_t hash (const typename H::value_type &); + static inline bool equal_keys (const typename H::value_type &, + const typename H::value_type &); + template static inline void remove (T &); + template static inline bool is_empty (const T &); + template static inline bool is_deleted (const T &); + template static inline void mark_empty (T &); + template static inline void mark_deleted (T &); +}; + +template +inline hashval_t +simple_hashmap_traits ::hash (const typename H::value_type &h) +{ + return H::hash (h); +} + +template +inline bool +simple_hashmap_traits ::equal_keys (const typename H::value_type &k1, + const typename H::value_type &k2) +{ + return H::equal (k1, k2); +} + +template +template +inline void +simple_hashmap_traits ::remove (T &entry) +{ + H::remove (entry.m_key); +} + +template +template +inline bool +simple_hashmap_traits ::is_empty (const T &entry) +{ + return H::is_empty (entry.m_key); +} + +template +template +inline bool +simple_hashmap_traits ::is_deleted (const T &entry) +{ + return H::is_deleted (entry.m_key); +} + +template +template +inline void +simple_hashmap_traits ::mark_empty (T &entry) +{ + H::mark_empty (entry.m_key); +} + +template +template +inline void +simple_hashmap_traits ::mark_deleted (T &entry) +{ + H::mark_deleted (entry.m_key); +} + #endif // HASH_MAP_TRAITS_H Index: gcc/mem-stats.h =================================================================== --- gcc/mem-stats.h 2015-06-23 15:42:24.132002236 +0100 +++ gcc/mem-stats.h 2015-06-23 15:42:24.128002280 +0100 @@ -3,7 +3,7 @@ #define GCC_MEM_STATS_H /* Forward declaration. */ template + typename Traits = simple_hashmap_traits > > class hash_map; #define LOCATION_LINE_EXTRA_SPACE 30