From patchwork Sat May 4 08:30:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 89443 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 AEBC8386F427 for ; Sat, 4 May 2024 08:32:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 73ADD3844750 for ; Sat, 4 May 2024 08:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73ADD3844750 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 73ADD3844750 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; cv=none; b=YYQvaeWoBHWxWFsP4twuDyENsSgeZsWT5Oz6xRWU4zfhLRPzEt/dF0sDcS84pWVp9pysDCMJeuoLOpO0VAXcfdJ6a/jjHOsbB9UORyRdE8qRatytIN6bkmiEpAcoB8vrn+5C8oaLjNmKNhKgOprbMuOPzUf0FNigO5DFkLF5lDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; c=relaxed/simple; bh=p45CWFJ5WyYjcdvU9SNEMdg4JOimEngi84CfozGhjLo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wBFQ7eijM4b0+sFZVFyGYulTqiEkrmi7P2ugMZD5EZswNLeCz4jL3A26TeC3gJcpqdUhyH7s2o43FmCSA5NWtOZeyoFBcz0X3cUu4rG98taiqnsav2nZgA15OC7Gb+dTxV2NI2Dn9QxOzRpLMjgY3sFrni4ZmrNNZWb/ZR+fI5k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IjFJwgGiw+XZfj8Q1tTjHxUeHgq0lT8zvfqJja2QzDk=; b=C4ZfUIQj+tKL/BNfuiyaQ6hLbB/lBFyFqLCl2lqIoWbLNQGI/isiXIHun6ksARxZHKpKX/ Y/lw9I5iRStyErEerwltZ805Ksy+m/GBw1yor3lpnQnn5YotfKDlDwPJBG2z2G6VIH2mkH 8IQMXAoowsUbow+ZSaQ2CRW5OzFW8+U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-V8m3E8atP_eShtcmkkz2hQ-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: V8m3E8atP_eShtcmkkz2hQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAF1E834FB1 for ; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A2FA3C13FA1; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uxq6139800 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448UxP0139799; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 04/23] Add storage support for prange. Date: Sat, 4 May 2024 10:30:32 +0200 Message-ID: <20240504083056.139719-5-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 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, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_LOW, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org gcc/ChangeLog: * value-range-storage.cc (vrange_allocator::clone_varying): Add prange support. (vrange_allocator::clone_undefined): Same. (vrange_storage::alloc): Same. (vrange_storage::set_vrange): Same. (vrange_storage::get_vrange): Same. (vrange_storage::fits_p): Same. (vrange_storage::equal_p): Same. (prange_storage::alloc): New. (prange_storage::prange_storage): New. (prange_storage::set_prange): New. (prange_storage::get_prange): New. (prange_storage::equal_p): New. (prange_storage::fits_p): New. * value-range-storage.h (class prange_storage): Add prange support. --- gcc/value-range-storage.cc | 117 +++++++++++++++++++++++++++++++++++++ gcc/value-range-storage.h | 33 +++++++++++ 2 files changed, 150 insertions(+) diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index 09a29776a0e..bbae0da4772 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -118,6 +118,8 @@ vrange_allocator::clone_varying (tree type) { if (irange::supports_p (type)) return irange_storage::alloc (*m_alloc, int_range <1> (type)); + if (prange::supports_p (type)) + return prange_storage::alloc (*m_alloc, prange (type)); if (frange::supports_p (type)) return frange_storage::alloc (*m_alloc, frange (type)); return NULL; @@ -128,6 +130,8 @@ vrange_allocator::clone_undefined (tree type) { if (irange::supports_p (type)) return irange_storage::alloc (*m_alloc, int_range<1> ()); + if (prange::supports_p (type)) + return prange_storage::alloc (*m_alloc, prange ()); if (frange::supports_p (type)) return frange_storage::alloc (*m_alloc, frange ()); return NULL; @@ -141,6 +145,8 @@ vrange_storage::alloc (vrange_internal_alloc &allocator, const vrange &r) { if (is_a (r)) return irange_storage::alloc (allocator, as_a (r)); + if (is_a (r)) + return prange_storage::alloc (allocator, as_a (r)); if (is_a (r)) return frange_storage::alloc (allocator, as_a (r)); return NULL; @@ -157,6 +163,12 @@ vrange_storage::set_vrange (const vrange &r) gcc_checking_assert (s->fits_p (as_a (r))); s->set_irange (as_a (r)); } + else if (is_a (r)) + { + prange_storage *s = static_cast (this); + gcc_checking_assert (s->fits_p (as_a (r))); + s->set_prange (as_a (r)); + } else if (is_a (r)) { frange_storage *s = static_cast (this); @@ -190,6 +202,11 @@ vrange_storage::get_vrange (vrange &r, tree type) const const irange_storage *s = static_cast (this); s->get_irange (as_a (r), type); } + else if (is_a (r)) + { + const prange_storage *s = static_cast (this); + s->get_prange (as_a (r), type); + } else if (is_a (r)) { const frange_storage *s = static_cast (this); @@ -209,6 +226,11 @@ vrange_storage::fits_p (const vrange &r) const const irange_storage *s = static_cast (this); return s->fits_p (as_a (r)); } + if (is_a (r)) + { + const prange_storage *s = static_cast (this); + return s->fits_p (as_a (r)); + } if (is_a (r)) { const frange_storage *s = static_cast (this); @@ -230,6 +252,11 @@ vrange_storage::equal_p (const vrange &r) const const irange_storage *s = static_cast (this); return s->equal_p (as_a (r)); } + if (is_a (r)) + { + const prange_storage *s = static_cast (this); + return s->equal_p (as_a (r)); + } if (is_a (r)) { const frange_storage *s = static_cast (this); @@ -559,6 +586,96 @@ frange_storage::fits_p (const frange &) const return true; } +//============================================================================ +// prange_storage implementation +//============================================================================ + +prange_storage * +prange_storage::alloc (vrange_internal_alloc &allocator, const prange &r) +{ + // Assume all pointers are the same size. + unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node)); + gcc_checking_assert (r.undefined_p () || TYPE_PRECISION (r.type ()) == prec); + + typedef trailing_wide_ints twi; + size_t size = sizeof (prange_storage) + twi::extra_size (prec); + prange_storage *p = static_cast (allocator.alloc (size)); + new (p) prange_storage (r); + return p; +} + +// Initialize the storage with R. + +prange_storage::prange_storage (const prange &r) +{ + // It is the caller's responsibility to allocate enough space such + // that the precision fits. + unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node)); + m_trailing_ints.set_precision (prec); + + set_prange (r); +} + +void +prange_storage::set_prange (const prange &r) +{ + if (r.undefined_p ()) + m_kind = VR_UNDEFINED; + else if (r.varying_p ()) + m_kind = VR_VARYING; + else + { + m_kind = VR_RANGE; + set_low (r.lower_bound ()); + set_high (r.upper_bound ()); + irange_bitmask bm = r.m_bitmask; + set_value (bm.value ()); + set_mask (bm.mask ()); + } +} + +void +prange_storage::get_prange (prange &r, tree type) const +{ + gcc_checking_assert (r.supports_type_p (type)); + + if (m_kind == VR_UNDEFINED) + r.set_undefined (); + else if (m_kind == VR_VARYING) + r.set_varying (type); + else + { + gcc_checking_assert (m_kind == VR_RANGE); + gcc_checking_assert (TYPE_PRECISION (type) == m_trailing_ints.get_precision ()); + r.m_kind = VR_RANGE; + r.m_type = type; + r.m_min = get_low (); + r.m_max = get_high (); + r.m_bitmask = irange_bitmask (get_value (), get_mask ()); + if (flag_checking) + r.verify_range (); + } +} + +bool +prange_storage::equal_p (const prange &r) const +{ + if (r.undefined_p ()) + return m_kind == VR_UNDEFINED; + + prange tmp; + get_prange (tmp, r.type ()); + return tmp == r; +} + +bool +prange_storage::fits_p (const prange &) const +{ + // All pointers are the same size. + return true; +} + + static vrange_allocator ggc_vrange_allocator (true); vrange_storage *ggc_alloc_vrange_storage (tree type) diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h index 5756de7e32d..dd6813873ea 100644 --- a/gcc/value-range-storage.h +++ b/gcc/value-range-storage.h @@ -98,6 +98,39 @@ private: irange_storage (const irange &r); }; +// Efficient memory storage for a prange. + +class prange_storage : public vrange_storage +{ +public: + static prange_storage *alloc (vrange_internal_alloc &, const prange &); + void set_prange (const prange &r); + void get_prange (prange &r, tree type) const; + bool equal_p (const prange &r) const; + bool fits_p (const prange &r) const; + void dump () const; +private: + DISABLE_COPY_AND_ASSIGN (prange_storage); + prange_storage (const prange &r); + + enum value_range_kind m_kind : 3; + + // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here + // must be const. Perhaps TRAILING_WIDE_INT_ACCESSOR could be made + // const and return wide_int instead of trailing_wide_int. + wide_int get_low () const { return m_trailing_ints[0]; } + wide_int get_high () const { return m_trailing_ints[1]; } + wide_int get_value () const { return m_trailing_ints[2]; } + wide_int get_mask () const { return m_trailing_ints[3]; } + template void set_low (const T &x) { m_trailing_ints[0] = x; } + template void set_high (const T &x) { m_trailing_ints[1] = x; } + template void set_value (const T &x) { m_trailing_ints[2] = x; } + template void set_mask (const T &x) { m_trailing_ints[3] = x; } + + static const unsigned int NINTS = 4; + trailing_wide_ints m_trailing_ints; +}; + // Efficient memory storage for an frange. class frange_storage : public vrange_storage