From patchwork Mon Nov 1 09:53:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1549068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yw+6UDCE; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HjT0j4fb8z9sS8 for ; Mon, 1 Nov 2021 20:55:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 365793857C43 for ; Mon, 1 Nov 2021 09:54:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 365793857C43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635760498; bh=ExKmqdskhFCUBVc9LAtxJW/hbUjbFzD2/lwL4WJVw7E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=yw+6UDCEevBqc1tfXe8Y/pRWK7FPInzcqIi/v+28PZIiJFNXaadYWlONNRvxBVVW2 qSsQpKjH6sZBFekdEbLZTcF2Z+8G3dC8RhnOJp2SbwTD4ocCmq0/11T8bOI5y+HvJ1 sPfDUUoVhT0fV13S+2lYFHZ4ZrPNKtIR6goZcPy4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 90F1B3858422 for ; Mon, 1 Nov 2021 09:54:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 90F1B3858422 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-297-syz7ROO3ORSnfh9eF_LR2g-1; Mon, 01 Nov 2021 05:54:15 -0400 X-MC-Unique: syz7ROO3ORSnfh9eF_LR2g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CB25BBEE7; Mon, 1 Nov 2021 09:54:14 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 045E3171FF; Mon, 1 Nov 2021 09:54:11 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 1A19s9tA727359 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 1 Nov 2021 10:54:09 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 1A19s9aA727358; Mon, 1 Nov 2021 10:54:09 +0100 To: Jeff Law Subject: [PATCH] Move statics to threader pass class. Date: Mon, 1 Nov 2021 10:53:58 +0100 Message-Id: <20211101095358.727235-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: GCC patches Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch moves all the static functions into the pass class, and cleans up things a little. The goal is to shuffle things around such that we can add debug counters that depend on different threading passes, but it's a clean-up on its own right. Tested on x86-64 Linux. OK? gcc/ChangeLog: * tree-ssa-threadbackward.c (BT_NONE): New. (BT_SPEED): New. (BT_RESOLVE): New. (back_threader::back_threader): Add flags. Move loop initialization here. (back_threader::~back_threader): New. (back_threader::find_taken_edge_switch): Change solver and ranger to pointers. (back_threader::find_taken_edge_cond): Same. (back_threader::find_paths_to_names): Same. (back_threader::find_paths): Same. (back_threader::dump): Same. (try_thread_blocks): Merge into thread_blocks. (back_threader::thread_blocks): New. (do_early_thread_jumps): Merge into thread_blocks. (do_thread_jumps): Merge into thread_blocks. (back_threader::thread_through_all_blocks): Remove. --- gcc/tree-ssa-threadbackward.c | 116 +++++++++++++++++----------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c index 9979bfdedf4..c66e74d159a 100644 --- a/gcc/tree-ssa-threadbackward.c +++ b/gcc/tree-ssa-threadbackward.c @@ -69,13 +69,22 @@ private: const bool m_speed_p; }; +// Back threader flags. +#define BT_NONE 0 +// Generate fast code at the expense of code size. +#define BT_SPEED 1 +// Resolve unknown SSAs on entry to a threading path. If set, use the +// ranger. If not, assume all ranges on entry to a path are VARYING. +#define BT_RESOLVE 2 + class back_threader { public: - back_threader (bool speed_p, bool resolve); - void maybe_thread_block (basic_block bb); - bool thread_through_all_blocks (bool may_peel_loop_headers); + back_threader (function *fun, unsigned flags); + ~back_threader (); + unsigned thread_blocks (); private: + void maybe_thread_block (basic_block bb); void find_paths (basic_block bb, tree name); edge maybe_register_path (); bool find_paths_to_names (basic_block bb, bitmap imports); @@ -89,8 +98,8 @@ private: back_threader_registry m_registry; back_threader_profitability m_profit; - gimple_ranger m_ranger; - path_range_query m_solver; + gimple_ranger *m_ranger; + path_range_query *m_solver; // Current path being analyzed. auto_vec m_path; @@ -109,19 +118,35 @@ private: // Set to TRUE if unknown SSA names along a path should be resolved // with the ranger. Otherwise, unknown SSA names are assumed to be // VARYING. Setting to true is more precise but slower. - bool m_resolve; + function *m_fun; + unsigned m_flags; }; // Used to differentiate unreachable edges, so we may stop the search // in a the given direction. const edge back_threader::UNREACHABLE_EDGE = (edge) -1; -back_threader::back_threader (bool speed_p, bool resolve) - : m_profit (speed_p), - m_solver (m_ranger, resolve) +back_threader::back_threader (function *fun, unsigned flags) + : m_profit (flags & BT_SPEED) { + if (flags & BT_SPEED) + loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES); + else + loop_optimizer_init (AVOID_CFG_MODIFICATIONS); + + m_fun = fun; + m_flags = flags; + m_ranger = new gimple_ranger; + m_solver = new path_range_query (*m_ranger, flags & BT_RESOLVE); m_last_stmt = NULL; - m_resolve = resolve; +} + +back_threader::~back_threader () +{ + delete m_solver; + delete m_ranger; + + loop_optimizer_finalize (); } // Register the current path for jump threading if it's profitable to @@ -186,8 +211,8 @@ back_threader::find_taken_edge_switch (const vec &path, tree name = gimple_switch_index (sw); int_range_max r; - m_solver.compute_ranges (path, m_imports); - m_solver.range_of_expr (r, name, sw); + m_solver->compute_ranges (path, m_imports); + m_solver->range_of_expr (r, name, sw); if (r.undefined_p ()) return UNREACHABLE_EDGE; @@ -210,10 +235,10 @@ back_threader::find_taken_edge_cond (const vec &path, { int_range_max r; - m_solver.compute_ranges (path, m_imports); - m_solver.range_of_stmt (r, cond); + m_solver->compute_ranges (path, m_imports); + m_solver->range_of_stmt (r, cond); - if (m_solver.unreachable_path_p ()) + if (m_solver->unreachable_path_p ()) return UNREACHABLE_EDGE; int_range<2> true_range (boolean_true_node, boolean_true_node); @@ -381,7 +406,7 @@ back_threader::find_paths_to_names (basic_block bb, bitmap interesting) // Examine blocks that define or export an interesting SSA, // since they may compute a range which resolve this path. if ((def_bb == bb - || bitmap_bit_p (m_ranger.gori ().exports (bb), i)) + || bitmap_bit_p (m_ranger->gori ().exports (bb), i)) && m_path.length () > 1) { if (maybe_register_path ()) @@ -436,7 +461,7 @@ back_threader::find_paths (basic_block bb, tree name) bitmap_clear (m_imports); auto_bitmap interesting; - bitmap_copy (m_imports, m_ranger.gori ().imports (bb)); + bitmap_copy (m_imports, m_ranger->gori ().imports (bb)); bitmap_copy (interesting, m_imports); find_paths_to_names (bb, interesting); } @@ -486,14 +511,6 @@ back_threader::maybe_thread_block (basic_block bb) find_paths (bb, name); } -// Perform the actual jump threading for the all queued paths. - -bool -back_threader::thread_through_all_blocks (bool may_peel_loop_headers) -{ - return m_registry.thread_through_all_blocks (may_peel_loop_headers); -} - // Dump a sequence of BBs through the CFG. DEBUG_FUNCTION void @@ -517,7 +534,7 @@ debug (const vec &path) void back_threader::dump (FILE *out) { - m_solver.dump (out); + m_solver->dump (out); fprintf (out, "\nCandidates for pre-computation:\n"); fprintf (out, "===================================\n"); @@ -888,40 +905,20 @@ back_threader_registry::register_path (const vec &m_path, // // Return TRUE if any jump thread paths were registered. -static bool -try_thread_blocks (function *fun, bool resolve, bool speed) +unsigned int +back_threader::thread_blocks () { - back_threader threader (speed, resolve); basic_block bb; - FOR_EACH_BB_FN (bb, fun) - { - if (EDGE_COUNT (bb->succs) > 1) - threader.maybe_thread_block (bb); - } - return threader.thread_through_all_blocks (/*peel_loop_headers=*/true); -} - -static unsigned int -do_early_thread_jumps (function *fun, bool resolve) -{ - loop_optimizer_init (AVOID_CFG_MODIFICATIONS); - - try_thread_blocks (fun, resolve, /*speed=*/false); + FOR_EACH_BB_FN (bb, m_fun) + if (EDGE_COUNT (bb->succs) > 1) + maybe_thread_block (bb); - loop_optimizer_finalize (); - return 0; -} - -static unsigned int -do_thread_jumps (function *fun, bool resolve) -{ - loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES); + bool changed = m_registry.thread_through_all_blocks (true); - bool changed = try_thread_blocks (fun, resolve, /*speed=*/true); + if (m_flags & BT_SPEED) + return changed ? TODO_cleanup_cfg : 0; - loop_optimizer_finalize (); - - return changed ? TODO_cleanup_cfg : 0; + return false; } namespace { @@ -983,7 +980,8 @@ public: } unsigned int execute (function *fun) override { - return do_early_thread_jumps (fun, /*resolve=*/false); + back_threader threader (fun, BT_NONE); + return threader.thread_blocks (); } }; @@ -1004,7 +1002,8 @@ public: } unsigned int execute (function *fun) override { - return do_thread_jumps (fun, /*resolve=*/false); + back_threader threader (fun, BT_SPEED); + return threader.thread_blocks (); } }; @@ -1025,7 +1024,8 @@ public: } unsigned int execute (function *fun) override { - return do_thread_jumps (fun, /*resolve=*/true); + back_threader threader (fun, BT_SPEED | BT_RESOLVE); + return threader.thread_blocks (); } };