From patchwork Tue Jun 23 14:55:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 487676 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 1B4C714010F for ; Wed, 24 Jun 2015 00:55:26 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=qaky2GZo; 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=ZK+ 7q4cDkuqLivIG+sSjO7Zv8ROJilEbFSVZnA+LAdq0Lh6QvG6S5oDFffBvNcPeX6u MOAL3bLglBpCk2VuQB+15w8NP4EiDiz0UhXxWzJUia/sCVvaK56u9+i70KVnnM1B JewdneMdnGl7YjGuGsA3sPgxzT3Ojhl2bCtbT1iE= 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=/nW3ThEO+ JsVb/jwFx4U/22Ltzo=; b=qaky2GZoE7cDKQfZZY8yjCS1D0ILali33kEVbC+li 3VAaqlcA9lHbHUKOKoFgEu/ejHhnvexMYvAFo/Hwl5nvHycYgFdJGc1hjqZsKQjW qQUnMfXER7JWXcs5sj//GE17rD8Epuaxqg9J+LdWFp1BzU4Y434KD28ybt9YXyjp UQ= Received: (qmail 60673 invoked by alias); 23 Jun 2015 14:55:20 -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 60646 invoked by uid 89); 23 Jun 2015 14:55:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 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) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Jun 2015 14:55:16 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-5-vQczlsK9RgqMnVhjDl-rlA-1 Received: from localhost ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 23 Jun 2015 15:55:13 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [10/12] Add helper class for valued-based empty and deleted slots References: <87egl2bicm.fsf@e105548-lin.cambridge.arm.com> Date: Tue, 23 Jun 2015 15:55:13 +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: <87381ia2zy.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: vQczlsK9RgqMnVhjDl-rlA-1 part_traits in cfgexpand.c needs to use the value rather than the key to represent empty and deleted slots. What it's doing is pretty generic, so this patch adds a helper class to hash-map-traits.h. gcc/ * hash-map-traits.h (unbounded_hashmap_traits): New class. (unbounded_int_hashmap_traits): Likewise. * cfgexpand.c (part_traits): Use unbounded_int_hashmap_traits. Index: gcc/hash-map-traits.h =================================================================== --- gcc/hash-map-traits.h 2015-06-23 15:54:04.515950631 +0100 +++ gcc/hash-map-traits.h 2015-06-23 15:54:04.511950679 +0100 @@ -174,4 +174,84 @@ simple_hashmap_traits ::mark_deleted H::mark_deleted (entry.m_key); } +/* Implement traits for a hash_map with values of type Value for cases + in which the key cannot represent empty and deleted slots. Instead + record empty and deleted entries in Value. Derived classes must + implement the hash and equal_keys functions. */ + +template +struct unbounded_hashmap_traits +{ + 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 +template +inline void +unbounded_hashmap_traits ::remove (T &entry) +{ + default_hash_traits ::remove (entry.m_value); +} + +template +template +inline bool +unbounded_hashmap_traits ::is_empty (const T &entry) +{ + return default_hash_traits ::is_empty (entry.m_value); +} + +template +template +inline bool +unbounded_hashmap_traits ::is_deleted (const T &entry) +{ + return default_hash_traits ::is_deleted (entry.m_value); +} + +template +template +inline void +unbounded_hashmap_traits ::mark_empty (T &entry) +{ + default_hash_traits ::mark_empty (entry.m_value); +} + +template +template +inline void +unbounded_hashmap_traits ::mark_deleted (T &entry) +{ + default_hash_traits ::mark_deleted (entry.m_value); +} + +/* Implement traits for a hash_map from integer type Key to Value in + cases where Key has no spare values for recording empty and deleted + slots. */ + +template +struct unbounded_int_hashmap_traits : unbounded_hashmap_traits +{ + static inline hashval_t hash (Key); + static inline bool equal_keys (Key, Key); +}; + +template +inline hashval_t +unbounded_int_hashmap_traits ::hash (Key k) +{ + return k; +} + +template +inline bool +unbounded_int_hashmap_traits ::equal_keys (Key k1, Key k2) +{ + return k1 == k2; +} + #endif // HASH_MAP_TRAITS_H Index: gcc/cfgexpand.c =================================================================== --- gcc/cfgexpand.c 2015-06-23 15:54:04.515950631 +0100 +++ gcc/cfgexpand.c 2015-06-23 15:54:04.511950679 +0100 @@ -612,25 +612,7 @@ stack_var_cmp (const void *a, const void return 0; } -struct part_traits : default_hashmap_traits -{ - template - static bool - is_deleted (T &e) - { return e.m_value == reinterpret_cast (1); } - - template static bool is_empty (T &e) { return e.m_value == NULL; } - template - static void - mark_deleted (T &e) - { e.m_value = reinterpret_cast (1); } - - template - static void - mark_empty (T &e) - { e.m_value = NULL; } -}; - +struct part_traits : unbounded_int_hashmap_traits {}; typedef hash_map part_hashmap; /* If the points-to solution *PI points to variables that are in a partition