From patchwork Wed Sep 6 22:07:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1830598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tMGquAN4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RgxMW37k5z1yh5 for ; Thu, 7 Sep 2023 08:08:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9154538582A9 for ; Wed, 6 Sep 2023 22:08:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9154538582A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694038083; bh=YwH/C4vRNf5AA9zA6mj2M52Xq8XBY/Y0UE72oIp0XAY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tMGquAN4b1KR9TAdaKIX4ZQSf7wJOr3KJXZbAVGQ9KNi5MSaog9NildZqS5p4RzH0 yv0uGHzSwDbwIWvovcv66tnjyJkA7Zoz650XXgm/q078m95OxgO5O9qNYUVfmPGhFN PRgIyeOERlmf+69319LkmT8K6aG0mYHwrEXjA9qs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 51D1C3858C78 for ; Wed, 6 Sep 2023 22:07:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51D1C3858C78 Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-JWzxkFBdP4Gk3aFAOEKncA-1; Wed, 06 Sep 2023 18:07:40 -0400 X-MC-Unique: JWzxkFBdP4Gk3aFAOEKncA-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-4936b96d2f1so131844e0c.0 for ; Wed, 06 Sep 2023 15:07:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694038059; x=1694642859; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YwH/C4vRNf5AA9zA6mj2M52Xq8XBY/Y0UE72oIp0XAY=; b=NmvgTrmeprES/mKg12SLqOiW+fgfIyjpyFQj6HDJDE77loPhmA6nPiCjmzQ/6E1TUl OWx+nCBXFJUDrkWHp2dZf7nzrsCUUV0XAe8PcvhkJAxLCCODzVg3XiXjamAJdu/bSATg hcgP2Sbd90mtZvJImY0t1S6HEE7CDCxnYGBfOMZwHN/SuXDCilqJ1HPUTqy+X2Sd1BtF 60VnteVE2Mr4/DcVDAfpeRWdZuUX3ptCyk4pGSLrQPnZ7KkCRTMu/z5Kfg2xGUVwI1w5 fofD7mK5MdMgF9TIYwGefOwTatK5QezrQqPweStUcUdmpncGscTPG7IZPmpQvXtxYrY+ 4bhA== X-Gm-Message-State: AOJu0YzSuv5pQ0tCQeuKJ70TWnauD+NoLSOmN2KuprCgKdk7PTTwlEZO gmBh6W8y2+mnGrWEP8ZxLWwPxxsUBbDoCr26QfFPdD4ZPci2SM38v24dYRYdux8woHi4SupUOei rcSeSIoK3y4a3COolSQvjTgWcLBeuC0n8wNfI5cvqN6wZZzFQ7JUkCv3bRLgnzz5uqTILM2E276 Q= X-Received: by 2002:a1f:6241:0:b0:48c:2b9f:ee1d with SMTP id w62-20020a1f6241000000b0048c2b9fee1dmr3718252vkb.16.1694038059492; Wed, 06 Sep 2023 15:07:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTNoHoCnGN982zpTanZISHM2PpmVxm+Mqt6v9HFNON9MYVovR9QOmce9dxiwOLbreDeSDjKA== X-Received: by 2002:a1f:6241:0:b0:48c:2b9f:ee1d with SMTP id w62-20020a1f6241000000b0048c2b9fee1dmr3718242vkb.16.1694038059139; Wed, 06 Sep 2023 15:07:39 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id fg18-20020a05622a581200b00403c1a19a2bsm5608010qtb.92.2023.09.06.15.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 15:07:38 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: cache conversion function lookup Date: Wed, 6 Sep 2023 18:07:37 -0400 Message-ID: <20230906220737.4049357-1-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.122.g1fc548b2d6 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? This cache apparently has a 98% hit rate for TYPE_HAS_CONVERSION types on some test files. -- >8 -- gcc/cp/ChangeLog: * config-lang.in (gtfiles): Add search.cc. * search.cc (lookup_conversions_cache): Define. (lookup_conversions): Use it to cache he lookup. Improve cache rate by considering TYPE_MAIN_VARIANT of the type. --- gcc/cp/config-lang.in | 1 + gcc/cp/search.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/gcc/cp/config-lang.in b/gcc/cp/config-lang.in index a6c7883cc24..e34c392d208 100644 --- a/gcc/cp/config-lang.in +++ b/gcc/cp/config-lang.in @@ -52,6 +52,7 @@ gtfiles="\ \$(srcdir)/cp/name-lookup.cc \ \$(srcdir)/cp/parser.cc \$(srcdir)/cp/pt.cc \ \$(srcdir)/cp/rtti.cc \ +\$(srcdir)/cp/search.cc \ \$(srcdir)/cp/semantics.cc \ \$(srcdir)/cp/tree.cc \$(srcdir)/cp/typeck2.cc \ \$(srcdir)/cp/vtable-class-hierarchy.cc \ diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index cd80f285ac9..d5a2c57f59c 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -2582,6 +2582,10 @@ lookup_conversions_r (tree binfo, int virtual_depth, int virtualness, return my_virtualness; } +/* A cache of the result of lookup_conversions. */ + +static GTY((cache)) type_tree_cache_map *lookup_conversions_cache; + /* Return a TREE_LIST containing all the non-hidden user-defined conversion functions for TYPE (and its base-classes). The TREE_VALUE of each node is the FUNCTION_DECL of the conversion @@ -2596,10 +2600,14 @@ lookup_conversions (tree type) { tree convs; + type = TYPE_MAIN_VARIANT (type); complete_type (type); if (!CLASS_TYPE_P (type) || !TYPE_BINFO (type)) return NULL_TREE; + if (tree *c = hash_map_safe_get (lookup_conversions_cache, type)) + return *c; + lookup_conversions_r (TYPE_BINFO (type), 0, 0, NULL_TREE, NULL_TREE, &convs); tree list = NULL_TREE; @@ -2618,6 +2626,7 @@ lookup_conversions (tree type) } } + hash_map_safe_put (lookup_conversions_cache, type, list); return list; } @@ -2798,3 +2807,5 @@ any_dependent_bases_p (tree type) return false; } + +#include "gt-cp-search.h"