From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id ABA88383E814 for ; Tue, 22 Dec 2020 22:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ABA88383E814 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oliva@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 82977116DA7; Tue, 22 Dec 2020 17:03:28 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id AVecSPqIKynU; Tue, 22 Dec 2020 17:03:28 -0500 (EST) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 49534116C6B; Tue, 22 Dec 2020 17:03:28 -0500 (EST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 0BMM3Lkx059895 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 19:03:22 -0300 From: Alexandre Oliva To: Richard Biener Cc: GCC Patches Subject: make FOR_EACH_IMM_USE_STMT safe for early exits (was: Re: move sincos after pre) Organization: Free thinker, does not speak for AdaCore References: Errors-To: aoliva@lxoliva.fsfla.org Date: Tue, 22 Dec 2020 19:03:21 -0300 In-Reply-To: (Richard Biener's message of "Wed, 28 Oct 2020 14:01:52 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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-List-Received-Date: Tue, 22 Dec 2020 22:03:29 -0000 On Oct 28, 2020, Richard Biener wrote: >> BTW, any reason why we are not (yet?) using something like: >> >> #define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR) \ >> for (auto_end_imm_use_stmt_traverse auto_end \ >> ((((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR))), \ >> &(ITER))); \ >> !end_imm_use_stmt_p (&(ITER)); \ >> (void) ((STMT) = next_imm_use_stmt (&(ITER)))) > Just laziness. Or rather last time I remembered this I tried to do it > more fancy via range-for but didn't get very far due to the nested > iteration ... Use a dtor to automatically remove ITER from IMM_USE list in FOR_EACH_IMM_USE_STMT. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog * ssa-iterators.h (end_imm_use_stmt_traverse): Forward declare. (auto_end_imm_use_stmt_traverse): New struct. (FOR_EACH_IMM_USE_STMT): Use it. --- gcc/ssa-iterators.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/gcc/ssa-iterators.h b/gcc/ssa-iterators.h index 98724da14522d..817997aa952d4 100644 --- a/gcc/ssa-iterators.h +++ b/gcc/ssa-iterators.h @@ -77,16 +77,35 @@ struct imm_use_iterator !end_readonly_imm_use_p (&(ITER)); \ (void) ((DEST) = next_readonly_imm_use (&(ITER)))) -/* Use this iterator to visit each stmt which has a use of SSAVAR. */ +/* Forward declare for use in the class below. */ +static inline void end_imm_use_stmt_traverse (imm_use_iterator *); + +/* arrange to automatically call, upon descruction, end_imm_use_stmt_traverse + with a given pointer to imm_use_iterator. */ +struct auto_end_imm_use_stmt_traverse +{ + imm_use_iterator *imm; + auto_end_imm_use_stmt_traverse (imm_use_iterator *imm) + : imm (imm) {} + ~auto_end_imm_use_stmt_traverse () + { end_imm_use_stmt_traverse (imm); } +}; + +/* Use this iterator to visit each stmt which has a use of SSAVAR. The + destructor of the auto_end_imm_use_stmt_traverse object deals with removing + ITER from SSAVAR's IMM_USE list even when leaving the scope early. */ #define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR) \ - for ((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR)); \ + for (struct auto_end_imm_use_stmt_traverse \ + auto_end_imm_use_stmt_traverse \ + ((((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR))), \ + &(ITER))); \ !end_imm_use_stmt_p (&(ITER)); \ (void) ((STMT) = next_imm_use_stmt (&(ITER)))) -/* Use this to terminate the FOR_EACH_IMM_USE_STMT loop early. Failure to - do so will result in leaving a iterator marker node in the immediate - use list, and nothing good will come from that. */ +/* These used to be needed to exit FOR_EACH_IMM_USE_STMT early, without leaving + ITER behind in the stmt lists. This is now taken care of automatically, but + it doesn't hurt to use the macros for documentation purposes. */ #define BREAK_FROM_IMM_USE_STMT(ITER) \ { \ end_imm_use_stmt_traverse (&(ITER)); \ -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer Vim, Vi, Voltei pro Emacs -- GNUlius Caesar