From patchwork Mon Apr 4 17:08:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 605941 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 3qdz3p1yG0z9s9x for ; Tue, 5 Apr 2016 03:09:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Kly4Dk+B; 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:cc:subject:date:message-id; q=dns; s=default; b=GTEjp4B9MFZz 2dIs8B9ELLU23kIwMPrw6bp1xmNbJskUZN4yoaQmZRbHTyHqp0q6gJVd7iQcG/t8 Ze4fE+Mu9H+cVPS5ZZBxu4/QrOkcuJQVzYzRnrzFlSFDlY32t1OliTR7turpH40z VLq0MZL33ATg5lGkcD5K7MBkg+5FWOI= 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:cc:subject:date:message-id; s=default; bh=TgIrLBYrsfgZdfzGGr QjC1/ou1I=; b=Kly4Dk+BH3DB0VDMf+CdQE7Rf2W5gGu7gQkAgdHhLenQCBaXIg DhvjetiE+B5J4PdT1Ntzg6jompGx9rhiK4DF/23BALKw9I+zy+MAQ2O6hq2V8CRL XQQXq1HD2UTI5izEo6YtDnHffMGPB6qfbphXtJ1cohDLS9316/gCmA4qA= Received: (qmail 49080 invoked by alias); 4 Apr 2016 17:08:59 -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 49065 invoked by uid 89); 4 Apr 2016 17:08:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=friend X-HELO: mail-qg0-f66.google.com Received: from mail-qg0-f66.google.com (HELO mail-qg0-f66.google.com) (209.85.192.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 04 Apr 2016 17:08:48 +0000 Received: by mail-qg0-f66.google.com with SMTP id f105so2954161qge.3 for ; Mon, 04 Apr 2016 10:08:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=x0rNOpkwS5J3JNcB5motgKYU+sxXBvueOOVZ8e0zLyE=; b=MXRHfijSd0oVOajPBuvATnVbWBkHkm8ex+yTBWUOOEat4AXZc2QzjfR0dGQKZzKqtN 9AlakfD4BUc3Va/hzehU5mDsz5fQa4FeVAdrxnmX1DmNLZxSXvqtZhsVeI35OvqcmmaT tPUvxJ07syudh42tYMSzTWrefIbtI0vQ9h2V3phs9DYiqzOCYnrenxgSOWW6afgBAc9p /qjQbMli8Szwi+F3B3lGKx6bhoEjh/2m5GBy4KLOQjey1nKyA2ZjgrWNKy3+Kgq3deqE iRJZyh+B25ae4JmOrUKxqjk9Co368AkBnZy9ratr8SYwTQtWMCU0YUa1XdB00Y2Xla85 rujA== X-Gm-Message-State: AD7BkJLWWrmS3Cim2kW3eIlC2BIdEqPHVKWglUwGsSAAmOGca+ddWmWbAyZOtA3TJzmlGg== X-Received: by 10.140.161.198 with SMTP id h189mr43696789qhh.24.1459789726413; Mon, 04 Apr 2016 10:08:46 -0700 (PDT) Received: from localhost.localdomain (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id a207sm12749663qkb.28.2016.04.04.10.08.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Apr 2016 10:08:45 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Remove class cache_map and use ggc hash_maps instead (PR c++/70452) Date: Mon, 4 Apr 2016 13:08:09 -0400 Message-Id: <1459789689-15305-1-git-send-email-patrick@parcs.ath.cx> On Mon, 4 Apr 2016, Jason Merrill wrote: > Hmm, I thought I remembered hitting the breakpoint in gt_cleare_cache and it > being non-null. But I guess we can get rid of the cache_map class and use the > approach you have here, of a deletable gc-allocated hash_map pointer; I'd > still use ->empty() for dumping the cache outside of GC, though. Is this what you had in mind? gcc/cp/ChangeLog: PR c++/70452 * cp-tree.h (class cache_map): Remove. * constexpr.c (cv_cache): Change type to GTY((deletable)) hash_map *. (maybe_constant_value): Adjust following the change to cv_cache. (clear_cv_cache): New static function. (clear_cv_and_fold_caches): Use it. * cp-gimplify.c (fold_cache): Change type to GTY((deletable)) hash_map *. (clear_fold_cache): Adjust following the change to fold_cache. (cp_fold): Likewise. --- gcc/cp/constexpr.c | 27 ++++++++++++++++++--------- gcc/cp/cp-gimplify.c | 17 +++++++++++------ gcc/cp/cp-tree.h | 36 ------------------------------------ 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index bcbf9bd..8f080ee 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4304,7 +4304,7 @@ maybe_constant_value_1 (tree t, tree decl) return r; } -static GTY((cache, deletable)) cache_map cv_cache; +static GTY((deletable)) hash_map *cv_cache; /* If T is a constant expression, returns its reduced value. Otherwise, if T does not have TREE_CONSTANT set, returns T. @@ -4313,13 +4313,22 @@ static GTY((cache, deletable)) cache_map cv_cache; tree maybe_constant_value (tree t, tree decl) { - tree ret = cv_cache.get (t); - if (!ret) - { - ret = maybe_constant_value_1 (t, decl); - cv_cache.put (t, ret); - } - return ret; + if (cv_cache == NULL) + cv_cache = hash_map::create_ggc (101); + + tree *slot = &cv_cache->get_or_insert (t, NULL); + if (*slot == NULL_TREE) + *slot = maybe_constant_value_1 (t, decl); + return *slot; +} + +/* Dispose of the whole CV_CACHE. */ + +static void +clear_cv_cache (void) +{ + if (cv_cache != NULL) + cv_cache->empty (); } /* Dispose of the whole CV_CACHE and FOLD_CACHE. */ @@ -4327,7 +4336,7 @@ maybe_constant_value (tree t, tree decl) void clear_cv_and_fold_caches (void) { - gt_cleare_cache (cv_cache); + clear_cv_cache (); clear_fold_cache (); } diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index b6e1d27..61ac187 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1902,14 +1902,15 @@ c_fully_fold (tree x, bool /*in_init*/, bool */*maybe_const*/) return cp_fold_rvalue (x); } -static GTY((cache, deletable)) cache_map fold_cache; +static GTY((deletable)) hash_map *fold_cache; /* Dispose of the whole FOLD_CACHE. */ void clear_fold_cache (void) { - gt_cleare_cache (fold_cache); + if (fold_cache != NULL) + fold_cache->empty (); } /* This function tries to fold an expression X. @@ -1939,8 +1940,12 @@ cp_fold (tree x) if (DECL_P (x) || CONSTANT_CLASS_P (x)) return x; - if (tree cached = fold_cache.get (x)) - return cached; + if (fold_cache == NULL) + fold_cache = hash_map::create_ggc (101); + + tree *slot = &fold_cache->get_or_insert (x, NULL); + if (*slot != NULL_TREE) + return *slot; code = TREE_CODE (x); switch (code) @@ -2295,10 +2300,10 @@ cp_fold (tree x) return org_x; } - fold_cache.put (org_x, x); + *slot = x; /* Prevent that we try to fold an already folded result again. */ if (x != org_x) - fold_cache.put (x, x); + fold_cache->put (x, x); return x; } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index b1d2bfa..0f7e08f 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5527,42 +5527,6 @@ extern cp_parameter_declarator *no_parameters; /* True if we saw "#pragma GCC java_exceptions". */ extern bool pragma_java_exceptions; -/* Data structure for a mapping from tree to tree that's only used as a cache; - we don't GC-mark trees in the map, and we clear the map when collecting - garbage. Global variables of this type must be marked - GTY((cache,deletable)) so that the gt_cleare_cache function is called by - ggc_collect but we don't try to load the map pointer from a PCH. - - FIXME improve to use keep_cache_entry. */ -class cache_map -{ - /* Use a lazily initialized pointer rather than a map member since a - hash_map can't be constructed in a static initializer. */ - hash_map *map; - -public: - tree get (tree key) - { - if (map) - if (tree *slot = map->get (key)) - return *slot; - return NULL_TREE; - } - - bool put (tree key, tree val) - { - if (!map) - map = new hash_map; - return map->put (key, val); - } - - friend inline void gt_cleare_cache (cache_map &cm) - { - if (cm.map) - cm.map->empty(); - } -}; - /* in call.c */ extern bool check_dtor_name (tree, tree); int magic_varargs_p (tree);