From patchwork Tue Jun 16 08:45: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: 484849 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 DB8961402A5 for ; Tue, 16 Jun 2015 18:46:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=PuA+Q9Ws; 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=XgP 0NGBwBicyT0BdwXzdx7ZFNokXB+gjpPMdjtrfHaJcrSxSKllX/VYkd1NZU8hw8ZK 24DS8JZGofx6thjtWiJ2t6c/mbm1XDlH3HCh3TR2CWXQSGP5LjdC4xYMDIjGECGi lIG0yeGnjoSc7z5UM5M3Nowe+mYnXGO20MLyC2Kw= 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=eISA8GksR 0UF/T0CqI5P+sKuyzI=; b=PuA+Q9WsVGb3COCm6km6Ja3l/3Pu3YLH09sCpLki7 FkEbp4R5jVCNnGNmX3ZfCeCDSsrXlIawYYTMWSkKX5CMrEVTYhEerpWlmw41gdVo +dVq9t1J8Ermy9bIH/XVEVbMllzdSBOZwfWPIr2+Y4GIcWVuh2POvkO9HfSd1ZSm 1g= Received: (qmail 104005 invoked by alias); 16 Jun 2015 08:46: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 103988 invoked by uid 89); 16 Jun 2015 08:46: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, 16 Jun 2015 08:46:00 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by uk-mta-14.uk.mimecast.lan; Tue, 16 Jun 2015 09:45:57 +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 09:45:57 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [02/13] Replace handle_cache_entry with new interface References: <87fv5s2gej.fsf@e105548-lin.cambridge.arm.com> Date: Tue, 16 Jun 2015 09:45:56 +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: <877fr42g8r.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: St45ljMySoynbABEzN6APg-1 As described in the covering note, this patch replaces handle_cache_entry with a new function keep_cache_entry. It also ensures that elements are deleted using the proper function, so that m_n_deleted is updated. I couldn't tell whether the unusual name of the function ("gt_cleare_cache") is deliberate or not, but I left it be. gcc/ada/ * gcc-interface/decl.c (value_annotation_hasher::handle_cache_entry): Delete. (value_annotation_hasher::keep_cache_entry): New function. * gcc-interface/utils.c (pad_type_hasher::handle_cache_entry): Delete. (pad_type_hasher::keep_cache_entry): New function. gcc/ * hash-table.h (hash_table): Add gt_cleare_cache as a friend. (gt_cleare_cache): Check here for deleted and empty entries. Replace handle_cache_entry with a call to keep_cache_entry. * hash-traits.h (ggc_cache_hasher::handle_cache_entry): Delete. (ggc_cache_hasher::keep_cache_entry): New function. * trans-mem.c (tm_wrapper_hasher::handle_cache_entry): Delete. (tm_wrapper_hasher::keep_cache_entry): New function. * tree.h (tree_decl_map_cache_hasher::handle_cache_entry): Delete. (tree_vec_map_cache_hasher::keep_cache_entry): New function. * tree.c (type_cache_hasher::handle_cache_entry): Delete. (type_cache_hasher::keep_cache_entry): New function. (tree_vec_map_cache_hasher::handle_cache_entry): Delete. (tree_vec_map_cache_hasher::keep_cache_entry): New function. * ubsan.c (tree_type_map_cache_hasher::handle_cache_entry): Delete. (tree_type_map_cache_hasher::keep_cache_entry): New function. * varasm.c (tm_clone_hasher::handle_cache_entry): Delete. (tm_clone_hasher::keep_cache_entry): New function. * config/i386/i386.c (dllimport_hasher::handle_cache_entry): Delete. (dllimport_hasher::keep_cache_entry): New function. Index: gcc/ada/gcc-interface/decl.c =================================================================== --- gcc/ada/gcc-interface/decl.c 2015-06-15 16:04:47.379633614 +0100 +++ gcc/ada/gcc-interface/decl.c 2015-06-15 16:04:47.363633798 +0100 @@ -149,16 +149,10 @@ struct value_annotation_hasher : ggc_cac return a->base.from == b->base.from; } - static void - handle_cache_entry (tree_int_map *&m) + static int + keep_cache_entry (tree_int_map *&m) { - extern void gt_ggc_mx (tree_int_map *&); - if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (m->base.from)) - gt_ggc_mx (m); - else - m = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (m->base.from); } }; Index: gcc/ada/gcc-interface/utils.c =================================================================== --- gcc/ada/gcc-interface/utils.c 2015-06-15 16:04:47.379633614 +0100 +++ gcc/ada/gcc-interface/utils.c 2015-06-15 16:04:47.359633844 +0100 @@ -243,7 +243,7 @@ struct pad_type_hasher : ggc_cache_hashe { static inline hashval_t hash (pad_type_hash *t) { return t->hash; } static bool equal (pad_type_hash *a, pad_type_hash *b); - static void handle_cache_entry (pad_type_hash *&); + static int keep_cache_entry (pad_type_hash *&); }; static GTY ((cache)) @@ -1170,16 +1170,10 @@ make_type_from_size (tree type, tree siz /* See if the data pointed to by the hash table slot is marked. */ -void -pad_type_hasher::handle_cache_entry (pad_type_hash *&t) +int +pad_type_hasher::keep_cache_entry (pad_type_hash *&t) { - extern void gt_ggc_mx (pad_type_hash *&); - if (t == HTAB_EMPTY_ENTRY || t == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (t->type)) - gt_ggc_mx (t); - else - t = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (t->type); } /* Return true iff the padded types are equivalent. */ Index: gcc/hash-table.h =================================================================== --- gcc/hash-table.h 2015-06-15 16:04:47.379633614 +0100 +++ gcc/hash-table.h 2015-06-15 16:04:47.355633890 +0100 @@ -52,6 +52,16 @@ Software Foundation; either version 3, o individual elements of the table need to be disposed of (e.g., when deleting a hash table, removing elements from the table, etc). + - An optional static function named 'keep_cache_entry'. This + function is provided only for garbage-collected elements that + are not marked by the normal gc mark pass. It describes what + what should happen to the element at the end of the gc mark phase. + The return value should be: + - 0 if the element should be deleted + - 1 if the element should be kept and needs to be marked + - -1 if the element should be kept and is already marked. + Returning -1 rather than 1 is purely an optimization. + 3. The type of the hash table itself. (More later.) In very special circumstances, users may need to know about a fourth type. @@ -584,6 +594,8 @@ struct mark_empty_helper friend void gt_pch_nx (hash_table *, gt_pointer_operator, void *); + template friend void gt_cleare_cache (hash_table *); + value_type *alloc_entries (size_t n CXX_MEM_STAT_INFO) const; value_type *find_empty_slot_for_expand (hashval_t); void expand (); @@ -1131,12 +1143,20 @@ gt_pch_nx (hash_table *h, gt_pointer_ inline void gt_cleare_cache (hash_table *h) { + extern void gt_ggc_mx (typename H::value_type &t); + typedef hash_table table; if (!h) return; - for (typename hash_table::iterator iter = h->begin (); iter != h->end (); - ++iter) - H::handle_cache_entry (*iter); + for (typename table::iterator iter = h->begin (); iter != h->end (); ++iter) + if (!table::is_empty (*iter) && !table::is_deleted (*iter)) + { + int res = H::keep_cache_entry (*iter); + if (res == 0) + h->clear_slot (&*iter); + else if (res != -1) + gt_ggc_mx (*iter); + } } #endif /* TYPED_HASHTAB_H */ Index: gcc/hash-traits.h =================================================================== --- gcc/hash-traits.h 2015-06-15 16:04:47.379633614 +0100 +++ gcc/hash-traits.h 2015-06-15 16:04:47.355633890 +0100 @@ -146,13 +146,10 @@ struct ggc_cache_hasher op (&p, cookie); } - /* Clear out entries if they are about to be gc'd. */ - - static void - handle_cache_entry (T &e) + static int + keep_cache_entry (T &e) { - if (e != HTAB_EMPTY_ENTRY && e != HTAB_DELETED_ENTRY && !ggc_marked_p (e)) - e = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (e) ? -1 : 0; } }; Index: gcc/trans-mem.c =================================================================== --- gcc/trans-mem.c 2015-06-15 16:04:47.379633614 +0100 +++ gcc/trans-mem.c 2015-06-15 16:04:47.359633844 +0100 @@ -483,17 +483,11 @@ struct tm_wrapper_hasher : ggc_cache_has return a->base.from == b->base.from; } - static void - handle_cache_entry (tree_map *&m) - { - extern void gt_ggc_mx (tree_map *&); - if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (m->base.from)) - gt_ggc_mx (m); - else - m = static_cast (HTAB_DELETED_ENTRY); - } + static int + keep_cache_entry (tree_map *&m) + { + return ggc_marked_p (m->base.from); + } }; static GTY((cache)) hash_table *tm_wrap_map; Index: gcc/tree.h =================================================================== --- gcc/tree.h 2015-06-15 16:04:47.379633614 +0100 +++ gcc/tree.h 2015-06-15 16:04:47.375633660 +0100 @@ -4637,16 +4637,10 @@ struct tree_decl_map_cache_hasher : ggc_ return tree_decl_map_eq (a, b); } - static void - handle_cache_entry (tree_decl_map *&m) + static int + keep_cache_entry (tree_decl_map *&m) { - extern void gt_ggc_mx (tree_decl_map *&); - if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (m->base.from)) - gt_ggc_mx (m); - else - m = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (m->base.from); } }; Index: gcc/tree.c =================================================================== --- gcc/tree.c 2015-06-15 16:04:47.379633614 +0100 +++ gcc/tree.c 2015-06-15 16:04:47.375633660 +0100 @@ -203,16 +203,10 @@ struct type_cache_hasher : ggc_cache_has static hashval_t hash (type_hash *t) { return t->hash; } static bool equal (type_hash *a, type_hash *b); - static void - handle_cache_entry (type_hash *&t) + static int + keep_cache_entry (type_hash *&t) { - extern void gt_ggc_mx (type_hash *&); - if (t == HTAB_DELETED_ENTRY || t == HTAB_EMPTY_ENTRY) - return; - else if (ggc_marked_p (t->type)) - gt_ggc_mx (t); - else - t = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (t->type); } }; @@ -261,7 +255,7 @@ static GTY ((cache)) static GTY ((cache)) hash_table *value_expr_for_decl; - struct tree_vec_map_cache_hasher : ggc_cache_hasher +struct tree_vec_map_cache_hasher : ggc_cache_hasher { static hashval_t hash (tree_vec_map *m) { return DECL_UID (m->base.from); } @@ -271,16 +265,10 @@ static GTY ((cache)) return a->base.from == b->base.from; } - static void - handle_cache_entry (tree_vec_map *&m) + static int + keep_cache_entry (tree_vec_map *&m) { - extern void gt_ggc_mx (tree_vec_map *&); - if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (m->base.from)) - gt_ggc_mx (m); - else - m = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (m->base.from); } }; Index: gcc/ubsan.c =================================================================== --- gcc/ubsan.c 2015-06-15 16:04:47.379633614 +0100 +++ gcc/ubsan.c 2015-06-15 16:04:47.359633844 +0100 @@ -99,16 +99,10 @@ struct tree_type_map_cache_hasher : ggc_ return a->type.from == b->type.from; } - static void - handle_cache_entry (tree_type_map *&m) + static int + keep_cache_entry (tree_type_map *&m) { - extern void gt_ggc_mx (tree_type_map *&); - if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (m->type.from)) - gt_ggc_mx (m); - else - m = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (m->type.from); } }; Index: gcc/varasm.c =================================================================== --- gcc/varasm.c 2015-06-15 16:04:47.379633614 +0100 +++ gcc/varasm.c 2015-06-15 16:04:47.375633660 +0100 @@ -5797,16 +5797,10 @@ struct tm_clone_hasher : ggc_cache_hashe static hashval_t hash (tree_map *m) { return tree_map_hash (m); } static bool equal (tree_map *a, tree_map *b) { return tree_map_eq (a, b); } - static void - handle_cache_entry (tree_map *&e) + static int + keep_cache_entry (tree_map *&e) { - extern void gt_ggc_mx (tree_map *&); - if (e == HTAB_EMPTY_ENTRY || e == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (e->base.from)) - gt_ggc_mx (e); - else - e = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (e->base.from); } }; Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c 2015-06-15 16:04:47.379633614 +0100 +++ gcc/config/i386/i386.c 2015-06-15 16:04:47.371633705 +0100 @@ -14212,16 +14212,10 @@ struct dllimport_hasher : ggc_cache_hash return a->base.from == b->base.from; } - static void - handle_cache_entry (tree_map *&m) + static int + keep_cache_entry (tree_map *&m) { - extern void gt_ggc_mx (tree_map *&); - if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY) - return; - else if (ggc_marked_p (m->base.from)) - gt_ggc_mx (m); - else - m = static_cast (HTAB_DELETED_ENTRY); + return ggc_marked_p (m->base.from); } };