From patchwork Wed Nov 10 16:45:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1553513 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=tsmEpFJP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9jS6BSgz9sCD for ; Thu, 11 Nov 2021 03:46:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9ACFE385840C for ; Wed, 10 Nov 2021 16:46:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9ACFE385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636562794; bh=KY6u2Eacky40H3v7quedlvVLIKrrqUSp9lqGkHcvz/A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tsmEpFJP2oSUyqGPB7PX1e4SxYheGFAlalkxUmFRIBQo/0dqf8mkIMBOtWoeUjahR 8kfdvbnYDtLQBN1/v3zZLcawbbIvTB4Gdh0xTeAow5Pkev1/WPmOy9jjc51mR+9/Mf O1fRLEDo2XcXxI6PBSPtb4axTPsWTEFLLut6zskE= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 179A33858400 for ; Wed, 10 Nov 2021 16:46:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 179A33858400 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-582-Ut_wpxKPPAGZblmzpUFuZA-1; Wed, 10 Nov 2021 11:46:11 -0500 X-MC-Unique: Ut_wpxKPPAGZblmzpUFuZA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D046804149; Wed, 10 Nov 2021 16:46:10 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.203]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B6D919D9F; Wed, 10 Nov 2021 16:45:51 +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 1AAGjnBh681111 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 10 Nov 2021 17:45:49 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 1AAGjnMC681110; Wed, 10 Nov 2021 17:45:49 +0100 To: GCC patches Subject: [COMMITTED] path solver: Adjustments for use outside of the backward threader. Date: Wed, 10 Nov 2021 17:45:41 +0100 Message-Id: <20211110164541.681061-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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 Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here are some enhancements to make it easier for other clients to use the path solver. First, I've made the imports to the solver optional since we can calculate them ourselves. However, I've left the ability to set them, since the backward threader adds a few SSA names in addition to the default ones. As a follow-up I may move all the import set up code from the threader to the solver, as the extra imports tend to improve the behavior slightly. Second, Richi suggested an entry point where you just feed the solver an edge, which will be quite convenient for a subsequent patch adding a client in the header copying pass. The required some shuffling, since we'll be adding the blocks on the fly. There's now a vector copy, but the impact will be minimal, since these are just 5-6 entries at the most. Tested on ppc64le Linux. gcc/ChangeLog: * gimple-range-path.cc (path_range_query::path_range_query): Do not init m_path. (path_range_query::dump): Change m_path uses to non-pointer. (path_range_query::defined_outside_path): Same. (path_range_query::set_path): Same. (path_range_query::add_copies_to_imports): Same. (path_range_query::range_of_stmt): Same. (path_range_query::compute_outgoing_relations): Same. (path_range_query::compute_ranges): Imports are now optional. Implement overload that takes an edge. * gimple-range-path.h (class path_range_query): Make imports optional for compute_ranges. Add compute_ranges(edge) overload. Make m_path an auto_vec instead of a pointer and adjust accordingly. --- gcc/gimple-range-path.cc | 41 +++++++++++++++++++++++++++++----------- gcc/gimple-range-path.h | 17 +++++++++-------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 99ac947581b..6da01c7067f 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -41,7 +41,6 @@ path_range_query::path_range_query (gimple_ranger &ranger, bool resolve) { m_cache = new ssa_global_cache; m_has_cache_entry = BITMAP_ALLOC (NULL); - m_path = NULL; m_resolve = resolve; m_oracle = new path_oracle (ranger.oracle ()); } @@ -92,13 +91,13 @@ path_range_query::dump (FILE *dump_file) { push_dump_file save (dump_file, dump_flags & ~TDF_DETAILS); - if (m_path->is_empty ()) + if (m_path.is_empty ()) return; unsigned i; bitmap_iterator bi; - dump_ranger (dump_file, *m_path); + dump_ranger (dump_file, m_path); fprintf (dump_file, "Imports:\n"); EXECUTE_IF_SET_IN_BITMAP (m_imports, 0, i, bi) @@ -125,7 +124,7 @@ path_range_query::defined_outside_path (tree name) gimple *def = SSA_NAME_DEF_STMT (name); basic_block bb = gimple_bb (def); - return !bb || !m_path->contains (bb); + return !bb || !m_path.contains (bb); } // Return the range of NAME on entry to the path. @@ -230,8 +229,8 @@ void path_range_query::set_path (const vec &path) { gcc_checking_assert (path.length () > 1); - m_path = &path; - m_pos = m_path->length () - 1; + m_path = path.copy (); + m_pos = m_path.length () - 1; bitmap_clear (m_has_cache_entry); } @@ -486,7 +485,7 @@ path_range_query::add_copies_to_imports () tree arg = gimple_phi_arg (phi, i)->def; if (TREE_CODE (arg) == SSA_NAME - && m_path->contains (e->src) + && m_path.contains (e->src) && bitmap_set_bit (m_imports, SSA_NAME_VERSION (arg))) worklist.safe_push (arg); } @@ -497,7 +496,8 @@ path_range_query::add_copies_to_imports () // Compute the ranges for IMPORTS along PATH. // // IMPORTS are the set of SSA names, any of which could potentially -// change the value of the final conditional in PATH. +// change the value of the final conditional in PATH. Default to the +// imports of the last block in the path if none is given. void path_range_query::compute_ranges (const vec &path, @@ -507,9 +507,16 @@ path_range_query::compute_ranges (const vec &path, fprintf (dump_file, "\n==============================================\n"); set_path (path); - bitmap_copy (m_imports, imports); m_undefined_path = false; + if (imports) + bitmap_copy (m_imports, imports); + else + { + bitmap imports = m_ranger.gori ().imports (exit_bb ()); + bitmap_copy (m_imports, imports); + } + if (m_resolve) { add_copies_to_imports (); @@ -561,6 +568,18 @@ path_range_query::compute_ranges (const vec &path, } } +// Convenience function to compute ranges along a path consisting of +// E->SRC and E->DEST. + +void +path_range_query::compute_ranges (edge e) +{ + auto_vec bbs (2); + bbs.quick_push (e->dest); + bbs.quick_push (e->src); + compute_ranges (bbs); +} + // A folding aid used to register and query relations along a path. // When queried, it returns relations as they would appear on exit to // the path. @@ -643,7 +662,7 @@ path_range_query::range_of_stmt (irange &r, gimple *stmt, tree) if (m_resolve) { fold_using_range f; - jt_fur_source src (stmt, this, &m_ranger.gori (), *m_path); + jt_fur_source src (stmt, this, &m_ranger.gori (), m_path); if (!f.fold_stmt (r, stmt, src)) r.set_varying (type); } @@ -734,7 +753,7 @@ path_range_query::compute_outgoing_relations (basic_block bb, basic_block next) else gcc_unreachable (); - jt_fur_source src (NULL, this, &m_ranger.gori (), *m_path); + jt_fur_source src (NULL, this, &m_ranger.gori (), m_path); src.register_outgoing_edges (cond, r, e0, e1); } } diff --git a/gcc/gimple-range-path.h b/gcc/gimple-range-path.h index f21d07f71c4..b73549f01a5 100644 --- a/gcc/gimple-range-path.h +++ b/gcc/gimple-range-path.h @@ -34,7 +34,8 @@ class path_range_query : public range_query public: path_range_query (class gimple_ranger &ranger, bool resolve); virtual ~path_range_query (); - void compute_ranges (const vec &, const bitmap_head *imports); + void compute_ranges (const vec &, const bitmap_head *imports = NULL); + void compute_ranges (edge e); bool range_of_expr (irange &r, tree name, gimple * = NULL) override; bool range_of_stmt (irange &r, gimple *, tree name = NULL) override; bool unreachable_path_p (); @@ -66,12 +67,12 @@ private: // Path navigation. void set_path (const vec &); - basic_block entry_bb () { return (*m_path)[m_path->length () - 1]; } - basic_block exit_bb () { return (*m_path)[0]; } - basic_block curr_bb () { return (*m_path)[m_pos]; } - basic_block prev_bb () { return (*m_path)[m_pos + 1]; } - basic_block next_bb () { return (*m_path)[m_pos - 1]; } - bool at_entry () { return m_pos == m_path->length () - 1; } + basic_block entry_bb () { return m_path[m_path.length () - 1]; } + basic_block exit_bb () { return m_path[0]; } + basic_block curr_bb () { return m_path[m_pos]; } + basic_block prev_bb () { return m_path[m_pos + 1]; } + basic_block next_bb () { return m_path[m_pos - 1]; } + bool at_entry () { return m_pos == m_path.length () - 1; } bool at_exit () { return m_pos == 0; } void move_next () { --m_pos; } @@ -82,7 +83,7 @@ private: bitmap m_has_cache_entry; // Path being analyzed. - const vec *m_path; + auto_vec m_path; auto_bitmap m_imports; gimple_ranger &m_ranger;