From patchwork Thu Jun 30 12:47:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 55598 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E7083842ADF for ; Thu, 30 Jun 2022 12:48:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E7083842ADF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656593327; bh=PkRLgL1AaDgjwctbiJUGF8DUR+35vmQbpqmXyob7rLY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=s9FlGJoW3LhHbPGIBuGsZW4M9wO5pkUHg72yLoU+DIQHX9wpmCOrLzArrphFNhfvi jDqqyq8SrVRwbLZvzub8StEa1TSMPvH1XMQywKM6hZEljKnGYSJM8MEjI6sSLaa/X7 lOUSNytLcMzhMqFqnuARQdzO8m5AX2j/om0l8Nak= 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 1CD183842AD7 for ; Thu, 30 Jun 2022 12:48:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1CD183842AD7 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-imQzChJNOuy2K_J9_YRxVg-1; Thu, 30 Jun 2022 08:48:15 -0400 X-MC-Unique: imQzChJNOuy2K_J9_YRxVg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA2DC2919ECE for ; Thu, 30 Jun 2022 12:48:14 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.244]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 812BD40C1289; Thu, 30 Jun 2022 12:48:14 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 25UCmBTZ551238 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 30 Jun 2022 14:48:12 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 25UCmBaC551237; Thu, 30 Jun 2022 14:48:11 +0200 To: GCC patches Subject: [COMMITTED] Implement ggc_vrange_allocator. Date: Thu, 30 Jun 2022 14:47:55 +0200 Message-Id: <20220630124754.551201-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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, 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch makes the vrange_allocator an abstract class, and uses it to implement the obstack allocator as well as a new GC allocator. The GC bits will be used to implement the vrange storage class for global ranges, which will be contributed in the next week or so. Tested and benchmarked on x86-64 Linux. gcc/ChangeLog: * gimple-range-cache.cc (block_range_cache::block_range_cache): Rename vrange_allocator to obstack_vrange_allocator. (ssa_global_cache::ssa_global_cache): Same. * gimple-range-edge.h (class gimple_outgoing_range): Same. * gimple-range-infer.h (class infer_range_manager): Same. * value-range.h (class vrange_allocator): Make abstract. (class obstack_vrange_allocator): Inherit from vrange_allocator. (class ggc_vrange_allocator): New. --- gcc/gimple-range-cache.cc | 4 +-- gcc/gimple-range-edge.h | 2 +- gcc/gimple-range-infer.h | 2 +- gcc/value-range.h | 57 ++++++++++++++++++++++++--------------- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 5df744184c4..5bb52d5f70f 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -320,7 +320,7 @@ block_range_cache::block_range_cache () bitmap_obstack_initialize (&m_bitmaps); m_ssa_ranges.create (0); m_ssa_ranges.safe_grow_cleared (num_ssa_names); - m_range_allocator = new vrange_allocator; + m_range_allocator = new obstack_vrange_allocator; } // Remove any m_block_caches which have been created. @@ -478,7 +478,7 @@ block_range_cache::dump (FILE *f, basic_block bb, bool print_varying) ssa_global_cache::ssa_global_cache () { m_tab.create (0); - m_range_allocator = new vrange_allocator; + m_range_allocator = new obstack_vrange_allocator; } // Deconstruct a global cache. diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h index a9c4af8715b..c81b943dae6 100644 --- a/gcc/gimple-range-edge.h +++ b/gcc/gimple-range-edge.h @@ -47,7 +47,7 @@ private: int m_max_edges; hash_map *m_edge_table; - vrange_allocator m_range_allocator; + obstack_vrange_allocator m_range_allocator; }; // If there is a range control statement at the end of block BB, return it. diff --git a/gcc/gimple-range-infer.h b/gcc/gimple-range-infer.h index aafa8bb74f0..bf27d0d3423 100644 --- a/gcc/gimple-range-infer.h +++ b/gcc/gimple-range-infer.h @@ -78,7 +78,7 @@ private: bitmap m_seen; bitmap_obstack m_bitmaps; struct obstack m_list_obstack; - vrange_allocator m_range_allocator; + obstack_vrange_allocator m_range_allocator; }; #endif // GCC_GIMPLE_RANGE_SIDE_H diff --git a/gcc/value-range.h b/gcc/value-range.h index dc6f6b0f935..627d221fe0f 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -903,39 +903,54 @@ vrp_val_min (const_tree type) class vrange_allocator { public: - vrange_allocator (); - ~vrange_allocator (); + vrange_allocator () { } + virtual ~vrange_allocator () { } // Allocate a range of TYPE. vrange *alloc_vrange (tree type); // Allocate a memory block of BYTES. - void *alloc (unsigned bytes); + virtual void *alloc (unsigned bytes) = 0; + virtual void free (void *p) = 0; // Return a clone of SRC. template T *clone (const T &src); private: irange *alloc_irange (unsigned pairs); - DISABLE_COPY_AND_ASSIGN (vrange_allocator); - struct obstack m_obstack; + void operator= (const vrange_allocator &) = delete; }; -inline -vrange_allocator::vrange_allocator () +class obstack_vrange_allocator : public vrange_allocator { - obstack_init (&m_obstack); -} - -inline -vrange_allocator::~vrange_allocator () -{ - obstack_free (&m_obstack, NULL); -} - -// Provide a hunk of memory from the obstack. +public: + obstack_vrange_allocator () + { + obstack_init (&m_obstack); + } + virtual ~obstack_vrange_allocator () final override + { + obstack_free (&m_obstack, NULL); + } + virtual void *alloc (unsigned bytes) final override + { + return obstack_alloc (&m_obstack, bytes); + } + virtual void free (void *) final override { } +private: + obstack m_obstack; +}; -inline void * -vrange_allocator::alloc (unsigned bytes) +class ggc_vrange_allocator : public vrange_allocator { - return obstack_alloc (&m_obstack, bytes); -} +public: + ggc_vrange_allocator () { } + virtual ~ggc_vrange_allocator () final override { } + virtual void *alloc (unsigned bytes) final override + { + return ggc_internal_alloc (bytes); + } + virtual void free (void *p) final override + { + return ggc_free (p); + } +}; // Return a new range to hold ranges of TYPE. The newly allocated // range is initialized to VR_UNDEFINED.