From patchwork Tue Jun 8 18:54:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1489598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: 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=BoZqpUKq; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G00kn4Gxkz9tl3 for ; Wed, 9 Jun 2021 05:32:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 159103983038 for ; Tue, 8 Jun 2021 19:32:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 159103983038 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623180767; bh=x8YV2b/h8u9X5sqCak3G+1qqAPKzFjU9H2l7x/o+n6o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BoZqpUKqUA/NG74EWo4dISkTbcHkjs3PzH2U4MkHvBE8T7PB0x3kHU69aif94oWhf KyZEdqY+ajG5yNLKFt+W+UIE0PhabIoaVyfyr3qQSTdg8L5lxl5Hd2n1RijBdbn4nj PX3f1uIGHRVwN4OEq2p9EEpy+FlpidHazwAcshtU= 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 ESMTP id 1C77B3982434 for ; Tue, 8 Jun 2021 18:54:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C77B3982434 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-432-A5ZZBwmuPfeYKArbSGB1Ew-1; Tue, 08 Jun 2021 14:54:41 -0400 X-MC-Unique: A5ZZBwmuPfeYKArbSGB1Ew-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0D5F10074A7 for ; Tue, 8 Jun 2021 18:54:40 +0000 (UTC) Received: from t14s.localdomain.com (ovpn-112-42.phx2.redhat.com [10.3.112.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98E6418B4B; Tue, 8 Jun 2021 18:54:40 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: split out struct bit_range from class concrete_binding Date: Tue, 8 Jun 2021 14:54:39 -0400 Message-Id: <20210608185439.1047331-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as 6b400aef1bdc84bbdf5011caff3fe5f82c68d253. gcc/analyzer/ChangeLog: * store.cc (concrete_binding::dump_to_pp): Move bulk of implementation to... (bit_range::dump_to_pp): ...this new function. (bit_range::cmp): New. (concrete_binding::overlaps_p): Update for use of bit_range. (concrete_binding::cmp_ptr_ptr): Likewise. * store.h (struct bit_range): New. (class concrete_binding): Replace fields m_start_bit_offset and m_size_in_bits with new field m_bit_range. Signed-off-by: David Malcolm --- gcc/analyzer/store.cc | 38 +++++++++++++++++++-------- gcc/analyzer/store.h | 61 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 22 deletions(-) diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc index b1874a5a2d3..f4bb7def781 100644 --- a/gcc/analyzer/store.cc +++ b/gcc/analyzer/store.cc @@ -236,15 +236,12 @@ binding_key::cmp (const binding_key *k1, const binding_key *k2) } } -/* class concrete_binding : public binding_key. */ - -/* Implementation of binding_key::dump_to_pp vfunc for concrete_binding. */ +/* struct struct bit_range. */ void -concrete_binding::dump_to_pp (pretty_printer *pp, bool simple) const +bit_range::dump_to_pp (pretty_printer *pp) const { - binding_key::dump_to_pp (pp, simple); - pp_string (pp, ", start: "); + pp_string (pp, "start: "); pp_wide_int (pp, m_start_bit_offset, SIGNED); pp_string (pp, ", size: "); pp_wide_int (pp, m_size_in_bits, SIGNED); @@ -252,12 +249,34 @@ concrete_binding::dump_to_pp (pretty_printer *pp, bool simple) const pp_wide_int (pp, get_next_bit_offset (), SIGNED); } +int +bit_range::cmp (const bit_range &br1, const bit_range &br2) +{ + if (int start_cmp = wi::cmps (br1.m_start_bit_offset, + br2.m_start_bit_offset)) + return start_cmp; + + return wi::cmpu (br1.m_size_in_bits, br2.m_size_in_bits); +} + +/* class concrete_binding : public binding_key. */ + +/* Implementation of binding_key::dump_to_pp vfunc for concrete_binding. */ + +void +concrete_binding::dump_to_pp (pretty_printer *pp, bool simple) const +{ + binding_key::dump_to_pp (pp, simple); + pp_string (pp, ", "); + m_bit_range.dump_to_pp (pp); +} + /* Return true if this binding overlaps with OTHER. */ bool concrete_binding::overlaps_p (const concrete_binding &other) const { - if (m_start_bit_offset < other.get_next_bit_offset () + if (get_start_bit_offset () < other.get_next_bit_offset () && get_next_bit_offset () > other.get_start_bit_offset ()) return true; return false; @@ -274,10 +293,7 @@ concrete_binding::cmp_ptr_ptr (const void *p1, const void *p2) if (int kind_cmp = b1->get_kind () - b2->get_kind ()) return kind_cmp; - if (int start_cmp = wi::cmps (b1->m_start_bit_offset, b2->m_start_bit_offset)) - return start_cmp; - - return wi::cmpu (b1->m_size_in_bits, b2->m_size_in_bits); + return bit_range::cmp (b1->m_bit_range, b2->m_bit_range); } /* class symbolic_binding : public binding_key. */ diff --git a/gcc/analyzer/store.h b/gcc/analyzer/store.h index d68513ca94c..be09b427366 100644 --- a/gcc/analyzer/store.h +++ b/gcc/analyzer/store.h @@ -267,6 +267,42 @@ private: enum binding_kind m_kind; }; +struct bit_range +{ + bit_range (bit_offset_t start_bit_offset, bit_size_t size_in_bits) + : m_start_bit_offset (start_bit_offset), + m_size_in_bits (size_in_bits) + {} + + void dump_to_pp (pretty_printer *pp) const; + + bit_offset_t get_start_bit_offset () const + { + return m_start_bit_offset; + } + bit_offset_t get_next_bit_offset () const + { + return m_start_bit_offset + m_size_in_bits; + } + + bool contains_p (bit_offset_t offset) const + { + return (offset >= get_start_bit_offset () + && offset < get_next_bit_offset ()); + } + + bool operator== (const bit_range &other) const + { + return (m_start_bit_offset == other.m_start_bit_offset + && m_size_in_bits == other.m_size_in_bits); + } + + static int cmp (const bit_range &br1, const bit_range &br2); + + bit_offset_t m_start_bit_offset; + bit_size_t m_size_in_bits; +}; + /* Concrete subclass of binding_key, for describing a concrete range of bits within the binding_map (e.g. "bits 8-15"). */ @@ -279,24 +315,22 @@ public: concrete_binding (bit_offset_t start_bit_offset, bit_size_t size_in_bits, enum binding_kind kind) : binding_key (kind), - m_start_bit_offset (start_bit_offset), - m_size_in_bits (size_in_bits) + m_bit_range (start_bit_offset, size_in_bits) {} bool concrete_p () const FINAL OVERRIDE { return true; } hashval_t hash () const { inchash::hash hstate; - hstate.add_wide_int (m_start_bit_offset); - hstate.add_wide_int (m_size_in_bits); + hstate.add_wide_int (m_bit_range.m_start_bit_offset); + hstate.add_wide_int (m_bit_range.m_size_in_bits); return hstate.end () ^ binding_key::impl_hash (); } bool operator== (const concrete_binding &other) const { if (!binding_key::impl_eq (other)) return false; - return (m_start_bit_offset == other.m_start_bit_offset - && m_size_in_bits == other.m_size_in_bits); + return m_bit_range == other.m_bit_range; } void dump_to_pp (pretty_printer *pp, bool simple) const FINAL OVERRIDE; @@ -304,12 +338,18 @@ public: const concrete_binding *dyn_cast_concrete_binding () const FINAL OVERRIDE { return this; } - bit_offset_t get_start_bit_offset () const { return m_start_bit_offset; } - bit_size_t get_size_in_bits () const { return m_size_in_bits; } + bit_offset_t get_start_bit_offset () const + { + return m_bit_range.m_start_bit_offset; + } + bit_size_t get_size_in_bits () const + { + return m_bit_range.m_size_in_bits; + } /* Return the next bit offset after the end of this binding. */ bit_offset_t get_next_bit_offset () const { - return m_start_bit_offset + m_size_in_bits; + return m_bit_range.get_next_bit_offset (); } bool overlaps_p (const concrete_binding &other) const; @@ -317,8 +357,7 @@ public: static int cmp_ptr_ptr (const void *, const void *); private: - bit_offset_t m_start_bit_offset; - bit_size_t m_size_in_bits; + bit_range m_bit_range; }; } // namespace ana