From patchwork Wed May 24 21:19:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1785867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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=heApfGz4; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QRPG15zC2z20Q0 for ; Thu, 25 May 2023 07:19:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1FD7385735A for ; Wed, 24 May 2023 21:19:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1FD7385735A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684963174; bh=VXZ2+Hza/5Cvula+mMPCpMRmpJKae8Td0zd0psgVBUc=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=heApfGz4uuqKM5ZdrOi2nLn7dTtdXKqx2nqcfrwI3bBwU8a8gH51ggGR+wzp3ROgU s6JcfjvzkGLLlxxa6G+SFvnt37grzl7Rte7kBLABHwL7UQWc4o2pz3cMv6FbM04sdd rJ7JnDr6q/muM7ObRUFYeCa4URL0Y6uYGbFJjoUA= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 69A383857710 for ; Wed, 24 May 2023 21:19:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69A383857710 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-F5tlERoaNeOMQUk6cPLZ3Q-1; Wed, 24 May 2023 17:19:10 -0400 X-MC-Unique: F5tlERoaNeOMQUk6cPLZ3Q-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6238a4e544bso2759966d6.0 for ; Wed, 24 May 2023 14:19:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684963150; x=1687555150; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Iq4ame4ESPjJh95Ow3MB6rTmT8xifHJMgV2IUAIVC3c=; b=idvofVWrP8CrOUc1M/QG4LqdO39YfgD/S70t2CN2yKd20FueVZqcpSkyCC4Td7sGqC orlnHQEQUsgZmBo25KuaIehT975IrFuLcnxiV6XIcgU8ajkOtmONnwt3GEtri8N1+Al0 z7Ng0TzFr9yBkMNynTDGaKD+IZBeLC2SxL3bswSUtDaMlvlyvK51ujR4zGOCtupnHHgp r3RyRLzZiLQiHGZz5zpslZDeRHqK3gTogYo0YbM4DkkMVa+1GgQ3FdIEb2QX5DP9gVg2 pYy9w7B9yGINLd7ONheqCGGhw00xnqfB3Kpb+N1qRg5+il/NFoI2v30Apk2TFclotLXU 5Ceg== X-Gm-Message-State: AC+VfDzdVpXpzyvfVyhgtWwaO7d/yA2QdSmTjYGOuYmP4V0HklCIJk8u MVXnJxEbz+O99FGF6rsdifID3kbDbdhxempZ54GMnB0tp+yekAYVbMhdWtLNe3sAt4BpXXudcot c2lj2AMErLd85Rjztv1TqTryIqNqKsDqKXxYlgDVW8mFGfTXrwJafFRWcn7HklFDknaRJwNJvr3 mNgA== X-Received: by 2002:a05:6214:21a7:b0:5cd:1adc:30e2 with SMTP id t7-20020a05621421a700b005cd1adc30e2mr28891514qvc.11.1684963149852; Wed, 24 May 2023 14:19:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7qKDvTFC1mmRKbKO9OEwKGf88wHtmUDWX5izy7N8F37u1OyhOHGmlWNnbDlMfy3iK5YACtlQ== X-Received: by 2002:a05:6214:21a7:b0:5cd:1adc:30e2 with SMTP id t7-20020a05621421a700b005cd1adc30e2mr28891492qvc.11.1684963149523; Wed, 24 May 2023 14:19:09 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::933? ([2607:fea8:51df:4200::933]) by smtp.gmail.com with ESMTPSA id p7-20020a0cf687000000b006238cf6d2a8sm3890646qvn.2.2023.05.24.14.19.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 14:19:09 -0700 (PDT) Message-ID: Date: Wed, 24 May 2023 17:19:07 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED 1/4] - Make ssa_cache and ssa_lazy_cache virtual. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" I originally implemented the lazy ssa cache by inheriting from an ssa_cache in protected mode and providing the required routines. This makes it a little awkward to do various things, and they also become not quite as interchangeable as I'd like.   Making the routines virtual and using proper inheritance will avoid an inevitable issue down the road, and allows me to remove the printing hack which provided a protected output routine. Overall performance impact is pretty negligible, so lets just clean it up. Bootstraps on x86_64-pc-linux-gnu  with no regressions.  Pushed. Andrew From 3079056d0b779b907f8adc01d48a8aa495b8a661 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 24 May 2023 08:49:30 -0400 Subject: [PATCH 1/4] Make ssa_cache and ssa_lazy_cache virtual. Making them virtual allows us to interchangebly use the caches. * gimple-range-cache.cc (ssa_cache::dump): Use get_range. (ssa_cache::dump_range_query): Delete. (ssa_lazy_cache::dump_range_query): Delete. (ssa_lazy_cache::get_range): Move from header file. (ssa_lazy_cache::clear_range): ditto. (ssa_lazy_cache::clear): Ditto. * gimple-range-cache.h (class ssa_cache): Virtualize. (class ssa_lazy_cache): Inherit and virtualize. --- gcc/gimple-range-cache.cc | 43 +++++++++++++++++++++++++++------------ gcc/gimple-range-cache.h | 37 ++++++++++----------------------- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index e069241bc9d..f25abaffd34 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -626,7 +626,7 @@ ssa_cache::dump (FILE *f) // Invoke dump_range_query which is a private virtual version of // get_range. This avoids performance impacts on general queries, // but allows sharing of the dump routine. - if (dump_range_query (r, ssa_name (x)) && !r.varying_p ()) + if (get_range (r, ssa_name (x)) && !r.varying_p ()) { if (print_header) { @@ -648,23 +648,14 @@ ssa_cache::dump (FILE *f) fputc ('\n', f); } -// Virtual private get_range query for dumping. +// Return true if NAME has an active range in the cache. bool -ssa_cache::dump_range_query (vrange &r, tree name) const +ssa_lazy_cache::has_range (tree name) const { - return get_range (r, name); + return bitmap_bit_p (active_p, SSA_NAME_VERSION (name)); } -// Virtual private get_range query for dumping. - -bool -ssa_lazy_cache::dump_range_query (vrange &r, tree name) const -{ - return get_range (r, name); -} - - // Set range of NAME to R in a lazy cache. Return FALSE if it did not already // have a range. @@ -684,6 +675,32 @@ ssa_lazy_cache::set_range (tree name, const vrange &r) return false; } +// Return TRUE if NAME has a range, and return it in R. + +bool +ssa_lazy_cache::get_range (vrange &r, tree name) const +{ + if (!bitmap_bit_p (active_p, SSA_NAME_VERSION (name))) + return false; + return ssa_cache::get_range (r, name); +} + +// Remove NAME from the active range list. + +void +ssa_lazy_cache::clear_range (tree name) +{ + bitmap_clear_bit (active_p, SSA_NAME_VERSION (name)); +} + +// Remove all ranges from the active range list. + +void +ssa_lazy_cache::clear () +{ + bitmap_clear (active_p); +} + // -------------------------------------------------------------------------- diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index 871255a8116..4fc98230430 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -57,14 +57,13 @@ class ssa_cache public: ssa_cache (); ~ssa_cache (); - bool has_range (tree name) const; - bool get_range (vrange &r, tree name) const; - bool set_range (tree name, const vrange &r); - void clear_range (tree name); - void clear (); + virtual bool has_range (tree name) const; + virtual bool get_range (vrange &r, tree name) const; + virtual bool set_range (tree name, const vrange &r); + virtual void clear_range (tree name); + virtual void clear (); void dump (FILE *f = stderr); protected: - virtual bool dump_range_query (vrange &r, tree name) const; vec m_tab; vrange_allocator *m_range_allocator; }; @@ -72,35 +71,21 @@ protected: // This is the same as global cache, except it maintains an active bitmap // rather than depending on a zero'd out vector of pointers. This is better // for sparsely/lightly used caches. -// It could be made a fully derived class, but at this point there doesnt seem -// to be a need to take the performance hit for it. -class ssa_lazy_cache : protected ssa_cache +class ssa_lazy_cache : public ssa_cache { public: inline ssa_lazy_cache () { active_p = BITMAP_ALLOC (NULL); } inline ~ssa_lazy_cache () { BITMAP_FREE (active_p); } - bool set_range (tree name, const vrange &r); - inline bool get_range (vrange &r, tree name) const; - inline void clear_range (tree name) - { bitmap_clear_bit (active_p, SSA_NAME_VERSION (name)); } ; - inline void clear () { bitmap_clear (active_p); } - inline void dump (FILE *f = stderr) { ssa_cache::dump (f); } + virtual bool has_range (tree name) const; + virtual bool set_range (tree name, const vrange &r); + virtual bool get_range (vrange &r, tree name) const; + virtual void clear_range (tree name); + virtual void clear (); protected: - virtual bool dump_range_query (vrange &r, tree name) const; bitmap active_p; }; -// Return TRUE if NAME has a range, and return it in R. - -bool -ssa_lazy_cache::get_range (vrange &r, tree name) const -{ - if (!bitmap_bit_p (active_p, SSA_NAME_VERSION (name))) - return false; - return ssa_cache::get_range (r, name); -} - // This class provides all the caches a global ranger may need, and makes // them available for gori-computes to query so outgoing edges can be // properly calculated. -- 2.40.1