From patchwork Wed Sep 4 10:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 1980585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=j1sanFHI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WzJcf5KPqz1yg3 for ; Wed, 4 Sep 2024 20:28:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC7EC385F032 for ; Wed, 4 Sep 2024 10:28:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id CD297385F028 for ; Wed, 4 Sep 2024 10:28:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD297385F028 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CD297385F028 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725445697; cv=none; b=Nybl2aDsOTWPGeCZWUqHjhaP/37Uedw0qMg956aDYega8JSz/4hE+VmRmVN2xVneLS4qDoXS3R8BwAHtYyYG/Nn+pf3dhxbgwuYmgnMSrH405d4zxGMdCHL9oKwBS70vPsqaLhgamB3bQsutrrBDwiJRQzko6lM3D8Osik4W98M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725445697; c=relaxed/simple; bh=Jzeg16ebu9R8Xc5mh2pxrSN/XGXZelq+lIPWd5vRhG4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Uhnvxhm6CgHX1wtVMRDxSU0QLPTPHMRNdrKT4Nwu7FcEFqZg4cNPB3AlU/fD3Q2imvOUDIfFligKTknuMSgSOv1e9pl7IhfDvDePJRAV27CWy1CkxUSo4+ewx80Oh9ZZNiosVpTVYcuGqRa2jQqba5a6XyMABJD+IIkfv3kAA08= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-374c326c638so2520065f8f.2 for ; Wed, 04 Sep 2024 03:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725445693; x=1726050493; darn=gcc.gnu.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=sGaKk0gEBSTuoWtkc5iszKZA3s1qs5aCfk2Tjp5zDww=; b=j1sanFHI9wt9qWMoBwyqRmK6qyA3sno5MIncdfDN7UeS7reRGVNpYAaDttg3xTaKKg C0VwouhrLFF+6pFgRb6t2C5wapHdvGo1WYP2EpBPzoblDJc6AsXPsdcD953S4ZB4IQM7 iZT4o6hC5vfoG6slM5KmUrer6KlsW6wKMAKj6vpZoMRJUpKZpiMcxglHPcRGiDvNhCOa yDEnW/utUA5O78uQF5sL/JSUf8ZIyGNkphYhQOJ/lzurOL/A9ooewyUyX30/gapgRZ8k 0oyw5XiU90iPjfLq6HJy5s/x4O/Id3iCrmYB7rSTGZ9416thNmbAwOiZEoM5mL2gNvq3 PVBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725445693; x=1726050493; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sGaKk0gEBSTuoWtkc5iszKZA3s1qs5aCfk2Tjp5zDww=; b=SAgiW+0XedOWZnCFxxsKlzqSvP62dlWCbrZNmBFqXafL4b8sDq11SC1GrFItiLQg4k 1w2a19Sz7dlzQ4ZcRxUAdY0EqgRFsY4GG+JChRQ4Q3Nc/NWG7dOuf/2ENtyKAyfo7L5G 8NVOzKwOnHzc/p5j67bX73pZrP1yFzk3hfDhxd5lvbchN87ahBAI7izqKUk0Egaosmnh lxU1kO9RdAIXJrt4b5x6la4BUazrvQ/fIEvL6YH8RV3HTCpCqOvVaHCp6kXE/y4KqUrw ASrBQJeH5x9lfv2SuwdkLLDZOdtadUoTm5edP+Nxz4sGnJA1W2/BpLK757XiDpRSjM2Z 8I9g== X-Forwarded-Encrypted: i=1; AJvYcCWkMJs7rwUauCUCQfe/3hbWyi8xb3zanby3MUr0VxEdhsOgtOBTBwi8t9ikaC/7I6t65NJcsn4KkWMPnQ==@gcc.gnu.org X-Gm-Message-State: AOJu0Yxi3cCPem94yDVVpqzT7u6HtJ4oI4X2hJUls7Ca06xSjQy9urIq 5X98mPsMwJVU1/bxT1326icpzACWVbf+MWGh9XNllTy+YQhQNPB+BVvn9EBHQGM= X-Google-Smtp-Source: AGHT+IFkZoxxexO51vXPtU/HwhTanxaoNUID7VL7J34TAgGcJHW6NSEGjU2yvygPHgEJOXISvoCJRg== X-Received: by 2002:a5d:468a:0:b0:36b:aa9d:785c with SMTP id ffacd0b85a97d-374bf1e34bamr8805318f8f.52.1725445693185; Wed, 04 Sep 2024 03:28:13 -0700 (PDT) Received: from euler.schwinge.ddns.net (p200300c8b733b9005e8fc6f38b6af531.dip0.t-ipconnect.de. [2003:c8:b733:b900:5e8f:c6f3:8b6a:f531]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-374ccab8a76sm7204076f8f.99.2024.09.04.03.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 03:28:12 -0700 (PDT) From: Thomas Schwinge To: David Malcolm , gcc-patches@gcc.gnu.org Subject: [PING] Handle 'NUM' in 'PUSH_INSERT_PASSES_WITHIN' (was: [PATCH 03/11] Handwritten part of conversion of passes to C++ classes) In-Reply-To: <87ed8htdwy.fsf@euler.schwinge.ddns.net> References: <1374851081-32153-1-git-send-email-dmalcolm@redhat.com> <1374851081-32153-4-git-send-email-dmalcolm@redhat.com> <87ed8htdwy.fsf@euler.schwinge.ddns.net> User-Agent: Notmuch/0.30+8~g47a4bad (https://notmuchmail.org) Emacs/29.4 (x86_64-pc-linux-gnu) Date: Wed, 04 Sep 2024 12:28:10 +0200 Message-ID: <87y147yapx.fsf@euler.schwinge.ddns.net> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! Ping. On 2024-06-28T15:06:21+0200, I wrote: > As part of this: > > On 2013-07-26T11:04:33-0400, David Malcolm wrote: >> This patch is the hand-written part of the conversion of passes from >> C structs to C++ classes. > >> --- a/gcc/passes.c >> +++ b/gcc/passes.c > > ..., we did hard-code 'PUSH_INSERT_PASSES_WITHIN(PASS)' to always refer > to the first instance of 'PASS': > >> #define PUSH_INSERT_PASSES_WITHIN(PASS) \ >> { \ >> - struct opt_pass **p = &(PASS).pass.sub; >> + struct opt_pass **p = &(PASS ## _1)->sub; > > ..., however we did change 'NEXT_PASS(PASS, NUM)' to actually use 'NUM': > >> -#define NEXT_PASS(PASS, NUM) (p = next_pass_1 (p, &((PASS).pass))) >> +#define NEXT_PASS(PASS, NUM) \ >> + do { \ >> + gcc_assert (NULL == PASS ## _ ## NUM); \ >> + if ((NUM) == 1) \ >> + PASS ## _1 = make_##PASS (ctxt_); \ >> + else \ >> + { \ >> + gcc_assert (PASS ## _1); \ >> + PASS ## _ ## NUM = PASS ## _1->clone (); \ >> + } \ >> + p = next_pass_1 (p, PASS ## _ ## NUM); \ >> + } while (0) > > This was never re-synchronized later on, and is problematic if you try to > do something like this; change: > > [...] > NEXT_PASS (pass_postreload); > PUSH_INSERT_PASSES_WITHIN (pass_postreload) > NEXT_PASS (pass_postreload_cse); > [...] > NEXT_PASS (pass_cprop_hardreg); > NEXT_PASS (pass_fast_rtl_dce); > NEXT_PASS (pass_reorder_blocks); > [...] > POP_INSERT_PASSES () > [...] > > ... into: > > [...] > NEXT_PASS (pass_postreload); > PUSH_INSERT_PASSES_WITHIN (pass_postreload) > NEXT_PASS (pass_postreload_cse); > [...] > NEXT_PASS (pass_cprop_hardreg); > POP_INSERT_PASSES () > NEXT_PASS (pass_fast_rtl_dce); > NEXT_PASS (pass_postreload); > PUSH_INSERT_PASSES_WITHIN (pass_postreload) > NEXT_PASS (pass_reorder_blocks); > [...] > POP_INSERT_PASSES () > [...] > > That is, interrupt the pass pipeline within 'pass_postreload', in order > to unconditionally run 'pass_fast_rtl_dce' even if not running > 'pass_postreload'. What happens is that the second > 'PUSH_INSERT_PASSES_WITHIN (pass_postreload)' overwrites the first > 'PUSH_INSERT_PASSES_WITHIN (pass_postreload)' instead of applying to the > second (preceding) 'NEXT_PASS (pass_postreload);'. > > (I ran into this in context of what I tried in > > "nvptx vs. [PATCH] Add a late-combine pass [PR106594]"; discuss that > specific use case over there, not here.) > > OK to address this with the attached > "Handle 'NUM' in 'PUSH_INSERT_PASSES_WITHIN'"? > > This depends on > > "Rewrite usage comment at the top of 'gcc/passes.def'" to avoid running > into the 'ERROR: Can't locate [...]' that I'm adding, while processing > the 'PUSH_INSERT_PASSES_WITHIN (PASS)' in the usage comment at the top of > 'gcc/passes.def', where 'NEXT_PASS (PASS)' only appears later. ;-) (Already pushed.) > I've verified this does the expected thing for the main 'gcc/passes.def', > and that 'PUSH_INSERT_PASSES_WITHIN' is not used/not applicable for > 'PASSES_EXTRA' ('gcc/config/*/*-passes.def'). Grüße Thomas From e368ccba93f5bbaee882076c80849adb55a68fa0 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Fri, 28 Jun 2024 12:10:12 +0200 Subject: [PATCH] Handle 'NUM' in 'PUSH_INSERT_PASSES_WITHIN' ..., such that also for repeated 'NEXT_PASS', 'PUSH_INSERT_PASSES_WITHIN' for a given 'PASS', the 'PUSH_INSERT_PASSES_WITHIN' applies to the preceeding 'NEXT_PASS', and not unconditionally applies to the first 'NEXT_PASS'. gcc/ * gen-pass-instances.awk: Handle 'PUSH_INSERT_PASSES_WITHIN'. * pass_manager.h (PUSH_INSERT_PASSES_WITHIN): Adjust. * passes.cc (PUSH_INSERT_PASSES_WITHIN): Likewise. --- gcc/gen-pass-instances.awk | 28 +++++++++++++++++++++++++--- gcc/pass_manager.h | 2 +- gcc/passes.cc | 6 +++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/gcc/gen-pass-instances.awk b/gcc/gen-pass-instances.awk index 449889663f7..871ac0cdb52 100644 --- a/gcc/gen-pass-instances.awk +++ b/gcc/gen-pass-instances.awk @@ -16,7 +16,7 @@ # This Awk script takes passes.def and writes pass-instances.def, # counting the instances of each kind of pass, adding an instance number -# to everywhere that NEXT_PASS is used. +# to everywhere that NEXT_PASS or PUSH_INSERT_PASSES_WITHIN are used. # Also handle INSERT_PASS_AFTER, INSERT_PASS_BEFORE and REPLACE_PASS # directives. # @@ -222,9 +222,31 @@ END { if (with_arg) printf ",%s", with_arg; printf ")%s\n", postfix; + + continue; } - else - print lines[i]; + + ret = parse_line(lines[i], "PUSH_INSERT_PASSES_WITHIN"); + if (ret) + { + pass_name = args[1]; + + pass_num = pass_final_counts[pass_name]; + if (!pass_num) + { + print "ERROR: Can't locate instance of the pass mentioned in " pass_name; + exit 1; + } + + printf "%s", prefix; + printf "PUSH_INSERT_PASSES_WITHIN"; + printf " (%s, %s", pass_name, pass_num; + printf ")%s\n", postfix; + + continue; + } + + print lines[i]; } } diff --git a/gcc/pass_manager.h b/gcc/pass_manager.h index be324d5dff7..edd775e9a9c 100644 --- a/gcc/pass_manager.h +++ b/gcc/pass_manager.h @@ -126,7 +126,7 @@ private: opt_pass *pass_copy_prop_8; */ #define INSERT_PASSES_AFTER(PASS) -#define PUSH_INSERT_PASSES_WITHIN(PASS) +#define PUSH_INSERT_PASSES_WITHIN(PASS, NUM) #define POP_INSERT_PASSES() #define NEXT_PASS(PASS, NUM) opt_pass *PASS ## _ ## NUM #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM) diff --git a/gcc/passes.cc b/gcc/passes.cc index b01a79ef96c..023631046a6 100644 --- a/gcc/passes.cc +++ b/gcc/passes.cc @@ -1574,7 +1574,7 @@ pass_manager::pass_manager (context *ctxt) /* Zero-initialize pass members. */ #define INSERT_PASSES_AFTER(PASS) -#define PUSH_INSERT_PASSES_WITHIN(PASS) +#define PUSH_INSERT_PASSES_WITHIN(PASS, NUM) #define POP_INSERT_PASSES() #define NEXT_PASS(PASS, NUM) PASS ## _ ## NUM = NULL #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM) @@ -1604,9 +1604,9 @@ pass_manager::pass_manager (context *ctxt) *p = NULL; \ } -#define PUSH_INSERT_PASSES_WITHIN(PASS) \ +#define PUSH_INSERT_PASSES_WITHIN(PASS, NUM) \ { \ - opt_pass **p = &(PASS ## _1)->sub; + opt_pass **p = &(PASS ## _ ## NUM)->sub; #define POP_INSERT_PASSES() \ } -- 2.34.1