From patchwork Tue Aug 6 12:14:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filip Kastl X-Patchwork-Id: 1969456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=3VBjWSQ/; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vtS27cAh; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=OA+2Lny5; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QWDDOmUr; 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 4WdXM24yWrz1yXs for ; Tue, 6 Aug 2024 22:15:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B4B9385842A for ; Tue, 6 Aug 2024 12:15:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id EAA973858C56 for ; Tue, 6 Aug 2024 12:15:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAA973858C56 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EAA973858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722946503; cv=none; b=pv129y4JVWxWLttMq2eUbDblFgLWAdU9XzJlO2JW0MARyxaRvhfGPOa26u2h4eeoAathM1F1Iha0FYl189jTArP+MSC5Lkt9rjZpnYt321qpV9/6Zb4Sj9xJJ0OsqE/TFrigY/QNkvgYMpXxBSsm9Ob4EOyAxzM0Pvl1jdcQM/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722946503; c=relaxed/simple; bh=MOwnUosOjqYwNDbbG4L39X9raIuMCBKW4+/GSCazh+Q=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=iZz8R+wa0s1X//pz6+Sz1OLWAZ44pD3zi9vr4wzNWrDKMArC3jg2ZVN+AN34GNAaEC0A1D0q0w54e6eKX17ukeFEQ3McNtvoPNHr7nZSTk+qi0FEXFYEA23yjObpnShNfEbs3C4xtsj0PZcVJhqbIlu6opeuL4X7v80m+nV4+uc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id F00411FB47; Tue, 6 Aug 2024 12:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1722946500; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=fZHY4XIpLDmg9iNHK2ApDAWQ4UsnBzUDZoLqpLnlvJc=; b=3VBjWSQ/MmSRsZmTiLB7zHA82+/qYgjFM+0capd/tv0UPLG4vDhkKrgnJtRThvN5QT3GEZ jQ2F16w6ArLXvglaVD/NznhHTQos4gu5FAf8C1sLex0nG0yBgpAHdwrZAQPIKAU5YAcTCF E3xC/u8NLuOU2nFsAzqFZiONM895eIo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1722946500; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=fZHY4XIpLDmg9iNHK2ApDAWQ4UsnBzUDZoLqpLnlvJc=; b=vtS27cAh0/ZeN72hNOu+KlYa0ekU7d+HrPTaaQMymXnU5nR33P1Ne5CR8BUyC4VNTlqAlJ 5KsP0tEzhjKAjwDg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1722946499; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=fZHY4XIpLDmg9iNHK2ApDAWQ4UsnBzUDZoLqpLnlvJc=; b=OA+2Lny5IPdaN6KHraGzecMf7inqBLCd+F1trzCGiC91M5VTCfIL76H4hTBPdTTT61CpJL NIkLtD+KCboHTf+UpTs0vZOhM9e9A8ZdS0vcWpgTt86WEddaM6bizdee//dxZAtLH7EiGb n1zdJT/s+7OtvPlwSgh6fHVbIg1+ZG8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1722946499; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=fZHY4XIpLDmg9iNHK2ApDAWQ4UsnBzUDZoLqpLnlvJc=; b=QWDDOmUrGl6BYHv1J1+BVVd+PgXYuc+bnMYEHNtxOKNXGcpiLIuYRnJsRWqnFh1lz8HIZT V4MiRbu8CyD9a+CA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E7ECE13770; Tue, 6 Aug 2024 12:14:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id a8GbOMMTsmbhMQAAD6G6ig (envelope-from ); Tue, 06 Aug 2024 12:14:59 +0000 Date: Tue, 6 Aug 2024 14:14:59 +0200 From: Filip Kastl To: gcc-patches@gcc.gnu.org Cc: pinskia@gmail.com, rguenther@suse.de Subject: [PATCH] gimple ssa: Put SCCOPY logic into a class Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Level: X-Spamd-Result: default: False [-1.30 / 50.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_CC(0.00)[gmail.com,suse.de]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROMTLD(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url,imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -1.30 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP 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 Hello everybody, In pr113054[1] Andrew said that he doesn't like the 'dead_stmts' static variable I used when implementing the sccopy pass. We agreed that wrapping the relevant code from the pass in a class would be most likely the best solution. Here is a patch that does exactly that. I waited until stage 1 to submit it. Bootstrapped and regtested on x86_64. Is the patch ok to be pushed to trunk? Cheers, Filip Kastl [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113054 -- 8< -- Currently the main logic of the sccopy pass is implemented as static functions. This patch instead puts the code into a class. This also gets rid of a global variable (dead_stmts). gcc/ChangeLog: * gimple-ssa-sccopy.cc (class scc_copy_prop): New class. (replace_scc_by_value): Put into... (scc_copy_prop::replace_scc_by_value): ...scc_copy_prop. (sccopy_visit_op): Put into... (scc_copy_prop::visit_op): ...scc_copy_prop. (sccopy_propagate): Put into... (scc_copy_prop::propagate): ...scc_copy_prop. (init_sccopy): Replace by... (scc_copy_prop::scc_copy_prop): ...the construtor. (finalize_sccopy): Replace by... (scc_copy_prop::~scc_copy_prop): ...the destructor. (pass_sccopy::execute): Use scc_copy_prop. Signed-off-by: Filip Kastl --- gcc/gimple-ssa-sccopy.cc | 66 ++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/gcc/gimple-ssa-sccopy.cc b/gcc/gimple-ssa-sccopy.cc index 191a4c0b451..d9eaeab4abb 100644 --- a/gcc/gimple-ssa-sccopy.cc +++ b/gcc/gimple-ssa-sccopy.cc @@ -94,11 +94,6 @@ along with GCC; see the file COPYING3. If not see namespace { -/* Bitmap tracking statements which were propagated to be removed at the end of - the pass. */ - -static bitmap dead_stmts; - /* State of vertex during SCC discovery. unvisited Vertex hasn't yet been popped from worklist. @@ -459,11 +454,33 @@ get_all_stmt_may_generate_copy (void) return result; } +/* SCC copy propagation + + 'scc_copy_prop::propagate ()' is the main function of this pass. */ + +class scc_copy_prop +{ +public: + scc_copy_prop (); + ~scc_copy_prop (); + void propagate (); + +private: + /* Bitmap tracking statements which were propagated so that they can be + removed at the end of the pass. */ + bitmap dead_stmts; + + void visit_op (tree op, hash_set &outer_ops, + hash_set &scc_set, bool &is_inner, + tree &last_outer_op); + void replace_scc_by_value (vec scc, tree val); +}; + /* For each statement from given SCC, replace its usages by value VAL. */ -static void -replace_scc_by_value (vec scc, tree val) +void +scc_copy_prop::replace_scc_by_value (vec scc, tree val) { for (gimple *stmt : scc) { @@ -476,12 +493,12 @@ replace_scc_by_value (vec scc, tree val) fprintf (dump_file, "Replacing SCC of size %d\n", scc.length ()); } -/* Part of 'sccopy_propagate ()'. */ +/* Part of 'scc_copy_prop::propagate ()'. */ -static void -sccopy_visit_op (tree op, hash_set &outer_ops, - hash_set &scc_set, bool &is_inner, - tree &last_outer_op) +void +scc_copy_prop::visit_op (tree op, hash_set &outer_ops, + hash_set &scc_set, bool &is_inner, + tree &last_outer_op) { bool op_in_scc = false; @@ -539,8 +556,8 @@ sccopy_visit_op (tree op, hash_set &outer_ops, Braun, Buchwald, Hack, Leissa, Mallon, Zwinkau, 2013, LNCS vol. 7791, Section 3.2. */ -static void -sccopy_propagate () +void +scc_copy_prop::propagate () { auto_vec useful_stmts = get_all_stmt_may_generate_copy (); scc_discovery discovery; @@ -575,14 +592,12 @@ sccopy_propagate () for (j = 0; j < gimple_phi_num_args (phi); j++) { op = gimple_phi_arg_def (phi, j); - sccopy_visit_op (op, outer_ops, scc_set, is_inner, - last_outer_op); + visit_op (op, outer_ops, scc_set, is_inner, last_outer_op); } break; case GIMPLE_ASSIGN: op = gimple_assign_rhs1 (stmt); - sccopy_visit_op (op, outer_ops, scc_set, is_inner, - last_outer_op); + visit_op (op, outer_ops, scc_set, is_inner, last_outer_op); break; default: gcc_unreachable (); @@ -613,19 +628,13 @@ sccopy_propagate () } } -/* Called when pass execution starts. */ - -static void -init_sccopy (void) +scc_copy_prop::scc_copy_prop () { /* For propagated statements. */ dead_stmts = BITMAP_ALLOC (NULL); } -/* Called before pass execution ends. */ - -static void -finalize_sccopy (void) +scc_copy_prop::~scc_copy_prop () { /* Remove all propagated statements. */ simple_dce_from_worklist (dead_stmts); @@ -668,9 +677,8 @@ public: unsigned pass_sccopy::execute (function *) { - init_sccopy (); - sccopy_propagate (); - finalize_sccopy (); + scc_copy_prop sccopy; + sccopy.propagate (); return 0; }