public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v3)] Add caching of BB insns. Date: Wed, 24 Nov 2021 14:04:22 +0000 (GMT) [thread overview] Message-ID: <20211124140422.A81233857C65@sourceware.org> (raw) https://gcc.gnu.org/g:4395f309f86026f79542a2e371aeaec2b94c11c3 commit 4395f309f86026f79542a2e371aeaec2b94c11c3 Author: Martin Liska <mliska@suse.cz> Date: Wed Nov 24 12:12:25 2021 +0100 Add caching of BB insns. Diff: --- gcc/tree-ssa-loop-unswitch.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index 57ddd769b31..35b8be935b2 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -106,6 +106,24 @@ static void hoist_guard (class loop *, edge); static bool check_exit_phi (class loop *); static tree get_vop_from_header (class loop *); +static void +calculate_loop_insns (class loop *loop) +{ + basic_block *bbs = get_loop_body (loop); + + for (unsigned i = 0; i < loop->num_nodes; i++) + { + unsigned insns = 0; + for (gimple_stmt_iterator gsi = gsi_start_bb (bbs[i]); !gsi_end_p (gsi); + gsi_next (&gsi)) + insns += estimate_num_insns (gsi_stmt (gsi), &eni_size_weights); + + bbs[i]->aux = (void *)(size_t)insns; + } + + free (bbs); +} + /* Main entry point. Perform loop unswitching on all suitable loops. */ unsigned int @@ -119,8 +137,11 @@ tree_ssa_unswitch_loops (void) for (auto loop : loops_list (cfun, LI_FROM_INNERMOST)) { if (!loop->inner) - /* Unswitch innermost loop. */ - changed |= tree_unswitch_single_loop (loop, 0, ranger, NULL, false); + { + /* Unswitch innermost loop. */ + calculate_loop_insns (loop); + changed |= tree_unswitch_single_loop (loop, 0, ranger, NULL, false); + } else changed |= tree_unswitch_outer_loop (loop); } @@ -418,9 +439,7 @@ evaluate_insns (class loop *loop, basic_block *bbs, for (unsigned i = 0; i < loop->num_nodes; i++) if (bbs[i]->flags & reachable_flag) - for (gimple_stmt_iterator gsi = gsi_start_bb (bbs[i]); !gsi_end_p (gsi); - gsi_next (&gsi)) - size += estimate_num_insns (gsi_stmt (gsi), &eni_size_weights); + size += (size_t)bbs[i]->aux; /* Clear the flag from basic blocks. */ for (unsigned i = 0; i < loop->num_nodes; i++) @@ -544,6 +563,13 @@ tree_unswitch_single_loop (class loop *loop, int num, gimple_ranger *ranger, goto exit; } + /* Copy BB costs. */ + basic_block *bbs2 = get_loop_body (nloop); + for (unsigned i = 0; i < nloop->num_nodes; i++) + bbs2[i]->aux = get_bb_original (bbs2[i])->aux; + + free (bbs2); + /* Update the SSA form after unswitching. */ update_ssa (TODO_update_ssa); free_original_copy_tables ();
next reply other threads:[~2021-11-24 14:04 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-24 14:04 Martin Liska [this message] 2021-11-24 14:34 Martin Liska 2021-11-29 11:13 Martin Liska
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211124140422.A81233857C65@sourceware.org \ --to=marxin@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).