From patchwork Tue Mar 16 23:35:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 1454352 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4F0V6G0DLmz9sVb for ; Wed, 17 Mar 2021 10:36:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42D003851C26; Tue, 16 Mar 2021 23:36:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 22E27385481A for ; Tue, 16 Mar 2021 23:35:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 22E27385481A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Thomas_Schwinge@mentor.com IronPort-SDR: s/y8bcU/Ih6tOcyjamaA4XMJaen4pn9p9JGIOec/wub2HJ3xb0c+hC9nNUzxAr4SY3144NG76y l2pQGd61B9pJwVMbgTr0tV6sVoc6roMO9tEh3gcgkOc0EAptg10RmJZOdEqTq0s966Q0h3xz2E Kh1ZtJDtIaEJHu+UfZ6zEFIhXHR6oRzZeEvplujrzaWb3UKtwY0Cjm5nnsr2EdQ8jPIjcXIG30 PBWFvoM6jOxPnefN1diH0T2pf3SFTe5NoYQC0j/77lGGslBVXIKwQtSed43SfZyPGrlEqOtSt4 GnY= X-IronPort-AV: E=Sophos;i="5.81,254,1610438400"; d="scan'208,223";a="61517521" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 16 Mar 2021 15:35:57 -0800 IronPort-SDR: fLFzidG1LopUF1JRbpbX+e4LD/u7ZUiExXznQRs4YGPLRMHpmhGOCrWQ9xRwXFpch3eUXb1TIJ rHwLeYP0MY7ojVTkfgRF346VLEN+gKIugel928xsyu1AqK609zYnXZGUad6x8LBwhYG+BnzKxN c7+Vnjvt4JO8sbNF66TgsTGXiDSvCOSsCQUCVHwEJSsb21qktX601aDhmxD3QLWKQoOrbUqC2X KNPpNZdqOuhwV4fZjIQXO1tIKbQLQ5YnZ9izMWjkIuA9a8gVxV1lpwqCZ7WJ3YUt1/JO9nMp9H X/E= From: Thomas Schwinge To: Subject: [WIP] 'walk_gimple_seq' backward In-Reply-To: <87eege1y2g.fsf@dem-tschwing-1.ger.mentorg.com> References: <87pn00z2st.fsf@euler.schwinge.homeip.net> <87mtv3ywdp.fsf@euler.schwinge.homeip.net> <87eege1y2g.fsf@dem-tschwing-1.ger.mentorg.com> User-Agent: Notmuch/0.29.1+93~g67ed7df (https://notmuchmail.org) Emacs/25.2.2 (x86_64-pc-linux-gnu) Date: Wed, 17 Mar 2021 00:35:51 +0100 Message-ID: <87blbi1xk8.fsf@dem-tschwing-1.ger.mentorg.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, 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: , Cc: Jakub Jelinek , Michael Matz Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! On 2021-03-17T00:24:55+0100, I wrote: > Now, walking each function backwards (!), [...] > I've now got a simple 'callback_op', which for '!is_lhs' looks at > 'get_base_address ([op])', and if that 'var' is contained in the set of > current candidates (initialized per containg 'bind's, which we enter > first, even if walking a 'gimple_seq' backwards), removes that 'var' as a > candidate for such optimization. (Plus some "details", of couse.) This > seems to work fine, as far as I can tell. :-) Is something like the attached "[WIP] 'walk_gimple_seq' backward" OK conceptually? (For next development stage 1 and with all the TODOs resolved, of course.) The 'backward' flag cannot simply be a argument to 'walk_gimple_seq' etc.: it needs to also be passed to 'walk_gimple_seq_mod' calls triggered from inside 'walk_gimple_stmt'. Hence, I've put it into the state 'struct walk_stmt_info'. Grüße Thomas ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf From 48036d65cea6bb47c7d4eca3b4fea77e058f29e3 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Mon, 15 Mar 2021 17:31:00 +0100 Subject: [PATCH] [WIP] 'walk_gimple_seq' backward This seems to work -- for the one case where I'm using it... --- gcc/doc/gimple.texi | 2 ++ gcc/gimple-walk.c | 15 ++++++++++++--- gcc/gimple-walk.h | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi index 5e0fc2e0dc5..51fe0f2d715 100644 --- a/gcc/doc/gimple.texi +++ b/gcc/doc/gimple.texi @@ -2778,4 +2778,6 @@ calling @code{walk_gimple_stmt} on each one. @code{WI} is as in @code{walk_gimple_stmt}. If @code{walk_gimple_stmt} returns non-@code{NULL}, the walk is stopped and the value returned. Otherwise, all the statements are walked and @code{NULL_TREE} returned. + +TODO update for forward vs. backward. @end deftypefn diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c index 9a761f32578..dfc2f0b4dbc 100644 --- a/gcc/gimple-walk.c +++ b/gcc/gimple-walk.c @@ -32,6 +32,8 @@ along with GCC; see the file COPYING3. If not see /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt on each one. WI is as in walk_gimple_stmt. + TODO update for forward vs. backward. + If walk_gimple_stmt returns non-NULL, the walk is stopped, and the value is stored in WI->CALLBACK_RESULT. Also, the statement that produced the value is returned if this statement has not been @@ -44,9 +46,10 @@ gimple * walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt, walk_tree_fn callback_op, struct walk_stmt_info *wi) { - gimple_stmt_iterator gsi; + bool forward = !(wi && wi->backward); - for (gsi = gsi_start (*pseq); !gsi_end_p (gsi); ) + gimple_stmt_iterator gsi = forward ? gsi_start (*pseq) : gsi_last (*pseq); + for (; !gsi_end_p (gsi); ) { tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi); if (ret) @@ -60,7 +63,13 @@ walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt, } if (!wi->removed_stmt) - gsi_next (&gsi); + { + if (forward) + gsi_next (&gsi); + else //TODO Correct? + gsi_prev (&gsi); + //TODO This could do with some unit testing, to make sure all the corner cases (removing first/last, for example) work correctly. + } } if (wi) diff --git a/gcc/gimple-walk.h b/gcc/gimple-walk.h index bdc7351f190..9590c63ba18 100644 --- a/gcc/gimple-walk.h +++ b/gcc/gimple-walk.h @@ -71,6 +71,10 @@ struct walk_stmt_info /* True if we've removed the statement that was processed. */ BOOL_BITFIELD removed_stmt : 1; + + /*TODO */ + //TODO Only applicable for 'walk_gimple_seq'. + BOOL_BITFIELD backward : 1; }; /* Callback for walk_gimple_stmt. Called for every statement found -- 2.17.1