public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/pheeck/heads/sccp)] added cleanup from tree-ssa-propagate to sccp
@ 2023-02-27 18:42 Filip Kastl
  0 siblings, 0 replies; only message in thread
From: Filip Kastl @ 2023-02-27 18:42 UTC (permalink / raw)
  To: gcc-cvs

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

commit e85c306a66ac49cff74882f62267bc28a68d61d7
Author: Filip Kastl <filip.kastl@gmail.com>
Date:   Mon Feb 27 19:42:46 2023 +0100

    added cleanup from tree-ssa-propagate to sccp

Diff:
---
 gcc/sccp.cc               |  32 +++++++++++--
 gcc/tree-ssa-propagate.cc | 116 ++++++++++++++++++++++++++++------------------
 gcc/tree-ssa-propagate.h  |   7 +++
 3 files changed, 104 insertions(+), 51 deletions(-)

diff --git a/gcc/sccp.cc b/gcc/sccp.cc
index da8b38e6971..33a8ac3795f 100644
--- a/gcc/sccp.cc
+++ b/gcc/sccp.cc
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-fold.h"
 #include "gimplify.h"
 #include "tree-cfg.h"
+#include "tree-ssa-propagate.h"
 
 // DEBUG
 #include <iostream>
@@ -445,7 +446,8 @@ tarjan_compute_sccs (auto_vec<gimple *> &copy_stmts)
 }
 
 static void
-replace_use_by (tree get_replaced, tree replace_by)
+replace_use_by (tree get_replaced, tree replace_by, bitmap need_eh_cleanup,
+		bitmap need_ab_cleanup, vec<gimple *> stmts_to_fixup)
 {
   /* Replace each occurence of 'get_replaced' by 'replace_by'.  */
   use_operand_p use_p;
@@ -467,7 +469,10 @@ replace_use_by (tree get_replaced, tree replace_by)
 
       /* Cleanup.  */
       gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
-      fold_stmt_inplace (&gsi);
+      fold_stmt (&gsi);
+      cleanup_after_replace (use_stmt, gsi_stmt (gsi), need_eh_cleanup,
+			     need_ab_cleanup, stmts_to_fixup,
+			     false, false);
       update_stmt (use_stmt);
     }
 }
@@ -476,7 +481,9 @@ replace_use_by (tree get_replaced, tree replace_by)
    variable.  */
 
 static void
-replace_scc_by_value (vec<gimple *> scc, tree replace_by)
+replace_scc_by_value (vec<gimple *> scc, tree replace_by, bitmap
+		      need_eh_cleanup, bitmap need_ab_cleanup, vec<gimple *>
+		      stmts_to_fixup)
 {
   // DEBUG
   /*
@@ -489,7 +496,8 @@ replace_scc_by_value (vec<gimple *> scc, tree replace_by)
   for (gimple *stmt : scc)
     {
       tree get_replaced = gimple_get_lhs (stmt);
-      replace_use_by (get_replaced, replace_by);
+      replace_use_by (get_replaced, replace_by, need_eh_cleanup,
+		      need_ab_cleanup, stmts_to_fixup);
     }
 }
 
@@ -548,6 +556,11 @@ sccp_propagate (auto_vec<gimple *> &copy_stmts)
   auto_vec<vec<gimple *>> worklist;
   worklist = tarjan_compute_sccs (copy_stmts);
 
+  /* Prepare data structs for cleanup after stmt modification.  */
+  bitmap need_eh_cleanup = BITMAP_ALLOC (NULL);
+  bitmap need_ab_cleanup = BITMAP_ALLOC (NULL);
+  vec<gimple *> stmts_to_fixup = vNULL;
+
   while (!worklist.is_empty ())
     {
       vec<gimple *> scc = worklist.pop ();
@@ -601,7 +614,8 @@ sccp_propagate (auto_vec<gimple *> &copy_stmts)
 	  /* The only operand in outer_ops.  */
 	  tree outer_op = last_outer_op;
 
-	  replace_scc_by_value (scc, outer_op);
+	  replace_scc_by_value (scc, outer_op, need_eh_cleanup,
+				need_ab_cleanup, stmts_to_fixup);
 	}
       else if (outer_ops.elements () > 1)
 	{
@@ -620,6 +634,14 @@ sccp_propagate (auto_vec<gimple *> &copy_stmts)
       scc.release ();
     }
 
+  cleanup_after_all_replaces_done (need_eh_cleanup, need_ab_cleanup,
+				   stmts_to_fixup);
+
+  /* Remove data structs for cleanup after stmt modification.  */
+  BITMAP_FREE (need_eh_cleanup);
+  BITMAP_FREE (need_ab_cleanup);
+  // TODO Should I free the vec? Or is it freed automatically?
+
   /* We want to remove dead MEM PHIs because memory is in FUD SSA and the dead
      PHIs would break the FUD property.  */
   remove_zero_uses_phis ();
diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc
index 976b035eeec..e0eeae70ece 100644
--- a/gcc/tree-ssa-propagate.cc
+++ b/gcc/tree-ssa-propagate.cc
@@ -129,7 +129,6 @@ static vec<gimple *> uid_to_stmt;
 /* Current RPO index in the iteration.  */
 static int curr_order;
 
-
 /* We have just defined a new value for VAR.  If IS_VARYING is true,
    add all immediate uses of VAR to VARYING_SSA_EDGES, otherwise add
    them to INTERESTING_SSA_EDGES.  */
@@ -905,31 +904,9 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
 	{
 	  foreach_new_stmt_in_bb (prev_gsi, i);
 
-	  /* If we cleaned up EH information from the statement,
-	     remove EH edges.  */
-	  if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
-	    bitmap_set_bit (need_eh_cleanup, bb->index);
-
-	  /* If we turned a call with possible abnormal control transfer
-	     into one that doesn't, remove abnormal edges.  */
-	  if (can_make_abnormal_goto
-	      && !stmt_can_make_abnormal_goto (stmt))
-	    bitmap_set_bit (need_ab_cleanup, bb->index);
-
-	  /* If we turned a not noreturn call into a noreturn one
-	     schedule it for fixup.  */
-	  if (!was_noreturn
-	      && is_gimple_call (stmt)
-	      && gimple_call_noreturn_p (stmt))
-	    stmts_to_fixup.safe_push (stmt);
-
-	  if (gimple_assign_single_p (stmt))
-	    {
-	      tree rhs = gimple_assign_rhs1 (stmt);
-
-	      if (TREE_CODE (rhs) == ADDR_EXPR)
-		recompute_tree_invariant_for_addr_expr (rhs);
-	    }
+	  cleanup_after_replace (old_stmt, stmt, need_eh_cleanup,
+				 need_ab_cleanup, stmts_to_fixup,
+				 can_make_abnormal_goto, was_noreturn);
 
 	  /* Determine what needs to be done to update the SSA form.  */
 	  update_stmt_if_modified (stmt);
@@ -1021,26 +998,9 @@ substitute_and_fold_engine::substitute_and_fold (basic_block block)
 	}
     }
 
-  if (!bitmap_empty_p (walker.need_eh_cleanup))
-    gimple_purge_all_dead_eh_edges (walker.need_eh_cleanup);
-  if (!bitmap_empty_p (walker.need_ab_cleanup))
-    gimple_purge_all_dead_abnormal_call_edges (walker.need_ab_cleanup);
-
-  /* Fixup stmts that became noreturn calls.  This may require splitting
-     blocks and thus isn't possible during the dominator walk.  Do this
-     in reverse order so we don't inadvertedly remove a stmt we want to
-     fixup by visiting a dominating now noreturn call first.  */
-  while (!walker.stmts_to_fixup.is_empty ())
-    {
-      gimple *stmt = walker.stmts_to_fixup.pop ();
-      if (dump_file && dump_flags & TDF_DETAILS)
-	{
-	  fprintf (dump_file, "Fixing up noreturn call ");
-	  print_gimple_stmt (dump_file, stmt, 0);
-	  fprintf (dump_file, "\n");
-	}
-      fixup_noreturn_call (stmt);
-    }
+  cleanup_after_all_replaces_done (walker.need_eh_cleanup,
+				   walker.need_ab_cleanup,
+				   walker.stmts_to_fixup);
 
   statistics_counter_event (cfun, "Constants propagated",
 			    prop_stats.num_const_prop);
@@ -1321,3 +1281,67 @@ clean_up_loop_closed_phi (function *fun)
 
   return 0;
 }
+
+/* TODO Comment.  */
+
+void
+cleanup_after_replace (gimple *old_stmt, gimple *stmt, bitmap need_eh_cleanup,
+		       bitmap need_ab_cleanup, vec<gimple *> stmts_to_fixup,
+		       bool can_make_abnormal_goto, bool was_noreturn)
+{
+  basic_block bb = old_stmt->bb;
+
+  /* If we cleaned up EH information from the statement,
+     remove EH edges.  */
+  if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
+    bitmap_set_bit (need_eh_cleanup, bb->index);
+
+  /* If we turned a call with possible abnormal control transfer
+     into one that doesn't, remove abnormal edges.  */
+  if (can_make_abnormal_goto
+      && !stmt_can_make_abnormal_goto (stmt))
+    bitmap_set_bit (need_ab_cleanup, bb->index);
+
+  /* If we turned a not noreturn call into a noreturn one
+     schedule it for fixup.  */
+  if (!was_noreturn
+      && is_gimple_call (stmt)
+      && gimple_call_noreturn_p (stmt))
+    stmts_to_fixup.safe_push (stmt);
+
+  if (gimple_assign_single_p (stmt))
+    {
+      tree rhs = gimple_assign_rhs1 (stmt);
+
+      if (TREE_CODE (rhs) == ADDR_EXPR)
+	recompute_tree_invariant_for_addr_expr (rhs);
+    }
+}
+
+/* TODO Comment.  */
+
+void
+cleanup_after_all_replaces_done (bitmap need_eh_cleanup, bitmap
+				 need_ab_cleanup, vec<gimple *> stmts_to_fixup)
+{
+  if (!bitmap_empty_p (need_eh_cleanup))
+    gimple_purge_all_dead_eh_edges (need_eh_cleanup);
+  if (!bitmap_empty_p (need_ab_cleanup))
+    gimple_purge_all_dead_abnormal_call_edges (need_ab_cleanup);
+
+  /* Fixup stmts that became noreturn calls.  This may require splitting
+     blocks and thus isn't possible during the dominator walk.  Do this
+     in reverse order so we don't inadvertedly remove a stmt we want to
+     fixup by visiting a dominating now noreturn call first.  */
+  while (!stmts_to_fixup.is_empty ())
+    {
+      gimple *stmt = stmts_to_fixup.pop ();
+      if (dump_file && dump_flags & TDF_DETAILS)
+	{
+	  fprintf (dump_file, "Fixing up noreturn call ");
+	  print_gimple_stmt (dump_file, stmt, 0);
+	  fprintf (dump_file, "\n");
+	}
+      fixup_noreturn_call (stmt);
+    }
+}
diff --git a/gcc/tree-ssa-propagate.h b/gcc/tree-ssa-propagate.h
index 1c03c6c2211..455f00e86b0 100644
--- a/gcc/tree-ssa-propagate.h
+++ b/gcc/tree-ssa-propagate.h
@@ -72,6 +72,13 @@ extern void propagate_value (use_operand_p, tree);
 extern void replace_exp (use_operand_p, tree);
 extern void propagate_tree_value (tree *, tree);
 extern void propagate_tree_value_into_stmt (gimple_stmt_iterator *, tree);
+extern void cleanup_after_replace (gimple *old_stmt, gimple *stmt, bitmap
+				   need_eh_cleanup, bitmap need_ab_cleanup,
+				   vec<gimple *> stmts_to_fixup, bool
+				   can_make_abnormal_goto, bool was_noreturn);
+extern void cleanup_after_all_replaces_done (bitmap need_eh_cleanup, bitmap
+					     need_ab_cleanup, vec<gimple *>
+					     stms_to_fixup);
 
 /* Public interface into the SSA propagation engine.  Clients should inherit
    from this class and provide their own visitors.  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-27 18:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 18:42 [gcc(refs/users/pheeck/heads/sccp)] added cleanup from tree-ssa-propagate to sccp Filip Kastl

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