From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id E415738708CB for ; Mon, 4 Jan 2021 13:10:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E415738708CB Received: by mail-ej1-x62a.google.com with SMTP id q22so36755381eja.2 for ; Mon, 04 Jan 2021 05:10:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YYy+NpaDg5kBS/Hva9zvnSqku5umBaO8oYDTAGs+ATg=; b=tq2uP9Dbi1RYOJVhKar0tku+MG4faEgZ9o/yiOuzbJMmQ7yvzgZZrr/NXP2qlzDKXf 9cE/cWFz9btHW2tZcIdB0pBBDfLlwtFkbKO2oNEgpKGEGf84Bc1T4e3LVKGf0H5t4T+E ilS70XLkTF+RyySrcuTFsGCtoM1aeyntV2YqUV6zgweXuyutcOfwOfqIASG1VoRNTVO/ pJ4LVwtvGHDopBX0dxm5uuD/CEFws6ldALXmNg6yEmfIXuvj2lL9n+GxTdR8HcsZxfNJ xKXumusiI/Cqjt3dHn25UiGXw2auPUmKEo7DtupPLSgrsvuh4EIvTUUhhaOTuxje+Yoi BnHA== X-Gm-Message-State: AOAM530MVMB77nQxoJsmToThzs9jtx4wuTPLa1J4PxVA0WJkbcEpm5Li 025hIRbzReNyIVgSkXw2O0TFjo2hpc3u1GP7hRa1Xpbt6w0= X-Google-Smtp-Source: ABdhPJx4QlO2t/oaiToYJlDulXe/TQpy/4zw0HE3NMQn/BJOs7FxWSE6HGDsfY5fIi+7PWcrDNAxY/jsOZtUHzzbGsw= X-Received: by 2002:a17:906:4348:: with SMTP id z8mr61998804ejm.371.1609765815860; Mon, 04 Jan 2021 05:10:15 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Mon, 4 Jan 2021 14:10:04 +0100 Message-ID: Subject: Re: make FOR_EACH_IMM_USE_STMT safe for early exits (was: Re: move sincos after pre) To: Alexandre Oliva Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Mon, 04 Jan 2021 13:10:18 -0000 On Tue, Dec 22, 2020 at 11:03 PM Alexandre Oliva wrote: > > 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? Hmm - while the change looks good, doesn't it end up calling end_imm_use_stmt_tranverse twice for those uses still calling BREAK_FROM_IMM_USE_STMT? Thus, please remove uses of BREAK_FROM_IMM_USE_STMT together with this patch. Thanks, Richard. > > 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