From patchwork Sun Sep 19 15:37:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 45159 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 419B03857C5B for ; Sun, 19 Sep 2021 15:38:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 419B03857C5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632065880; bh=eJ2bZDeq0oQwDRbs6TP4da5G9IxsO6BHbjuNgGxMpxk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WD5GMmUEVcwOefRbBCqk4eePIpobyviR57JpYMFF+se8ZC/txp6qm+4zFQ3sqUu/7 vZ/3KjXY6DqEYqqEXhdw/HLSeGbjsetOE76q4Korlq2ihqxlGYiVXLPsAA5c8WMpyi nJFVwk54pa4fax/yFL/vDk6yYKLqCqUacBXZSQ4I= 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 ESMTP id 5F3DB3858415 for ; Sun, 19 Sep 2021 15:37:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F3DB3858415 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-145-xDkHOZnVO76XEnuR8b9zhQ-1; Sun, 19 Sep 2021 11:37:27 -0400 X-MC-Unique: xDkHOZnVO76XEnuR8b9zhQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EE12835DE3; Sun, 19 Sep 2021 15:37:26 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 561436B90C; Sun, 19 Sep 2021 15:37:23 +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 18JFbKlL177735 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 19 Sep 2021 17:37:21 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 18JFbKqo177734; Sun, 19 Sep 2021 17:37:20 +0200 To: GCC patches Subject: [PATCH] Minor cleanups to forward threader. Date: Sun, 19 Sep 2021 17:37:14 +0200 Message-Id: <20210919153715.177684-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.8 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Every time we allocate a threading edge we push it onto the path in a distinct step. There's no need to do this in two steps, and avoiding this, keeps us from exposing the internals of the registry. I've also did some tiny cleanups in thread_across_edge, most importantly removing the bitmap in favor of an auto_bitmap. There are no functional changes. OK pending tests? gcc/ChangeLog: * tree-ssa-threadbackward.c (back_threader_registry::register_path): Use push_edge. * tree-ssa-threadedge.c (jump_threader::thread_around_empty_blocks): Same. (jump_threader::thread_through_normal_block): Same. (jump_threader::thread_across_edge): Same. Also, use auto_bitmap. Tidy up code. * tree-ssa-threadupdate.c (jt_path_registry::allocate_thread_edge): Remove. (jt_path_registry::push_edge): New. (dump_jump_thread_path): Make static. * tree-ssa-threadupdate.h (allocate_thread_edge): Remove. (push_edge): New. --- gcc/tree-ssa-threadbackward.c | 10 ++--- gcc/tree-ssa-threadedge.c | 69 ++++++++++------------------------- gcc/tree-ssa-threadupdate.c | 12 +++--- gcc/tree-ssa-threadupdate.h | 2 +- 4 files changed, 30 insertions(+), 63 deletions(-) diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c index 805b7ac5ef6..c6530d3a6bb 100644 --- a/gcc/tree-ssa-threadbackward.c +++ b/gcc/tree-ssa-threadbackward.c @@ -902,15 +902,11 @@ back_threader_registry::register_path (const vec &m_path, edge e = find_edge (bb1, bb2); gcc_assert (e); - jump_thread_edge *x - = m_lowlevel_registry.allocate_thread_edge (e, EDGE_COPY_SRC_BLOCK); - jump_thread_path->safe_push (x); + m_lowlevel_registry.push_edge (jump_thread_path, e, EDGE_COPY_SRC_BLOCK); } - jump_thread_edge *x - = m_lowlevel_registry.allocate_thread_edge (taken_edge, - EDGE_NO_COPY_SRC_BLOCK); - jump_thread_path->safe_push (x); + m_lowlevel_registry.push_edge (jump_thread_path, + taken_edge, EDGE_NO_COPY_SRC_BLOCK); if (m_lowlevel_registry.register_jump_thread (jump_thread_path)) ++m_threaded_paths; diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index 2b9a4c31592..04138cb06fe 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -898,10 +898,7 @@ jump_threader::thread_around_empty_blocks (vec *path, if (!bitmap_bit_p (visited, taken_edge->dest->index)) { - jump_thread_edge *x - = m_registry->allocate_thread_edge (taken_edge, - EDGE_NO_COPY_SRC_BLOCK); - path->safe_push (x); + m_registry->push_edge (path, taken_edge, EDGE_NO_COPY_SRC_BLOCK); bitmap_set_bit (visited, taken_edge->dest->index); return thread_around_empty_blocks (path, taken_edge, visited); } @@ -942,10 +939,7 @@ jump_threader::thread_around_empty_blocks (vec *path, return false; bitmap_set_bit (visited, taken_edge->dest->index); - jump_thread_edge *x - = m_registry->allocate_thread_edge (taken_edge, - EDGE_NO_COPY_SRC_BLOCK); - path->safe_push (x); + m_registry->push_edge (path, taken_edge, EDGE_NO_COPY_SRC_BLOCK); thread_around_empty_blocks (path, taken_edge, visited); return true; @@ -1051,16 +1045,9 @@ jump_threader::thread_through_normal_block (vec *path, /* Only push the EDGE_START_JUMP_THREAD marker if this is first edge on the path. */ if (path->length () == 0) - { - jump_thread_edge *x - = m_registry->allocate_thread_edge (e, EDGE_START_JUMP_THREAD); - path->safe_push (x); - } + m_registry->push_edge (path, e, EDGE_START_JUMP_THREAD); - jump_thread_edge *x - = m_registry->allocate_thread_edge (taken_edge, - EDGE_COPY_SRC_BLOCK); - path->safe_push (x); + m_registry->push_edge (path, taken_edge, EDGE_COPY_SRC_BLOCK); /* See if we can thread through DEST as well, this helps capture secondary effects of threading without having to re-run DOM or @@ -1146,53 +1133,43 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e) void jump_threader::thread_across_edge (edge e) { - bitmap visited = BITMAP_ALLOC (NULL); + auto_bitmap visited; m_state->push (e); stmt_count = 0; vec *path = m_registry->allocate_thread_path (); - bitmap_clear (visited); bitmap_set_bit (visited, e->src->index); bitmap_set_bit (visited, e->dest->index); - int threaded; + int threaded = 0; if ((e->flags & EDGE_DFS_BACK) == 0) threaded = thread_through_normal_block (path, e, visited); - else - threaded = 0; if (threaded > 0) { propagate_threaded_block_debug_into (path->last ()->e->dest, e->dest); - BITMAP_FREE (visited); m_registry->register_jump_thread (path); m_state->pop (); return; } - else - { - /* Negative and zero return values indicate no threading was possible, - thus there should be no edges on the thread path and no need to walk - through the vector entries. */ - gcc_assert (path->length () == 0); - path->release (); - /* A negative status indicates the target block was deemed too big to - duplicate. Just quit now rather than trying to use the block as - a joiner in a jump threading path. + gcc_checking_assert (path->length () == 0); + path->release (); + + if (threaded < 0) + { + /* The target block was deemed too big to duplicate. Just quit + now rather than trying to use the block as a joiner in a jump + threading path. This prevents unnecessary code growth, but more importantly if we do not look at all the statements in the block, then we may have missed some invalidations if we had traversed a backedge! */ - if (threaded < 0) - { - BITMAP_FREE (visited); - m_state->pop (); - return; - } + m_state->pop (); + return; } /* We were unable to determine what out edge from E->dest is taken. However, @@ -1217,7 +1194,6 @@ jump_threader::thread_across_edge (edge e) if (taken_edge->flags & EDGE_COMPLEX) { m_state->pop (); - BITMAP_FREE (visited); return; } @@ -1235,17 +1211,11 @@ jump_threader::thread_across_edge (edge e) bitmap_set_bit (visited, e->src->index); bitmap_set_bit (visited, e->dest->index); bitmap_set_bit (visited, taken_edge->dest->index); - vec *path = m_registry->allocate_thread_path (); - /* Record whether or not we were able to thread through a successor - of E->dest. */ - jump_thread_edge *x - = m_registry->allocate_thread_edge (e, EDGE_START_JUMP_THREAD); - path->safe_push (x); + vec *path = m_registry->allocate_thread_path (); + m_registry->push_edge (path, e, EDGE_START_JUMP_THREAD); + m_registry->push_edge (path, taken_edge, EDGE_COPY_SRC_JOINER_BLOCK); - x = m_registry->allocate_thread_edge (taken_edge, - EDGE_COPY_SRC_JOINER_BLOCK); - path->safe_push (x); found = thread_around_empty_blocks (path, taken_edge, visited); if (!found) @@ -1267,7 +1237,6 @@ jump_threader::thread_across_edge (edge e) m_state->pop (); } - BITMAP_FREE (visited); } m_state->pop (); diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index c5a742312ef..baac11280fa 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -196,10 +196,12 @@ back_jt_path_registry::back_jt_path_registry () { } -jump_thread_edge * -jt_path_registry::allocate_thread_edge (edge e, jump_thread_edge_type t) +void +jt_path_registry::push_edge (vec *path, + edge e, jump_thread_edge_type type) { - return m_allocator.allocate_thread_edge (e, t); + jump_thread_edge *x = m_allocator.allocate_thread_edge (e, type); + path->safe_push (x); } vec * @@ -211,9 +213,9 @@ jt_path_registry::allocate_thread_path () /* Dump a jump threading path, including annotations about each edge in the path. */ -void +static void dump_jump_thread_path (FILE *dump_file, - const vec path, + const vec &path, bool registering) { fprintf (dump_file, diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h index 94c9bc8d3bb..8b48a671212 100644 --- a/gcc/tree-ssa-threadupdate.h +++ b/gcc/tree-ssa-threadupdate.h @@ -66,7 +66,7 @@ public: virtual ~jt_path_registry (); bool register_jump_thread (vec *); bool thread_through_all_blocks (bool peel_loop_headers); - jump_thread_edge *allocate_thread_edge (edge e, jump_thread_edge_type t); + void push_edge (vec *path, edge, jump_thread_edge_type); vec *allocate_thread_path (); void debug (); protected: