From patchwork Tue Apr 18 09:06:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 67889 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 CE7853857011 for ; Tue, 18 Apr 2023 09:08:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE7853857011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681808886; bh=gBrUBKtCKn5sYIz/DBrCfSyUON1GuIYyBbujhNV8TuM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=aSAf8vvlpE1BUj6w2GBOXhNyNWDSTw0OKXHYNESsFHo9h039ZUuzA1Ih4nmA6AP/9 4ewGZ7ntdBhWwayZ+AITJag7OsDecbfbFKX3J7s9bI0vqllb23OSRkJVGgqwyZBQd8 zJ7S5+fGoBRLDzur2Scb7vjNbIsUBTpfwSqgfX6M= 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 1B3E13858414 for ; Tue, 18 Apr 2023 09:06:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B3E13858414 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-Rz89LM53OlWfsHKG1VXfSA-1; Tue, 18 Apr 2023 05:06:52 -0400 X-MC-Unique: Rz89LM53OlWfsHKG1VXfSA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8578F80D091; Tue, 18 Apr 2023 09:06:52 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.164]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A483492B0D; Tue, 18 Apr 2023 09:06:52 +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 33I96nXF253169 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 18 Apr 2023 11:06:49 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 33I96nFD253168; Tue, 18 Apr 2023 11:06:49 +0200 To: GCC patches Cc: Andrew MacLeod , Richard Biener , Aldy Hernandez Subject: [PATCH] Add inchash support for vrange. Date: Tue, 18 Apr 2023 11:06:38 +0200 Message-Id: <20230418090637.253140-2-aldyh@redhat.com> In-Reply-To: <20230418090637.253140-1-aldyh@redhat.com> References: <20230418090637.253140-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.3 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_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: 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 provides inchash support for vrange. It is along the lines of the streaming support I just posted and will be used for IPA hashing of ranges. Thoughts? gcc/ChangeLog: * inchash.cc (hash::add_real_value): New. * inchash.h (class hash): Add add_real_value. * value-range.cc (add_vrange): New. * value-range.h (inchash::add_vrange): New. --- gcc/inchash.cc | 20 +++++++++++++++++++ gcc/inchash.h | 2 ++ gcc/value-range.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++ gcc/value-range.h | 6 ++++++ 4 files changed, 76 insertions(+) diff --git a/gcc/inchash.cc b/gcc/inchash.cc index a30662b97fe..914e3cc92cd 100644 --- a/gcc/inchash.cc +++ b/gcc/inchash.cc @@ -24,3 +24,23 @@ along with GCC; see the file COPYING3. If not see #endif #include "system.h" #include "coretypes.h" +#include "real.h" +#include "inchash.h" + +namespace inchash +{ + +/* This is here instead of inchash.h to keep us from having to put + real.h in coretypes.h. */ +void +hash::add_real_value (const real_value &v) +{ + add_int (v.sign); + add_int (v.uexp); + for (unsigned i = 0; i < SIGSZ; ++i) + add_hwi (v.sig[i]); + /* Ignore the rest of the flags, as sign, exponent, and + significant bits should be enough. */ +} + +} // namespace inchash diff --git a/gcc/inchash.h b/gcc/inchash.h index bf76308431d..41ae153d1c5 100644 --- a/gcc/inchash.h +++ b/gcc/inchash.h @@ -88,6 +88,8 @@ class hash add_hwi (x.sext_elt (i)); } + void add_real_value (const class real_value &v); + /* Hash in pointer PTR. */ void add_ptr (const void *ptr) { diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 963330eed79..31ec832e185 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -232,6 +232,54 @@ vrange::dump (FILE *file) const pp_flush (&buffer); } +namespace inchash +{ + +void +add_vrange (const vrange &v, inchash::hash &hstate, + unsigned int) +{ + if (v.undefined_p ()) + { + hstate.add_int (VR_UNDEFINED); + return; + } + // Types are ignored throughout to inhibit two ranges being equal + // but having different hash values. This can happen when two + // ranges are equal types_compatible_p is true. + if (is_a (v)) + { + const irange &r = as_a (v); + if (r.varying_p ()) + hstate.add_int (VR_VARYING); + else + hstate.add_int (VR_RANGE); + for (unsigned i = 0; i < r.num_pairs (); ++i) + { + hstate.add_wide_int (r.lower_bound (i)); + hstate.add_wide_int (r.upper_bound (i)); + } + hstate.add_wide_int (r.get_nonzero_bits ()); + return; + } + if (is_a (v)) + { + const frange &r = as_a (v); + if (r.varying_p ()) + hstate.add_int (VR_VARYING); + else + hstate.add_int (VR_RANGE); + hstate.add_real_value (r.m_min); + hstate.add_real_value (r.m_max); + hstate.add_int (r.m_pos_nan); + hstate.add_int (r.m_neg_nan); + return; + } + gcc_unreachable (); +} + +} //namespace inchash + bool irange::supports_type_p (const_tree type) const { diff --git a/gcc/value-range.h b/gcc/value-range.h index e56df9db901..cb7418208d4 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -109,6 +109,11 @@ protected: const ENUM_BITFIELD(value_range_discriminator) m_discriminator : 4; }; +namespace inchash +{ + extern void add_vrange (const vrange &, hash &, unsigned flags = 0); +} + // An integer range without any storage. class GTY((user)) irange : public vrange @@ -332,6 +337,7 @@ class frange : public vrange friend void streamer_read_value_range (class lto_input_block *, class data_in *, class Value_Range &); + friend void inchash::add_vrange (const vrange &, inchash::hash &, unsigned); public: frange (); frange (const frange &);