From patchwork Wed Nov 3 09:00:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 46982 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 70A6A385803F for ; Wed, 3 Nov 2021 13:23:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70A6A385803F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635945822; bh=OcrYSl+6EjPnWZjhiqZGPO7UnOqIL4QLZHFjT87LpME=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Lm2HJnKKjvcGrNgSbxqRbfEe8VyncpqKGMI/q4Eid4Wn7pjS6hbpml2aqqyeI16iK UzeluCP6uK6zhoxPodt9z/kxF56wnMY1qjwYCI7hEDufPA92F3GxxP+/9fA9dcOA8C qdWzafYovt6UQFqE/GcgcBONoo6N5YZZp7aU9OXk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 1D55A3858420 for ; Wed, 3 Nov 2021 13:17:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1D55A3858420 Received: from smtp-out2.suse.de ([195.135.220.29]:56864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1miC8L-00072i-NR for gcc-patches@gcc.gnu.org; Wed, 03 Nov 2021 05:00:39 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1CB471FD3E for ; Wed, 3 Nov 2021 09:00:35 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 084D213CE3 for ; Wed, 3 Nov 2021 09:00:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iTDeALNPgmEyYwAAMHmgww (envelope-from ) for ; Wed, 03 Nov 2021 09:00:35 +0000 Date: Wed, 3 Nov 2021 10:00:34 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Make sbitmap bitmap_set_bit and bitmap_clear_bit return changed state Message-ID: <2254rpoo-q44s-p85-o21n-94s74n98nqqn@fhfr.qr> MIME-Version: 1.0 Received-SPF: pass client-ip=195.135.220.29; envelope-from=rguenther@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following adjusts the sbitmap bitmap_set_bit and bitmap_clear_bit APIs to match that of bitmap by returning a bool indicating whether the bitmap was changed. I've also changed bitmap_bit_p to return a bool rather than an int and made use of the sbitmap bitmap_set_bit API change in one place. Bootstrap and regtest pending on x86_64-unknown-linux-gnu. 2021-11-03 Richard Biener * bitmap.h (bitmap_bit_p): Change the return type to bool. * bitmap.c (bitmap_bit_p): Likewise. * sbitmap.h (bitmap_bit_p): Likewise. (bitmap_set_bit): Return whether the bit changed. (bitmap_clear_bit): Likewise. * tree-ssa.c (verify_vssa): Make use of the changed state from bitmap_set_bit. --- gcc/bitmap.c | 2 +- gcc/bitmap.h | 2 +- gcc/sbitmap.h | 28 +++++++++++++++++++--------- gcc/tree-ssa.c | 4 +--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/gcc/bitmap.c b/gcc/bitmap.c index 98c6d0b9e05..1aa8e4b3134 100644 --- a/gcc/bitmap.c +++ b/gcc/bitmap.c @@ -983,7 +983,7 @@ bitmap_set_bit (bitmap head, int bit) /* Return whether a bit is set within a bitmap. */ -int +bool bitmap_bit_p (const_bitmap head, int bit) { unsigned int indx = bit / BITMAP_ELEMENT_ALL_BITS; diff --git a/gcc/bitmap.h b/gcc/bitmap.h index 1bddcdbfaee..fc33877c89d 100644 --- a/gcc/bitmap.h +++ b/gcc/bitmap.h @@ -436,7 +436,7 @@ extern bool bitmap_clear_bit (bitmap, int); extern bool bitmap_set_bit (bitmap, int); /* Return true if a bit is set in a bitmap. */ -extern int bitmap_bit_p (const_bitmap, int); +extern bool bitmap_bit_p (const_bitmap, int); /* Set and get multiple bit values in a sparse bitmap. This allows a bitmap to function as a sparse array of bit patterns where the patterns are diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h index 17660e5a65e..5fb0e005957 100644 --- a/gcc/sbitmap.h +++ b/gcc/sbitmap.h @@ -114,7 +114,7 @@ bitmap_check_sizes (const_sbitmap a, const_sbitmap b) } /* Test if bit number bitno in the bitmap is set. */ -static inline SBITMAP_ELT_TYPE +static inline bool bitmap_bit_p (const_sbitmap map, int bitno) { bitmap_check_index (map, bitno); @@ -124,26 +124,36 @@ bitmap_bit_p (const_sbitmap map, int bitno) return (map->elms[i] >> s) & (SBITMAP_ELT_TYPE) 1; } -/* Set bit number BITNO in the sbitmap MAP. */ +/* Set bit number BITNO in the sbitmap MAP. + Return true if the bit changed. */ -static inline void +static inline bool bitmap_set_bit (sbitmap map, int bitno) { bitmap_check_index (map, bitno); - map->elms[bitno / SBITMAP_ELT_BITS] - |= (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS; + size_t i = bitno / SBITMAP_ELT_BITS; + unsigned int s = bitno % SBITMAP_ELT_BITS; + if (map->elms[i] & ((SBITMAP_ELT_TYPE) 1 << s)) + return false; + map->elms[i] |= (SBITMAP_ELT_TYPE) 1 << s; + return true; } -/* Reset bit number BITNO in the sbitmap MAP. */ +/* Reset bit number BITNO in the sbitmap MAP. + Return true if the bit changed. */ -static inline void +static inline bool bitmap_clear_bit (sbitmap map, int bitno) { bitmap_check_index (map, bitno); - map->elms[bitno / SBITMAP_ELT_BITS] - &= ~((SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS); + size_t i = bitno / SBITMAP_ELT_BITS; + unsigned int s = bitno % SBITMAP_ELT_BITS; + if (!(map->elms[i] & ((SBITMAP_ELT_TYPE) 1 << s))) + return false; + map->elms[i] &= ~((SBITMAP_ELT_TYPE) 1 << s); + return true; } /* The iterator for sbitmap. */ diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index fde13defebf..3f25d654d3f 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -649,11 +649,9 @@ verify_vssa (basic_block bb, tree current_vdef, sbitmap visited) { bool err = false; - if (bitmap_bit_p (visited, bb->index)) + if (!bitmap_set_bit (visited, bb->index)) return false; - bitmap_set_bit (visited, bb->index); - /* Pick up the single virtual PHI def. */ gphi *phi = NULL; for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);