public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v3)] Add caching of BB insns.
@ 2021-11-24 14:34 Martin Liska
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Liska @ 2021-11-24 14:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:099d62f35327cbce186df2e70076826bb4ea6833

commit 099d62f35327cbce186df2e70076826bb4ea6833
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 ();


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v3)] Add caching of BB insns.
@ 2021-11-29 11:13 Martin Liska
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Liska @ 2021-11-29 11:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d39e5f541b7dbfc64ee7737eab51da43cb9cef12

commit d39e5f541b7dbfc64ee7737eab51da43cb9cef12
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 ();


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v3)] Add caching of BB insns.
@ 2021-11-24 14:04 Martin Liska
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Liska @ 2021-11-24 14:04 UTC (permalink / raw)
  To: gcc-cvs

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 ();


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-29 11:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 14:34 [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v3)] Add caching of BB insns Martin Liska
  -- strict thread matches above, loose matches on Subject: below --
2021-11-29 11:13 Martin Liska
2021-11-24 14:04 Martin Liska

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).