From patchwork Fri Apr 21 11:25:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 86250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp992557vqo; Fri, 21 Apr 2023 04:26:00 -0700 (PDT) X-Google-Smtp-Source: AKy350ZeyZvpE1gS39szr5tQa58BxOd3uATkHHscTJzgIYRJIt8faYL/1YTnKlJcRNSawHkybmMo X-Received: by 2002:aa7:ccd7:0:b0:509:bd16:db9b with SMTP id y23-20020aa7ccd7000000b00509bd16db9bmr1796241edt.22.1682076360781; Fri, 21 Apr 2023 04:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682076360; cv=none; d=google.com; s=arc-20160816; b=mlb/2L7kpKJ89+c+2mUDNtBZvQNDG63XyGVffLF7PsXANLD0v0DGZ89iyRTwPueeSK L/tM5UhnWORZ82XJMzf4vr81OgLw4ECVT8yIB+fvOoMAUeY4WXqPU09ftqbJz1qTzpJl MMnwwRioQFhtNdFDKa8tGBa0CyL2hFqQKEVIlAu69jhyoaLm2GCsnZCikxd9mgt/eMfe ehHW/Hq49yV3KGDfBv3eRbWLy4mejvE+4M0JoGAKRd4BPrttIc3IEbIk3Gl0tQDHnNsG qRx+Ycv7Ncfs43I8jvHJZQFmjPeOkKkg9GOh1Lo/RJQMn66kiYblITRwPIOpE6kfUIad MDmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=r/MviRuekkzkWVxDvPBsO30JYglLh3mcyDmD/cvTRpE=; b=hNVjE8CFx2//jdUxhiAhCBBbWbt0bJawu0pE7h1nJ40CX/6rIKUbh9VpOjvIRS3fuj gf/ov0qvVU22PH4SDX8aPPJumk4cF9ZBntQpKmim9FZPZR0Esf9aw0emOIxb8hjyzTmQ st/sAcP3TemBtCk4Tv4MyRFwyi3Jqn2dHsBO4K/sGGy89avgppm4kCX9lclgMHp4KRC6 FrqtqprlWytIrGL7sf685pZR6pN04dy2n3/Vl5ZlyRpQVdK/97zW9jAcUcgvHA939feb 8OcnXW2ShO9SsAodyUUIunXiKby3fN2TJ34RQLbsFlboLM+0C1nHI+oBMYms8Wz9UJ3t edGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PPWmbmiA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j16-20020aa7ca50000000b005069836fed6si757480edt.608.2023.04.21.04.26.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 04:26:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PPWmbmiA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EF3BC385700A for ; Fri, 21 Apr 2023 11:25:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF3BC385700A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682076353; bh=r/MviRuekkzkWVxDvPBsO30JYglLh3mcyDmD/cvTRpE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PPWmbmiAXCgcyBIPKlyJN1r0MRUlwtTGdAgbmGuDXQkFUlWrrOc47lQeCrb4dewWZ VNHmjGmsct1zRghPlF7j9XUSkFoXwhCyRtEvC/alk0cITKwPeHnm7VlX0xvqwklGlo BNUgvKZmWyiS+CHjsPVateV0HNyQUBEsQ1XyRqMA= 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:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 81F793857732 for ; Fri, 21 Apr 2023 11:25:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81F793857732 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B17621FDDC for ; Fri, 21 Apr 2023 11:25:05 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9E91D13456 for ; Fri, 21 Apr 2023 11:25:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zqelJZFyQmQMEgAAMHmgww (envelope-from ) for ; Fri, 21 Apr 2023 11:25:05 +0000 Date: Fri, 21 Apr 2023 13:25:05 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] change inverted_post_order_compute to inverted_rev_post_order_compute MIME-Version: 1.0 Message-Id: <20230421112505.9E91D13456@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763784902394755469?= X-GMAIL-MSGID: =?utf-8?q?1763784902394755469?= The following changes the inverted_post_order_compute API back to a plain C array interface and computing a reverse post order since that's what's always required. It will make massaging DF to use the correct iteration orders easier. Elsewhere it requires turning backward iteration over the computed order with forward iteration. Bootstrapped and tested on x86_64-unknown-linux-gnu. * cfganal.h (inverted_rev_post_order_compute): Rename from ... (inverted_post_order_compute): ... this. Add struct function argument, change allocation to a C array. * cfganal.cc (inverted_rev_post_order_compute): Likewise. * lcm.cc (compute_antinout_edge): Adjust. * lra-lives.cc (lra_create_live_ranges_1): Likewise. * tree-ssa-dce.cc (remove_dead_stmt): Likewise. * tree-ssa-pre.cc (compute_antic): Likewise. --- gcc/cfganal.cc | 41 ++++++++++++++++++++++------------------- gcc/cfganal.h | 3 ++- gcc/lcm.cc | 9 +++++---- gcc/lra-lives.cc | 11 ++++++----- gcc/tree-ssa-dce.cc | 15 ++++++++------- gcc/tree-ssa-pre.cc | 18 ++++++++++-------- 6 files changed, 53 insertions(+), 44 deletions(-) diff --git a/gcc/cfganal.cc b/gcc/cfganal.cc index ef24c5e4d15..cc858b99e64 100644 --- a/gcc/cfganal.cc +++ b/gcc/cfganal.cc @@ -740,7 +740,7 @@ post_order_compute (int *post_order, bool include_entry_exit, } -/* Helper routine for inverted_post_order_compute +/* Helper routine for inverted_rev_post_order_compute flow_dfs_compute_reverse_execute, and the reverse-CFG deapth first search in dominance.cc. BB has to belong to a region of CFG @@ -820,12 +820,14 @@ dfs_find_deadend (basic_block bb) and start looking for a "dead end" from that block and do another inverted traversal from that block. */ -void -inverted_post_order_compute (vec *post_order, - sbitmap *start_points) +int +inverted_rev_post_order_compute (struct function *fn, + int *rev_post_order, + sbitmap *start_points) { basic_block bb; - post_order->reserve_exact (n_basic_blocks_for_fn (cfun)); + + int rev_post_order_num = n_basic_blocks_for_fn (fn) - 1; if (flag_checking) verify_no_unreachable_blocks (); @@ -855,17 +857,17 @@ inverted_post_order_compute (vec *post_order, } } else - /* Put all blocks that have no successor into the initial work list. */ - FOR_ALL_BB_FN (bb, cfun) - if (EDGE_COUNT (bb->succs) == 0) - { - /* Push the initial edge on to the stack. */ - if (EDGE_COUNT (bb->preds) > 0) - { - stack.quick_push (ei_start (bb->preds)); - bitmap_set_bit (visited, bb->index); - } - } + /* Put all blocks that have no successor into the initial work list. */ + FOR_ALL_BB_FN (bb, cfun) + if (EDGE_COUNT (bb->succs) == 0) + { + /* Push the initial edge on to the stack. */ + if (EDGE_COUNT (bb->preds) > 0) + { + stack.quick_push (ei_start (bb->preds)); + bitmap_set_bit (visited, bb->index); + } + } do { @@ -893,13 +895,13 @@ inverted_post_order_compute (vec *post_order, time, check its predecessors. */ stack.quick_push (ei_start (pred->preds)); else - post_order->quick_push (pred->index); + rev_post_order[rev_post_order_num--] = pred->index; } else { if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun) && ei_one_before_end_p (ei)) - post_order->quick_push (bb->index); + rev_post_order[rev_post_order_num--] = bb->index; if (!ei_one_before_end_p (ei)) ei_next (&stack.last ()); @@ -957,7 +959,8 @@ inverted_post_order_compute (vec *post_order, while (!stack.is_empty ()); /* EXIT_BLOCK is always included. */ - post_order->quick_push (EXIT_BLOCK); + rev_post_order[rev_post_order_num--] = EXIT_BLOCK; + return n_basic_blocks_for_fn (fn); } /* Compute the depth first search order of FN and store in the array diff --git a/gcc/cfganal.h b/gcc/cfganal.h index 0b6c67dfab5..5af917c27dd 100644 --- a/gcc/cfganal.h +++ b/gcc/cfganal.h @@ -66,7 +66,8 @@ extern void add_noreturn_fake_exit_edges (void); extern void connect_infinite_loops_to_exit (void); extern int post_order_compute (int *, bool, bool); extern basic_block dfs_find_deadend (basic_block); -extern void inverted_post_order_compute (vec *postorder, sbitmap *start_points = 0); +extern int inverted_rev_post_order_compute (struct function *, + int *, sbitmap *start_points = 0); extern int pre_and_rev_post_order_compute_fn (struct function *, int *, int *, bool); extern int pre_and_rev_post_order_compute (int *, int *, bool); diff --git a/gcc/lcm.cc b/gcc/lcm.cc index 5adb4eb1a11..94a3ed43aea 100644 --- a/gcc/lcm.cc +++ b/gcc/lcm.cc @@ -102,17 +102,18 @@ compute_antinout_edge (sbitmap *antloc, sbitmap *transp, sbitmap *antin, optimistic initialization of ANTIN above. Use reverse postorder on the inverted graph to make the backward dataflow problem require less iterations. */ - auto_vec postorder; - inverted_post_order_compute (&postorder); - for (int i = postorder.length () - 1; i >= 0; --i) + int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); + int n = inverted_rev_post_order_compute (cfun, rpo); + for (int i = 0; i < n; ++i) { - bb = BASIC_BLOCK_FOR_FN (cfun, postorder[i]); + bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]); if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)) continue; *qin++ = bb; bb->aux = bb; } + free (rpo); qin = worklist; qend = &worklist[n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS]; diff --git a/gcc/lra-lives.cc b/gcc/lra-lives.cc index f7a7066055a..f7a3ba8d76a 100644 --- a/gcc/lra-lives.cc +++ b/gcc/lra-lives.cc @@ -1405,19 +1405,20 @@ lra_create_live_ranges_1 (bool all_p, bool dead_insn_p) point_freq_vec.truncate (0); point_freq_vec.reserve_exact (new_length); lra_point_freq = point_freq_vec.address (); - auto_vec post_order_rev_cfg; - inverted_post_order_compute (&post_order_rev_cfg); - lra_assert (post_order_rev_cfg.length () == (unsigned) n_basic_blocks_for_fn (cfun)); + int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); + int n = inverted_rev_post_order_compute (cfun, rpo); + lra_assert (n == n_basic_blocks_for_fn (cfun)); bb_live_change_p = false; - for (i = post_order_rev_cfg.length () - 1; i >= 0; --i) + for (i = 0; i < n; ++i) { - bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]); + bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]); if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)) continue; if (process_bb_lives (bb, curr_point, dead_insn_p)) bb_live_change_p = true; } + free (rpo); if (bb_live_change_p) { /* We need to clear pseudo live info as some pseudos can diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index bda780876f3..08876bfc1c7 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -1095,7 +1095,7 @@ remove_dead_stmt (gimple_stmt_iterator *i, basic_block bb, nothing to the program, then we not only remove it, but we need to update the CFG. We can chose any of edges out of BB as long as we are sure to not close infinite loops. This is done by always choosing the edge closer to - exit in inverted_post_order_compute order. */ + exit in inverted_rev_post_order_compute order. */ if (is_ctrl_stmt (stmt)) { edge_iterator ei; @@ -1111,17 +1111,18 @@ remove_dead_stmt (gimple_stmt_iterator *i, basic_block bb, { if (!bb_postorder) { - auto_vec postorder; - inverted_post_order_compute (&postorder, - &bb_contains_live_stmts); + int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); + int n = inverted_rev_post_order_compute (cfun, rpo, + &bb_contains_live_stmts); bb_postorder = XNEWVEC (int, last_basic_block_for_fn (cfun)); - for (unsigned int i = 0; i < postorder.length (); ++i) - bb_postorder[postorder[i]] = i; + for (int i = 0; i < n; ++i) + bb_postorder[rpo[i]] = i; + free (rpo); } FOR_EACH_EDGE (e2, ei, bb->succs) if (!e || e2->dest == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb_postorder [e->dest->index] - < bb_postorder [e2->dest->index]) + >= bb_postorder [e2->dest->index]) e = e2; } gcc_assert (e); diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index 37cad36f2de..943936df808 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -2464,8 +2464,8 @@ compute_antic (void) /* For ANTIC computation we need a postorder that also guarantees that a block with a single successor is visited after its successor. RPO on the inverted CFG has this property. */ - auto_vec postorder; - inverted_post_order_compute (&postorder); + int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); + int n = inverted_rev_post_order_compute (cfun, rpo); auto_sbitmap worklist (last_basic_block_for_fn (cfun) + 1); bitmap_clear (worklist); @@ -2481,11 +2481,11 @@ compute_antic (void) for PA ANTIC computation. */ num_iterations++; changed = false; - for (i = postorder.length () - 1; i >= 0; i--) + for (i = 0; i < n; ++i) { - if (bitmap_bit_p (worklist, postorder[i])) + if (bitmap_bit_p (worklist, rpo[i])) { - basic_block block = BASIC_BLOCK_FOR_FN (cfun, postorder[i]); + basic_block block = BASIC_BLOCK_FOR_FN (cfun, rpo[i]); bitmap_clear_bit (worklist, block->index); if (compute_antic_aux (block, bitmap_bit_p (has_abnormal_preds, @@ -2513,15 +2513,17 @@ compute_antic (void) if (do_partial_partial) { /* For partial antic we ignore backedges and thus we do not need - to perform any iteration when we process blocks in postorder. */ - for (i = postorder.length () - 1; i >= 0; i--) + to perform any iteration when we process blocks in rpo. */ + for (i = 0; i < n; ++i) { - basic_block block = BASIC_BLOCK_FOR_FN (cfun, postorder[i]); + basic_block block = BASIC_BLOCK_FOR_FN (cfun, rpo[i]); compute_partial_antic_aux (block, bitmap_bit_p (has_abnormal_preds, block->index)); } } + + free (rpo); }