public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:15e9e247658b203866116e47f99cee7a646de233

commit 15e9e247658b203866116e47f99cee7a646de233
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 18:57:36 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 5 +----
 gcc/tree-ssa-threadupdate.h | 3 +++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 30c6cbf9125..346b093a0df 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -145,6 +145,7 @@ jump_thread_path_registry::jump_thread_path_registry ()
   paths.create (5);
   m_removed_edges = new hash_table<struct removed_edges> (17);
   m_num_threaded_edges = 0;
+  m_redirection_data = NULL;
 }
 
 jump_thread_path_registry::~jump_thread_path_registry ()
@@ -348,10 +349,6 @@ create_block_for_threading (basic_block bb,
     bitmap_set_bit (*duplicate_blocks, rd->dup_blocks[count]->index);
 }
 
-/* Main data structure to hold information for duplicates of BB.  */
-
-static hash_table<redirection_data> *m_redirection_data;
-
 /* Given an outgoing edge E lookup and return its entry in our hash table.
 
    If INSERT is true, then we insert the entry into the hash table if
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index a32ef78189f..c914ceae161 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -99,6 +99,9 @@ private:
 
   // Jump threading statistics.
   unsigned long m_num_threaded_edges;
+
+  // Main data structure to hold information for duplicates of BB.
+  hash_table<redirection_data> *m_redirection_data;
 };
 
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

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

commit fe7b08680eaa00b83e9bd2f84db4dd1bdf0d406a
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 13:19:24 2020 +0100

    wip wip
    
    PASS

Diff:
---
 gcc/tree-ssa-threadupdate.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index eedc3f3cf50..5af69535f8f 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -56,7 +56,8 @@ public:
   // ?? Is this method really necessary?  I mean, the pointers in
   // m_path live in an obstack that gets automatically cleaned up.  So
   // technically we'd only leave the container up for the GC to
-  // cleanup.
+  // cleanup.  I've changed this method to a NOP with no adverse
+  // effects.
   void release ();
 
 private:
@@ -160,8 +161,7 @@ jump_thread_path::block_remove (unsigned ix, unsigned len)
 inline void
 jump_thread_path::release ()
 {
-  // FIXME: put this back
-  //m_path.release ();
+  m_path.release ();
 }
 
 // Rather than search all the edges in jump thread paths each time DOM


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

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

commit ff2c78fd8f5a92d861531615140253c97c1f636a
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 12:09:49 2020 +0100

    wip wip
    
    PASS

Diff:
---
 gcc/tree-ssa-threadedge.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 24ba6f0772d..32e5e5eead8 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -82,12 +82,18 @@ protected:
   avail_exprs_stack *m_avail_exprs_stack;
 };
 
+extern void propagate_threaded_block_debug_into (basic_block, basic_block);
+
+// ?? All this ssa_name_values stuff is the store of values for
+// avail_exprs_stack and const_and_copies, so it really belongs in the
+// jump_threader class.  However, it's probably not worth touching
+// this, since all this windable state is slated to go with the
+// ranger.
 extern vec<tree> ssa_name_values;
 #define SSA_NAME_VALUE(x) \
     (SSA_NAME_VERSION (x) < ssa_name_values.length () \
      ? ssa_name_values[SSA_NAME_VERSION (x)] \
      : NULL_TREE)
 extern void set_ssa_name_value (tree, tree);
-extern void propagate_threaded_block_debug_into (basic_block, basic_block);
 
 #endif /* GCC_TREE_SSA_THREADEDGE_H */


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:950fca7f6e242882f674beb7dd4fd63b85170c8b

commit 950fca7f6e242882f674beb7dd4fd63b85170c8b
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:42:52 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 61 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index cec4be61455..eedc3f3cf50 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -45,23 +45,19 @@ public:
 class jump_thread_path
 {
 public:
-  jump_thread_path () { m_path.create (5); }
-  jump_thread_edge *&operator[] (int i) { return m_path[i]; }
-  const jump_thread_edge *last (void) { return m_path.last (); }
-  void safe_push (jump_thread_edge *e) { m_path.safe_push (e); }
-  unsigned length () { return m_path.length (); }
+  jump_thread_path ();
+  jump_thread_edge *&operator[] (int);
+  jump_thread_edge *last ();
+  void safe_push (jump_thread_edge *);
+  unsigned length ();
   void dump (FILE *, bool registering);
   void dump (FILE *);
-  void block_remove (unsigned ix, unsigned len)
-  {
-    return m_path.block_remove (ix, len);
-  }
+  void block_remove (unsigned ix, unsigned len);
   // ?? Is this method really necessary?  I mean, the pointers in
   // m_path live in an obstack that gets automatically cleaned up.  So
   // technically we'd only leave the container up for the GC to
   // cleanup.
-  // FIXME: put this back VVVVVVVVVVVVVVVVVVV
-  void release () { } //m_path.release (); }
+  void release ();
 
 private:
   DISABLE_COPY_AND_ASSIGN (jump_thread_path);
@@ -125,6 +121,49 @@ private:
   jump_thread_path_allocator m_allocator;
 };
 
+inline
+jump_thread_path::jump_thread_path ()
+{
+  m_path.create (5);
+}
+
+inline jump_thread_edge *&
+jump_thread_path::operator[] (int i)
+{
+  return m_path[i];
+}
+
+inline jump_thread_edge *
+jump_thread_path::last ()
+{
+  return m_path.last ();
+}
+
+inline void
+jump_thread_path::safe_push (jump_thread_edge *e)
+{
+  m_path.safe_push (e);
+}
+
+inline unsigned
+jump_thread_path::length ()
+{
+  return m_path.length ();
+}
+
+inline void
+jump_thread_path::block_remove (unsigned ix, unsigned len)
+{
+  return m_path.block_remove (ix, len);
+}
+
+inline void
+jump_thread_path::release ()
+{
+  // FIXME: put this back
+  //m_path.release ();
+}
+
 // Rather than search all the edges in jump thread paths each time DOM
 // is able to simply if control statement, we build a hash table with
 // the deleted edges.  We only care about the address of the edge, not


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4c44de1ecf06c4419016aa8e1c60d089542ff4d8

commit 4c44de1ecf06c4419016aa8e1c60d089542ff4d8
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:29:11 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index a9509735d1e..42ce69f4932 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -1085,7 +1085,7 @@ jump_threader::thread_through_normal_block (jump_thread_path *path,
 	  if (path->length () == 0)
 	    {
               jump_thread_edge *x
-	        = m_registry->allocate_thread_edge (e, EDGE_START_JUMP_THREAD);
+		= m_registry->allocate_thread_edge (e, EDGE_START_JUMP_THREAD);
 	      path->safe_push (x);
 	    }
 
@@ -1228,7 +1228,7 @@ jump_threader::thread_across_edge (edge e)
 	{
 	  BITMAP_FREE (visited);
 	  m_const_and_copies->pop_to_marker ();
-          m_avail_exprs_stack->pop_to_marker ();
+	  m_avail_exprs_stack->pop_to_marker ();
 	  if (m_evrp_range_analyzer)
 	    m_evrp_range_analyzer->pop_to_marker ();
 	  return;
@@ -1257,7 +1257,7 @@ jump_threader::thread_across_edge (edge e)
       if (taken_edge->flags & EDGE_COMPLEX)
 	{
 	  m_const_and_copies->pop_to_marker ();
-          m_avail_exprs_stack->pop_to_marker ();
+	  m_avail_exprs_stack->pop_to_marker ();
 	  if (m_evrp_range_analyzer)
 	    m_evrp_range_analyzer->pop_to_marker ();
 	  BITMAP_FREE (visited);
@@ -1287,11 +1287,11 @@ jump_threader::thread_across_edge (edge e)
 
 	/* Record whether or not we were able to thread through a successor
 	   of E->dest.  */
-        jump_thread_edge *x
+	jump_thread_edge *x
 	  = m_registry->allocate_thread_edge (e, EDGE_START_JUMP_THREAD);
 	path->safe_push (x);
 
-        x = m_registry->allocate_thread_edge (taken_edge,
+	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);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3678cef5a006daddb2fc846ea1568a2bca21d4d1

commit 3678cef5a006daddb2fc846ea1568a2bca21d4d1
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:23:53 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 3 ---
 gcc/tree-ssa-threadupdate.h | 1 -
 2 files changed, 4 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 415a4f3d31d..8133e69b7e2 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2773,9 +2773,6 @@ jump_thread_path_registry::register_jump_thread (jump_thread_path *path)
   if (dump_file && (dump_flags & TDF_DETAILS))
     path->dump (dump_file, true);
 
-  if (!m_paths.exists ())
-    m_paths.create (5);
-
   m_paths.safe_push (path);
 }
 
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index b803a323b32..cec4be61455 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -42,7 +42,6 @@ public:
   jump_thread_edge_type type;
 };
 
-// FIXME: audit callers.  most should take a const.
 class jump_thread_path
 {
 public:


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:69e59c26005f645214566585167b0cd19f301854

commit 69e59c26005f645214566585167b0cd19f301854
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:20:30 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 9272f748817..b803a323b32 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -48,7 +48,7 @@ class jump_thread_path
 public:
   jump_thread_path () { m_path.create (5); }
   jump_thread_edge *&operator[] (int i) { return m_path[i]; }
-  jump_thread_edge *&last (void) { return m_path.last (); }
+  const jump_thread_edge *last (void) { return m_path.last (); }
   void safe_push (jump_thread_edge *e) { m_path.safe_push (e); }
   unsigned length () { return m_path.length (); }
   void dump (FILE *, bool registering);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:753e899eb0d24fa84b9c6862c68891d3a051cc06

commit 753e899eb0d24fa84b9c6862c68891d3a051cc06
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:15:57 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 3c011b690db..9272f748817 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -61,7 +61,8 @@ public:
   // m_path live in an obstack that gets automatically cleaned up.  So
   // technically we'd only leave the container up for the GC to
   // cleanup.
-  void release () { m_path.release (); }
+  // FIXME: put this back VVVVVVVVVVVVVVVVVVV
+  void release () { } //m_path.release (); }
 
 private:
   DISABLE_COPY_AND_ASSIGN (jump_thread_path);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

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

commit f5f7a295e348f07c6b4af3e564feb74f9d3f9a4a
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:12:09 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c   |  2 +-
 gcc/tree-ssa-threadupdate.c | 39 +++++++++++++++------------------------
 gcc/tree-ssa-threadupdate.h |  8 +++++---
 3 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 62548750aaa..a9509735d1e 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -1311,7 +1311,7 @@ jump_threader::thread_across_edge (edge e)
 	    m_registry->register_jump_thread (path);
 	  }
 	else
-	  delete_jump_thread_path (path);
+	  path->release ();
 
 	/* And unwind the equivalence table.  */
 	if (m_evrp_range_analyzer)
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index e64e63e9d89..415a4f3d31d 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -1320,7 +1320,7 @@ ssa_redirect_edges (struct redirection_data **slot,
 
       /* Go ahead and clear E->aux.  It's not needed anymore and failure
 	 to clear it will cause all kinds of unpleasant problems later.  */
-      delete_jump_thread_path (path);
+      path->release ();
       e->aux = NULL;
 
     }
@@ -1438,7 +1438,7 @@ jump_thread_path_registry::thread_block_1 (basic_block bb,
 	      /* Since this case is not handled by our special code
 		 to thread through a loop header, we must explicitly
 		 cancel the threading request here.  */
-	      delete_jump_thread_path (path);
+	      path->release ();
 	      e->aux = NULL;
 	      continue;
 	    }
@@ -1477,7 +1477,7 @@ jump_thread_path_registry::thread_block_1 (basic_block bb,
 
 	      if (i != path->length ())
 		{
-		  delete_jump_thread_path (path);
+		  path->release ();
 		  e->aux = NULL;
 		  continue;
 		}
@@ -1836,7 +1836,7 @@ fail:
 
       if (path)
 	{
-	  delete_jump_thread_path (path);
+	  path->release ();
 	  e->aux = NULL;
 	}
     }
@@ -1966,7 +1966,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 	      m_paths.unordered_remove (i);
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		path->dump (dump_file, false);
-	      delete_jump_thread_path (path);
+	      path->release ();
 	    }
 	}
       else
@@ -2003,7 +2003,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 	      m_paths.unordered_remove (i);
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		path->dump (dump_file, false);
-	      delete_jump_thread_path (path);
+	      path->release ();
 	    }
 	}
       else
@@ -2051,7 +2051,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 		  {
 		    if (dump_file && (dump_flags & TDF_DETAILS))
 		      path->dump (dump_file, false);
-		    delete_jump_thread_path (path);
+		    path->release ();
 		    e->aux = NULL;
 		  }
 		else
@@ -2098,7 +2098,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 
 		  if (e2 && !phi_args_equal_on_edges (e2, final_edge))
 		    {
-		      delete_jump_thread_path (path);
+		      path->release ();
 		      e->aux = NULL;
 		    }
 		}
@@ -2321,7 +2321,7 @@ jump_thread_path_registry::adjust_paths_after_duplication
 	    remove_candidate_from_list:
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		fprintf (dump_file, "adjusted candidate: [EMPTY]\n");
-	      delete_jump_thread_path (cand_path);
+	      cand_path->release ();
 	      m_paths.unordered_remove (cand_path_num);
 	      continue;
 	    }
@@ -2583,7 +2583,7 @@ jump_thread_path_registry::thread_through_all_blocks
 
 	if (j != path->length ())
 	  {
-	    delete_jump_thread_path (path);
+	    path->release ();
 	    m_paths.unordered_remove (i);
 	    continue;
 	  }
@@ -2617,7 +2617,7 @@ jump_thread_path_registry::thread_through_all_blocks
 	  || !valid_jump_thread_path (path))
 	{
 	  /* Remove invalid FSM jump-thread paths.  */
-	  delete_jump_thread_path (path);
+	  path->release ();
 	  m_paths.unordered_remove (i);
 	  continue;
 	}
@@ -2638,7 +2638,7 @@ jump_thread_path_registry::thread_through_all_blocks
 	  m_num_threaded_edges++;
 	}
 
-      delete_jump_thread_path (path);
+      path->release ();
       m_paths.unordered_remove (i);
       free (region);
     }
@@ -2653,7 +2653,7 @@ jump_thread_path_registry::thread_through_all_blocks
       /* Do not jump-thread twice from the same block.  */
       if (visited_starting_edges.contains (entry))
 	{
-	  delete_jump_thread_path (path);
+	  path->release ();
 	  m_paths.unordered_remove (i);
 	}
       else
@@ -2729,15 +2729,6 @@ jump_thread_path_registry::thread_through_all_blocks
   return retval;
 }
 
-/* Delete the jump threading path PATH.  We have to explicitly delete
-   each entry in the vector, then the container.  */
-
-void
-delete_jump_thread_path (jump_thread_path *path)
-{
-  path->release();
-}
-
 /* Register a jump threading opportunity.  We queue up all the jump
    threading opportunities discovered by a pass and update the CFG
    and SSA form all at once.
@@ -2751,7 +2742,7 @@ jump_thread_path_registry::register_jump_thread (jump_thread_path *path)
 {
   if (!dbg_cnt (registered_jump_thread))
     {
-      delete_jump_thread_path (path);
+      path->release ();
       return;
     }
 
@@ -2768,7 +2759,7 @@ jump_thread_path_registry::register_jump_thread (jump_thread_path *path)
 	      path->dump (dump_file, false);
 	    }
 
-	  delete_jump_thread_path (path);
+	  path->release ();
 	  return;
 	}
 
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 3d487c9126c..3c011b690db 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -51,13 +51,17 @@ public:
   jump_thread_edge *&last (void) { return m_path.last (); }
   void safe_push (jump_thread_edge *e) { m_path.safe_push (e); }
   unsigned length () { return m_path.length (); }
-  void release () { m_path.release (); }
   void dump (FILE *, bool registering);
   void dump (FILE *);
   void block_remove (unsigned ix, unsigned len)
   {
     return m_path.block_remove (ix, len);
   }
+  // ?? Is this method really necessary?  I mean, the pointers in
+  // m_path live in an obstack that gets automatically cleaned up.  So
+  // technically we'd only leave the container up for the GC to
+  // cleanup.
+  void release () { m_path.release (); }
 
 private:
   DISABLE_COPY_AND_ASSIGN (jump_thread_path);
@@ -131,8 +135,6 @@ struct removed_edges : nofree_ptr_hash<edge_def>
   static bool equal (edge e1, edge e2) { return e1 == e2; }
 };
 
-// FIXME: remove
-extern void delete_jump_thread_path (jump_thread_path *);
 extern unsigned int estimate_threading_killed_stmts (basic_block);
 
 enum bb_dom_status


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2c6bd3b444e0e4c56b84403e54284bfeb85659bf

commit 2c6bd3b444e0e4c56b84403e54284bfeb85659bf
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:05:22 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c   | 1 -
 gcc/tree-ssa-threadupdate.c | 4 ----
 2 files changed, 5 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index a3712a5c5b5..62548750aaa 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -1216,7 +1216,6 @@ jump_threader::thread_across_edge (edge e)
 	 through the vector entries.  */
       gcc_assert (path->length () == 0);
       path->release ();
-      delete path;
 
       /* A negative status indicates the target block was deemed too big to
 	 duplicate.  Just quit now rather than trying to use the block as
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 9a2bee14b30..e64e63e9d89 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -153,8 +153,6 @@ jump_thread_edge *
 jump_thread_path_allocator::allocate_thread_edge (edge e,
 						  jump_thread_edge_type type)
 {
-  return new jump_thread_edge (e, type); // FIXME
-
   void *r = obstack_alloc (&m_obstack, sizeof (jump_thread_edge));
   return new (r) jump_thread_edge (e, type);
 }
@@ -162,8 +160,6 @@ jump_thread_path_allocator::allocate_thread_edge (edge e,
 jump_thread_path *
 jump_thread_path_allocator::allocate_thread_path ()
 {
-  return new jump_thread_path (); // FIXME
-
   void *r = obstack_alloc (&m_obstack, sizeof (jump_thread_path));
   return new (r) jump_thread_path ();
 }


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

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

commit a813d316fdab2770d72c49041f7bfcf46fc1663f
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 10:03:57 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index e5fd1d6a290..9a2bee14b30 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2739,10 +2739,7 @@ jump_thread_path_registry::thread_through_all_blocks
 void
 delete_jump_thread_path (jump_thread_path *path)
 {
-  for (unsigned int i = 0; i < path->length (); i++)
-    delete (*path)[i];
   path->release();
-  delete path;
 }
 
 /* Register a jump threading opportunity.  We queue up all the jump


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:52 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:46fe8ceb98787a29e9864f83df7a0670e76be04f

commit 46fe8ceb98787a29e9864f83df7a0670e76be04f
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 09:47:51 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c |  6 ++++++
 gcc/tree-ssa-threadupdate.h | 12 +++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index a68732e3333..e5fd1d6a290 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -232,6 +232,12 @@ jump_thread_path::dump (FILE *dump_file, bool registering)
   fputc ('\n', dump_file);
 }
 
+void
+jump_thread_path::dump (FILE *f)
+{
+  dump (f, true);
+}
+
 /* Simple hashing function.  For any given incoming edge E, we're going
    to be most concerned with the final destination of its jump thread
    path.  So hash on the block index of the final edge in the path.  */
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 18e533236d3..3d487c9126c 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -42,6 +42,7 @@ public:
   jump_thread_edge_type type;
 };
 
+// FIXME: audit callers.  most should take a const.
 class jump_thread_path
 {
 public:
@@ -50,20 +51,16 @@ public:
   jump_thread_edge *&last (void) { return m_path.last (); }
   void safe_push (jump_thread_edge *e) { m_path.safe_push (e); }
   unsigned length () { return m_path.length (); }
-  // FIXME: remove
-  // FIXME: remove extern delete_jump_thread_path
   void release () { m_path.release (); }
-  // FIXME: remove
+  void dump (FILE *, bool registering);
+  void dump (FILE *);
   void block_remove (unsigned ix, unsigned len)
   {
     return m_path.block_remove (ix, len);
   }
-  void dump (FILE *, bool registering);
-  void dump (FILE *f) { dump (f, true); }
 
 private:
-  // FIXME: should be in an obstack and automatically freed by pass
-  // that created it.
+  DISABLE_COPY_AND_ASSIGN (jump_thread_path);
   vec<jump_thread_edge *> m_path;
 };
 
@@ -134,6 +131,7 @@ struct removed_edges : nofree_ptr_hash<edge_def>
   static bool equal (edge e1, edge e2) { return e1 == e2; }
 };
 
+// FIXME: remove
 extern void delete_jump_thread_path (jump_thread_path *);
 extern unsigned int estimate_threading_killed_stmts (basic_block);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit f0d8b36ce113297a9ccf382ffc404f6a9ea85a9c
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 09:32:53 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadbackward.c | 2 +-
 gcc/tree-ssa-threadedge.c     | 4 ++--
 gcc/tree-ssa-threadupdate.h   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index 2d9c416a2b7..002cb22977f 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -464,7 +464,7 @@ thread_jumps::profitable_jump_thread_path (basic_block bbi, tree name,
 void
 thread_jumps::convert_and_register_current_path (edge taken_edge)
 {
-  jump_thread_path *path = new jump_thread_path ();
+  jump_thread_path *path = m_registry.allocate_thread_path ();
 
   /* Record the edges between the blocks in PATH.  */
   for (unsigned int j = 0; j + 1 < m_path.length (); j++)
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 514bc5b7439..a3712a5c5b5 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -1186,7 +1186,7 @@ jump_threader::thread_across_edge (edge e)
 
   stmt_count = 0;
 
-  jump_thread_path *path = new jump_thread_path ();
+  jump_thread_path *path = m_registry->allocate_thread_path ();
   bitmap_clear (visited);
   bitmap_set_bit (visited, e->src->index);
   bitmap_set_bit (visited, e->dest->index);
@@ -1284,7 +1284,7 @@ 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);
-	jump_thread_path *path = new jump_thread_path ();
+	jump_thread_path *path = m_registry->allocate_thread_path ();
 
 	/* Record whether or not we were able to thread through a successor
 	   of E->dest.  */
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index dac815545f1..18e533236d3 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -91,9 +91,9 @@ public:
   void register_jump_thread (jump_thread_path *);
   void remove_jump_threads_including (edge);
   bool thread_through_all_blocks (bool);
-  void dump ();
   jump_thread_edge *allocate_thread_edge (edge e, jump_thread_edge_type t);
   jump_thread_path *allocate_thread_path ();
+  void dump ();
 
 private:
   void debug_path (FILE *, int pathno);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit ae329625afd64edd23bf30940357278d97ab6bb7
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 25 09:29:18 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 266f50ad816..514bc5b7439 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -923,7 +923,8 @@ jump_threader::thread_around_empty_blocks (jump_thread_path *path,
 	  if (!bitmap_bit_p (visited, taken_edge->dest->index))
 	    {
 	      jump_thread_edge *x
-		= new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
+		= m_registry->allocate_thread_edge (taken_edge,
+						    EDGE_NO_COPY_SRC_BLOCK);
 	      path->safe_push (x);
 	      bitmap_set_bit (visited, taken_edge->dest->index);
 	      return thread_around_empty_blocks (path, taken_edge, visited);
@@ -966,7 +967,8 @@ jump_threader::thread_around_empty_blocks (jump_thread_path *path,
       bitmap_set_bit (visited, taken_edge->dest->index);
 
       jump_thread_edge *x
-	= new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
+	= m_registry->allocate_thread_edge (taken_edge,
+					    EDGE_NO_COPY_SRC_BLOCK);
       path->safe_push (x);
 
       thread_around_empty_blocks (path, taken_edge, visited);
@@ -1083,12 +1085,13 @@ jump_threader::thread_through_normal_block (jump_thread_path *path,
 	  if (path->length () == 0)
 	    {
               jump_thread_edge *x
-	        = new jump_thread_edge (e, EDGE_START_JUMP_THREAD);
+	        = m_registry->allocate_thread_edge (e, EDGE_START_JUMP_THREAD);
 	      path->safe_push (x);
 	    }
 
 	  jump_thread_edge *x
-	    = new jump_thread_edge (taken_edge, EDGE_COPY_SRC_BLOCK);
+	    = m_registry->allocate_thread_edge (taken_edge,
+						EDGE_COPY_SRC_BLOCK);
 	  path->safe_push (x);
 
 	  /* See if we can thread through DEST as well, this helps capture
@@ -1285,10 +1288,12 @@ jump_threader::thread_across_edge (edge e)
 
 	/* Record whether or not we were able to thread through a successor
 	   of E->dest.  */
-        jump_thread_edge *x = new jump_thread_edge (e, EDGE_START_JUMP_THREAD);
+        jump_thread_edge *x
+	  = m_registry->allocate_thread_edge (e, EDGE_START_JUMP_THREAD);
 	path->safe_push (x);
 
-        x = new jump_thread_edge (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);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit b8a461674da18e8e4ab96b692d74bea27c123008
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 21:45:55 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 86 ++++++++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 43 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 3b894ad94b9..2974dee6c2d 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -21,49 +21,6 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef _TREE_SSA_THREADUPDATE_H
 #define _TREE_SSA_THREADUPDATE_H 1
 
-// This is the underlying jump thread registry.  When all candidates
-// have been registered with register_jump_thread(),
-// thread_through_all_blocks() is called to actually change the CFG.
-
-class jump_thread_path_registry
-{
-public:
-  jump_thread_path_registry ();
-  ~jump_thread_path_registry ();
-  void register_jump_thread (class jump_thread_path *);
-  void remove_jump_threads_including (edge);
-  // Perform CFG changes after all threadable candidates have been
-  // registered.
-  bool thread_through_all_blocks (bool);
-  void dump ();
-
-private:
-  void debug_path (FILE *, int pathno);
-  void mark_threaded_blocks (bitmap threaded_blocks);
-  bool rewire_first_differing_edge (unsigned path_num, unsigned edge_num);
-  void adjust_paths_after_duplication (unsigned curr_path_num);
-  bool duplicate_thread_path (edge entry,
-			      edge exit,
-			      basic_block *region,
-			      unsigned n_region,
-			      unsigned current_path_no);
-  bool thread_block_1 (basic_block, bool noloop_only, bool joiners);
-  bool thread_block (basic_block, bool noloop_only);
-  bool thread_through_loop_header (class loop *loop,
-				   bool may_peel_loop_headers);
-  class redirection_data *lookup_redirection_data (edge e, enum insert_option);
-
-  vec<class jump_thread_path *> m_paths;
-
-  hash_table<struct removed_edges> *m_removed_edges;
-
-  // Main data structure to hold information for duplicates of BB.
-  hash_table<redirection_data> *m_redirection_data;
-
-  // Jump threading statistics.
-  unsigned long m_num_threaded_edges;
-};
-
 enum jump_thread_edge_type
 {
   EDGE_START_JUMP_THREAD,
@@ -110,6 +67,49 @@ private:
   vec<jump_thread_edge *> m_path;
 };
 
+// This is the underlying jump thread registry.  When all candidates
+// have been registered with register_jump_thread(),
+// thread_through_all_blocks() is called to actually change the CFG.
+
+class jump_thread_path_registry
+{
+public:
+  jump_thread_path_registry ();
+  ~jump_thread_path_registry ();
+  void register_jump_thread (jump_thread_path *);
+  void remove_jump_threads_including (edge);
+  // Perform CFG changes after all threadable candidates have been
+  // registered.
+  bool thread_through_all_blocks (bool);
+  void dump ();
+
+private:
+  void debug_path (FILE *, int pathno);
+  void mark_threaded_blocks (bitmap threaded_blocks);
+  bool rewire_first_differing_edge (unsigned path_num, unsigned edge_num);
+  void adjust_paths_after_duplication (unsigned curr_path_num);
+  bool duplicate_thread_path (edge entry,
+			      edge exit,
+			      basic_block *region,
+			      unsigned n_region,
+			      unsigned current_path_no);
+  bool thread_block_1 (basic_block, bool noloop_only, bool joiners);
+  bool thread_block (basic_block, bool noloop_only);
+  bool thread_through_loop_header (class loop *loop,
+				   bool may_peel_loop_headers);
+  class redirection_data *lookup_redirection_data (edge e, enum insert_option);
+
+  vec<jump_thread_path *> m_paths;
+
+  hash_table<struct removed_edges> *m_removed_edges;
+
+  // Main data structure to hold information for duplicates of BB.
+  hash_table<redirection_data> *m_redirection_data;
+
+  // Jump threading statistics.
+  unsigned long m_num_threaded_edges;
+};
+
 // Rather than search all the edges in jump thread paths each time DOM
 // is able to simply if control statement, we build a hash table with
 // the deleted edges.  We only care about the address of the edge, not


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit e48742326309e2625c4057f2f2b9cb3923b94bf7
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 19:04:57 2020 +0100

    wip wip
    
    PASS

Diff:
---
 gcc/tree-ssa-threadupdate.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index dcb08b921b6..3b894ad94b9 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -93,7 +93,10 @@ public:
   jump_thread_edge *&last (void) { return m_path.last (); }
   void safe_push (jump_thread_edge *e) { m_path.safe_push (e); }
   unsigned length () { return m_path.length (); }
+  // FIXME: remove
+  // FIXME: remove extern delete_jump_thread_path
   void release () { m_path.release (); }
+  // FIXME: remove
   void block_remove (unsigned ix, unsigned len)
   {
     return m_path.block_remove (ix, len);
@@ -102,6 +105,8 @@ public:
   void dump (FILE *f) { dump (f, true); }
 
 private:
+  // FIXME: should be in an obstack and automatically freed by pass
+  // that created it.
   vec<jump_thread_edge *> m_path;
 };


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2e5885a61272b5c30e87ed090059838f3f04f8fb

commit 2e5885a61272b5c30e87ed090059838f3f04f8fb
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 18:58:23 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 26 ++++++++++++--------------
 gcc/tree-ssa-threadedge.h | 11 ++++-------
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 1982f55d6ac..266f50ad816 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -879,9 +879,9 @@ propagate_threaded_block_debug_into (basic_block dest, basic_block src)
    The available expression table is referenced via AVAIL_EXPRS_STACK.  */
 
 bool
-jump_threader::thread_around_empty_blocks (edge taken_edge,
-					   bitmap visited,
-					   jump_thread_path *path)
+jump_threader::thread_around_empty_blocks (jump_thread_path *path,
+					   edge taken_edge,
+					   bitmap visited)
 {
   basic_block bb = taken_edge->dest;
   gimple_stmt_iterator gsi;
@@ -926,7 +926,7 @@ jump_threader::thread_around_empty_blocks (edge taken_edge,
 		= new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
 	      path->safe_push (x);
 	      bitmap_set_bit (visited, taken_edge->dest->index);
-	      return thread_around_empty_blocks (taken_edge, visited, path);
+	      return thread_around_empty_blocks (path, taken_edge, visited);
 	    }
 	}
 
@@ -969,7 +969,7 @@ jump_threader::thread_around_empty_blocks (edge taken_edge,
 	= new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
       path->safe_push (x);
 
-      thread_around_empty_blocks (taken_edge, visited, path);
+      thread_around_empty_blocks (path, taken_edge, visited);
       return true;
     }
 
@@ -1001,9 +1001,8 @@ jump_threader::thread_around_empty_blocks (edge taken_edge,
    suitable for a joiner in a jump threading path.  */
 
 int
-jump_threader::thread_through_normal_block (edge e,
-					    jump_thread_path *path,
-					    bitmap visited)
+jump_threader::thread_through_normal_block (jump_thread_path *path,
+					    edge e, bitmap visited)
 {
   /* We want to record any equivalences created by traversing E.  */
   record_temporary_equivalences (e, m_const_and_copies, m_avail_exprs_stack);
@@ -1100,7 +1099,7 @@ jump_threader::thread_through_normal_block (edge e,
  	     visited.  This may be overly conservative.  */
 	  bitmap_set_bit (visited, dest->index);
 	  bitmap_set_bit (visited, e->dest->index);
-	  thread_around_empty_blocks (taken_edge, visited, path);
+	  thread_around_empty_blocks (path, taken_edge, visited);
 	  return 1;
 	}
     }
@@ -1191,7 +1190,7 @@ jump_threader::thread_across_edge (edge e)
 
   int threaded;
   if ((e->flags & EDGE_DFS_BACK) == 0)
-    threaded = thread_through_normal_block (e, path, visited);
+    threaded = thread_through_normal_block (path, e, visited);
   else
     threaded = 0;
 
@@ -1291,12 +1290,11 @@ jump_threader::thread_across_edge (edge e)
 
         x = new jump_thread_edge (taken_edge, EDGE_COPY_SRC_JOINER_BLOCK);
 	path->safe_push (x);
-	found = thread_around_empty_blocks (taken_edge, visited, path);
+	found = thread_around_empty_blocks (path, taken_edge, visited);
 
 	if (!found)
-	  found = thread_through_normal_block (path->last ()->e,
-					       path,
-					       visited) > 0;
+	  found = thread_through_normal_block (path,
+					       path->last ()->e, visited) > 0;
 
 	/* If we were able to thread through a successor of E->dest, then
 	   record the jump threading opportunity.  */
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 0ba990b37ee..b880d37e32a 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -49,13 +49,10 @@ private:
 					  tree op1,
 					  unsigned limit);
 
-  // FIXME: Change order of arguments with these 2 funcs.
-  bool thread_around_empty_blocks (edge,
-				   bitmap visited,
-				   class jump_thread_path *path);
-  int thread_through_normal_block (edge,
-				   jump_thread_path *path,
-				   bitmap visited);
+  bool thread_around_empty_blocks (class jump_thread_path *path,
+				   edge, bitmap visited);
+  int thread_through_normal_block (jump_thread_path *path,
+				   edge, bitmap visited);
   void thread_across_edge (edge);
   bool record_temporary_equivalences_from_phis (edge);
   gimple *record_temporary_equivalences_from_stmts_at_dest (edge);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7c9733a03b85b3b9faec31051ff98c51a0bc20ed

commit 7c9733a03b85b3b9faec31051ff98c51a0bc20ed
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 18:55:05 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 39 +++++++++++++++++++--------------------
 gcc/tree-ssa-threadupdate.h |  2 ++
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 7df224cbfde..586fd7a4691 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -156,37 +156,36 @@ jump_thread_path_registry::~jump_thread_path_registry ()
 /* Dump a jump threading path, including annotations about each
    edge in the path.  */
 
-static void
-dump_jump_thread_path (FILE *dump_file, jump_thread_path path,
-		       bool registering)
+void
+jump_thread_path::dump (FILE *dump_file, bool registering)
 {
   fprintf (dump_file,
 	   "  %s%s jump thread: (%d, %d) incoming edge; ",
 	   (registering ? "Registering" : "Cancelling"),
-	   (path[0]->type == EDGE_FSM_THREAD ? " FSM": ""),
-	   path[0]->e->src->index, path[0]->e->dest->index);
+	   (m_path[0]->type == EDGE_FSM_THREAD ? " FSM": ""),
+	   m_path[0]->e->src->index, m_path[0]->e->dest->index);
 
-  for (unsigned int i = 1; i < path.length (); i++)
+  for (unsigned int i = 1; i < m_path.length (); i++)
     {
       /* We can get paths with a NULL edge when the final destination
 	 of a jump thread turns out to be a constant address.  We dump
 	 those paths when debugging, so we have to be prepared for that
 	 possibility here.  */
-      if (path[i]->e == NULL)
+      if (m_path[i]->e == NULL)
 	continue;
 
-      if (path[i]->type == EDGE_COPY_SRC_JOINER_BLOCK)
+      if (m_path[i]->type == EDGE_COPY_SRC_JOINER_BLOCK)
 	fprintf (dump_file, " (%d, %d) joiner; ",
-		 path[i]->e->src->index, path[i]->e->dest->index);
-      if (path[i]->type == EDGE_COPY_SRC_BLOCK)
+		 m_path[i]->e->src->index, m_path[i]->e->dest->index);
+      if (m_path[i]->type == EDGE_COPY_SRC_BLOCK)
        fprintf (dump_file, " (%d, %d) normal;",
-		 path[i]->e->src->index, path[i]->e->dest->index);
-      if (path[i]->type == EDGE_NO_COPY_SRC_BLOCK)
+		 m_path[i]->e->src->index, m_path[i]->e->dest->index);
+      if (m_path[i]->type == EDGE_NO_COPY_SRC_BLOCK)
        fprintf (dump_file, " (%d, %d) nocopy;",
-		 path[i]->e->src->index, path[i]->e->dest->index);
-      if (path[0]->type == EDGE_FSM_THREAD)
+		 m_path[i]->e->src->index, m_path[i]->e->dest->index);
+      if (m_path[0]->type == EDGE_FSM_THREAD)
 	fprintf (dump_file, " (%d, %d) ",
-		 path[i]->e->src->index, path[i]->e->dest->index);
+		 m_path[i]->e->src->index, m_path[i]->e->dest->index);
     }
   fputc ('\n', dump_file);
 }
@@ -1922,7 +1921,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 	    {
 	      m_paths.unordered_remove (i);
 	      if (dump_file && (dump_flags & TDF_DETAILS))
-		dump_jump_thread_path (dump_file, *path, false);
+		path->dump (dump_file, false);
 	      delete_jump_thread_path (path);
 	    }
 	}
@@ -1959,7 +1958,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 	      e->aux = NULL;
 	      m_paths.unordered_remove (i);
 	      if (dump_file && (dump_flags & TDF_DETAILS))
-		dump_jump_thread_path (dump_file, *path, false);
+		path->dump (dump_file, false);
 	      delete_jump_thread_path (path);
 	    }
 	}
@@ -2007,7 +2006,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 		if (j != path->length ())
 		  {
 		    if (dump_file && (dump_flags & TDF_DETAILS))
-		      dump_jump_thread_path (dump_file, *path, 0);
+		      path->dump (dump_file, false);
 		    delete_jump_thread_path (path);
 		    e->aux = NULL;
 		  }
@@ -2725,7 +2724,7 @@ jump_thread_path_registry::register_jump_thread (jump_thread_path *path)
 	    {
 	      fprintf (dump_file,
 		       "Found NULL edge in jump threading path.  Cancelling jump thread:\n");
-	      dump_jump_thread_path (dump_file, *path, false);
+	      path->dump (dump_file, false);
 	    }
 
 	  delete_jump_thread_path (path);
@@ -2740,7 +2739,7 @@ jump_thread_path_registry::register_jump_thread (jump_thread_path *path)
     }
 
   if (dump_file && (dump_flags & TDF_DETAILS))
-    dump_jump_thread_path (dump_file, *path, true);
+    path->dump (dump_file, true);
 
   if (!m_paths.exists ())
     m_paths.create (5);
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 99e54ff13b9..dcb08b921b6 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -98,6 +98,8 @@ public:
   {
     return m_path.block_remove (ix, len);
   }
+  void dump (FILE *, bool registering);
+  void dump (FILE *f) { dump (f, true); }
 
 private:
   vec<jump_thread_edge *> m_path;


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit ebc715c22dec0bea71acdcd881e2b434c6c85f42
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 17:31:34 2020 +0100

    wip wip
    
    PASS

Diff:
---
 gcc/tree-ssa-threadupdate.h | 87 ++++++++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 44 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 44c908d627e..7d847ee0791 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -21,7 +21,49 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef _TREE_SSA_THREADUPDATE_H
 #define _TREE_SSA_THREADUPDATE_H 1
 
-// FIXME: put this in jump_thread_edge
+// This is the underlying jump thread registry.  When all candidates
+// have been registered with register_jump_thread(),
+// thread_through_all_blocks() is called to actually change the CFG.
+
+class jump_thread_path_registry
+{
+public:
+  jump_thread_path_registry ();
+  ~jump_thread_path_registry ();
+  void register_jump_thread (vec <class jump_thread_edge *> *);
+  void remove_jump_threads_including (edge);
+  // Perform CFG changes after all threadable candidates have been
+  // registered.
+  bool thread_through_all_blocks (bool);
+  void dump ();
+
+private:
+  void debug_path (FILE *, int pathno);
+  void mark_threaded_blocks (bitmap threaded_blocks);
+  bool rewire_first_differing_edge (unsigned path_num, unsigned edge_num);
+  void adjust_paths_after_duplication (unsigned curr_path_num);
+  bool duplicate_thread_path (edge entry,
+			      edge exit,
+			      basic_block *region,
+			      unsigned n_region,
+			      unsigned current_path_no);
+  bool thread_block_1 (basic_block, bool noloop_only, bool joiners);
+  bool thread_block (basic_block, bool noloop_only);
+  bool thread_through_loop_header (class loop *loop,
+				   bool may_peel_loop_headers);
+  class redirection_data *lookup_redirection_data (edge e, enum insert_option);
+
+  vec<vec<jump_thread_edge *> *> m_paths;
+
+  hash_table<struct removed_edges> *m_removed_edges;
+
+  // Main data structure to hold information for duplicates of BB.
+  hash_table<redirection_data> *m_redirection_data;
+
+  // Jump threading statistics.
+  unsigned long m_num_threaded_edges;
+};
+
 enum jump_thread_edge_type
 {
   EDGE_START_JUMP_THREAD,
@@ -65,49 +107,6 @@ private:
   vec<jump_thread_edge *> *m_path;
 };
 
-// This is the underlying jump thread registry.  When all candidates
-// have been registered with register_jump_thread(),
-// thread_through_all_blocks() is called to actually change the CFG.
-
-class jump_thread_path_registry
-{
-public:
-  jump_thread_path_registry ();
-  ~jump_thread_path_registry ();
-  void register_jump_thread (vec <jump_thread_edge *> *);
-  void remove_jump_threads_including (edge);
-  // Perform CFG changes after all threadable candidates have been
-  // registered.
-  bool thread_through_all_blocks (bool);
-  void dump ();
-
-private:
-  void debug_path (FILE *, int pathno);
-  void mark_threaded_blocks (bitmap threaded_blocks);
-  bool rewire_first_differing_edge (unsigned path_num, unsigned edge_num);
-  void adjust_paths_after_duplication (unsigned curr_path_num);
-  bool duplicate_thread_path (edge entry,
-			      edge exit,
-			      basic_block *region,
-			      unsigned n_region,
-			      unsigned current_path_no);
-  bool thread_block_1 (basic_block, bool noloop_only, bool joiners);
-  bool thread_block (basic_block, bool noloop_only);
-  bool thread_through_loop_header (class loop *loop,
-				   bool may_peel_loop_headers);
-  class redirection_data *lookup_redirection_data (edge e, enum insert_option);
-
-  vec<vec<jump_thread_edge *> *> m_paths;
-
-  hash_table<struct removed_edges> *m_removed_edges;
-
-  // Main data structure to hold information for duplicates of BB.
-  hash_table<redirection_data> *m_redirection_data;
-
-  // Jump threading statistics.
-  unsigned long m_num_threaded_edges;
-};
-
 // Rather than search all the edges in jump thread paths each time DOM
 // is able to simply if control statement, we build a hash table with
 // the deleted edges.  We only care about the address of the edge, not


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:69d208e3c85edce41e1862a2704fd2cb320ebbdd

commit 69d208e3c85edce41e1862a2704fd2cb320ebbdd
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 17:29:46 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.h | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index c4d52b69219..5468a9ca2d7 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -20,38 +20,24 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_TREE_SSA_THREADEDGE_H
 #define GCC_TREE_SSA_THREADEDGE_H
 
-class jump_thread_path_registry;
-class jump_thread_edge;
-class jump_threader_simplifier;
-class vr_values;
-class const_and_copies;
-class avail_exprs_stack;
-class evrp_range_analyzer;
-
 // This is the high level threader.  The entry point is
-// thread_outgoing_edges(), which calculates and registers path to be
+// thread_outgoing_edges(), which calculates and registers paths to be
 // threaded.  When all candidates have been registered,
 // thread_through_all_blocks() is called to actually change the CFG.
 
 class jump_threader
 {
 public:
-  jump_threader (const_and_copies *,
+  jump_threader (class const_and_copies *,
 		 avail_exprs_stack *,
-		 jump_threader_simplifier *,
-  		 evrp_range_analyzer * = NULL);
+		 class jump_threader_simplifier *,
+		 class evrp_range_analyzer * = NULL);
   ~jump_threader ();
   // Entry point to calculate and register threadable paths.
   void thread_outgoing_edges (basic_block);
   void remove_jump_threads_including (edge_def *);
   // Perform CFG changes after all threadable candidates have been
   // registered.
-  //
-  // TODO: Audit all calls to jump_threader::thread_through_all_blocks
-  // to see if we can remove this method, and call
-  // registry->thread_through_all_blocks() from the jump_threader
-  // destructor.  I'm just not 100% sure if this can be called after
-  // scev_finalize() and loop_optimizer_finalize(), etc.
   bool thread_through_all_blocks (bool may_peel_loop_headers);
 
 private:
@@ -65,7 +51,7 @@ private:
 
   bool thread_around_empty_blocks (edge,
 				   bitmap visited,
-				   vec<jump_thread_edge *> *path);
+				   vec<class jump_thread_edge *> *path);
   int thread_through_normal_block (edge,
 				   vec<jump_thread_edge *> *path,
 				   bitmap visited);
@@ -76,8 +62,8 @@ private:
   // Dummy condition to avoid creating lots of throw away statements.
   gcond *dummy_cond;
 
-  class const_and_copies *m_const_and_copies;
-  class avail_exprs_stack *m_avail_exprs_stack;
+  const_and_copies *m_const_and_copies;
+  avail_exprs_stack *m_avail_exprs_stack;
   class jump_thread_path_registry *m_registry;
   jump_threader_simplifier *m_simplifier;
   evrp_range_analyzer *m_evrp_range_analyzer;
@@ -88,7 +74,7 @@ private:
 class jump_threader_simplifier
 {
 public:
-  jump_threader_simplifier (vr_values *v,
+  jump_threader_simplifier (class vr_values *v,
 			    avail_exprs_stack *avails)
     : m_vr_values (v),
       m_avail_exprs_stack (avails)


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:038352db447368a872e3871f4cab4553c27a222e

commit 038352db447368a872e3871f4cab4553c27a222e
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 17:23:45 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c        | 4 ++--
 gcc/tree-ssa-threadedge.c | 4 ++--
 gcc/tree-ssa-threadedge.h | 4 ++--
 gcc/tree-vrp.c            | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 514a7a5e9f9..6b45effc770 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -748,8 +748,8 @@ pass_dominator::execute (function *fun)
   /* Recursively walk the dominator tree optimizing statements.  */
   evrp_range_analyzer analyzer (true);
   dom_jump_threader_simplifier simplifier (&analyzer, avail_exprs_stack);
-  jump_threader threader (const_and_copies, avail_exprs_stack, &analyzer,
-			  &simplifier);
+  jump_threader threader (const_and_copies, avail_exprs_stack,
+			  &simplifier, &analyzer);
   dom_opt_dom_walker walker (CDI_DOMINATORS,
 			     &threader,
 			     &analyzer,
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 8a0849243f6..190decd0f6c 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -63,8 +63,8 @@ set_ssa_name_value (tree name, tree value)
 
 jump_threader::jump_threader (const_and_copies *copies,
 			      avail_exprs_stack *avails,
-			      evrp_range_analyzer *analyzer,
-			      jump_threader_simplifier *simplifier)
+			      jump_threader_simplifier *simplifier,
+			      evrp_range_analyzer *analyzer)
 {
   /* Initialize the per SSA_NAME value-handles array.  */
   gcc_assert (!ssa_name_values.exists ());
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 059fcc4a233..c4d52b69219 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -38,8 +38,8 @@ class jump_threader
 public:
   jump_threader (const_and_copies *,
 		 avail_exprs_stack *,
-		 evrp_range_analyzer *,
-		 jump_threader_simplifier *);
+		 jump_threader_simplifier *,
+  		 evrp_range_analyzer * = NULL);
   ~jump_threader ();
   // Entry point to calculate and register threadable paths.
   void thread_outgoing_edges (basic_block);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index e0b9d402af8..68a6cfa7eb1 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4277,7 +4277,7 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
   m_simplifier = new vrp_jump_threader_simplifier (m_vr_values,
 						   m_avail_exprs_stack);
   m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack,
-				  NULL, m_simplifier);
+				  m_simplifier);
 }
 
 vrp_jump_threader::~vrp_jump_threader ()


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:51 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2949d4be222d9cd7ead22b51edf04c14bfbd000f

commit 2949d4be222d9cd7ead22b51edf04c14bfbd000f
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 17:19:58 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c        |  7 ++---
 gcc/tree-ssa-threadedge.c | 78 +++++++++++++++++++++--------------------------
 gcc/tree-ssa-threadedge.h | 16 +++++-----
 gcc/tree-vrp.c            |  4 +--
 4 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 5d84e569888..514a7a5e9f9 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -748,7 +748,8 @@ pass_dominator::execute (function *fun)
   /* Recursively walk the dominator tree optimizing statements.  */
   evrp_range_analyzer analyzer (true);
   dom_jump_threader_simplifier simplifier (&analyzer, avail_exprs_stack);
-  jump_threader threader (const_and_copies, avail_exprs_stack, &simplifier);
+  jump_threader threader (const_and_copies, avail_exprs_stack, &analyzer,
+			  &simplifier);
   dom_opt_dom_walker walker (CDI_DOMINATORS,
 			     &threader,
 			     &analyzer,
@@ -1464,9 +1465,7 @@ dom_opt_dom_walker::before_dom_children (basic_block bb)
 void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
-  m_threader->thread_outgoing_edges (bb, m_evrp_range_analyzer);
-
-  /* These remove expressions local to BB from the tables.  */
+  m_threader->thread_outgoing_edges (bb);
   m_avail_exprs_stack->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();
   m_evrp_range_analyzer->leave (bb);
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index a8fae1804b0..8a0849243f6 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -63,6 +63,7 @@ set_ssa_name_value (tree name, tree value)
 
 jump_threader::jump_threader (const_and_copies *copies,
 			      avail_exprs_stack *avails,
+			      evrp_range_analyzer *analyzer,
 			      jump_threader_simplifier *simplifier)
 {
   /* Initialize the per SSA_NAME value-handles array.  */
@@ -76,6 +77,7 @@ jump_threader::jump_threader (const_and_copies *copies,
   m_avail_exprs_stack = avails;
   m_registry = new jump_thread_path_registry ();
   m_simplifier = simplifier;
+  m_evrp_range_analyzer = analyzer;
 }
 
 jump_threader::~jump_threader (void)
@@ -139,8 +141,7 @@ potentially_threadable_block (basic_block bb)
    indicating we should not thread this edge, else return TRUE.  */
 
 bool
-jump_threader::record_temporary_equivalences_from_phis (edge e,
-    evrp_range_analyzer *evrp_range_analyzer)
+jump_threader::record_temporary_equivalences_from_phis (edge e)
 {
   gphi_iterator gsi;
 
@@ -174,12 +175,12 @@ jump_threader::record_temporary_equivalences_from_phis (edge e,
 
 	 Note that even if SRC is a constant we need to set a suitable
 	 output range so that VR_UNDEFINED ranges do not leak through.  */
-      if (evrp_range_analyzer)
+      if (m_evrp_range_analyzer)
 	{
 	  /* Get an empty new VR we can pass to update_value_range and save
 	     away in the VR stack.  */
 	  value_range_equiv *new_vr
-			  = evrp_range_analyzer->allocate_value_range_equiv ();
+	    = m_evrp_range_analyzer->allocate_value_range_equiv ();
 	  new (new_vr) value_range_equiv ();
 
 	  /* There are three cases to consider:
@@ -193,14 +194,14 @@ jump_threader::record_temporary_equivalences_from_phis (edge e,
 	       Otherwise set NEW_VR to varying.  This may be overly
 	       conservative.  */
 	  if (TREE_CODE (src) == SSA_NAME)
-	    new_vr->deep_copy (evrp_range_analyzer->get_value_range (src));
+	    new_vr->deep_copy (m_evrp_range_analyzer->get_value_range (src));
 	  else if (TREE_CODE (src) == INTEGER_CST)
 	    new_vr->set (src);
 	  else
 	    new_vr->set_varying (TREE_TYPE (src));
 
 	  /* This is a temporary range for DST, so push it.  */
-	  evrp_range_analyzer->push_value_range (dst, new_vr);
+	  m_evrp_range_analyzer->push_value_range (dst, new_vr);
 	}
     }
   return true;
@@ -238,8 +239,7 @@ threadedge_valueize (tree t)
    later statements in E->dest.  */
 
 gimple *
-jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
-    evrp_range_analyzer *evrp_range_analyzer)
+jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e)
 {
   gimple *stmt = NULL;
   gimple_stmt_iterator gsi;
@@ -300,8 +300,8 @@ jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
 
       /* These are temporary ranges, do nto reflect them back into
 	 the global range data.  */
-      if (evrp_range_analyzer)
-	evrp_range_analyzer->record_ranges_from_stmt (stmt, true);
+      if (m_evrp_range_analyzer)
+	m_evrp_range_analyzer->record_ranges_from_stmt (stmt, true);
 
       /* If this is not a statement that sets an SSA_NAME to a new
 	 value, then do not try to simplify this statement as it will
@@ -1001,11 +1001,9 @@ jump_threader::thread_around_empty_blocks (edge taken_edge,
    suitable for a joiner in a jump threading path.  */
 
 int
-jump_threader::thread_through_normal_block
-				(edge e,
-				 evrp_range_analyzer *evrp_range_analyzer,
-				 vec<jump_thread_edge *> *path,
-				 bitmap visited)
+jump_threader::thread_through_normal_block (edge e,
+					    vec<jump_thread_edge *> *path,
+					    bitmap visited)
 {
   /* We want to record any equivalences created by traversing E.  */
   record_temporary_equivalences (e, m_const_and_copies, m_avail_exprs_stack);
@@ -1014,14 +1012,12 @@ jump_threader::thread_through_normal_block
      Note that if we found a PHI that made the block non-threadable, then
      we need to bubble that up to our caller in the same manner we do
      when we prematurely stop processing statements below.  */
-  if (!record_temporary_equivalences_from_phis (e, evrp_range_analyzer))
+  if (!record_temporary_equivalences_from_phis (e))
     return -1;
 
   /* Now walk each statement recording any context sensitive
      temporary equivalences we can detect.  */
-  gimple *stmt
-    = record_temporary_equivalences_from_stmts_at_dest (e,
-							evrp_range_analyzer);
+  gimple *stmt = record_temporary_equivalences_from_stmts_at_dest (e);
 
   /* There's two reasons STMT might be null, and distinguishing
      between them is important.
@@ -1177,15 +1173,14 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e)
    jump which has a known value when reached via E.  */
 
 void
-jump_threader::thread_across_edge (edge e,
-				   evrp_range_analyzer *evrp_range_analyzer)
+jump_threader::thread_across_edge (edge e)
 {
   bitmap visited = BITMAP_ALLOC (NULL);
 
   m_const_and_copies->push_marker ();
   m_avail_exprs_stack->push_marker ();
-  if (evrp_range_analyzer)
-    evrp_range_analyzer->push_marker ();
+  if (m_evrp_range_analyzer)
+    m_evrp_range_analyzer->push_marker ();
 
   stmt_count = 0;
 
@@ -1196,8 +1191,7 @@ jump_threader::thread_across_edge (edge e,
 
   int threaded;
   if ((e->flags & EDGE_DFS_BACK) == 0)
-    threaded = thread_through_normal_block (e, evrp_range_analyzer,
-					    path, visited);
+    threaded = thread_through_normal_block (e, path, visited);
   else
     threaded = 0;
 
@@ -1207,8 +1201,8 @@ jump_threader::thread_across_edge (edge e,
 					   e->dest);
       m_const_and_copies->pop_to_marker ();
       m_avail_exprs_stack->pop_to_marker ();
-      if (evrp_range_analyzer)
-	evrp_range_analyzer->pop_to_marker ();
+      if (m_evrp_range_analyzer)
+	m_evrp_range_analyzer->pop_to_marker ();
       BITMAP_FREE (visited);
       m_registry->register_jump_thread (path);
       return;
@@ -1234,8 +1228,8 @@ jump_threader::thread_across_edge (edge e,
 	  BITMAP_FREE (visited);
 	  m_const_and_copies->pop_to_marker ();
           m_avail_exprs_stack->pop_to_marker ();
-	  if (evrp_range_analyzer)
-	    evrp_range_analyzer->pop_to_marker ();
+	  if (m_evrp_range_analyzer)
+	    m_evrp_range_analyzer->pop_to_marker ();
 	  return;
 	}
     }
@@ -1263,8 +1257,8 @@ jump_threader::thread_across_edge (edge e,
 	{
 	  m_const_and_copies->pop_to_marker ();
           m_avail_exprs_stack->pop_to_marker ();
-	  if (evrp_range_analyzer)
-	    evrp_range_analyzer->pop_to_marker ();
+	  if (m_evrp_range_analyzer)
+	    m_evrp_range_analyzer->pop_to_marker ();
 	  BITMAP_FREE (visited);
 	  return;
 	}
@@ -1280,8 +1274,8 @@ jump_threader::thread_across_edge (edge e,
 	   for each of E->dest's successors.  */
 	m_const_and_copies->push_marker ();
 	m_avail_exprs_stack->push_marker ();
-	if (evrp_range_analyzer)
-	  evrp_range_analyzer->push_marker ();
+	if (m_evrp_range_analyzer)
+	  m_evrp_range_analyzer->push_marker ();
 
 	/* Avoid threading to any block we have already visited.  */
 	bitmap_clear (visited);
@@ -1301,7 +1295,6 @@ jump_threader::thread_across_edge (edge e,
 
 	if (!found)
 	  found = thread_through_normal_block (path->last ()->e,
-					       evrp_range_analyzer,
 					       path,
 					       visited) > 0;
 
@@ -1319,16 +1312,16 @@ jump_threader::thread_across_edge (edge e,
 	  delete_jump_thread_path (path);
 
 	/* And unwind the equivalence table.  */
-	if (evrp_range_analyzer)
-	  evrp_range_analyzer->pop_to_marker ();
+	if (m_evrp_range_analyzer)
+	  m_evrp_range_analyzer->pop_to_marker ();
 	m_avail_exprs_stack->pop_to_marker ();
 	m_const_and_copies->pop_to_marker ();
       }
     BITMAP_FREE (visited);
   }
 
-  if (evrp_range_analyzer)
-    evrp_range_analyzer->pop_to_marker ();
+  if (m_evrp_range_analyzer)
+    m_evrp_range_analyzer->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();
   m_avail_exprs_stack->pop_to_marker ();
 }
@@ -1337,8 +1330,7 @@ jump_threader::thread_across_edge (edge e,
    try to thread them.  */
 
 void
-jump_threader::thread_outgoing_edges (basic_block bb,
-				      evrp_range_analyzer *evrp_range_analyzer)
+jump_threader::thread_outgoing_edges (basic_block bb)
 {
   int flags = (EDGE_IGNORE | EDGE_COMPLEX | EDGE_ABNORMAL);
   gimple *last;
@@ -1351,7 +1343,7 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       && (single_succ_edge (bb)->flags & flags) == 0
       && potentially_threadable_block (single_succ (bb)))
     {
-      thread_across_edge (single_succ_edge (bb), evrp_range_analyzer);
+      thread_across_edge (single_succ_edge (bb));
     }
   else if ((last = last_stmt (bb))
 	   && gimple_code (last) == GIMPLE_COND
@@ -1366,11 +1358,11 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       /* Only try to thread the edge if it reaches a target block with
 	 more than one predecessor and more than one successor.  */
       if (potentially_threadable_block (true_edge->dest))
-	thread_across_edge (true_edge, evrp_range_analyzer);
+	thread_across_edge (true_edge);
 
       /* Similarly for the ELSE arm.  */
       if (potentially_threadable_block (false_edge->dest))
-	thread_across_edge (false_edge, evrp_range_analyzer);
+	thread_across_edge (false_edge);
     }
 }
 
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index ea9dbb2f0db..059fcc4a233 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -36,11 +36,13 @@ class evrp_range_analyzer;
 class jump_threader
 {
 public:
-  jump_threader (const_and_copies *, avail_exprs_stack *,
+  jump_threader (const_and_copies *,
+		 avail_exprs_stack *,
+		 evrp_range_analyzer *,
 		 jump_threader_simplifier *);
   ~jump_threader ();
   // Entry point to calculate and register threadable paths.
-  void thread_outgoing_edges (basic_block, evrp_range_analyzer *);
+  void thread_outgoing_edges (basic_block);
   void remove_jump_threads_including (edge_def *);
   // Perform CFG changes after all threadable candidates have been
   // registered.
@@ -65,14 +67,11 @@ private:
 				   bitmap visited,
 				   vec<jump_thread_edge *> *path);
   int thread_through_normal_block (edge,
-				   evrp_range_analyzer *,
 				   vec<jump_thread_edge *> *path,
 				   bitmap visited);
-  void thread_across_edge (edge, evrp_range_analyzer *);
-  bool record_temporary_equivalences_from_phis (edge,
-						evrp_range_analyzer *);
-  gimple *record_temporary_equivalences_from_stmts_at_dest (edge,
-    evrp_range_analyzer *);
+  void thread_across_edge (edge);
+  bool record_temporary_equivalences_from_phis (edge);
+  gimple *record_temporary_equivalences_from_stmts_at_dest (edge);
 
   // Dummy condition to avoid creating lots of throw away statements.
   gcond *dummy_cond;
@@ -81,6 +80,7 @@ private:
   class avail_exprs_stack *m_avail_exprs_stack;
   class jump_thread_path_registry *m_registry;
   jump_threader_simplifier *m_simplifier;
+  evrp_range_analyzer *m_evrp_range_analyzer;
 };
 
 // Statement simplifier callback for the jump threader.
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 718e3a2a0b7..e0b9d402af8 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4277,7 +4277,7 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
   m_simplifier = new vrp_jump_threader_simplifier (m_vr_values,
 						   m_avail_exprs_stack);
   m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack,
-				  m_simplifier);
+				  NULL, m_simplifier);
 }
 
 vrp_jump_threader::~vrp_jump_threader ()
@@ -4337,7 +4337,7 @@ vrp_jump_threader::before_dom_children (basic_block bb)
 void
 vrp_jump_threader::after_dom_children (basic_block bb)
 {
-  m_threader->thread_outgoing_edges (bb, NULL);
+  m_threader->thread_outgoing_edges (bb);
   m_avail_exprs_stack->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();
 }


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

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

commit b30e9e9125f6fcf35a248a90e182a20c7e838ee6
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 16:47:59 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c          |  82 ++++++++++++++++-----------------
 gcc/tree-ssa-threadedge.c   |  92 ++++++++++++++-----------------------
 gcc/tree-ssa-threadedge.h   |  23 ++++------
 gcc/tree-ssa-threadupdate.h |   1 +
 gcc/tree-vrp.c              | 108 ++++++++++++++++++++++----------------------
 5 files changed, 137 insertions(+), 169 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 718eb3c2aca..5d84e569888 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -585,17 +585,42 @@ record_edge_info (basic_block bb)
     }
 }
 
+class dom_jump_threader_simplifier : public jump_threader_simplifier
+{
+public:
+  dom_jump_threader_simplifier (vr_values *v,
+				avail_exprs_stack *avails)
+    : jump_threader_simplifier (v, avails) {}
+
+private:
+  tree simplify (gimple *, gimple *, basic_block);
+};
+
+tree
+dom_jump_threader_simplifier::simplify (gimple *stmt,
+					gimple *within_stmt,
+					basic_block bb)
+{
+  /* First see if the conditional is in the hash table.  */
+  tree cached_lhs =  m_avail_exprs_stack->lookup_avail_expr (stmt,
+							     false, true);
+  if (cached_lhs)
+    return cached_lhs;
+
+  return jump_threader_simplifier::simplify (stmt, within_stmt, bb);
+}
 
 class dom_opt_dom_walker : public dom_walker
 {
 public:
   dom_opt_dom_walker (cdi_direction direction,
 		      jump_threader *threader,
+		      evrp_range_analyzer *analyzer,
 		      const_and_copies *const_and_copies,
 		      avail_exprs_stack *avail_exprs_stack)
-    : dom_walker (direction, REACHABLE_BLOCKS),
-      evrp_range_analyzer (true)
+    : dom_walker (direction, REACHABLE_BLOCKS)
     {
+      m_evrp_range_analyzer = analyzer;
       m_dummy_cond = gimple_build_cond (NE_EXPR, integer_zero_node,
 					integer_zero_node, NULL, NULL);
       m_const_and_copies = const_and_copies;
@@ -612,9 +637,6 @@ private:
   class const_and_copies *m_const_and_copies;
   class avail_exprs_stack *m_avail_exprs_stack;
 
-  /* VRP data.  */
-  class evrp_range_analyzer evrp_range_analyzer;
-
   /* Dummy condition to avoid creating lots of throw away statements.  */
   gcond *m_dummy_cond;
 
@@ -627,7 +649,9 @@ private:
 
   void test_for_singularity (gimple *, avail_exprs_stack *);
 
+  dom_jump_threader_simplifier *m_simplifier;
   jump_threader *m_threader;
+  evrp_range_analyzer *m_evrp_range_analyzer;
 };
 
 /* Jump threading, redundancy elimination and const/copy propagation.
@@ -722,9 +746,12 @@ pass_dominator::execute (function *fun)
     record_edge_info (bb);
 
   /* Recursively walk the dominator tree optimizing statements.  */
-  jump_threader threader (const_and_copies, avail_exprs_stack);
+  evrp_range_analyzer analyzer (true);
+  dom_jump_threader_simplifier simplifier (&analyzer, avail_exprs_stack);
+  jump_threader threader (const_and_copies, avail_exprs_stack, &simplifier);
   dom_opt_dom_walker walker (CDI_DOMINATORS,
 			     &threader,
+			     &analyzer,
 			     const_and_copies,
 			     avail_exprs_stack);
   walker.walk (fun->cfg->x_entry_block_ptr);
@@ -866,31 +893,6 @@ make_pass_dominator (gcc::context *ctxt)
   return new pass_dominator (ctxt);
 }
 
-class dom_jump_threader_simplifier : public jump_threader_simplifier
-{
-public:
-  dom_jump_threader_simplifier (vr_values *v,
-				avail_exprs_stack *avails)
-    : jump_threader_simplifier (v, avails) {}
-
-private:
-  tree simplify (gimple *, gimple *, basic_block);
-};
-
-tree
-dom_jump_threader_simplifier::simplify (gimple *stmt,
-					gimple *within_stmt,
-					basic_block bb)
-{
-  /* First see if the conditional is in the hash table.  */
-  tree cached_lhs =  m_avail_exprs_stack->lookup_avail_expr (stmt,
-							     false, true);
-  if (cached_lhs)
-    return cached_lhs;
-
-  return jump_threader_simplifier::simplify (stmt, within_stmt, bb);
-}
-
 /* Valueize hook for gimple_fold_stmt_to_constant_1.  */
 
 static tree
@@ -1379,7 +1381,7 @@ dom_opt_dom_walker::before_dom_children (basic_block bb)
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file, "\n\nOptimizing block #%d\n\n", bb->index);
 
-  evrp_range_analyzer.enter (bb);
+  m_evrp_range_analyzer->enter (bb);
 
   /* Push a marker on the stacks of local information so that we know how
      far to unwind when we finalize this block.  */
@@ -1417,7 +1419,7 @@ dom_opt_dom_walker::before_dom_children (basic_block bb)
 	}
 
       /* Compute range information and optimize the stmt.  */
-      evrp_range_analyzer.record_ranges_from_stmt (gsi_stmt (gsi), false);
+      m_evrp_range_analyzer->record_ranges_from_stmt (gsi_stmt (gsi), false);
       bool removed_p = false;
       taken_edge = this->optimize_stmt (bb, &gsi, &removed_p);
       if (!removed_p)
@@ -1462,16 +1464,12 @@ dom_opt_dom_walker::before_dom_children (basic_block bb)
 void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
-  dom_jump_threader_simplifier jthread_simplifier (&evrp_range_analyzer,
-						   m_avail_exprs_stack);
-  m_threader->thread_outgoing_edges (bb,
-				     &evrp_range_analyzer,
-				     jthread_simplifier);
+  m_threader->thread_outgoing_edges (bb, m_evrp_range_analyzer);
 
   /* These remove expressions local to BB from the tables.  */
   m_avail_exprs_stack->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();
-  evrp_range_analyzer.leave (bb);
+  m_evrp_range_analyzer->leave (bb);
 }
 
 /* Search for redundant computations in STMT.  If any are found, then
@@ -1932,7 +1930,7 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si,
   opt_stats.num_stmts++;
 
   /* Const/copy propagate into USES, VUSES and the RHS of VDEFs.  */
-  cprop_into_stmt (stmt, &evrp_range_analyzer);
+  cprop_into_stmt (stmt, m_evrp_range_analyzer);
 
   /* If the statement has been modified with constant replacements,
      fold its RHS before checking for redundant computations.  */
@@ -2030,8 +2028,8 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si,
 		 SSA_NAMES.  */
 	      update_stmt_if_modified (stmt);
 	      edge taken_edge = NULL;
-	      evrp_range_analyzer.vrp_visit_cond_stmt (as_a <gcond *> (stmt),
-						       &taken_edge);
+	      m_evrp_range_analyzer->vrp_visit_cond_stmt
+		(as_a <gcond *> (stmt), &taken_edge);
 	      if (taken_edge)
 		{
 		  if (taken_edge->flags & EDGE_TRUE_VALUE)
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 1af72b2dcaf..a8fae1804b0 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -62,7 +62,8 @@ set_ssa_name_value (tree name, tree value)
 }
 
 jump_threader::jump_threader (const_and_copies *copies,
-			      avail_exprs_stack *avails)
+			      avail_exprs_stack *avails,
+			      jump_threader_simplifier *simplifier)
 {
   /* Initialize the per SSA_NAME value-handles array.  */
   gcc_assert (!ssa_name_values.exists ());
@@ -74,6 +75,7 @@ jump_threader::jump_threader (const_and_copies *copies,
   m_const_and_copies = copies;
   m_avail_exprs_stack = avails;
   m_registry = new jump_thread_path_registry ();
+  m_simplifier = simplifier;
 }
 
 jump_threader::~jump_threader (void)
@@ -237,8 +239,7 @@ threadedge_valueize (tree t)
 
 gimple *
 jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
-    evrp_range_analyzer *evrp_range_analyzer,
-    jump_threader_simplifier &simplifier)
+    evrp_range_analyzer *evrp_range_analyzer)
 {
   gimple *stmt = NULL;
   gimple_stmt_iterator gsi;
@@ -401,7 +402,7 @@ jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
 		    SET_USE (use_p, tmp);
 		}
 
-	      cached_lhs = simplifier.simplify (stmt, stmt, e->src);
+	      cached_lhs = m_simplifier->simplify (stmt, stmt, e->src);
 
 	      /* Restore the statement's original uses/defs.  */
 	      i = 0;
@@ -431,10 +432,7 @@ jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
    the CASE_LABEL_EXPR that will be taken.  */
 
 tree
-jump_threader::simplify_control_stmt_condition
-			(edge e,
-			 gimple *stmt,
-			 jump_threader_simplifier &simplifier)
+jump_threader::simplify_control_stmt_condition (edge e, gimple *stmt)
 {
   tree cond, cached_lhs;
   enum gimple_code code = gimple_code (stmt);
@@ -478,9 +476,7 @@ jump_threader::simplify_control_stmt_condition
       const unsigned recursion_limit = 4;
 
       cached_lhs
-	= simplify_control_stmt_condition_1 (e, stmt,
-					     op0, cond_code, op1,
-					     simplifier,
+	= simplify_control_stmt_condition_1 (e, stmt, op0, cond_code, op1,
 					     recursion_limit);
 
       /* If we were testing an integer/pointer against a constant, then
@@ -550,11 +546,11 @@ jump_threader::simplify_control_stmt_condition
 		 the label that is proven to be taken.  */
 	      gswitch *dummy_switch = as_a<gswitch *> (gimple_copy (stmt));
 	      gimple_switch_set_index (dummy_switch, cached_lhs);
-	      cached_lhs = simplifier.simplify (dummy_switch, stmt, e->src);
+	      cached_lhs = m_simplifier->simplify (dummy_switch, stmt, e->src);
 	      ggc_free (dummy_switch);
 	    }
 	  else
-	    cached_lhs = simplifier.simplify (stmt, stmt, e->src);
+	    cached_lhs = m_simplifier->simplify (stmt, stmt, e->src);
 	}
 
       /* We couldn't find an invariant.  But, callers of this
@@ -578,7 +574,6 @@ jump_threader::simplify_control_stmt_condition_1
 					 tree op0,
 					 enum tree_code cond_code,
 					 tree op1,
-					 jump_threader_simplifier &simplifier,
 					 unsigned limit)
 {
   if (limit == 0)
@@ -616,7 +611,7 @@ jump_threader::simplify_control_stmt_condition_1
 	  const tree res1
 	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs1, NE_EXPR, op1,
-						 simplifier, limit - 1);
+						 limit - 1);
 	  if (res1 == NULL_TREE)
 	    ;
 	  else if (rhs_code == BIT_AND_EXPR && integer_zerop (res1))
@@ -642,7 +637,7 @@ jump_threader::simplify_control_stmt_condition_1
 	  const tree res2
 	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs2, NE_EXPR, op1,
-						 simplifier, limit - 1);
+						 limit - 1);
 	  if (res2 == NULL_TREE)
 	    ;
 	  else if (rhs_code == BIT_AND_EXPR && integer_zerop (res2))
@@ -706,7 +701,7 @@ jump_threader::simplify_control_stmt_condition_1
 	  tree res
 	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs1, new_cond, rhs2,
-						 simplifier, limit - 1);
+						 limit - 1);
 	  if (res != NULL_TREE && is_gimple_min_invariant (res))
 	    return res;
 	}
@@ -732,7 +727,7 @@ jump_threader::simplify_control_stmt_condition_1
      then use the pass specific callback to simplify the condition.  */
   if (!res
       || !is_gimple_min_invariant (res))
-    res = simplifier.simplify (dummy_cond, stmt, e->src);
+    res = m_simplifier->simplify (dummy_cond, stmt, e->src);
 
   return res;
 }
@@ -884,11 +879,9 @@ propagate_threaded_block_debug_into (basic_block dest, basic_block src)
    The available expression table is referenced via AVAIL_EXPRS_STACK.  */
 
 bool
-jump_threader::thread_around_empty_blocks
-			(edge taken_edge,
-			 jump_threader_simplifier &simplifier,
-			 bitmap visited,
-			 vec<jump_thread_edge *> *path)
+jump_threader::thread_around_empty_blocks (edge taken_edge,
+					   bitmap visited,
+					   vec<jump_thread_edge *> *path)
 {
   basic_block bb = taken_edge->dest;
   gimple_stmt_iterator gsi;
@@ -933,10 +926,7 @@ jump_threader::thread_around_empty_blocks
 		= new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
 	      path->safe_push (x);
 	      bitmap_set_bit (visited, taken_edge->dest->index);
-	      return thread_around_empty_blocks (taken_edge,
-						 simplifier,
-						 visited,
-						 path);
+	      return thread_around_empty_blocks (taken_edge, visited, path);
 	    }
 	}
 
@@ -953,7 +943,7 @@ jump_threader::thread_around_empty_blocks
     return false;
 
   /* Extract and simplify the condition.  */
-  cond = simplify_control_stmt_condition (taken_edge, stmt, simplifier);
+  cond = simplify_control_stmt_condition (taken_edge, stmt);
 
   /* If the condition can be statically computed and we have not already
      visited the destination edge, then add the taken edge to our thread
@@ -979,7 +969,7 @@ jump_threader::thread_around_empty_blocks
 	= new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
       path->safe_push (x);
 
-      thread_around_empty_blocks (taken_edge, simplifier, visited, path);
+      thread_around_empty_blocks (taken_edge, visited, path);
       return true;
     }
 
@@ -1002,8 +992,6 @@ jump_threader::thread_around_empty_blocks
    STACK is used to undo temporary equivalences created during the walk of
    E->dest.
 
-   SIMPLIFIER is a pass-specific function used to simplify statements.
-
    Our caller is responsible for restoring the state of the expression
    and const_and_copies stacks.
 
@@ -1016,7 +1004,6 @@ int
 jump_threader::thread_through_normal_block
 				(edge e,
 				 evrp_range_analyzer *evrp_range_analyzer,
-				 jump_threader_simplifier &simplifier,
 				 vec<jump_thread_edge *> *path,
 				 bitmap visited)
 {
@@ -1034,8 +1021,7 @@ jump_threader::thread_through_normal_block
      temporary equivalences we can detect.  */
   gimple *stmt
     = record_temporary_equivalences_from_stmts_at_dest (e,
-							evrp_range_analyzer,
-							simplifier);
+							evrp_range_analyzer);
 
   /* There's two reasons STMT might be null, and distinguishing
      between them is important.
@@ -1072,7 +1058,7 @@ jump_threader::thread_through_normal_block
       tree cond;
 
       /* Extract and simplify the condition.  */
-      cond = simplify_control_stmt_condition (e, stmt, simplifier);
+      cond = simplify_control_stmt_condition (e, stmt);
 
       if (!cond)
 	return 0;
@@ -1118,7 +1104,7 @@ jump_threader::thread_through_normal_block
  	     visited.  This may be overly conservative.  */
 	  bitmap_set_bit (visited, dest->index);
 	  bitmap_set_bit (visited, e->dest->index);
-	  thread_around_empty_blocks (taken_edge, simplifier, visited, path);
+	  thread_around_empty_blocks (taken_edge, visited, path);
 	  return 1;
 	}
     }
@@ -1188,14 +1174,11 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e)
 }
 
 /* We are exiting E->src, see if E->dest ends with a conditional
-   jump which has a known value when reached via E.
-
-   SIMPLIFIER is a pass-specific function used to simplify statements.  */
+   jump which has a known value when reached via E.  */
 
 void
 jump_threader::thread_across_edge (edge e,
-				   evrp_range_analyzer *evrp_range_analyzer,
-				   jump_threader_simplifier &simplifier)
+				   evrp_range_analyzer *evrp_range_analyzer)
 {
   bitmap visited = BITMAP_ALLOC (NULL);
 
@@ -1213,10 +1196,8 @@ jump_threader::thread_across_edge (edge e,
 
   int threaded;
   if ((e->flags & EDGE_DFS_BACK) == 0)
-    threaded = thread_through_normal_block (e,
-					    evrp_range_analyzer,
-					    simplifier, path,
-					    visited);
+    threaded = thread_through_normal_block (e, evrp_range_analyzer,
+					    path, visited);
   else
     threaded = 0;
 
@@ -1316,15 +1297,12 @@ jump_threader::thread_across_edge (edge e,
 
         x = new jump_thread_edge (taken_edge, EDGE_COPY_SRC_JOINER_BLOCK);
 	path->safe_push (x);
-	found = thread_around_empty_blocks (taken_edge,
-					    simplifier,
-					    visited,
-					    path);
+	found = thread_around_empty_blocks (taken_edge, visited, path);
 
 	if (!found)
 	  found = thread_through_normal_block (path->last ()->e,
 					       evrp_range_analyzer,
-					       simplifier, path,
+					       path,
 					       visited) > 0;
 
 	/* If we were able to thread through a successor of E->dest, then
@@ -1356,14 +1334,11 @@ jump_threader::thread_across_edge (edge e,
 }
 
 /* Examine the outgoing edges from BB and conditionally
-   try to thread them.
-
-   SIMPLIFIER is a pass-specific function used to simplify statements.  */
+   try to thread them.  */
 
 void
 jump_threader::thread_outgoing_edges (basic_block bb,
-				      evrp_range_analyzer *evrp_range_analyzer,
-				      jump_threader_simplifier &simplifier)
+				      evrp_range_analyzer *evrp_range_analyzer)
 {
   int flags = (EDGE_IGNORE | EDGE_COMPLEX | EDGE_ABNORMAL);
   gimple *last;
@@ -1376,8 +1351,7 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       && (single_succ_edge (bb)->flags & flags) == 0
       && potentially_threadable_block (single_succ (bb)))
     {
-      thread_across_edge (single_succ_edge (bb),
-			  evrp_range_analyzer, simplifier);
+      thread_across_edge (single_succ_edge (bb), evrp_range_analyzer);
     }
   else if ((last = last_stmt (bb))
 	   && gimple_code (last) == GIMPLE_COND
@@ -1392,11 +1366,11 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       /* Only try to thread the edge if it reaches a target block with
 	 more than one predecessor and more than one successor.  */
       if (potentially_threadable_block (true_edge->dest))
-	thread_across_edge (true_edge, evrp_range_analyzer, simplifier);
+	thread_across_edge (true_edge, evrp_range_analyzer);
 
       /* Similarly for the ELSE arm.  */
       if (potentially_threadable_block (false_edge->dest))
-	thread_across_edge (false_edge, evrp_range_analyzer, simplifier);
+	thread_across_edge (false_edge, evrp_range_analyzer);
     }
 }
 
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index e85b146fe2a..ea9dbb2f0db 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -36,12 +36,11 @@ class evrp_range_analyzer;
 class jump_threader
 {
 public:
-  jump_threader (const_and_copies *, avail_exprs_stack *);
+  jump_threader (const_and_copies *, avail_exprs_stack *,
+		 jump_threader_simplifier *);
   ~jump_threader ();
   // Entry point to calculate and register threadable paths.
-  void thread_outgoing_edges (basic_block,
-			      evrp_range_analyzer *,
-			      jump_threader_simplifier &);
+  void thread_outgoing_edges (basic_block, evrp_range_analyzer *);
   void remove_jump_threads_including (edge_def *);
   // Perform CFG changes after all threadable candidates have been
   // registered.
@@ -54,41 +53,34 @@ public:
   bool thread_through_all_blocks (bool may_peel_loop_headers);
 
 private:
-  tree simplify_control_stmt_condition (edge, gimple *,
-					jump_threader_simplifier &);
+  tree simplify_control_stmt_condition (edge, gimple *);
   tree simplify_control_stmt_condition_1 (edge,
 					  gimple *,
 					  tree op0,
 					  tree_code cond_code,
 					  tree op1,
-					  jump_threader_simplifier &simplify,
 					  unsigned limit);
 
   bool thread_around_empty_blocks (edge,
-				   jump_threader_simplifier &,
 				   bitmap visited,
 				   vec<jump_thread_edge *> *path);
   int thread_through_normal_block (edge,
 				   evrp_range_analyzer *,
-				   jump_threader_simplifier &,
 				   vec<jump_thread_edge *> *path,
 				   bitmap visited);
-  void thread_across_edge (edge,
-			   evrp_range_analyzer *,
-			   jump_threader_simplifier &simplify);
+  void thread_across_edge (edge, evrp_range_analyzer *);
   bool record_temporary_equivalences_from_phis (edge,
 						evrp_range_analyzer *);
   gimple *record_temporary_equivalences_from_stmts_at_dest (edge,
-    evrp_range_analyzer *,
-    jump_threader_simplifier &);
+    evrp_range_analyzer *);
 
   // Dummy condition to avoid creating lots of throw away statements.
   gcond *dummy_cond;
 
   class const_and_copies *m_const_and_copies;
   class avail_exprs_stack *m_avail_exprs_stack;
-
   class jump_thread_path_registry *m_registry;
+  jump_threader_simplifier *m_simplifier;
 };
 
 // Statement simplifier callback for the jump threader.
@@ -101,6 +93,7 @@ public:
     : m_vr_values (v),
       m_avail_exprs_stack (avails)
   { }
+  virtual ~jump_threader_simplifier () { }
   virtual tree simplify (gimple *, gimple *, basic_block);
 
 protected:
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 2c1dfd7cbac..44c908d627e 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef _TREE_SSA_THREADUPDATE_H
 #define _TREE_SSA_THREADUPDATE_H 1
 
+// FIXME: put this in jump_thread_edge
 enum jump_thread_edge_type
 {
   EDGE_START_JUMP_THREAD,
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 214aa86d889..718e3a2a0b7 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4152,6 +4152,54 @@ vrp_folder::fold_stmt (gimple_stmt_iterator *si)
   return simplifier.simplify (si);
 }
 
+class vrp_jump_threader_simplifier : public jump_threader_simplifier
+{
+public:
+  vrp_jump_threader_simplifier (vr_values *v, avail_exprs_stack *avails)
+    : jump_threader_simplifier (v, avails) {}
+
+private:
+  tree simplify (gimple *, gimple *, basic_block) OVERRIDE;
+};
+
+tree
+vrp_jump_threader_simplifier::simplify (gimple *stmt,
+					gimple *within_stmt,
+					basic_block bb)
+{
+  /* First see if the conditional is in the hash table.  */
+  tree cached_lhs = m_avail_exprs_stack->lookup_avail_expr (stmt, false, true);
+  if (cached_lhs && is_gimple_min_invariant (cached_lhs))
+    return cached_lhs;
+
+  if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
+    {
+      tree op0 = gimple_cond_lhs (cond_stmt);
+      op0 = lhs_of_dominating_assert (op0, bb, stmt);
+
+      tree op1 = gimple_cond_rhs (cond_stmt);
+      op1 = lhs_of_dominating_assert (op1, bb, stmt);
+
+      simplify_using_ranges simplifier (m_vr_values);
+      return simplifier.vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
+						  op0, op1, within_stmt);
+    }
+
+  if (gswitch *switch_stmt = dyn_cast <gswitch *> (stmt))
+    {
+      tree op = gimple_switch_index (switch_stmt);
+      if (TREE_CODE (op) != SSA_NAME)
+	return NULL_TREE;
+
+      op = lhs_of_dominating_assert (op, bb, stmt);
+
+      const value_range_equiv *vr = m_vr_values->get_value_range (op);
+      return find_case_label_range (switch_stmt, vr);
+    }
+
+  return jump_threader_simplifier::simplify (stmt, within_stmt, bb);
+}
+
 /* Blocks which have more than one predecessor and more than
    one successor present jump threading opportunities, i.e.,
    when the block is reached from a specific predecessor, we
@@ -4198,6 +4246,7 @@ private:
   const_and_copies *m_const_and_copies;
   avail_exprs_stack *m_avail_exprs_stack;
   hash_table<expr_elt_hasher> *m_avail_exprs;
+  vrp_jump_threader_simplifier *m_simplifier;
   jump_threader *m_threader;
 };
 
@@ -4225,7 +4274,10 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
   m_avail_exprs = new hash_table<expr_elt_hasher> (1024);
   m_avail_exprs_stack = new avail_exprs_stack (m_avail_exprs);
 
-  m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack);
+  m_simplifier = new vrp_jump_threader_simplifier (m_vr_values,
+						   m_avail_exprs_stack);
+  m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack,
+				  m_simplifier);
 }
 
 vrp_jump_threader::~vrp_jump_threader ()
@@ -4236,6 +4288,7 @@ vrp_jump_threader::~vrp_jump_threader ()
   delete m_const_and_copies;
   delete m_avail_exprs;
   delete m_avail_exprs_stack;
+  delete m_simplifier;
   delete m_threader;
 }
 
@@ -4279,63 +4332,12 @@ vrp_jump_threader::before_dom_children (basic_block bb)
   return NULL;
 }
 
-class vrp_jump_threader_simplifier : public jump_threader_simplifier
-{
-public:
-  vrp_jump_threader_simplifier (vr_values *v, avail_exprs_stack *avails)
-    : jump_threader_simplifier (v, avails) {}
-
-private:
-  tree simplify (gimple *, gimple *, basic_block) OVERRIDE;
-};
-
-tree
-vrp_jump_threader_simplifier::simplify (gimple *stmt,
-					gimple *within_stmt,
-					basic_block bb)
-{
-  /* First see if the conditional is in the hash table.  */
-  tree cached_lhs = m_avail_exprs_stack->lookup_avail_expr (stmt, false, true);
-  if (cached_lhs && is_gimple_min_invariant (cached_lhs))
-    return cached_lhs;
-
-  if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
-    {
-      tree op0 = gimple_cond_lhs (cond_stmt);
-      op0 = lhs_of_dominating_assert (op0, bb, stmt);
-
-      tree op1 = gimple_cond_rhs (cond_stmt);
-      op1 = lhs_of_dominating_assert (op1, bb, stmt);
-
-      simplify_using_ranges simplifier (m_vr_values);
-      return simplifier.vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
-						  op0, op1, within_stmt);
-    }
-
-  if (gswitch *switch_stmt = dyn_cast <gswitch *> (stmt))
-    {
-      tree op = gimple_switch_index (switch_stmt);
-      if (TREE_CODE (op) != SSA_NAME)
-	return NULL_TREE;
-
-      op = lhs_of_dominating_assert (op, bb, stmt);
-
-      const value_range_equiv *vr = m_vr_values->get_value_range (op);
-      return find_case_label_range (switch_stmt, vr);
-    }
-
-  return jump_threader_simplifier::simplify (stmt, within_stmt, bb);
-}
-
 /* Called after processing dominator children of BB.  This is where we
    actually call into the threader.  */
 void
 vrp_jump_threader::after_dom_children (basic_block bb)
 {
-  vrp_jump_threader_simplifier jthread_simplifier (m_vr_values,
-						   m_avail_exprs_stack);
-  m_threader->thread_outgoing_edges (bb, NULL, jthread_simplifier);
-
+  m_threader->thread_outgoing_edges (bb, NULL);
   m_avail_exprs_stack->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();
 }


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:25827c54457bb47010ca13ec14fb49449eec724a

commit 25827c54457bb47010ca13ec14fb49449eec724a
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 13:31:42 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.h   | 2 ++
 gcc/tree-ssa-threadupdate.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 87445a97033..e85b146fe2a 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -91,6 +91,8 @@ private:
   class jump_thread_path_registry *m_registry;
 };
 
+// Statement simplifier callback for the jump threader.
+
 class jump_threader_simplifier
 {
 public:
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index f515ca59f16..2c1dfd7cbac 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -32,6 +32,7 @@ enum jump_thread_edge_type
 
 // We keep the registered jump threading opportunities in this
 // vector as edge pairs (original_edge, target_edge).
+
 class jump_thread_edge
 {
 public:


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

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

commit d6abe7f8d1fd5385f26505763a5e0fed766da3e4
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 11:41:16 2020 +0100

    wip wip
    
    PASS

Diff:
---
 gcc/tree-ssa-threadedge.h   | 6 ++++--
 gcc/tree-ssa-threadupdate.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index d7bb323aaec..87445a97033 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -38,12 +38,14 @@ class jump_threader
 public:
   jump_threader (const_and_copies *, avail_exprs_stack *);
   ~jump_threader ();
+  // Entry point to calculate and register threadable paths.
   void thread_outgoing_edges (basic_block,
 			      evrp_range_analyzer *,
 			      jump_threader_simplifier &);
-  // ?? Temporary convenience functions that call through the
-  // registry.  This avoids having to expose the registry.
   void remove_jump_threads_including (edge_def *);
+  // Perform CFG changes after all threadable candidates have been
+  // registered.
+  //
   // TODO: Audit all calls to jump_threader::thread_through_all_blocks
   // to see if we can remove this method, and call
   // registry->thread_through_all_blocks() from the jump_threader
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index d98ecb9ae9c..f515ca59f16 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -74,6 +74,8 @@ public:
   ~jump_thread_path_registry ();
   void register_jump_thread (vec <jump_thread_edge *> *);
   void remove_jump_threads_including (edge);
+  // Perform CFG changes after all threadable candidates have been
+  // registered.
   bool thread_through_all_blocks (bool);
   void dump ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

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

commit d5f13bc7a902fb9ad1faa04d8f8536df173f8121
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 11:38:39 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.h   | 5 +++++
 gcc/tree-ssa-threadupdate.h | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 948d1ec4e3a..d7bb323aaec 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -28,6 +28,11 @@ class const_and_copies;
 class avail_exprs_stack;
 class evrp_range_analyzer;
 
+// This is the high level threader.  The entry point is
+// thread_outgoing_edges(), which calculates and registers path to be
+// threaded.  When all candidates have been registered,
+// thread_through_all_blocks() is called to actually change the CFG.
+
 class jump_threader
 {
 public:
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 1a4ef6fa5a5..d98ecb9ae9c 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -63,6 +63,10 @@ private:
   vec<jump_thread_edge *> *m_path;
 };
 
+// This is the underlying jump thread registry.  When all candidates
+// have been registered with register_jump_thread(),
+// thread_through_all_blocks() is called to actually change the CFG.
+
 class jump_thread_path_registry
 {
 public:


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:21479ada22b8d7b5feab266ec766db3b0f228db2

commit 21479ada22b8d7b5feab266ec766db3b0f228db2
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 11:32:01 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c   | 1 +
 gcc/tree-ssa-threadupdate.c | 2 +-
 gcc/tree-ssa-threadupdate.h | 4 ++--
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index bbb66e03747..1af72b2dcaf 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -79,6 +79,7 @@ jump_threader::jump_threader (const_and_copies *copies,
 jump_threader::~jump_threader (void)
 {
   ssa_name_values.release ();
+  ggc_free (dummy_cond);
   delete m_registry;
 }
 
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index c57aa5f140d..ee99c125338 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2142,7 +2142,7 @@ jump_thread_path_registry::debug_path (FILE *dump_file, int pathno)
 }
 
 void
-jump_thread_path_registry::debug_paths ()
+jump_thread_path_registry::dump ()
 {
   for (unsigned i = 0; i < m_paths.length (); ++i)
     debug_path (stderr, i);
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 48e80ac00ec..1a4ef6fa5a5 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -68,10 +68,10 @@ class jump_thread_path_registry
 public:
   jump_thread_path_registry ();
   ~jump_thread_path_registry ();
-  bool thread_through_all_blocks (bool);
   void register_jump_thread (vec <jump_thread_edge *> *);
   void remove_jump_threads_including (edge);
-  void debug_paths ();
+  bool thread_through_all_blocks (bool);
+  void dump ();
 
 private:
   void debug_path (FILE *, int pathno);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:68dbf2d3dc9b1dc4d36da74e35f8ed70bb39185c

commit 68dbf2d3dc9b1dc4d36da74e35f8ed70bb39185c
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 11:18:22 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 636a07b814e..948d1ec4e3a 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -39,6 +39,11 @@ public:
   // ?? Temporary convenience functions that call through the
   // registry.  This avoids having to expose the registry.
   void remove_jump_threads_including (edge_def *);
+  // TODO: Audit all calls to jump_threader::thread_through_all_blocks
+  // to see if we can remove this method, and call
+  // registry->thread_through_all_blocks() from the jump_threader
+  // destructor.  I'm just not 100% sure if this can be called after
+  // scev_finalize() and loop_optimizer_finalize(), etc.
   bool thread_through_all_blocks (bool may_peel_loop_headers);
 
 private:


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8b46a2353faf463ff735302bac5b91149dd6875f

commit 8b46a2353faf463ff735302bac5b91149dd6875f
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 11:15:38 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c        |  7 +++----
 gcc/tree-ssa-threadedge.c | 18 +++++++++++++++---
 gcc/tree-ssa-threadedge.h |  8 +++++---
 gcc/tree-vrp.c            | 25 +++++++++++--------------
 4 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 54bd5525d2b..718eb3c2aca 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -722,8 +722,7 @@ pass_dominator::execute (function *fun)
     record_edge_info (bb);
 
   /* Recursively walk the dominator tree optimizing statements.  */
-  jump_thread_path_registry registry;
-  jump_threader threader (&registry, const_and_copies, avail_exprs_stack);
+  jump_threader threader (const_and_copies, avail_exprs_stack);
   dom_opt_dom_walker walker (CDI_DOMINATORS,
 			     &threader,
 			     const_and_copies,
@@ -756,7 +755,7 @@ pass_dominator::execute (function *fun)
 	     containing any edge leaving BB.  */
 	  if (found)
 	    FOR_EACH_EDGE (e, ei, bb->succs)
-	      registry.remove_jump_threads_including (e);
+	      threader.remove_jump_threads_including (e);
 	}
     }
 
@@ -780,7 +779,7 @@ pass_dominator::execute (function *fun)
   free_all_edge_infos ();
 
   /* Thread jumps, creating duplicate blocks as needed.  */
-  cfg_altered |= registry.thread_through_all_blocks (may_peel_loop_headers_p);
+  cfg_altered |= threader.thread_through_all_blocks (may_peel_loop_headers_p);
 
   if (cfg_altered)
     free_dominance_info (CDI_DOMINATORS);
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index a2890b984d0..bbb66e03747 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -61,8 +61,7 @@ set_ssa_name_value (tree name, tree value)
   ssa_name_values[SSA_NAME_VERSION (name)] = value;
 }
 
-jump_threader::jump_threader (jump_thread_path_registry *registry,
-			      const_and_copies *copies,
+jump_threader::jump_threader (const_and_copies *copies,
 			      avail_exprs_stack *avails)
 {
   /* Initialize the per SSA_NAME value-handles array.  */
@@ -74,12 +73,25 @@ jump_threader::jump_threader (jump_thread_path_registry *registry,
 
   m_const_and_copies = copies;
   m_avail_exprs_stack = avails;
-  m_registry = registry;
+  m_registry = new jump_thread_path_registry ();
 }
 
 jump_threader::~jump_threader (void)
 {
   ssa_name_values.release ();
+  delete m_registry;
+}
+
+void
+jump_threader::remove_jump_threads_including (edge_def *e)
+{
+  m_registry->remove_jump_threads_including (e);
+}
+
+bool
+jump_threader::thread_through_all_blocks (bool may_peel_loop_headers)
+{
+  return m_registry->thread_through_all_blocks (may_peel_loop_headers);
 }
 
 /* Return TRUE if we may be able to thread an incoming edge into
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index da628a4f51d..636a07b814e 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -31,13 +31,15 @@ class evrp_range_analyzer;
 class jump_threader
 {
 public:
-  jump_threader (jump_thread_path_registry *,
-		 const_and_copies *,
-		 avail_exprs_stack *);
+  jump_threader (const_and_copies *, avail_exprs_stack *);
   ~jump_threader ();
   void thread_outgoing_edges (basic_block,
 			      evrp_range_analyzer *,
 			      jump_threader_simplifier &);
+  // ?? Temporary convenience functions that call through the
+  // registry.  This avoids having to expose the registry.
+  void remove_jump_threads_including (edge_def *);
+  bool thread_through_all_blocks (bool may_peel_loop_headers);
 
 private:
   tree simplify_control_stmt_condition (edge, gimple *,
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 3798b27a86a..214aa86d889 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4175,7 +4175,7 @@ vrp_folder::fold_stmt (gimple_stmt_iterator *si)
 class vrp_jump_threader : public dom_walker
 {
 public:
-  vrp_jump_threader (function *, vr_values *, jump_thread_path_registry *);
+  vrp_jump_threader (function *, vr_values *);
   ~vrp_jump_threader ();
 
   void thread_jumps ()
@@ -4183,6 +4183,12 @@ public:
     walk (m_fun->cfg->x_entry_block_ptr);
   }
 
+  void thread_through_all_blocks ()
+  {
+    // FIXME: Put this in the destructor?
+    m_threader->thread_through_all_blocks (false);
+  }
+
 private:
   virtual edge before_dom_children (basic_block);
   virtual void after_dom_children (basic_block);
@@ -4195,9 +4201,7 @@ private:
   jump_threader *m_threader;
 };
 
-vrp_jump_threader::vrp_jump_threader (struct function *fun,
-				      vr_values *v,
-				      jump_thread_path_registry *registry)
+vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
   : dom_walker (CDI_DOMINATORS, REACHABLE_BLOCKS)
 {
   /* Ugh.  When substituting values earlier in this pass we can wipe
@@ -4221,9 +4225,7 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun,
   m_avail_exprs = new hash_table<expr_elt_hasher> (1024);
   m_avail_exprs_stack = new avail_exprs_stack (m_avail_exprs);
 
-  m_threader = new jump_threader (registry,
-				  m_const_and_copies,
-				  m_avail_exprs_stack);
+  m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack);
 }
 
 vrp_jump_threader::~vrp_jump_threader ()
@@ -4492,8 +4494,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
 
   /* We must identify jump threading opportunities before we release
      the datastructures built by VRP.  */
-  jump_thread_path_registry registry;
-  vrp_jump_threader threader (fun, &vrp_vr_values, &registry);
+  vrp_jump_threader threader (fun, &vrp_vr_values);
   threader.thread_jumps ();
 
   /* A comparison of an SSA_NAME against a constant where the SSA_NAME
@@ -4532,11 +4533,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
 
      Note the SSA graph update will occur during the normal TODO
      processing by the pass manager.  */
-  // FIXME: the registry could be put in vrp_jump_threader and have
-  // its destructor call thread_through_all_blocks.  This would cause
-  // thread_through_all_blocks to happen after scev_finalize and
-  // loop_optimizer_finalize below.  Is this ok?
-  registry.thread_through_all_blocks (false);
+  threader.thread_through_all_blocks ();
 
   scev_finalize ();
   loop_optimizer_finalize ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

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

commit a6a2a0133745cf4c4612c249552748fcdb61dd08
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 10:59:17 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadbackward.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index a28a20d6de1..0b58e4c6b9b 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -39,11 +39,11 @@ along with GCC; see the file COPYING3.  If not see
 
 class thread_jumps
 {
- public:
-  thread_jumps (jump_thread_path_registry *r) : m_registry (r) { }
+public:
   void find_jump_threads_backwards (basic_block bb, bool speed_p);
+  bool thread_through_all_blocks ();
 
- private:
+private:
   edge profitable_jump_thread_path (basic_block bbi, tree name, tree arg,
 				    bool *creates_irreducible_loop);
   void convert_and_register_current_path (edge taken_edge);
@@ -68,9 +68,15 @@ class thread_jumps
      code path.  */
   bool m_speed_p;
 
-  jump_thread_path_registry *m_registry;
+  jump_thread_path_registry m_registry;
 };
 
+bool
+thread_jumps::thread_through_all_blocks ()
+{
+  return m_registry.thread_through_all_blocks (true);
+}
+
 /* Simple helper to get the last statement from BB, which is assumed
    to be a control statement.   Return NULL if the last statement is
    not a control statement.  */
@@ -477,7 +483,7 @@ thread_jumps::convert_and_register_current_path (edge taken_edge)
     = new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
   jump_thread_path->safe_push (x);
 
-  m_registry->register_jump_thread (jump_thread_path);
+  m_registry.register_jump_thread (jump_thread_path);
   --m_max_threaded_paths;
 }
 
@@ -819,18 +825,14 @@ pass_thread_jumps::execute (function *fun)
   loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES);
 
   /* Try to thread each block with more than one successor.  */
-  jump_thread_path_registry registry;
-  thread_jumps backwards_threader (&registry);
+  thread_jumps threader;
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
     {
       if (EDGE_COUNT (bb->succs) > 1)
-	backwards_threader.find_jump_threads_backwards (bb, true);
+	threader.find_jump_threads_backwards (bb, true);
     }
-  // FIXME: Put registry in thread_jumps and call thread_through_all_blocks
-  // from the destructor?  Is it ok to call thread_through_all_blocks
-  // before loop_optimizer_finalize below?
-  bool changed = registry.thread_through_all_blocks (true);
+  bool changed = threader.thread_through_all_blocks ();
 
   loop_optimizer_finalize ();
   return changed ? TODO_cleanup_cfg : 0;
@@ -884,18 +886,14 @@ pass_early_thread_jumps::execute (function *fun)
   loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
 
   /* Try to thread each block with more than one successor.  */
-  jump_thread_path_registry registry;
-  thread_jumps backwards_threader (&registry);
+  thread_jumps threader;
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
     {
       if (EDGE_COUNT (bb->succs) > 1)
-	backwards_threader.find_jump_threads_backwards (bb, false);
+	threader.find_jump_threads_backwards (bb, false);
     }
-  // FIXME: Put registry in thread_jumps and call thread_through_all_blocks
-  // from the destructor?  Is it ok to call thread_through_all_blocks
-  // before loop_optimizer_finalize below?
-  registry.thread_through_all_blocks (true);
+  threader.thread_through_all_blocks ();
 
   loop_optimizer_finalize ();
   return 0;


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9b3737d25df93f299f5f8d6d35a4a95b27453597

commit 9b3737d25df93f299f5f8d6d35a4a95b27453597
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 24 10:48:45 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c        | 19 +++++++++++--------
 gcc/tree-ssa-threadedge.c | 12 ++++--------
 gcc/tree-ssa-threadedge.h | 10 ++++++++--
 gcc/tree-vrp.c            | 15 +++++++--------
 4 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index e0baa65f36c..54bd5525d2b 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -870,24 +870,26 @@ make_pass_dominator (gcc::context *ctxt)
 class dom_jump_threader_simplifier : public jump_threader_simplifier
 {
 public:
-  dom_jump_threader_simplifier (vr_values *v) : jump_threader_simplifier (v) {}
+  dom_jump_threader_simplifier (vr_values *v,
+				avail_exprs_stack *avails)
+    : jump_threader_simplifier (v, avails) {}
 
 private:
-  tree simplify (gimple *, gimple *, avail_exprs_stack *, basic_block);
+  tree simplify (gimple *, gimple *, basic_block);
 };
 
 tree
-dom_jump_threader_simplifier::simplify (gimple *stmt, gimple *within_stmt,
-					avail_exprs_stack *avail_exprs_stack,
+dom_jump_threader_simplifier::simplify (gimple *stmt,
+					gimple *within_stmt,
 					basic_block bb)
 {
   /* First see if the conditional is in the hash table.  */
-  tree cached_lhs =  avail_exprs_stack->lookup_avail_expr (stmt, false, true);
+  tree cached_lhs =  m_avail_exprs_stack->lookup_avail_expr (stmt,
+							     false, true);
   if (cached_lhs)
     return cached_lhs;
 
-  return jump_threader_simplifier::simplify (stmt, within_stmt,
-					     avail_exprs_stack, bb);
+  return jump_threader_simplifier::simplify (stmt, within_stmt, bb);
 }
 
 /* Valueize hook for gimple_fold_stmt_to_constant_1.  */
@@ -1461,7 +1463,8 @@ dom_opt_dom_walker::before_dom_children (basic_block bb)
 void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
-  dom_jump_threader_simplifier jthread_simplifier (&evrp_range_analyzer);
+  dom_jump_threader_simplifier jthread_simplifier (&evrp_range_analyzer,
+						   m_avail_exprs_stack);
   m_threader->thread_outgoing_edges (bb,
 				     &evrp_range_analyzer,
 				     jthread_simplifier);
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 576f6217987..a2890b984d0 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -388,8 +388,7 @@ jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
 		    SET_USE (use_p, tmp);
 		}
 
-	      cached_lhs = simplifier.simplify (stmt, stmt,
-						m_avail_exprs_stack, e->src);
+	      cached_lhs = simplifier.simplify (stmt, stmt, e->src);
 
 	      /* Restore the statement's original uses/defs.  */
 	      i = 0;
@@ -538,13 +537,11 @@ jump_threader::simplify_control_stmt_condition
 		 the label that is proven to be taken.  */
 	      gswitch *dummy_switch = as_a<gswitch *> (gimple_copy (stmt));
 	      gimple_switch_set_index (dummy_switch, cached_lhs);
-	      cached_lhs = simplifier.simplify (dummy_switch, stmt,
-						m_avail_exprs_stack, e->src);
+	      cached_lhs = simplifier.simplify (dummy_switch, stmt, e->src);
 	      ggc_free (dummy_switch);
 	    }
 	  else
-	    cached_lhs = simplifier.simplify (stmt, stmt, m_avail_exprs_stack,
-					      e->src);
+	    cached_lhs = simplifier.simplify (stmt, stmt, e->src);
 	}
 
       /* We couldn't find an invariant.  But, callers of this
@@ -722,7 +719,7 @@ jump_threader::simplify_control_stmt_condition_1
      then use the pass specific callback to simplify the condition.  */
   if (!res
       || !is_gimple_min_invariant (res))
-    res = simplifier.simplify (dummy_cond, stmt, m_avail_exprs_stack, e->src);
+    res = simplifier.simplify (dummy_cond, stmt, e->src);
 
   return res;
 }
@@ -1393,7 +1390,6 @@ jump_threader::thread_outgoing_edges (basic_block bb,
 tree
 jump_threader_simplifier::simplify (gimple *stmt,
 				    gimple *within_stmt,
-				    avail_exprs_stack *,
 				    basic_block)
 {
   if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 4b23f7030f8..da628a4f51d 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -80,10 +80,16 @@ private:
 class jump_threader_simplifier
 {
 public:
-  jump_threader_simplifier (vr_values *v) : m_vr_values (v) { }
-  virtual tree simplify (gimple *, gimple *, avail_exprs_stack *, basic_block);
+  jump_threader_simplifier (vr_values *v,
+			    avail_exprs_stack *avails)
+    : m_vr_values (v),
+      m_avail_exprs_stack (avails)
+  { }
+  virtual tree simplify (gimple *, gimple *, basic_block);
+
 protected:
   vr_values *m_vr_values;
+  avail_exprs_stack *m_avail_exprs_stack;
 };
 
 extern vec<tree> ssa_name_values;
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 33a48fbfe6f..3798b27a86a 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4280,21 +4280,20 @@ vrp_jump_threader::before_dom_children (basic_block bb)
 class vrp_jump_threader_simplifier : public jump_threader_simplifier
 {
 public:
-  vrp_jump_threader_simplifier (vr_values *v) : jump_threader_simplifier (v) {}
+  vrp_jump_threader_simplifier (vr_values *v, avail_exprs_stack *avails)
+    : jump_threader_simplifier (v, avails) {}
 
 private:
-  tree simplify (gimple *, gimple *, avail_exprs_stack *,
-		 basic_block) OVERRIDE;
+  tree simplify (gimple *, gimple *, basic_block) OVERRIDE;
 };
 
 tree
 vrp_jump_threader_simplifier::simplify (gimple *stmt,
 					gimple *within_stmt,
-					avail_exprs_stack *avail_exprs_stack,
 					basic_block bb)
 {
   /* First see if the conditional is in the hash table.  */
-  tree cached_lhs = avail_exprs_stack->lookup_avail_expr (stmt, false, true);
+  tree cached_lhs = m_avail_exprs_stack->lookup_avail_expr (stmt, false, true);
   if (cached_lhs && is_gimple_min_invariant (cached_lhs))
     return cached_lhs;
 
@@ -4323,8 +4322,7 @@ vrp_jump_threader_simplifier::simplify (gimple *stmt,
       return find_case_label_range (switch_stmt, vr);
     }
 
-  return jump_threader_simplifier::simplify (stmt, within_stmt,
-					     avail_exprs_stack, bb);
+  return jump_threader_simplifier::simplify (stmt, within_stmt, bb);
 }
 
 /* Called after processing dominator children of BB.  This is where we
@@ -4332,7 +4330,8 @@ vrp_jump_threader_simplifier::simplify (gimple *stmt,
 void
 vrp_jump_threader::after_dom_children (basic_block bb)
 {
-  vrp_jump_threader_simplifier jthread_simplifier (m_vr_values);
+  vrp_jump_threader_simplifier jthread_simplifier (m_vr_values,
+						   m_avail_exprs_stack);
   m_threader->thread_outgoing_edges (bb, NULL, jthread_simplifier);
 
   m_avail_exprs_stack->pop_to_marker ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

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

commit d57deb6ca2101c42a70d1e5d22e64c49e84d7ecc
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 19:58:39 2020 +0100

    wip wip
    
    PASS

Diff:
---
 gcc/tree-ssa-threadupdate.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 0a9ae0f4f0d..48e80ac00ec 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -30,13 +30,15 @@ enum jump_thread_edge_type
   EDGE_NO_COPY_SRC_BLOCK
 };
 
+// We keep the registered jump threading opportunities in this
+// vector as edge pairs (original_edge, target_edge).
 class jump_thread_edge
 {
 public:
   jump_thread_edge (edge e, jump_thread_edge_type t) : e (e), type (t) {}
 
   edge e;
-  enum jump_thread_edge_type type;
+  jump_thread_edge_type type;
 };
 
 class jump_thread_path
@@ -44,6 +46,7 @@ class jump_thread_path
 public:
   jump_thread_path () { m_path = new vec<jump_thread_edge *> (); }
   jump_thread_edge *&operator[] (int i) { return (*m_path)[i]; }
+  jump_thread_edge *&last (void) { return m_path->last (); }
   void safe_push (jump_thread_edge *e) { m_path->safe_push (e); }
   unsigned length () { return m_path->length (); }
   void release ()
@@ -66,7 +69,7 @@ public:
   jump_thread_path_registry ();
   ~jump_thread_path_registry ();
   bool thread_through_all_blocks (bool);
-  void register_jump_thread (vec <class jump_thread_edge *> *);
+  void register_jump_thread (vec <jump_thread_edge *> *);
   void remove_jump_threads_including (edge);
   void debug_paths ();
 
@@ -86,8 +89,6 @@ private:
 				   bool may_peel_loop_headers);
   class redirection_data *lookup_redirection_data (edge e, enum insert_option);
 
-  // We keep the registered jump threading opportunities in this
-  // vector as edge pairs (original_edge, target_edge).
   vec<vec<jump_thread_edge *> *> m_paths;
 
   hash_table<struct removed_edges> *m_removed_edges;
@@ -109,7 +110,7 @@ struct removed_edges : nofree_ptr_hash<edge_def>
   static bool equal (edge e1, edge e2) { return e1 == e2; }
 };
 
-extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);
+extern void delete_jump_thread_path (vec <jump_thread_edge *> *);
 extern unsigned int estimate_threading_killed_stmts (basic_block);
 
 enum bb_dom_status


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:12ef19c37283812c898b3ff798ae91fdbbfb2a7b

commit 12ef19c37283812c898b3ff798ae91fdbbfb2a7b
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 19:46:17 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 1714537482a..0a9ae0f4f0d 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -43,11 +43,18 @@ class jump_thread_path
 {
 public:
   jump_thread_path () { m_path = new vec<jump_thread_edge *> (); }
-  void release () { m_path->release (); }
   jump_thread_edge *&operator[] (int i) { return (*m_path)[i]; }
   void safe_push (jump_thread_edge *e) { m_path->safe_push (e); }
   unsigned length () { return m_path->length (); }
-  //  void delete_jump_thread_path ();
+  void release ()
+  {
+    for (unsigned int i = 0; i < m_path->length (); i++)
+      delete (*m_path)[i];
+    m_path->release();
+    memset (m_path, 0x13, sizeof (*m_path));
+    delete m_path;
+    m_path = 0;
+  }
 
 private:
   vec<jump_thread_edge *> *m_path;


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:50 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:50 UTC (permalink / raw)
  To: gcc-cvs

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

commit eea2630c7219c06eabe5abfc9419b07c066ebb74
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 19:35:16 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 66 ++++++++++++++++++++++-----------------------
 gcc/tree-ssa-threadupdate.h | 12 ++++++++-
 2 files changed, 44 insertions(+), 34 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 346b093a0df..c57aa5f140d 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -142,7 +142,7 @@ struct redirection_data : free_ptr_hash<redirection_data>
 
 jump_thread_path_registry::jump_thread_path_registry ()
 {
-  paths.create (5);
+  m_paths.create (5);
   m_removed_edges = new hash_table<struct removed_edges> (17);
   m_num_threaded_edges = 0;
   m_redirection_data = NULL;
@@ -150,7 +150,7 @@ jump_thread_path_registry::jump_thread_path_registry ()
 
 jump_thread_path_registry::~jump_thread_path_registry ()
 {
-  paths.release ();
+  m_paths.release ();
   delete m_removed_edges;
 }
 
@@ -1885,9 +1885,9 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 
      So first convert the jump thread requests which do not require a
      joiner block.  */
-  for (i = 0; i < paths.length (); i++)
+  for (i = 0; i < m_paths.length (); i++)
     {
-      vec<jump_thread_edge *> *path = paths[i];
+      vec<jump_thread_edge *> *path = m_paths[i];
 
       if (path->length () > 1
 	  && (*path)[1]->type != EDGE_COPY_SRC_JOINER_BLOCK)
@@ -1906,9 +1906,9 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
      cases where the second path starts at a downstream edge on the same
      path).  First record all joiner paths, deleting any in the unexpected
      case where there is already a path for that incoming edge.  */
-  for (i = 0; i < paths.length ();)
+  for (i = 0; i < m_paths.length ();)
     {
-      vec<jump_thread_edge *> *path = paths[i];
+      vec<jump_thread_edge *> *path = m_paths[i];
 
       if (path->length () > 1
 	  && (*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK)
@@ -1921,7 +1921,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 	    }
 	  else
 	    {
-	      paths.unordered_remove (i);
+	      m_paths.unordered_remove (i);
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		dump_jump_thread_path (dump_file, *path, false);
 	      delete_jump_thread_path (path);
@@ -1935,9 +1935,9 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 
   /* Second, look for paths that have any other jump thread attached to
      them, and either finish converting them or cancel them.  */
-  for (i = 0; i < paths.length ();)
+  for (i = 0; i < m_paths.length ();)
     {
-      vec<jump_thread_edge *> *path = paths[i];
+      vec<jump_thread_edge *> *path = m_paths[i];
       edge e = (*path)[0]->e;
 
       if (path->length () > 1
@@ -1958,7 +1958,7 @@ jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 	  else
 	    {
 	      e->aux = NULL;
-	      paths.unordered_remove (i);
+	      m_paths.unordered_remove (i);
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		dump_jump_thread_path (dump_file, *path, false);
 	      delete_jump_thread_path (path);
@@ -2133,7 +2133,7 @@ bb_in_bbs (basic_block bb, basic_block *bbs, int n)
 void
 jump_thread_path_registry::debug_path (FILE *dump_file, int pathno)
 {
-  vec<jump_thread_edge *> *p = paths[pathno];
+  vec<jump_thread_edge *> *p = m_paths[pathno];
   fprintf (dump_file, "path: ");
   for (unsigned i = 0; i < p->length (); ++i)
     fprintf (dump_file, "%d -> %d, ",
@@ -2144,7 +2144,7 @@ jump_thread_path_registry::debug_path (FILE *dump_file, int pathno)
 void
 jump_thread_path_registry::debug_paths ()
 {
-  for (unsigned i = 0; i < paths.length (); ++i)
+  for (unsigned i = 0; i < m_paths.length (); ++i)
     debug_path (stderr, i);
 }
 
@@ -2160,7 +2160,7 @@ bool
 jump_thread_path_registry::rewire_first_differing_edge (unsigned path_num,
 							unsigned edge_num)
 {
-  vec<jump_thread_edge *> *path = paths[path_num];
+  vec<jump_thread_edge *> *path = m_paths[path_num];
   edge &e = (*path)[edge_num]->e;
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file, "rewiring edge candidate: %d -> %d\n",
@@ -2206,7 +2206,7 @@ void
 jump_thread_path_registry::adjust_paths_after_duplication
 	(unsigned curr_path_num)
 {
-  vec<jump_thread_edge *> *curr_path = paths[curr_path_num];
+  vec<jump_thread_edge *> *curr_path = m_paths[curr_path_num];
   gcc_assert ((*curr_path)[0]->type == EDGE_FSM_THREAD);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
@@ -2216,7 +2216,7 @@ jump_thread_path_registry::adjust_paths_after_duplication
     }
 
   /* Iterate through all the other paths and adjust them.  */
-  for (unsigned cand_path_num = 0; cand_path_num < paths.length (); )
+  for (unsigned cand_path_num = 0; cand_path_num < m_paths.length (); )
     {
       if (cand_path_num == curr_path_num)
 	{
@@ -2225,7 +2225,7 @@ jump_thread_path_registry::adjust_paths_after_duplication
 	}
       /* Make sure the candidate to adjust starts with the same path
 	 as the recently threaded path and is an FSM thread.  */
-      vec<jump_thread_edge *> *cand_path = paths[cand_path_num];
+      vec<jump_thread_edge *> *cand_path = m_paths[cand_path_num];
       if ((*cand_path)[0]->type != EDGE_FSM_THREAD
 	  || (*cand_path)[0]->e != (*curr_path)[0]->e)
 	{
@@ -2280,7 +2280,7 @@ jump_thread_path_registry::adjust_paths_after_duplication
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		fprintf (dump_file, "adjusted candidate: [EMPTY]\n");
 	      delete_jump_thread_path (cand_path);
-	      paths.unordered_remove (cand_path_num);
+	      m_paths.unordered_remove (cand_path_num);
 	      continue;
 	    }
 	  /* Otherwise, just remove the redundant sub-path.  */
@@ -2489,7 +2489,7 @@ valid_jump_thread_path (vec<jump_thread_edge *> *path)
 void
 jump_thread_path_registry::remove_jump_threads_including (edge_def *e)
 {
-  if (!paths.exists ())
+  if (!m_paths.exists ())
     return;
 
   edge *slot = m_removed_edges->find_slot (e, INSERT);
@@ -2517,7 +2517,7 @@ jump_thread_path_registry::thread_through_all_blocks
   auto_bitmap threaded_blocks;
   hash_set<edge> visited_starting_edges;
 
-  if (!paths.exists ())
+  if (!m_paths.exists ())
     {
       retval = false;
       goto out;
@@ -2527,10 +2527,10 @@ jump_thread_path_registry::thread_through_all_blocks
 
   /* Remove any paths that referenced removed edges.  */
   if (m_removed_edges)
-    for (i = 0; i < paths.length (); )
+    for (i = 0; i < m_paths.length (); )
       {
 	unsigned int j;
-	vec<jump_thread_edge *> *path = paths[i];
+	vec<jump_thread_edge *> *path = m_paths[i];
 
 	for (j = 0; j < path->length (); j++)
 	  {
@@ -2542,16 +2542,16 @@ jump_thread_path_registry::thread_through_all_blocks
 	if (j != path->length ())
 	  {
 	    delete_jump_thread_path (path);
-	    paths.unordered_remove (i);
+	    m_paths.unordered_remove (i);
 	    continue;
 	  }
 	i++;
       }
 
   /* Jump-thread all FSM threads before other jump-threads.  */
-  for (i = 0; i < paths.length ();)
+  for (i = 0; i < m_paths.length ();)
     {
-      vec<jump_thread_edge *> *path = paths[i];
+      vec<jump_thread_edge *> *path = m_paths[i];
       edge entry = (*path)[0]->e;
 
       /* Only code-generate FSM jump-threads in this loop.  */
@@ -2576,7 +2576,7 @@ jump_thread_path_registry::thread_through_all_blocks
 	{
 	  /* Remove invalid FSM jump-thread paths.  */
 	  delete_jump_thread_path (path);
-	  paths.unordered_remove (i);
+	  m_paths.unordered_remove (i);
 	  continue;
 	}
 
@@ -2597,22 +2597,22 @@ jump_thread_path_registry::thread_through_all_blocks
 	}
 
       delete_jump_thread_path (path);
-      paths.unordered_remove (i);
+      m_paths.unordered_remove (i);
       free (region);
     }
 
   /* Remove from PATHS all the jump-threads starting with an edge already
      jump-threaded.  */
-  for (i = 0; i < paths.length ();)
+  for (i = 0; i < m_paths.length ();)
     {
-      vec<jump_thread_edge *> *path = paths[i];
+      vec<jump_thread_edge *> *path = m_paths[i];
       edge entry = (*path)[0]->e;
 
       /* Do not jump-thread twice from the same block.  */
       if (visited_starting_edges.contains (entry))
 	{
 	  delete_jump_thread_path (path);
-	  paths.unordered_remove (i);
+	  m_paths.unordered_remove (i);
 	}
       else
 	i++;
@@ -2678,7 +2678,7 @@ jump_thread_path_registry::thread_through_all_blocks
 
   free_original_copy_tables ();
 
-  paths.release ();
+  m_paths.release ();
 
   if (retval)
     loops_state_set (LOOPS_NEED_FIXUP);
@@ -2743,10 +2743,10 @@ jump_thread_path_registry::register_jump_thread (vec<jump_thread_edge *> *path)
   if (dump_file && (dump_flags & TDF_DETAILS))
     dump_jump_thread_path (dump_file, *path, true);
 
-  if (!paths.exists ())
-    paths.create (5);
+  if (!m_paths.exists ())
+    m_paths.create (5);
 
-  paths.safe_push (path);
+  m_paths.safe_push (path);
 }
 
 /* Return how many uses of T there are within BB, as long as there
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 497162bc60c..1714537482a 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -41,6 +41,16 @@ public:
 
 class jump_thread_path
 {
+public:
+  jump_thread_path () { m_path = new vec<jump_thread_edge *> (); }
+  void release () { m_path->release (); }
+  jump_thread_edge *&operator[] (int i) { return (*m_path)[i]; }
+  void safe_push (jump_thread_edge *e) { m_path->safe_push (e); }
+  unsigned length () { return m_path->length (); }
+  //  void delete_jump_thread_path ();
+
+private:
+  vec<jump_thread_edge *> *m_path;
 };
 
 class jump_thread_path_registry
@@ -71,7 +81,7 @@ private:
 
   // We keep the registered jump threading opportunities in this
   // vector as edge pairs (original_edge, target_edge).
-  vec<vec<jump_thread_edge *> *> paths;
+  vec<vec<jump_thread_edge *> *> m_paths;
 
   hash_table<struct removed_edges> *m_removed_edges;


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

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

commit b0d22358a24a5575625b11183923a6ad423b9815
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 19:10:39 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index ce54b74d199..497162bc60c 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -39,29 +39,9 @@ public:
   enum jump_thread_edge_type type;
 };
 
-// Rather than search all the edges in jump thread paths each time DOM
-// is able to simply if control statement, we build a hash table with
-// the deleted edges.  We only care about the address of the edge, not
-// its contents.
-struct removed_edges : nofree_ptr_hash<edge_def>
-{
-  static hashval_t hash (edge e) { return htab_hash_pointer (e); }
-  static bool equal (edge e1, edge e2) { return e1 == e2; }
-};
-
-/*
 class jump_thread_path
 {
-public:
-  jump_thread_path ();
-  void add (jump_thread_edge);	 // safe_push
-  jump_thread_edge &operator[] (int i);
-  void operator delete (void *); // delete_jump_thread_path
-
-private:
-  vec<jump_thread_edge *> m_path;
 };
-*/
 
 class jump_thread_path_registry
 {
@@ -93,7 +73,7 @@ private:
   // vector as edge pairs (original_edge, target_edge).
   vec<vec<jump_thread_edge *> *> paths;
 
-  hash_table<removed_edges> *m_removed_edges;
+  hash_table<struct removed_edges> *m_removed_edges;
 
   // Main data structure to hold information for duplicates of BB.
   hash_table<redirection_data> *m_redirection_data;
@@ -102,6 +82,16 @@ private:
   unsigned long m_num_threaded_edges;
 };
 
+// Rather than search all the edges in jump thread paths each time DOM
+// is able to simply if control statement, we build a hash table with
+// the deleted edges.  We only care about the address of the edge, not
+// its contents.
+struct removed_edges : nofree_ptr_hash<edge_def>
+{
+  static hashval_t hash (edge e) { return htab_hash_pointer (e); }
+  static bool equal (edge e1, edge e2) { return e1 == e2; }
+};
+
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);
 extern unsigned int estimate_threading_killed_stmts (basic_block);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:58347075e625f546f9a615a9e1bec926eca0d5e9

commit 58347075e625f546f9a615a9e1bec926eca0d5e9
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 19:05:18 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 8c67778e9ef..ce54b74d199 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -33,7 +33,7 @@ enum jump_thread_edge_type
 class jump_thread_edge
 {
 public:
-  jump_thread_edge (edge e, jump_thread_edge_type type) : e (e), type (type) {}
+  jump_thread_edge (edge e, jump_thread_edge_type t) : e (e), type (t) {}
 
   edge e;
   enum jump_thread_edge_type type;


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:15b4c5354f67f94fdeb732fc64f7e32060cc6149

commit 15b4c5354f67f94fdeb732fc64f7e32060cc6149
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 19:04:52 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index c914ceae161..8c67778e9ef 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -21,7 +21,6 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef _TREE_SSA_THREADUPDATE_H
 #define _TREE_SSA_THREADUPDATE_H 1
 
-/* In tree-ssa-threadupdate.c.  */
 enum jump_thread_edge_type
 {
   EDGE_START_JUMP_THREAD,
@@ -34,17 +33,16 @@ enum jump_thread_edge_type
 class jump_thread_edge
 {
 public:
-  jump_thread_edge (edge e, enum jump_thread_edge_type type)
-    : e (e), type (type) {}
+  jump_thread_edge (edge e, jump_thread_edge_type type) : e (e), type (type) {}
 
   edge e;
   enum jump_thread_edge_type type;
 };
 
-/* Rather than search all the edges in jump thread paths each time
-   DOM is able to simply if control statement, we build a hash table
-   with the deleted edges.  We only care about the address of the edge,
-   not its contents.  */
+// Rather than search all the edges in jump thread paths each time DOM
+// is able to simply if control statement, we build a hash table with
+// the deleted edges.  We only care about the address of the edge, not
+// its contents.
 struct removed_edges : nofree_ptr_hash<edge_def>
 {
   static hashval_t hash (edge e) { return htab_hash_pointer (e); }
@@ -97,11 +95,11 @@ private:
 
   hash_table<removed_edges> *m_removed_edges;
 
-  // Jump threading statistics.
-  unsigned long m_num_threaded_edges;
-
   // Main data structure to hold information for duplicates of BB.
   hash_table<redirection_data> *m_redirection_data;
+
+  // Jump threading statistics.
+  unsigned long m_num_threaded_edges;
 };
 
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);
@@ -119,7 +117,7 @@ enum bb_dom_status
 
 enum bb_dom_status determine_bb_domination_status (class loop *, basic_block);
 
-// In tree-ssa-dom.c
+// In tree-ssa-dom.c.
 extern void free_dom_edge_info (edge);
 
 #endif


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

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

commit f4a0248501f2376b9a8dddb25498fa57ba0a2e07
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 18:54:15 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 21 +++++++++++----------
 gcc/tree-ssa-threadupdate.h |  1 +
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index fabe13e7442..30c6cbf9125 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -350,7 +350,7 @@ create_block_for_threading (basic_block bb,
 
 /* Main data structure to hold information for duplicates of BB.  */
 
-static hash_table<redirection_data> *redirection_data;
+static hash_table<redirection_data> *m_redirection_data;
 
 /* Given an outgoing edge E lookup and return its entry in our hash table.
 
@@ -358,8 +358,9 @@ static hash_table<redirection_data> *redirection_data;
    it is not already present.  INCOMING_EDGE is added to the list of incoming
    edges associated with E in the hash table.  */
 
-static struct redirection_data *
-lookup_redirection_data (edge e, enum insert_option insert)
+redirection_data *
+jump_thread_path_registry::lookup_redirection_data (edge e,
+						    enum insert_option insert)
 {
   struct redirection_data **slot;
   struct redirection_data *elt;
@@ -373,7 +374,7 @@ lookup_redirection_data (edge e, enum insert_option insert)
   elt->dup_blocks[1] = NULL;
   elt->incoming_edges = NULL;
 
-  slot = redirection_data->find_slot (elt, insert);
+  slot = m_redirection_data->find_slot (elt, insert);
 
   /* This will only happen if INSERT is false and the entry is not
      in the hash table.  */
@@ -1363,7 +1364,7 @@ jump_thread_path_registry::thread_block_1 (basic_block bb,
      use a hash table.  For normal code there should be no noticeable
      difference.  However, if we have a block with a large number of
      incoming and outgoing edges such linear searches can get expensive.  */
-  redirection_data
+  m_redirection_data
     = new hash_table<struct redirection_data> (EDGE_COUNT (bb->succs));
 
   /* Record each unique threaded destination into a hash table for
@@ -1482,7 +1483,7 @@ jump_thread_path_registry::thread_block_1 (basic_block bb,
   local_info.template_block = NULL;
   local_info.bb = bb;
   local_info.jumps_threaded = false;
-  redirection_data->traverse <ssa_local_info_t *, ssa_create_duplicates>
+  m_redirection_data->traverse <ssa_local_info_t *, ssa_create_duplicates>
 			    (&local_info);
 
   /* The template does not have an outgoing edge.  Create that outgoing
@@ -1490,19 +1491,19 @@ jump_thread_path_registry::thread_block_1 (basic_block bb,
 
      We do this after creating all the duplicates to avoid creating
      unnecessary edges.  */
-  redirection_data->traverse <ssa_local_info_t *, ssa_fixup_template_block>
+  m_redirection_data->traverse <ssa_local_info_t *, ssa_fixup_template_block>
 			    (&local_info);
 
   /* The hash table traversals above created the duplicate blocks (and the
      statements within the duplicate blocks).  This loop creates PHI nodes for
      the duplicated blocks and redirects the incoming edges into BB to reach
      the duplicates of BB.  */
-  redirection_data->traverse <ssa_local_info_t *, ssa_redirect_edges>
+  m_redirection_data->traverse <ssa_local_info_t *, ssa_redirect_edges>
 			    (&local_info);
 
   /* Done with this block.  Clear REDIRECTION_DATA.  */
-  delete redirection_data;
-  redirection_data = NULL;
+  delete m_redirection_data;
+  m_redirection_data = NULL;
 
   if (noloop_only
       && bb == bb->loop_father->header)
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 7f70721364e..a32ef78189f 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -89,6 +89,7 @@ private:
   bool thread_block (basic_block, bool noloop_only);
   bool thread_through_loop_header (class loop *loop,
 				   bool may_peel_loop_headers);
+  class redirection_data *lookup_redirection_data (edge e, enum insert_option);
 
   // We keep the registered jump threading opportunities in this
   // vector as edge pairs (original_edge, target_edge).


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:32bc2358edd07b91b6c6d7b3b188054874938d18

commit 32bc2358edd07b91b6c6d7b3b188054874938d18
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 18:34:28 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 42 +++++++++++++++++++++---------------------
 gcc/tree-ssa-threadupdate.h |  7 +++++++
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 4bd03350725..fabe13e7442 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -144,6 +144,7 @@ jump_thread_path_registry::jump_thread_path_registry ()
 {
   paths.create (5);
   m_removed_edges = new hash_table<struct removed_edges> (17);
+  m_num_threaded_edges = 0;
 }
 
 jump_thread_path_registry::~jump_thread_path_registry ()
@@ -251,6 +252,9 @@ struct ssa_local_info_t
      final destinations, then we may need to correct for potential
      profile insanities.  */
   bool need_profile_correction;
+
+  // Jump threading statistics.
+  unsigned long num_threaded_edges;
 };
 
 /* When we start updating the CFG for threading, data necessary for jump
@@ -258,16 +262,6 @@ struct ssa_local_info_t
    macros to access the underlying structure attached to the AUX field.  */
 #define THREAD_PATH(E) ((vec<jump_thread_edge *> *)(E)->aux)
 
-/* Jump threading statistics.  */
-
-struct thread_stats_d
-{
-  unsigned long num_threaded_edges;
-};
-
-struct thread_stats_d thread_stats;
-
-
 /* Remove the last statement in block BB if it is a control statement
    Also remove all outgoing edges except the edge which reaches DEST_BB.
    If DEST_BB is NULL, then remove all outgoing edges.  */
@@ -1267,7 +1261,7 @@ ssa_redirect_edges (struct redirection_data **slot,
       next = el->next;
       free (el);
 
-      thread_stats.num_threaded_edges++;
+      local_info->num_threaded_edges++;
 
       if (rd->dup_blocks[0])
 	{
@@ -1350,8 +1344,10 @@ redirection_block_p (basic_block bb)
 
    If JOINERS is true, then thread through joiner blocks as well.  */
 
-static bool
-thread_block_1 (basic_block bb, bool noloop_only, bool joiners)
+bool
+jump_thread_path_registry::thread_block_1 (basic_block bb,
+					   bool noloop_only,
+					   bool joiners)
 {
   /* E is an incoming edge into BB that we may or may not want to
      redirect to a duplicate of BB.  */
@@ -1361,6 +1357,7 @@ thread_block_1 (basic_block bb, bool noloop_only, bool joiners)
 
   local_info.duplicate_blocks = BITMAP_ALLOC (NULL);
   local_info.need_profile_correction = false;
+  local_info.num_threaded_edges = 0;
 
   /* To avoid scanning a linear array for the element we need we instead
      use a hash table.  For normal code there should be no noticeable
@@ -1514,6 +1511,8 @@ thread_block_1 (basic_block bb, bool noloop_only, bool joiners)
   BITMAP_FREE (local_info.duplicate_blocks);
   local_info.duplicate_blocks = NULL;
 
+  m_num_threaded_edges += local_info.num_threaded_edges;
+
   /* Indicate to our caller whether or not any jumps were threaded.  */
   return local_info.jumps_threaded;
 }
@@ -1526,8 +1525,8 @@ thread_block_1 (basic_block bb, bool noloop_only, bool joiners)
    not worry that copying a joiner block will create a jump threading
    opportunity.  */
 
-static bool
-thread_block (basic_block bb, bool noloop_only)
+bool
+jump_thread_path_registry::thread_block (basic_block bb, bool noloop_only)
 {
   bool retval;
   retval = thread_block_1 (bb, noloop_only, false);
@@ -1607,8 +1606,10 @@ determine_bb_domination_status (class loop *loop, basic_block bb)
    If MAY_PEEL_LOOP_HEADERS is false, we avoid threading from entry edges
    to the inside of the loop.  */
 
-static bool
-thread_through_loop_header (class loop *loop, bool may_peel_loop_headers)
+bool
+jump_thread_path_registry::thread_through_loop_header
+				(class loop *loop,
+				 bool may_peel_loop_headers)
 {
   basic_block header = loop->header;
   edge e, tgt_edge, latch = loop_latch_edge (loop);
@@ -2524,7 +2525,7 @@ jump_thread_path_registry::thread_through_all_blocks
       goto out;
     }
 
-  memset (&thread_stats, 0, sizeof (thread_stats));
+  m_num_threaded_edges = 0;
 
   /* Remove any paths that referenced removed edges.  */
   if (m_removed_edges)
@@ -2594,7 +2595,7 @@ jump_thread_path_registry::thread_through_all_blocks
 	  free_dominance_info (CDI_DOMINATORS);
 	  visited_starting_edges.add (entry);
 	  retval = true;
-	  thread_stats.num_threaded_edges++;
+	  m_num_threaded_edges++;
 	}
 
       delete_jump_thread_path (path);
@@ -2675,8 +2676,7 @@ jump_thread_path_registry::thread_through_all_blocks
 	gcc_assert (e->aux == NULL);
     }
 
-  statistics_counter_event (cfun, "Jumps threaded",
-			    thread_stats.num_threaded_edges);
+  statistics_counter_event (cfun, "Jumps threaded", m_num_threaded_edges);
 
   free_original_copy_tables ();
 
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 1455036b9a3..7f70721364e 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -85,12 +85,19 @@ private:
 			      basic_block *region,
 			      unsigned n_region,
 			      unsigned current_path_no);
+  bool thread_block_1 (basic_block, bool noloop_only, bool joiners);
+  bool thread_block (basic_block, bool noloop_only);
+  bool thread_through_loop_header (class loop *loop,
+				   bool may_peel_loop_headers);
 
   // We keep the registered jump threading opportunities in this
   // vector as edge pairs (original_edge, target_edge).
   vec<vec<jump_thread_edge *> *> paths;
 
   hash_table<removed_edges> *m_removed_edges;
+
+  // Jump threading statistics.
+  unsigned long m_num_threaded_edges;
 };
 
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:23cc4c81fef07b17c7cc7d39d95cca73f3bf89fa

commit 23cc4c81fef07b17c7cc7d39d95cca73f3bf89fa
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 18:18:49 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 25 +++++--------------------
 gcc/tree-ssa-threadupdate.h | 12 ++++++++++++
 2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index fcc9b754d3a..4bd03350725 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -143,11 +143,13 @@ struct redirection_data : free_ptr_hash<redirection_data>
 jump_thread_path_registry::jump_thread_path_registry ()
 {
   paths.create (5);
+  m_removed_edges = new hash_table<struct removed_edges> (17);
 }
 
 jump_thread_path_registry::~jump_thread_path_registry ()
 {
   paths.release ();
+  delete m_removed_edges;
 }
 
 /* Dump a jump threading path, including annotations about each
@@ -220,18 +222,6 @@ redirection_data::equal (const redirection_data *p1, const redirection_data *p2)
   return true;
 }
 
-/* Rather than search all the edges in jump thread paths each time
-   DOM is able to simply if control statement, we build a hash table
-   with the deleted edges.  We only care about the address of the edge,
-   not its contents.  */
-struct removed_edges : nofree_ptr_hash<edge_def>
-{
-  static hashval_t hash (edge e) { return htab_hash_pointer (e); }
-  static bool equal (edge e1, edge e2) { return e1 == e2; }
-};
-
-static hash_table<removed_edges> *removed_edges;
-
 /* Data structure of information to pass to hash table traversal routines.  */
 struct ssa_local_info_t
 {
@@ -2503,10 +2493,7 @@ jump_thread_path_registry::remove_jump_threads_including (edge_def *e)
   if (!paths.exists ())
     return;
 
-  if (!removed_edges)
-    removed_edges = new hash_table<struct removed_edges> (17);
-
-  edge *slot = removed_edges->find_slot (e, INSERT);
+  edge *slot = m_removed_edges->find_slot (e, INSERT);
   *slot = e;
 }
 
@@ -2540,7 +2527,7 @@ jump_thread_path_registry::thread_through_all_blocks
   memset (&thread_stats, 0, sizeof (thread_stats));
 
   /* Remove any paths that referenced removed edges.  */
-  if (removed_edges)
+  if (m_removed_edges)
     for (i = 0; i < paths.length (); )
       {
 	unsigned int j;
@@ -2549,7 +2536,7 @@ jump_thread_path_registry::thread_through_all_blocks
 	for (j = 0; j < path->length (); j++)
 	  {
 	    edge e = (*path)[j]->e;
-	    if (removed_edges->find_slot (e, NO_INSERT))
+	    if (m_removed_edges->find_slot (e, NO_INSERT))
 	      break;
 	  }
 
@@ -2699,8 +2686,6 @@ jump_thread_path_registry::thread_through_all_blocks
     loops_state_set (LOOPS_NEED_FIXUP);
 
  out:
-  delete removed_edges;
-  removed_edges = NULL;
   return retval;
 }
 
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 415a6da7ae1..1455036b9a3 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -41,6 +41,16 @@ public:
   enum jump_thread_edge_type type;
 };
 
+/* Rather than search all the edges in jump thread paths each time
+   DOM is able to simply if control statement, we build a hash table
+   with the deleted edges.  We only care about the address of the edge,
+   not its contents.  */
+struct removed_edges : nofree_ptr_hash<edge_def>
+{
+  static hashval_t hash (edge e) { return htab_hash_pointer (e); }
+  static bool equal (edge e1, edge e2) { return e1 == e2; }
+};
+
 /*
 class jump_thread_path
 {
@@ -79,6 +89,8 @@ private:
   // We keep the registered jump threading opportunities in this
   // vector as edge pairs (original_edge, target_edge).
   vec<vec<jump_thread_edge *> *> paths;
+
+  hash_table<removed_edges> *m_removed_edges;
 };
 
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

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

commit a68640a8f9f09cce8280233fea43750ceedd9b62
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 18:09:00 2020 +0100

    wip wip
    
    BOOTSTRAPS

Diff:
---
 gcc/tree-ssa-threadbackward.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index 542f422fd72..a28a20d6de1 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -827,6 +827,9 @@ pass_thread_jumps::execute (function *fun)
       if (EDGE_COUNT (bb->succs) > 1)
 	backwards_threader.find_jump_threads_backwards (bb, true);
     }
+  // FIXME: Put registry in thread_jumps and call thread_through_all_blocks
+  // from the destructor?  Is it ok to call thread_through_all_blocks
+  // before loop_optimizer_finalize below?
   bool changed = registry.thread_through_all_blocks (true);
 
   loop_optimizer_finalize ();
@@ -889,6 +892,9 @@ pass_early_thread_jumps::execute (function *fun)
       if (EDGE_COUNT (bb->succs) > 1)
 	backwards_threader.find_jump_threads_backwards (bb, false);
     }
+  // FIXME: Put registry in thread_jumps and call thread_through_all_blocks
+  // from the destructor?  Is it ok to call thread_through_all_blocks
+  // before loop_optimizer_finalize below?
   registry.thread_through_all_blocks (true);
 
   loop_optimizer_finalize ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

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

commit b5169f24f5019049502c4e83a61ecd745e9597c8
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 18:03:13 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.c | 2 +-
 gcc/tree-vrp.c              | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index a10ea303c2f..fcc9b754d3a 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -142,7 +142,7 @@ struct redirection_data : free_ptr_hash<redirection_data>
 
 jump_thread_path_registry::jump_thread_path_registry ()
 {
-  paths.create (100);
+  paths.create (5);
 }
 
 jump_thread_path_registry::~jump_thread_path_registry ()
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index c2a28dc5d07..33a48fbfe6f 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4533,6 +4533,10 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
 
      Note the SSA graph update will occur during the normal TODO
      processing by the pass manager.  */
+  // FIXME: the registry could be put in vrp_jump_threader and have
+  // its destructor call thread_through_all_blocks.  This would cause
+  // thread_through_all_blocks to happen after scev_finalize and
+  // loop_optimizer_finalize below.  Is this ok?
   registry.thread_through_all_blocks (false);
 
   scev_finalize ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:98155c411ecf2b3255d78ec64be7d84e21c6b801

commit 98155c411ecf2b3255d78ec64be7d84e21c6b801
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 17:56:05 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c            |  2 +-
 gcc/tree-ssa-threadbackward.c |  8 ++++----
 gcc/tree-ssa-threadedge.c     |  2 +-
 gcc/tree-ssa-threadedge.h     |  6 +++---
 gcc/tree-ssa-threadupdate.c   | 34 ++++++++++++++++++----------------
 gcc/tree-ssa-threadupdate.h   | 11 +++++------
 gcc/tree-vrp.c                |  6 +++---
 7 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index b65f5604d0d..e0baa65f36c 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -722,7 +722,7 @@ pass_dominator::execute (function *fun)
     record_edge_info (bb);
 
   /* Recursively walk the dominator tree optimizing statements.  */
-  jump_thread_registry registry;
+  jump_thread_path_registry registry;
   jump_threader threader (&registry, const_and_copies, avail_exprs_stack);
   dom_opt_dom_walker walker (CDI_DOMINATORS,
 			     &threader,
diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index d3dcaf3724b..542f422fd72 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -40,7 +40,7 @@ along with GCC; see the file COPYING3.  If not see
 class thread_jumps
 {
  public:
-  thread_jumps (jump_thread_registry *r) : m_registry (r) { }
+  thread_jumps (jump_thread_path_registry *r) : m_registry (r) { }
   void find_jump_threads_backwards (basic_block bb, bool speed_p);
 
  private:
@@ -68,7 +68,7 @@ class thread_jumps
      code path.  */
   bool m_speed_p;
 
-  jump_thread_registry *m_registry;
+  jump_thread_path_registry *m_registry;
 };
 
 /* Simple helper to get the last statement from BB, which is assumed
@@ -819,7 +819,7 @@ pass_thread_jumps::execute (function *fun)
   loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES);
 
   /* Try to thread each block with more than one successor.  */
-  jump_thread_registry registry;
+  jump_thread_path_registry registry;
   thread_jumps backwards_threader (&registry);
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
@@ -881,7 +881,7 @@ pass_early_thread_jumps::execute (function *fun)
   loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
 
   /* Try to thread each block with more than one successor.  */
-  jump_thread_registry registry;
+  jump_thread_path_registry registry;
   thread_jumps backwards_threader (&registry);
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 32d3ed24d72..576f6217987 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -61,7 +61,7 @@ set_ssa_name_value (tree name, tree value)
   ssa_name_values[SSA_NAME_VERSION (name)] = value;
 }
 
-jump_threader::jump_threader (jump_thread_registry *registry,
+jump_threader::jump_threader (jump_thread_path_registry *registry,
 			      const_and_copies *copies,
 			      avail_exprs_stack *avails)
 {
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index cc0bf36dc5b..4b23f7030f8 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_TREE_SSA_THREADEDGE_H
 #define GCC_TREE_SSA_THREADEDGE_H
 
-class jump_thread_registry;
+class jump_thread_path_registry;
 class jump_thread_edge;
 class jump_threader_simplifier;
 class vr_values;
@@ -31,7 +31,7 @@ class evrp_range_analyzer;
 class jump_threader
 {
 public:
-  jump_threader (jump_thread_registry *,
+  jump_threader (jump_thread_path_registry *,
 		 const_and_copies *,
 		 avail_exprs_stack *);
   ~jump_threader ();
@@ -74,7 +74,7 @@ private:
   class const_and_copies *m_const_and_copies;
   class avail_exprs_stack *m_avail_exprs_stack;
 
-  class jump_thread_registry *m_registry;
+  class jump_thread_path_registry *m_registry;
 };
 
 class jump_threader_simplifier
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 8ec409d4fdb..a10ea303c2f 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -140,12 +140,12 @@ struct redirection_data : free_ptr_hash<redirection_data>
   static inline int equal (const redirection_data *, const redirection_data *);
 };
 
-jump_thread_registry::jump_thread_registry ()
+jump_thread_path_registry::jump_thread_path_registry ()
 {
   paths.create (100);
 }
 
-jump_thread_registry::~jump_thread_registry ()
+jump_thread_path_registry::~jump_thread_path_registry ()
 {
   paths.release ();
 }
@@ -1873,7 +1873,7 @@ count_stmts_and_phis_in_block (basic_block bb)
    hash table lookups to map from threaded edge to new target.  */
 
 void
-jump_thread_registry::mark_threaded_blocks (bitmap threaded_blocks)
+jump_thread_path_registry::mark_threaded_blocks (bitmap threaded_blocks)
 {
   unsigned int i;
   bitmap_iterator bi;
@@ -2142,7 +2142,7 @@ bb_in_bbs (basic_block bb, basic_block *bbs, int n)
 }
 
 void
-jump_thread_registry::debug_path (FILE *dump_file, int pathno)
+jump_thread_path_registry::debug_path (FILE *dump_file, int pathno)
 {
   vec<jump_thread_edge *> *p = paths[pathno];
   fprintf (dump_file, "path: ");
@@ -2153,7 +2153,7 @@ jump_thread_registry::debug_path (FILE *dump_file, int pathno)
 }
 
 void
-jump_thread_registry::debug_paths ()
+jump_thread_path_registry::debug_paths ()
 {
   for (unsigned i = 0; i < paths.length (); ++i)
     debug_path (stderr, i);
@@ -2168,8 +2168,8 @@ jump_thread_registry::debug_paths ()
    Returns TRUE if we were able to successfully rewire the edge.  */
 
 bool
-jump_thread_registry::rewire_first_differing_edge (unsigned path_num,
-						   unsigned edge_num)
+jump_thread_path_registry::rewire_first_differing_edge (unsigned path_num,
+							unsigned edge_num)
 {
   vec<jump_thread_edge *> *path = paths[path_num];
   edge &e = (*path)[edge_num]->e;
@@ -2214,7 +2214,8 @@ jump_thread_registry::rewire_first_differing_edge (unsigned path_num,
    specifies the path that was just threaded.  */
 
 void
-jump_thread_registry::adjust_paths_after_duplication (unsigned curr_path_num)
+jump_thread_path_registry::adjust_paths_after_duplication
+	(unsigned curr_path_num)
 {
   vec<jump_thread_edge *> *curr_path = paths[curr_path_num];
   gcc_assert ((*curr_path)[0]->type == EDGE_FSM_THREAD);
@@ -2318,11 +2319,11 @@ jump_thread_registry::adjust_paths_after_duplication (unsigned curr_path_num)
    Returns false if it is unable to copy the region, true otherwise.  */
 
 bool
-jump_thread_registry::duplicate_thread_path (edge entry,
-					     edge exit,
-					     basic_block *region,
-					     unsigned n_region,
-					     unsigned current_path_no)
+jump_thread_path_registry::duplicate_thread_path (edge entry,
+						  edge exit,
+						  basic_block *region,
+						  unsigned n_region,
+						  unsigned current_path_no)
 {
   unsigned i;
   class loop *loop = entry->dest->loop_father;
@@ -2497,7 +2498,7 @@ valid_jump_thread_path (vec<jump_thread_edge *> *path)
    DOM/VRP rather than for every case where DOM optimizes away a COND_EXPR.  */
 
 void
-jump_thread_registry::remove_jump_threads_including (edge_def *e)
+jump_thread_path_registry::remove_jump_threads_including (edge_def *e)
 {
   if (!paths.exists ())
     return;
@@ -2521,7 +2522,8 @@ jump_thread_registry::remove_jump_threads_including (edge_def *e)
    Returns true if one or more edges were threaded, false otherwise.  */
 
 bool
-jump_thread_registry::thread_through_all_blocks (bool may_peel_loop_headers)
+jump_thread_path_registry::thread_through_all_blocks
+	(bool may_peel_loop_headers)
 {
   bool retval = false;
   unsigned int i;
@@ -2723,7 +2725,7 @@ delete_jump_thread_path (vec<jump_thread_edge *> *path)
    after fixing the SSA graph.  */
 
 void
-jump_thread_registry::register_jump_thread (vec<jump_thread_edge *> *path)
+jump_thread_path_registry::register_jump_thread (vec<jump_thread_edge *> *path)
 {
   if (!dbg_cnt (registered_jump_thread))
     {
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 40183e885b4..415a6da7ae1 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -55,12 +55,11 @@ private:
 };
 */
 
-// FIXME: rename to jump_threader_registry
-class jump_thread_registry
+class jump_thread_path_registry
 {
 public:
-  jump_thread_registry ();
-  ~jump_thread_registry ();
+  jump_thread_path_registry ();
+  ~jump_thread_path_registry ();
   bool thread_through_all_blocks (bool);
   void register_jump_thread (vec <class jump_thread_edge *> *);
   void remove_jump_threads_including (edge);
@@ -77,8 +76,8 @@ private:
 			      unsigned n_region,
 			      unsigned current_path_no);
 
-  /* We keep the registered jump threading opportunities in this
-     vector as edge pairs (original_edge, target_edge).  */
+  // We keep the registered jump threading opportunities in this
+  // vector as edge pairs (original_edge, target_edge).
   vec<vec<jump_thread_edge *> *> paths;
 };
 
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 60dc95842c2..c2a28dc5d07 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4175,7 +4175,7 @@ vrp_folder::fold_stmt (gimple_stmt_iterator *si)
 class vrp_jump_threader : public dom_walker
 {
 public:
-  vrp_jump_threader (function *, vr_values *, jump_thread_registry *);
+  vrp_jump_threader (function *, vr_values *, jump_thread_path_registry *);
   ~vrp_jump_threader ();
 
   void thread_jumps ()
@@ -4197,7 +4197,7 @@ private:
 
 vrp_jump_threader::vrp_jump_threader (struct function *fun,
 				      vr_values *v,
-				      jump_thread_registry *registry)
+				      jump_thread_path_registry *registry)
   : dom_walker (CDI_DOMINATORS, REACHABLE_BLOCKS)
 {
   /* Ugh.  When substituting values earlier in this pass we can wipe
@@ -4493,7 +4493,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
 
   /* We must identify jump threading opportunities before we release
      the datastructures built by VRP.  */
-  jump_thread_registry registry;
+  jump_thread_path_registry registry;
   vrp_jump_threader threader (fun, &vrp_vr_values, &registry);
   threader.thread_jumps ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

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

commit c6593f98b211b4373dd75dc5d7cc887d2d877f44
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 17:51:10 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c          |  2 +-
 gcc/tree-ssa-threadedge.c   |  6 +++---
 gcc/tree-ssa-threadedge.h   |  5 ++++-
 gcc/tree-ssa-threadupdate.c | 46 ++++++++++++++++++++++++++-------------------
 gcc/tree-ssa-threadupdate.h | 19 +++++++++++++++++++
 gcc/tree-vrp.c              | 12 ++++++++----
 6 files changed, 62 insertions(+), 28 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 91ad6a9e65a..b65f5604d0d 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -723,7 +723,7 @@ pass_dominator::execute (function *fun)
 
   /* Recursively walk the dominator tree optimizing statements.  */
   jump_thread_registry registry;
-  jump_threader threader (const_and_copies, avail_exprs_stack);
+  jump_threader threader (&registry, const_and_copies, avail_exprs_stack);
   dom_opt_dom_walker walker (CDI_DOMINATORS,
 			     &threader,
 			     const_and_copies,
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index baadcf6e720..32d3ed24d72 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -61,7 +61,8 @@ set_ssa_name_value (tree name, tree value)
   ssa_name_values[SSA_NAME_VERSION (name)] = value;
 }
 
-jump_threader::jump_threader (const_and_copies *copies,
+jump_threader::jump_threader (jump_thread_registry *registry,
+			      const_and_copies *copies,
 			      avail_exprs_stack *avails)
 {
   /* Initialize the per SSA_NAME value-handles array.  */
@@ -73,13 +74,12 @@ jump_threader::jump_threader (const_and_copies *copies,
 
   m_const_and_copies = copies;
   m_avail_exprs_stack = avails;
-  m_registry = new jump_thread_registry ();
+  m_registry = registry;
 }
 
 jump_threader::~jump_threader (void)
 {
   ssa_name_values.release ();
-  delete m_registry;
 }
 
 /* Return TRUE if we may be able to thread an incoming edge into
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 7be4ccbc895..cc0bf36dc5b 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_TREE_SSA_THREADEDGE_H
 #define GCC_TREE_SSA_THREADEDGE_H
 
+class jump_thread_registry;
 class jump_thread_edge;
 class jump_threader_simplifier;
 class vr_values;
@@ -30,7 +31,9 @@ class evrp_range_analyzer;
 class jump_threader
 {
 public:
-  jump_threader (const_and_copies *, avail_exprs_stack *);
+  jump_threader (jump_thread_registry *,
+		 const_and_copies *,
+		 avail_exprs_stack *);
   ~jump_threader ();
   void thread_outgoing_edges (basic_block,
 			      evrp_range_analyzer *,
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 8b37113e1bc..8ec409d4fdb 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -140,6 +140,16 @@ struct redirection_data : free_ptr_hash<redirection_data>
   static inline int equal (const redirection_data *, const redirection_data *);
 };
 
+jump_thread_registry::jump_thread_registry ()
+{
+  paths.create (100);
+}
+
+jump_thread_registry::~jump_thread_registry ()
+{
+  paths.release ();
+}
+
 /* Dump a jump threading path, including annotations about each
    edge in the path.  */
 
@@ -253,12 +263,6 @@ struct ssa_local_info_t
   bool need_profile_correction;
 };
 
-/* Passes which use the jump threading code register jump threading
-   opportunities as they are discovered.  We keep the registered
-   jump threading opportunities in this vector as edge pairs
-   (original_edge, target_edge).  */
-static vec<vec<jump_thread_edge *> *> paths;
-
 /* When we start updating the CFG for threading, data necessary for jump
    threading is attached to the AUX field for the incoming edge.  Use these
    macros to access the underlying structure attached to the AUX field.  */
@@ -1868,8 +1872,8 @@ count_stmts_and_phis_in_block (basic_block bb)
    discover blocks which need processing and avoids unnecessary
    hash table lookups to map from threaded edge to new target.  */
 
-static void
-mark_threaded_blocks (bitmap threaded_blocks)
+void
+jump_thread_registry::mark_threaded_blocks (bitmap threaded_blocks)
 {
   unsigned int i;
   bitmap_iterator bi;
@@ -2137,8 +2141,8 @@ bb_in_bbs (basic_block bb, basic_block *bbs, int n)
   return false;
 }
 
-DEBUG_FUNCTION void
-debug_path (FILE *dump_file, int pathno)
+void
+jump_thread_registry::debug_path (FILE *dump_file, int pathno)
 {
   vec<jump_thread_edge *> *p = paths[pathno];
   fprintf (dump_file, "path: ");
@@ -2148,8 +2152,8 @@ debug_path (FILE *dump_file, int pathno)
   fprintf (dump_file, "\n");
 }
 
-DEBUG_FUNCTION void
-debug_all_paths ()
+void
+jump_thread_registry::debug_paths ()
 {
   for (unsigned i = 0; i < paths.length (); ++i)
     debug_path (stderr, i);
@@ -2163,8 +2167,9 @@ debug_all_paths ()
 
    Returns TRUE if we were able to successfully rewire the edge.  */
 
-static bool
-rewire_first_differing_edge (unsigned path_num, unsigned edge_num)
+bool
+jump_thread_registry::rewire_first_differing_edge (unsigned path_num,
+						   unsigned edge_num)
 {
   vec<jump_thread_edge *> *path = paths[path_num];
   edge &e = (*path)[edge_num]->e;
@@ -2208,8 +2213,8 @@ rewire_first_differing_edge (unsigned path_num, unsigned edge_num)
    CURR_PATH_NUM is an index into the global paths table.  It
    specifies the path that was just threaded.  */
 
-static void
-adjust_paths_after_duplication (unsigned curr_path_num)
+void
+jump_thread_registry::adjust_paths_after_duplication (unsigned curr_path_num)
 {
   vec<jump_thread_edge *> *curr_path = paths[curr_path_num];
   gcc_assert ((*curr_path)[0]->type == EDGE_FSM_THREAD);
@@ -2312,9 +2317,12 @@ adjust_paths_after_duplication (unsigned curr_path_num)
 
    Returns false if it is unable to copy the region, true otherwise.  */
 
-static bool
-duplicate_thread_path (edge entry, edge exit, basic_block *region,
-		       unsigned n_region, unsigned current_path_no)
+bool
+jump_thread_registry::duplicate_thread_path (edge entry,
+					     edge exit,
+					     basic_block *region,
+					     unsigned n_region,
+					     unsigned current_path_no)
 {
   unsigned i;
   class loop *loop = entry->dest->loop_father;
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 99eeb8fbf17..40183e885b4 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -55,12 +55,31 @@ private:
 };
 */
 
+// FIXME: rename to jump_threader_registry
 class jump_thread_registry
 {
 public:
+  jump_thread_registry ();
+  ~jump_thread_registry ();
   bool thread_through_all_blocks (bool);
   void register_jump_thread (vec <class jump_thread_edge *> *);
   void remove_jump_threads_including (edge);
+  void debug_paths ();
+
+private:
+  void debug_path (FILE *, int pathno);
+  void mark_threaded_blocks (bitmap threaded_blocks);
+  bool rewire_first_differing_edge (unsigned path_num, unsigned edge_num);
+  void adjust_paths_after_duplication (unsigned curr_path_num);
+  bool duplicate_thread_path (edge entry,
+			      edge exit,
+			      basic_block *region,
+			      unsigned n_region,
+			      unsigned current_path_no);
+
+  /* We keep the registered jump threading opportunities in this
+     vector as edge pairs (original_edge, target_edge).  */
+  vec<vec<jump_thread_edge *> *> paths;
 };
 
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index e73b13dfc8b..60dc95842c2 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4175,7 +4175,7 @@ vrp_folder::fold_stmt (gimple_stmt_iterator *si)
 class vrp_jump_threader : public dom_walker
 {
 public:
-  vrp_jump_threader (struct function *, vr_values *);
+  vrp_jump_threader (function *, vr_values *, jump_thread_registry *);
   ~vrp_jump_threader ();
 
   void thread_jumps ()
@@ -4195,7 +4195,9 @@ private:
   jump_threader *m_threader;
 };
 
-vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
+vrp_jump_threader::vrp_jump_threader (struct function *fun,
+				      vr_values *v,
+				      jump_thread_registry *registry)
   : dom_walker (CDI_DOMINATORS, REACHABLE_BLOCKS)
 {
   /* Ugh.  When substituting values earlier in this pass we can wipe
@@ -4219,7 +4221,9 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
   m_avail_exprs = new hash_table<expr_elt_hasher> (1024);
   m_avail_exprs_stack = new avail_exprs_stack (m_avail_exprs);
 
-  m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack);
+  m_threader = new jump_threader (registry,
+				  m_const_and_copies,
+				  m_avail_exprs_stack);
 }
 
 vrp_jump_threader::~vrp_jump_threader ()
@@ -4490,7 +4494,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
   /* We must identify jump threading opportunities before we release
      the datastructures built by VRP.  */
   jump_thread_registry registry;
-  vrp_jump_threader threader (fun, &vrp_vr_values);
+  vrp_jump_threader threader (fun, &vrp_vr_values, &registry);
   threader.thread_jumps ();
 
   /* A comparison of an SSA_NAME against a constant where the SSA_NAME


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:49 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7504a8afee6706606795ac73ba17feca673dc6f3

commit 7504a8afee6706606795ac73ba17feca673dc6f3
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 16:52:59 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index efa1d4981e2..99eeb8fbf17 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -41,7 +41,7 @@ public:
   enum jump_thread_edge_type type;
 };
 
-// Step 2.
+/*
 class jump_thread_path
 {
 public:
@@ -53,8 +53,8 @@ public:
 private:
   vec<jump_thread_edge *> m_path;
 };
+*/
 
-// Step 1.
 class jump_thread_registry
 {
 public:


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:903aea786a5bd27877dfd6c69950d58734d3a7fa

commit 903aea786a5bd27877dfd6c69950d58734d3a7fa
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 16:52:29 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c          | 2 +-
 gcc/tree-ssa-threadupdate.c | 2 +-
 gcc/tree-ssa-threadupdate.h | 3 +--
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 659c9d3a5e4..91ad6a9e65a 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -756,7 +756,7 @@ pass_dominator::execute (function *fun)
 	     containing any edge leaving BB.  */
 	  if (found)
 	    FOR_EACH_EDGE (e, ei, bb->succs)
-	      remove_jump_threads_including (e);
+	      registry.remove_jump_threads_including (e);
 	}
     }
 
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index ff429ead860..8b37113e1bc 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2489,7 +2489,7 @@ valid_jump_thread_path (vec<jump_thread_edge *> *path)
    DOM/VRP rather than for every case where DOM optimizes away a COND_EXPR.  */
 
 void
-remove_jump_threads_including (edge_def *e)
+jump_thread_registry::remove_jump_threads_including (edge_def *e)
 {
   if (!paths.exists ())
     return;
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index d215b6a1fa7..efa1d4981e2 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -60,10 +60,9 @@ class jump_thread_registry
 public:
   bool thread_through_all_blocks (bool);
   void register_jump_thread (vec <class jump_thread_edge *> *);
-  //void remove_jump_threads_including (edge);
+  void remove_jump_threads_including (edge);
 };
 
-extern void remove_jump_threads_including (edge);
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);
 extern unsigned int estimate_threading_killed_stmts (basic_block);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

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

commit ea670b534b783eaf5e18b5c4a917c57f18368370
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 16:49:41 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadbackward.c | 10 +++++++---
 gcc/tree-ssa-threadedge.c     |  7 ++++---
 gcc/tree-ssa-threadedge.h     |  2 ++
 gcc/tree-ssa-threadupdate.c   |  2 +-
 gcc/tree-ssa-threadupdate.h   |  3 +--
 5 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index 18f6e322c39..d3dcaf3724b 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -40,7 +40,9 @@ along with GCC; see the file COPYING3.  If not see
 class thread_jumps
 {
  public:
+  thread_jumps (jump_thread_registry *r) : m_registry (r) { }
   void find_jump_threads_backwards (basic_block bb, bool speed_p);
+
  private:
   edge profitable_jump_thread_path (basic_block bbi, tree name, tree arg,
 				    bool *creates_irreducible_loop);
@@ -65,6 +67,8 @@ class thread_jumps
   /* Indicate that we could increase code size to improve the
      code path.  */
   bool m_speed_p;
+
+  jump_thread_registry *m_registry;
 };
 
 /* Simple helper to get the last statement from BB, which is assumed
@@ -473,7 +477,7 @@ thread_jumps::convert_and_register_current_path (edge taken_edge)
     = new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
   jump_thread_path->safe_push (x);
 
-  register_jump_thread (jump_thread_path);
+  m_registry->register_jump_thread (jump_thread_path);
   --m_max_threaded_paths;
 }
 
@@ -816,7 +820,7 @@ pass_thread_jumps::execute (function *fun)
 
   /* Try to thread each block with more than one successor.  */
   jump_thread_registry registry;
-  thread_jumps backwards_threader;
+  thread_jumps backwards_threader (&registry);
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
     {
@@ -878,7 +882,7 @@ pass_early_thread_jumps::execute (function *fun)
 
   /* Try to thread each block with more than one successor.  */
   jump_thread_registry registry;
-  thread_jumps backwards_threader;
+  thread_jumps backwards_threader (&registry);
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
     {
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 7fea3582431..baadcf6e720 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -73,12 +73,13 @@ jump_threader::jump_threader (const_and_copies *copies,
 
   m_const_and_copies = copies;
   m_avail_exprs_stack = avails;
+  m_registry = new jump_thread_registry ();
 }
 
 jump_threader::~jump_threader (void)
 {
-  /* Free the per SSA_NAME value-handle array.  */
   ssa_name_values.release ();
+  delete m_registry;
 }
 
 /* Return TRUE if we may be able to thread an incoming edge into
@@ -1218,7 +1219,7 @@ jump_threader::thread_across_edge (edge e,
       if (evrp_range_analyzer)
 	evrp_range_analyzer->pop_to_marker ();
       BITMAP_FREE (visited);
-      register_jump_thread (path);
+      m_registry->register_jump_thread (path);
       return;
     }
   else
@@ -1324,7 +1325,7 @@ jump_threader::thread_across_edge (edge e,
 	    if (taken_edge->dest != path->last ()->e->dest)
 	      propagate_threaded_block_debug_into (path->last ()->e->dest,
 						   taken_edge->dest);
-	    register_jump_thread (path);
+	    m_registry->register_jump_thread (path);
 	  }
 	else
 	  delete_jump_thread_path (path);
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index bfdd3fd4eda..7be4ccbc895 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -70,6 +70,8 @@ private:
 
   class const_and_copies *m_const_and_copies;
   class avail_exprs_stack *m_avail_exprs_stack;
+
+  class jump_thread_registry *m_registry;
 };
 
 class jump_threader_simplifier
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index e480dea9e4d..ff429ead860 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2715,7 +2715,7 @@ delete_jump_thread_path (vec<jump_thread_edge *> *path)
    after fixing the SSA graph.  */
 
 void
-register_jump_thread (vec<jump_thread_edge *> *path)
+jump_thread_registry::register_jump_thread (vec<jump_thread_edge *> *path)
 {
   if (!dbg_cnt (registered_jump_thread))
     {
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 30941ed4257..d215b6a1fa7 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -59,11 +59,10 @@ class jump_thread_registry
 {
 public:
   bool thread_through_all_blocks (bool);
-  //void register_jump_thread (jump_thread_path &);
+  void register_jump_thread (vec <class jump_thread_edge *> *);
   //void remove_jump_threads_including (edge);
 };
 
-extern void register_jump_thread (vec <class jump_thread_edge *> *);
 extern void remove_jump_threads_including (edge);
 extern void delete_jump_thread_path (vec <class jump_thread_edge *> *);
 extern unsigned int estimate_threading_killed_stmts (basic_block);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:22f8456fac8c2db8979f537d3dac3101f25f6433

commit 22f8456fac8c2db8979f537d3dac3101f25f6433
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 16:43:30 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c            | 29 +++++++++++++++++------------
 gcc/tree-ssa-threadbackward.c | 14 ++++++++------
 gcc/tree-ssa-threadupdate.c   |  2 +-
 gcc/tree-ssa-threadupdate.h   |  8 ++------
 gcc/tree-vrp.c                |  3 ++-
 5 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 6937a11bfc6..659c9d3a5e4 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -590,16 +590,17 @@ class dom_opt_dom_walker : public dom_walker
 {
 public:
   dom_opt_dom_walker (cdi_direction direction,
-		      class const_and_copies *const_and_copies,
-		      class avail_exprs_stack *avail_exprs_stack)
+		      jump_threader *threader,
+		      const_and_copies *const_and_copies,
+		      avail_exprs_stack *avail_exprs_stack)
     : dom_walker (direction, REACHABLE_BLOCKS),
-      m_const_and_copies (const_and_copies),
-      m_avail_exprs_stack (avail_exprs_stack),
-      evrp_range_analyzer (true),
-      threader (const_and_copies, avail_exprs_stack)
+      evrp_range_analyzer (true)
     {
       m_dummy_cond = gimple_build_cond (NE_EXPR, integer_zero_node,
 					integer_zero_node, NULL, NULL);
+      m_const_and_copies = const_and_copies;
+      m_avail_exprs_stack = avail_exprs_stack;
+      m_threader = threader;
     }
 
   virtual edge before_dom_children (basic_block);
@@ -626,7 +627,7 @@ private:
 
   void test_for_singularity (gimple *, avail_exprs_stack *);
 
-  jump_threader threader;
+  jump_threader *m_threader;
 };
 
 /* Jump threading, redundancy elimination and const/copy propagation.
@@ -721,7 +722,11 @@ pass_dominator::execute (function *fun)
     record_edge_info (bb);
 
   /* Recursively walk the dominator tree optimizing statements.  */
-  dom_opt_dom_walker walker (CDI_DOMINATORS, const_and_copies,
+  jump_thread_registry registry;
+  jump_threader threader (const_and_copies, avail_exprs_stack);
+  dom_opt_dom_walker walker (CDI_DOMINATORS,
+			     &threader,
+			     const_and_copies,
 			     avail_exprs_stack);
   walker.walk (fun->cfg->x_entry_block_ptr);
 
@@ -775,7 +780,7 @@ pass_dominator::execute (function *fun)
   free_all_edge_infos ();
 
   /* Thread jumps, creating duplicate blocks as needed.  */
-  cfg_altered |= thread_through_all_blocks (may_peel_loop_headers_p);
+  cfg_altered |= registry.thread_through_all_blocks (may_peel_loop_headers_p);
 
   if (cfg_altered)
     free_dominance_info (CDI_DOMINATORS);
@@ -1457,9 +1462,9 @@ void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
   dom_jump_threader_simplifier jthread_simplifier (&evrp_range_analyzer);
-  threader.thread_outgoing_edges (bb,
-				  &evrp_range_analyzer,
-				  jthread_simplifier);
+  m_threader->thread_outgoing_edges (bb,
+				     &evrp_range_analyzer,
+				     jthread_simplifier);
 
   /* These remove expressions local to BB from the tables.  */
   m_avail_exprs_stack->pop_to_marker ();
diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c
index 327628f1662..18f6e322c39 100644
--- a/gcc/tree-ssa-threadbackward.c
+++ b/gcc/tree-ssa-threadbackward.c
@@ -815,14 +815,15 @@ pass_thread_jumps::execute (function *fun)
   loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES);
 
   /* Try to thread each block with more than one successor.  */
-  thread_jumps threader;
+  jump_thread_registry registry;
+  thread_jumps backwards_threader;
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
     {
       if (EDGE_COUNT (bb->succs) > 1)
-	threader.find_jump_threads_backwards (bb, true);
+	backwards_threader.find_jump_threads_backwards (bb, true);
     }
-  bool changed = thread_through_all_blocks (true);
+  bool changed = registry.thread_through_all_blocks (true);
 
   loop_optimizer_finalize ();
   return changed ? TODO_cleanup_cfg : 0;
@@ -876,14 +877,15 @@ pass_early_thread_jumps::execute (function *fun)
   loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
 
   /* Try to thread each block with more than one successor.  */
-  thread_jumps threader;
+  jump_thread_registry registry;
+  thread_jumps backwards_threader;
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
     {
       if (EDGE_COUNT (bb->succs) > 1)
-	threader.find_jump_threads_backwards (bb, false);
+	backwards_threader.find_jump_threads_backwards (bb, false);
     }
-  thread_through_all_blocks (true);
+  registry.thread_through_all_blocks (true);
 
   loop_optimizer_finalize ();
   return 0;
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 0bcb726e775..e480dea9e4d 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2513,7 +2513,7 @@ remove_jump_threads_including (edge_def *e)
    Returns true if one or more edges were threaded, false otherwise.  */
 
 bool
-thread_through_all_blocks (bool may_peel_loop_headers)
+jump_thread_registry::thread_through_all_blocks (bool may_peel_loop_headers)
 {
   bool retval = false;
   unsigned int i;
diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 938a0faef6e..30941ed4257 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -22,7 +22,6 @@ along with GCC; see the file COPYING3.  If not see
 #define _TREE_SSA_THREADUPDATE_H 1
 
 /* In tree-ssa-threadupdate.c.  */
-extern bool thread_through_all_blocks (bool);
 enum jump_thread_edge_type
 {
   EDGE_START_JUMP_THREAD,
@@ -60,11 +59,8 @@ class jump_thread_registry
 {
 public:
   bool thread_through_all_blocks (bool);
-  void register_jump_thread (jump_thread_path &);
-  void remove_jump_threads_including (edge);
-
-private:
-  vec<jump_thread_path> m_paths;
+  //void register_jump_thread (jump_thread_path &);
+  //void remove_jump_threads_including (edge);
 };
 
 extern void register_jump_thread (vec <class jump_thread_edge *> *);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 158d74f3a27..e73b13dfc8b 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4489,6 +4489,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
 
   /* We must identify jump threading opportunities before we release
      the datastructures built by VRP.  */
+  jump_thread_registry registry;
   vrp_jump_threader threader (fun, &vrp_vr_values);
   threader.thread_jumps ();
 
@@ -4528,7 +4529,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
 
      Note the SSA graph update will occur during the normal TODO
      processing by the pass manager.  */
-  thread_through_all_blocks (false);
+  registry.thread_through_all_blocks (false);
 
   scev_finalize ();
   loop_optimizer_finalize ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

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

commit b35f8c4c409d8d64c79744928788e8e9d5232570
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 15:04:28 2020 +0100

    wip wip
    
    PASS

Diff:
---
 gcc/tree-ssa-threadedge.h | 55 ++++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index c980e106be9..bfdd3fd4eda 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -20,32 +20,20 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_TREE_SSA_THREADEDGE_H
 #define GCC_TREE_SSA_THREADEDGE_H
 
-class jump_threader_simplifier
-{
-public:
-  jump_threader_simplifier (class vr_values *v) : m_vr_values (v) { }
-  virtual tree simplify (gimple *, gimple *,
-			 class avail_exprs_stack *, basic_block);
-protected:
-  class vr_values *m_vr_values;
-};
-
-extern vec<tree> ssa_name_values;
-#define SSA_NAME_VALUE(x) \
-    (SSA_NAME_VERSION (x) < ssa_name_values.length () \
-     ? ssa_name_values[SSA_NAME_VERSION (x)] \
-     : NULL_TREE)
-extern void set_ssa_name_value (tree, tree);
-extern void propagate_threaded_block_debug_into (basic_block, basic_block);
+class jump_thread_edge;
+class jump_threader_simplifier;
+class vr_values;
+class const_and_copies;
+class avail_exprs_stack;
+class evrp_range_analyzer;
 
 class jump_threader
 {
 public:
-  jump_threader (class const_and_copies *,
-		 class avail_exprs_stack *);
+  jump_threader (const_and_copies *, avail_exprs_stack *);
   ~jump_threader ();
   void thread_outgoing_edges (basic_block,
-			      class evrp_range_analyzer *,
+			      evrp_range_analyzer *,
 			      jump_threader_simplifier &);
 
 private:
@@ -62,17 +50,17 @@ private:
   bool thread_around_empty_blocks (edge,
 				   jump_threader_simplifier &,
 				   bitmap visited,
-				   vec<class jump_thread_edge *> *path);
+				   vec<jump_thread_edge *> *path);
   int thread_through_normal_block (edge,
-				   class evrp_range_analyzer *,
+				   evrp_range_analyzer *,
 				   jump_threader_simplifier &,
-				   vec<class jump_thread_edge *> *path,
+				   vec<jump_thread_edge *> *path,
 				   bitmap visited);
   void thread_across_edge (edge,
-			   class evrp_range_analyzer *,
+			   evrp_range_analyzer *,
 			   jump_threader_simplifier &simplify);
   bool record_temporary_equivalences_from_phis (edge,
-						class evrp_range_analyzer *);
+						evrp_range_analyzer *);
   gimple *record_temporary_equivalences_from_stmts_at_dest (edge,
     evrp_range_analyzer *,
     jump_threader_simplifier &);
@@ -84,4 +72,21 @@ private:
   class avail_exprs_stack *m_avail_exprs_stack;
 };
 
+class jump_threader_simplifier
+{
+public:
+  jump_threader_simplifier (vr_values *v) : m_vr_values (v) { }
+  virtual tree simplify (gimple *, gimple *, avail_exprs_stack *, basic_block);
+protected:
+  vr_values *m_vr_values;
+};
+
+extern vec<tree> ssa_name_values;
+#define SSA_NAME_VALUE(x) \
+    (SSA_NAME_VERSION (x) < ssa_name_values.length () \
+     ? ssa_name_values[SSA_NAME_VERSION (x)] \
+     : NULL_TREE)
+extern void set_ssa_name_value (tree, tree);
+extern void propagate_threaded_block_debug_into (basic_block, basic_block);
+
 #endif /* GCC_TREE_SSA_THREADEDGE_H */


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:036108aeb9f2127a4d0f262bc1f78c7c7c33507a

commit 036108aeb9f2127a4d0f262bc1f78c7c7c33507a
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:53:23 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadupdate.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h
index 148bf149e3b..938a0faef6e 100644
--- a/gcc/tree-ssa-threadupdate.h
+++ b/gcc/tree-ssa-threadupdate.h
@@ -56,7 +56,7 @@ private:
 };
 
 // Step 1.
-class jump_thread_paths
+class jump_thread_registry
 {
 public:
   bool thread_through_all_blocks (bool);
@@ -64,7 +64,7 @@ public:
   void remove_jump_threads_including (edge);
 
 private:
-  vec<jump_thread_paths> m_paths;
+  vec<jump_thread_path> m_paths;
 };
 
 extern void register_jump_thread (vec <class jump_thread_edge *> *);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:408db5a749ebda711c0e0e244dc4082b70e7e99d

commit 408db5a749ebda711c0e0e244dc4082b70e7e99d
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:50:16 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 73 +++++++++++++++++++++++------------------------
 1 file changed, 35 insertions(+), 38 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 215a43095c5..7fea3582431 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -209,8 +209,8 @@ threadedge_valueize (tree t)
 
    Record unwind information for temporary equivalences onto STACK.
 
-   Use SIMPLIFY (a pointer to a callback function) to further simplify
-   statements using pass specific information.
+   Use SIMPLIFIER to further simplify statements using pass specific
+   information.
 
    We might consider marking just those statements which ultimately
    feed the COND_EXPR.  It's not clear if the overhead of bookkeeping
@@ -224,7 +224,7 @@ threadedge_valueize (tree t)
 gimple *
 jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
     evrp_range_analyzer *evrp_range_analyzer,
-    jump_threader_simplifier &simplify)
+    jump_threader_simplifier &simplifier)
 {
   gimple *stmt = NULL;
   gimple_stmt_iterator gsi;
@@ -387,8 +387,8 @@ jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
 		    SET_USE (use_p, tmp);
 		}
 
-	      cached_lhs = simplify.simplify (stmt, stmt, m_avail_exprs_stack,
-					      e->src);
+	      cached_lhs = simplifier.simplify (stmt, stmt,
+						m_avail_exprs_stack, e->src);
 
 	      /* Restore the statement's original uses/defs.  */
 	      i = 0;
@@ -421,7 +421,7 @@ tree
 jump_threader::simplify_control_stmt_condition
 			(edge e,
 			 gimple *stmt,
-			 jump_threader_simplifier &simplify)
+			 jump_threader_simplifier &simplifier)
 {
   tree cond, cached_lhs;
   enum gimple_code code = gimple_code (stmt);
@@ -467,7 +467,7 @@ jump_threader::simplify_control_stmt_condition
       cached_lhs
 	= simplify_control_stmt_condition_1 (e, stmt,
 					     op0, cond_code, op1,
-					     simplify,
+					     simplifier,
 					     recursion_limit);
 
       /* If we were testing an integer/pointer against a constant, then
@@ -537,13 +537,13 @@ jump_threader::simplify_control_stmt_condition
 		 the label that is proven to be taken.  */
 	      gswitch *dummy_switch = as_a<gswitch *> (gimple_copy (stmt));
 	      gimple_switch_set_index (dummy_switch, cached_lhs);
-	      cached_lhs = simplify.simplify (dummy_switch, stmt,
-					      m_avail_exprs_stack, e->src);
+	      cached_lhs = simplifier.simplify (dummy_switch, stmt,
+						m_avail_exprs_stack, e->src);
 	      ggc_free (dummy_switch);
 	    }
 	  else
-	    cached_lhs = simplify.simplify (stmt, stmt, m_avail_exprs_stack,
-					    e->src);
+	    cached_lhs = simplifier.simplify (stmt, stmt, m_avail_exprs_stack,
+					      e->src);
 	}
 
       /* We couldn't find an invariant.  But, callers of this
@@ -567,7 +567,7 @@ jump_threader::simplify_control_stmt_condition_1
 					 tree op0,
 					 enum tree_code cond_code,
 					 tree op1,
-					 jump_threader_simplifier &simplify,
+					 jump_threader_simplifier &simplifier,
 					 unsigned limit)
 {
   if (limit == 0)
@@ -605,7 +605,7 @@ jump_threader::simplify_control_stmt_condition_1
 	  const tree res1
 	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs1, NE_EXPR, op1,
-						 simplify, limit - 1);
+						 simplifier, limit - 1);
 	  if (res1 == NULL_TREE)
 	    ;
 	  else if (rhs_code == BIT_AND_EXPR && integer_zerop (res1))
@@ -631,7 +631,7 @@ jump_threader::simplify_control_stmt_condition_1
 	  const tree res2
 	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs2, NE_EXPR, op1,
-						 simplify, limit - 1);
+						 simplifier, limit - 1);
 	  if (res2 == NULL_TREE)
 	    ;
 	  else if (rhs_code == BIT_AND_EXPR && integer_zerop (res2))
@@ -695,7 +695,7 @@ jump_threader::simplify_control_stmt_condition_1
 	  tree res
 	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs1, new_cond, rhs2,
-						 simplify, limit - 1);
+						 simplifier, limit - 1);
 	  if (res != NULL_TREE && is_gimple_min_invariant (res))
 	    return res;
 	}
@@ -721,7 +721,7 @@ jump_threader::simplify_control_stmt_condition_1
      then use the pass specific callback to simplify the condition.  */
   if (!res
       || !is_gimple_min_invariant (res))
-    res = simplify.simplify (dummy_cond, stmt, m_avail_exprs_stack, e->src);
+    res = simplifier.simplify (dummy_cond, stmt, m_avail_exprs_stack, e->src);
 
   return res;
 }
@@ -875,7 +875,7 @@ propagate_threaded_block_debug_into (basic_block dest, basic_block src)
 bool
 jump_threader::thread_around_empty_blocks
 			(edge taken_edge,
-			 jump_threader_simplifier &simplify,
+			 jump_threader_simplifier &simplifier,
 			 bitmap visited,
 			 vec<jump_thread_edge *> *path)
 {
@@ -923,7 +923,7 @@ jump_threader::thread_around_empty_blocks
 	      path->safe_push (x);
 	      bitmap_set_bit (visited, taken_edge->dest->index);
 	      return thread_around_empty_blocks (taken_edge,
-						 simplify,
+						 simplifier,
 						 visited,
 						 path);
 	    }
@@ -942,7 +942,7 @@ jump_threader::thread_around_empty_blocks
     return false;
 
   /* Extract and simplify the condition.  */
-  cond = simplify_control_stmt_condition (taken_edge, stmt, simplify);
+  cond = simplify_control_stmt_condition (taken_edge, stmt, simplifier);
 
   /* If the condition can be statically computed and we have not already
      visited the destination edge, then add the taken edge to our thread
@@ -968,10 +968,7 @@ jump_threader::thread_around_empty_blocks
 	= new jump_thread_edge (taken_edge, EDGE_NO_COPY_SRC_BLOCK);
       path->safe_push (x);
 
-      thread_around_empty_blocks (taken_edge,
-				  simplify,
-				  visited,
-				  path);
+      thread_around_empty_blocks (taken_edge, simplifier, visited, path);
       return true;
     }
 
@@ -994,7 +991,7 @@ jump_threader::thread_around_empty_blocks
    STACK is used to undo temporary equivalences created during the walk of
    E->dest.
 
-   SIMPLIFY is a pass-specific function used to simplify statements.
+   SIMPLIFIER is a pass-specific function used to simplify statements.
 
    Our caller is responsible for restoring the state of the expression
    and const_and_copies stacks.
@@ -1008,7 +1005,7 @@ int
 jump_threader::thread_through_normal_block
 				(edge e,
 				 evrp_range_analyzer *evrp_range_analyzer,
-				 jump_threader_simplifier &simplify,
+				 jump_threader_simplifier &simplifier,
 				 vec<jump_thread_edge *> *path,
 				 bitmap visited)
 {
@@ -1027,7 +1024,7 @@ jump_threader::thread_through_normal_block
   gimple *stmt
     = record_temporary_equivalences_from_stmts_at_dest (e,
 							evrp_range_analyzer,
-							simplify);
+							simplifier);
 
   /* There's two reasons STMT might be null, and distinguishing
      between them is important.
@@ -1064,7 +1061,7 @@ jump_threader::thread_through_normal_block
       tree cond;
 
       /* Extract and simplify the condition.  */
-      cond = simplify_control_stmt_condition (e, stmt, simplify);
+      cond = simplify_control_stmt_condition (e, stmt, simplifier);
 
       if (!cond)
 	return 0;
@@ -1110,7 +1107,7 @@ jump_threader::thread_through_normal_block
  	     visited.  This may be overly conservative.  */
 	  bitmap_set_bit (visited, dest->index);
 	  bitmap_set_bit (visited, e->dest->index);
-	  thread_around_empty_blocks (taken_edge, simplify, visited, path);
+	  thread_around_empty_blocks (taken_edge, simplifier, visited, path);
 	  return 1;
 	}
     }
@@ -1182,12 +1179,12 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e)
 /* We are exiting E->src, see if E->dest ends with a conditional
    jump which has a known value when reached via E.
 
-   SIMPLIFY is a pass-specific function used to simplify statements.  */
+   SIMPLIFIER is a pass-specific function used to simplify statements.  */
 
 void
 jump_threader::thread_across_edge (edge e,
 				   evrp_range_analyzer *evrp_range_analyzer,
-				   jump_threader_simplifier &simplify)
+				   jump_threader_simplifier &simplifier)
 {
   bitmap visited = BITMAP_ALLOC (NULL);
 
@@ -1207,7 +1204,7 @@ jump_threader::thread_across_edge (edge e,
   if ((e->flags & EDGE_DFS_BACK) == 0)
     threaded = thread_through_normal_block (e,
 					    evrp_range_analyzer,
-					    simplify, path,
+					    simplifier, path,
 					    visited);
   else
     threaded = 0;
@@ -1309,14 +1306,14 @@ jump_threader::thread_across_edge (edge e,
         x = new jump_thread_edge (taken_edge, EDGE_COPY_SRC_JOINER_BLOCK);
 	path->safe_push (x);
 	found = thread_around_empty_blocks (taken_edge,
-					    simplify,
+					    simplifier,
 					    visited,
 					    path);
 
 	if (!found)
 	  found = thread_through_normal_block (path->last ()->e,
 					       evrp_range_analyzer,
-					       simplify, path,
+					       simplifier, path,
 					       visited) > 0;
 
 	/* If we were able to thread through a successor of E->dest, then
@@ -1350,12 +1347,12 @@ jump_threader::thread_across_edge (edge e,
 /* Examine the outgoing edges from BB and conditionally
    try to thread them.
 
-   SIMPLIFY is a pass-specific function used to simplify statements.  */
+   SIMPLIFIER is a pass-specific function used to simplify statements.  */
 
 void
 jump_threader::thread_outgoing_edges (basic_block bb,
 				      evrp_range_analyzer *evrp_range_analyzer,
-				      jump_threader_simplifier &simplify)
+				      jump_threader_simplifier &simplifier)
 {
   int flags = (EDGE_IGNORE | EDGE_COMPLEX | EDGE_ABNORMAL);
   gimple *last;
@@ -1369,7 +1366,7 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       && potentially_threadable_block (single_succ (bb)))
     {
       thread_across_edge (single_succ_edge (bb),
-			  evrp_range_analyzer, simplify);
+			  evrp_range_analyzer, simplifier);
     }
   else if ((last = last_stmt (bb))
 	   && gimple_code (last) == GIMPLE_COND
@@ -1384,11 +1381,11 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       /* Only try to thread the edge if it reaches a target block with
 	 more than one predecessor and more than one successor.  */
       if (potentially_threadable_block (true_edge->dest))
-	thread_across_edge (true_edge, evrp_range_analyzer, simplify);
+	thread_across_edge (true_edge, evrp_range_analyzer, simplifier);
 
       /* Similarly for the ELSE arm.  */
       if (potentially_threadable_block (false_edge->dest))
-	thread_across_edge (false_edge, evrp_range_analyzer, simplify);
+	thread_across_edge (false_edge, evrp_range_analyzer, simplifier);
     }
 }


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:503a2d355c7f61632f9ddadb2f2610985df5eb1e

commit 503a2d355c7f61632f9ddadb2f2610985df5eb1e
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:43:13 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 28 +++++++++++-----------------
 gcc/tree-ssa-threadedge.h |  5 +++++
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 5d8c1e71103..215a43095c5 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -117,15 +117,13 @@ potentially_threadable_block (basic_block bb)
 }
 
 /* Record temporary equivalences created by PHIs at the target of the
-   edge E.  Record unwind information for the equivalences into
-   CONST_AND_COPIES and EVRP_RANGE_DATA.
+   edge E.
 
    If a PHI which prevents threading is encountered, then return FALSE
    indicating we should not thread this edge, else return TRUE.  */
 
-static bool
-record_temporary_equivalences_from_phis (edge e,
-    const_and_copies *const_and_copies,
+bool
+jump_threader::record_temporary_equivalences_from_phis (edge e,
     evrp_range_analyzer *evrp_range_analyzer)
 {
   gphi_iterator gsi;
@@ -153,7 +151,7 @@ record_temporary_equivalences_from_phis (edge e,
       if (!virtual_operand_p (dst))
 	stmt_count++;
 
-      const_and_copies->record_const_or_copy (dst, src);
+      m_const_and_copies->record_const_or_copy (dst, src);
 
       /* Also update the value range associated with DST, using
 	 the range from SRC.
@@ -223,10 +221,8 @@ threadedge_valueize (tree t)
    a context sensitive equivalence which may help us simplify
    later statements in E->dest.  */
 
-static gimple *
-record_temporary_equivalences_from_stmts_at_dest (edge e,
-    const_and_copies *const_and_copies,
-    avail_exprs_stack *avail_exprs_stack,
+gimple *
+jump_threader::record_temporary_equivalences_from_stmts_at_dest (edge e,
     evrp_range_analyzer *evrp_range_analyzer,
     jump_threader_simplifier &simplify)
 {
@@ -391,7 +387,7 @@ record_temporary_equivalences_from_stmts_at_dest (edge e,
 		    SET_USE (use_p, tmp);
 		}
 
-	      cached_lhs = simplify.simplify (stmt, stmt, avail_exprs_stack,
+	      cached_lhs = simplify.simplify (stmt, stmt, m_avail_exprs_stack,
 					      e->src);
 
 	      /* Restore the statement's original uses/defs.  */
@@ -406,8 +402,8 @@ record_temporary_equivalences_from_stmts_at_dest (edge e,
       if (cached_lhs
 	  && (TREE_CODE (cached_lhs) == SSA_NAME
 	      || is_gimple_min_invariant (cached_lhs)))
-	const_and_copies->record_const_or_copy (gimple_get_lhs (stmt),
-						cached_lhs);
+	m_const_and_copies->record_const_or_copy (gimple_get_lhs (stmt),
+						  cached_lhs);
     }
   return stmt;
 }
@@ -1023,15 +1019,13 @@ jump_threader::thread_through_normal_block
      Note that if we found a PHI that made the block non-threadable, then
      we need to bubble that up to our caller in the same manner we do
      when we prematurely stop processing statements below.  */
-  if (!record_temporary_equivalences_from_phis (e, m_const_and_copies,
-					        evrp_range_analyzer))
+  if (!record_temporary_equivalences_from_phis (e, evrp_range_analyzer))
     return -1;
 
   /* Now walk each statement recording any context sensitive
      temporary equivalences we can detect.  */
   gimple *stmt
-    = record_temporary_equivalences_from_stmts_at_dest (e, m_const_and_copies,
-							m_avail_exprs_stack,
+    = record_temporary_equivalences_from_stmts_at_dest (e,
 							evrp_range_analyzer,
 							simplify);
 
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 6a1e30c478d..c980e106be9 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -71,6 +71,11 @@ private:
   void thread_across_edge (edge,
 			   class evrp_range_analyzer *,
 			   jump_threader_simplifier &simplify);
+  bool record_temporary_equivalences_from_phis (edge,
+						class evrp_range_analyzer *);
+  gimple *record_temporary_equivalences_from_stmts_at_dest (edge,
+    evrp_range_analyzer *,
+    jump_threader_simplifier &);
 
   // Dummy condition to avoid creating lots of throw away statements.
   gcond *dummy_cond;


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

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

commit b08dacd4c212ad0620aadc2fcde6405cf89d2a39
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:38:29 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 39 ++++++++++++---------------------------
 gcc/tree-ssa-threadedge.h |  2 --
 2 files changed, 12 insertions(+), 29 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 6e244c82253..5d8c1e71103 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -1011,27 +1011,26 @@ jump_threader::thread_around_empty_blocks
 int
 jump_threader::thread_through_normal_block
 				(edge e,
-				 const_and_copies *const_and_copies,
 				 evrp_range_analyzer *evrp_range_analyzer,
 				 jump_threader_simplifier &simplify,
 				 vec<jump_thread_edge *> *path,
 				 bitmap visited)
 {
   /* We want to record any equivalences created by traversing E.  */
-  record_temporary_equivalences (e, const_and_copies, m_avail_exprs_stack);
+  record_temporary_equivalences (e, m_const_and_copies, m_avail_exprs_stack);
 
   /* PHIs create temporary equivalences.
      Note that if we found a PHI that made the block non-threadable, then
      we need to bubble that up to our caller in the same manner we do
      when we prematurely stop processing statements below.  */
-  if (!record_temporary_equivalences_from_phis (e, const_and_copies,
+  if (!record_temporary_equivalences_from_phis (e, m_const_and_copies,
 					        evrp_range_analyzer))
     return -1;
 
   /* Now walk each statement recording any context sensitive
      temporary equivalences we can detect.  */
   gimple *stmt
-    = record_temporary_equivalences_from_stmts_at_dest (e, const_and_copies,
+    = record_temporary_equivalences_from_stmts_at_dest (e, m_const_and_copies,
 							m_avail_exprs_stack,
 							evrp_range_analyzer,
 							simplify);
@@ -1189,20 +1188,16 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e)
 /* We are exiting E->src, see if E->dest ends with a conditional
    jump which has a known value when reached via E.
 
-   CONST_AND_COPIES is used to undo temporary equivalences created during the
-   walk of E->dest.
-
    SIMPLIFY is a pass-specific function used to simplify statements.  */
 
 void
 jump_threader::thread_across_edge (edge e,
-				   const_and_copies *const_and_copies,
 				   evrp_range_analyzer *evrp_range_analyzer,
 				   jump_threader_simplifier &simplify)
 {
   bitmap visited = BITMAP_ALLOC (NULL);
 
-  const_and_copies->push_marker ();
+  m_const_and_copies->push_marker ();
   m_avail_exprs_stack->push_marker ();
   if (evrp_range_analyzer)
     evrp_range_analyzer->push_marker ();
@@ -1217,7 +1212,6 @@ jump_threader::thread_across_edge (edge e,
   int threaded;
   if ((e->flags & EDGE_DFS_BACK) == 0)
     threaded = thread_through_normal_block (e,
-					    const_and_copies,
 					    evrp_range_analyzer,
 					    simplify, path,
 					    visited);
@@ -1228,7 +1222,7 @@ jump_threader::thread_across_edge (edge e,
     {
       propagate_threaded_block_debug_into (path->last ()->e->dest,
 					   e->dest);
-      const_and_copies->pop_to_marker ();
+      m_const_and_copies->pop_to_marker ();
       m_avail_exprs_stack->pop_to_marker ();
       if (evrp_range_analyzer)
 	evrp_range_analyzer->pop_to_marker ();
@@ -1255,7 +1249,7 @@ jump_threader::thread_across_edge (edge e,
       if (threaded < 0)
 	{
 	  BITMAP_FREE (visited);
-	  const_and_copies->pop_to_marker ();
+	  m_const_and_copies->pop_to_marker ();
           m_avail_exprs_stack->pop_to_marker ();
 	  if (evrp_range_analyzer)
 	    evrp_range_analyzer->pop_to_marker ();
@@ -1284,7 +1278,7 @@ jump_threader::thread_across_edge (edge e,
     FOR_EACH_EDGE (taken_edge, ei, e->dest->succs)
       if (taken_edge->flags & EDGE_COMPLEX)
 	{
-	  const_and_copies->pop_to_marker ();
+	  m_const_and_copies->pop_to_marker ();
           m_avail_exprs_stack->pop_to_marker ();
 	  if (evrp_range_analyzer)
 	    evrp_range_analyzer->pop_to_marker ();
@@ -1301,7 +1295,7 @@ jump_threader::thread_across_edge (edge e,
 
 	/* Push a fresh marker so we can unwind the equivalences created
 	   for each of E->dest's successors.  */
-	const_and_copies->push_marker ();
+	m_const_and_copies->push_marker ();
 	m_avail_exprs_stack->push_marker ();
 	if (evrp_range_analyzer)
 	  evrp_range_analyzer->push_marker ();
@@ -1327,7 +1321,6 @@ jump_threader::thread_across_edge (edge e,
 
 	if (!found)
 	  found = thread_through_normal_block (path->last ()->e,
-					       const_and_copies,
 					       evrp_range_analyzer,
 					       simplify, path,
 					       visited) > 0;
@@ -1349,23 +1342,20 @@ jump_threader::thread_across_edge (edge e,
 	if (evrp_range_analyzer)
 	  evrp_range_analyzer->pop_to_marker ();
 	m_avail_exprs_stack->pop_to_marker ();
-	const_and_copies->pop_to_marker ();
+	m_const_and_copies->pop_to_marker ();
       }
     BITMAP_FREE (visited);
   }
 
   if (evrp_range_analyzer)
     evrp_range_analyzer->pop_to_marker ();
-  const_and_copies->pop_to_marker ();
+  m_const_and_copies->pop_to_marker ();
   m_avail_exprs_stack->pop_to_marker ();
 }
 
 /* Examine the outgoing edges from BB and conditionally
    try to thread them.
 
-   CONST_AND_COPIES is used to undo temporary equivalences created during the
-   walk of E->dest.
-
    SIMPLIFY is a pass-specific function used to simplify statements.  */
 
 void
@@ -1385,7 +1375,6 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       && potentially_threadable_block (single_succ (bb)))
     {
       thread_across_edge (single_succ_edge (bb),
-			  m_const_and_copies,
 			  evrp_range_analyzer, simplify);
     }
   else if ((last = last_stmt (bb))
@@ -1401,15 +1390,11 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       /* Only try to thread the edge if it reaches a target block with
 	 more than one predecessor and more than one successor.  */
       if (potentially_threadable_block (true_edge->dest))
-	thread_across_edge (true_edge,
-			    m_const_and_copies,
-			    evrp_range_analyzer, simplify);
+	thread_across_edge (true_edge, evrp_range_analyzer, simplify);
 
       /* Similarly for the ELSE arm.  */
       if (potentially_threadable_block (false_edge->dest))
-	thread_across_edge (false_edge,
-			    m_const_and_copies,
-			    evrp_range_analyzer, simplify);
+	thread_across_edge (false_edge, evrp_range_analyzer, simplify);
     }
 }
 
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 094d815898e..6a1e30c478d 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -64,13 +64,11 @@ private:
 				   bitmap visited,
 				   vec<class jump_thread_edge *> *path);
   int thread_through_normal_block (edge,
-				   class const_and_copies *,
 				   class evrp_range_analyzer *,
 				   jump_threader_simplifier &,
 				   vec<class jump_thread_edge *> *path,
 				   bitmap visited);
   void thread_across_edge (edge,
-			   class const_and_copies *,
 			   class evrp_range_analyzer *,
 			   jump_threader_simplifier &simplify);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

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

commit fbffccdf5744db62da9af042efd7326da05bec4b
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:35:38 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 42 +++++++++++++-----------------------------
 gcc/tree-ssa-threadedge.h |  3 ---
 2 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 6c7e3467b4f..6e244c82253 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -879,7 +879,6 @@ propagate_threaded_block_debug_into (basic_block dest, basic_block src)
 bool
 jump_threader::thread_around_empty_blocks
 			(edge taken_edge,
-			 avail_exprs_stack *avail_exprs_stack,
 			 jump_threader_simplifier &simplify,
 			 bitmap visited,
 			 vec<jump_thread_edge *> *path)
@@ -928,7 +927,6 @@ jump_threader::thread_around_empty_blocks
 	      path->safe_push (x);
 	      bitmap_set_bit (visited, taken_edge->dest->index);
 	      return thread_around_empty_blocks (taken_edge,
-						 avail_exprs_stack,
 						 simplify,
 						 visited,
 						 path);
@@ -975,7 +973,6 @@ jump_threader::thread_around_empty_blocks
       path->safe_push (x);
 
       thread_around_empty_blocks (taken_edge,
-				  avail_exprs_stack,
 				  simplify,
 				  visited,
 				  path);
@@ -1015,14 +1012,13 @@ int
 jump_threader::thread_through_normal_block
 				(edge e,
 				 const_and_copies *const_and_copies,
-				 avail_exprs_stack *avail_exprs_stack,
 				 evrp_range_analyzer *evrp_range_analyzer,
 				 jump_threader_simplifier &simplify,
 				 vec<jump_thread_edge *> *path,
 				 bitmap visited)
 {
   /* We want to record any equivalences created by traversing E.  */
-  record_temporary_equivalences (e, const_and_copies, avail_exprs_stack);
+  record_temporary_equivalences (e, const_and_copies, m_avail_exprs_stack);
 
   /* PHIs create temporary equivalences.
      Note that if we found a PHI that made the block non-threadable, then
@@ -1036,7 +1032,7 @@ jump_threader::thread_through_normal_block
      temporary equivalences we can detect.  */
   gimple *stmt
     = record_temporary_equivalences_from_stmts_at_dest (e, const_and_copies,
-							avail_exprs_stack,
+							m_avail_exprs_stack,
 							evrp_range_analyzer,
 							simplify);
 
@@ -1121,11 +1117,7 @@ jump_threader::thread_through_normal_block
  	     visited.  This may be overly conservative.  */
 	  bitmap_set_bit (visited, dest->index);
 	  bitmap_set_bit (visited, e->dest->index);
-	  thread_around_empty_blocks (taken_edge,
-				      avail_exprs_stack,
-				      simplify,
-				      visited,
-				      path);
+	  thread_around_empty_blocks (taken_edge, simplify, visited, path);
 	  return 1;
 	}
     }
@@ -1200,21 +1192,18 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e)
    CONST_AND_COPIES is used to undo temporary equivalences created during the
    walk of E->dest.
 
-   The available expression table is referenced vai AVAIL_EXPRS_STACK.
-
    SIMPLIFY is a pass-specific function used to simplify statements.  */
 
 void
 jump_threader::thread_across_edge (edge e,
 				   const_and_copies *const_and_copies,
-				   avail_exprs_stack *avail_exprs_stack,
 				   evrp_range_analyzer *evrp_range_analyzer,
 				   jump_threader_simplifier &simplify)
 {
   bitmap visited = BITMAP_ALLOC (NULL);
 
   const_and_copies->push_marker ();
-  avail_exprs_stack->push_marker ();
+  m_avail_exprs_stack->push_marker ();
   if (evrp_range_analyzer)
     evrp_range_analyzer->push_marker ();
 
@@ -1229,7 +1218,6 @@ jump_threader::thread_across_edge (edge e,
   if ((e->flags & EDGE_DFS_BACK) == 0)
     threaded = thread_through_normal_block (e,
 					    const_and_copies,
-					    avail_exprs_stack,
 					    evrp_range_analyzer,
 					    simplify, path,
 					    visited);
@@ -1241,7 +1229,7 @@ jump_threader::thread_across_edge (edge e,
       propagate_threaded_block_debug_into (path->last ()->e->dest,
 					   e->dest);
       const_and_copies->pop_to_marker ();
-      avail_exprs_stack->pop_to_marker ();
+      m_avail_exprs_stack->pop_to_marker ();
       if (evrp_range_analyzer)
 	evrp_range_analyzer->pop_to_marker ();
       BITMAP_FREE (visited);
@@ -1268,7 +1256,7 @@ jump_threader::thread_across_edge (edge e,
 	{
 	  BITMAP_FREE (visited);
 	  const_and_copies->pop_to_marker ();
-          avail_exprs_stack->pop_to_marker ();
+          m_avail_exprs_stack->pop_to_marker ();
 	  if (evrp_range_analyzer)
 	    evrp_range_analyzer->pop_to_marker ();
 	  return;
@@ -1297,7 +1285,7 @@ jump_threader::thread_across_edge (edge e,
       if (taken_edge->flags & EDGE_COMPLEX)
 	{
 	  const_and_copies->pop_to_marker ();
-          avail_exprs_stack->pop_to_marker ();
+          m_avail_exprs_stack->pop_to_marker ();
 	  if (evrp_range_analyzer)
 	    evrp_range_analyzer->pop_to_marker ();
 	  BITMAP_FREE (visited);
@@ -1314,7 +1302,7 @@ jump_threader::thread_across_edge (edge e,
 	/* Push a fresh marker so we can unwind the equivalences created
 	   for each of E->dest's successors.  */
 	const_and_copies->push_marker ();
-	avail_exprs_stack->push_marker ();
+	m_avail_exprs_stack->push_marker ();
 	if (evrp_range_analyzer)
 	  evrp_range_analyzer->push_marker ();
 
@@ -1333,7 +1321,6 @@ jump_threader::thread_across_edge (edge e,
         x = new jump_thread_edge (taken_edge, EDGE_COPY_SRC_JOINER_BLOCK);
 	path->safe_push (x);
 	found = thread_around_empty_blocks (taken_edge,
-					    avail_exprs_stack,
 					    simplify,
 					    visited,
 					    path);
@@ -1341,7 +1328,6 @@ jump_threader::thread_across_edge (edge e,
 	if (!found)
 	  found = thread_through_normal_block (path->last ()->e,
 					       const_and_copies,
-					       avail_exprs_stack,
 					       evrp_range_analyzer,
 					       simplify, path,
 					       visited) > 0;
@@ -1362,7 +1348,7 @@ jump_threader::thread_across_edge (edge e,
 	/* And unwind the equivalence table.  */
 	if (evrp_range_analyzer)
 	  evrp_range_analyzer->pop_to_marker ();
-	avail_exprs_stack->pop_to_marker ();
+	m_avail_exprs_stack->pop_to_marker ();
 	const_and_copies->pop_to_marker ();
       }
     BITMAP_FREE (visited);
@@ -1371,7 +1357,7 @@ jump_threader::thread_across_edge (edge e,
   if (evrp_range_analyzer)
     evrp_range_analyzer->pop_to_marker ();
   const_and_copies->pop_to_marker ();
-  avail_exprs_stack->pop_to_marker ();
+  m_avail_exprs_stack->pop_to_marker ();
 }
 
 /* Examine the outgoing edges from BB and conditionally
@@ -1380,8 +1366,6 @@ jump_threader::thread_across_edge (edge e,
    CONST_AND_COPIES is used to undo temporary equivalences created during the
    walk of E->dest.
 
-   The available expression table is referenced vai AVAIL_EXPRS_STACK.
-
    SIMPLIFY is a pass-specific function used to simplify statements.  */
 
 void
@@ -1401,7 +1385,7 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       && potentially_threadable_block (single_succ (bb)))
     {
       thread_across_edge (single_succ_edge (bb),
-			  m_const_and_copies, m_avail_exprs_stack,
+			  m_const_and_copies,
 			  evrp_range_analyzer, simplify);
     }
   else if ((last = last_stmt (bb))
@@ -1418,13 +1402,13 @@ jump_threader::thread_outgoing_edges (basic_block bb,
 	 more than one predecessor and more than one successor.  */
       if (potentially_threadable_block (true_edge->dest))
 	thread_across_edge (true_edge,
-			    m_const_and_copies, m_avail_exprs_stack,
+			    m_const_and_copies,
 			    evrp_range_analyzer, simplify);
 
       /* Similarly for the ELSE arm.  */
       if (potentially_threadable_block (false_edge->dest))
 	thread_across_edge (false_edge,
-			    m_const_and_copies, m_avail_exprs_stack,
+			    m_const_and_copies,
 			    evrp_range_analyzer, simplify);
     }
 }
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 0409b132e81..094d815898e 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -60,20 +60,17 @@ private:
 					  unsigned limit);
 
   bool thread_around_empty_blocks (edge,
-				   class avail_exprs_stack *,
 				   jump_threader_simplifier &,
 				   bitmap visited,
 				   vec<class jump_thread_edge *> *path);
   int thread_through_normal_block (edge,
 				   class const_and_copies *,
-				   class avail_exprs_stack *,
 				   class evrp_range_analyzer *,
 				   jump_threader_simplifier &,
 				   vec<class jump_thread_edge *> *path,
 				   bitmap visited);
   void thread_across_edge (edge,
 			   class const_and_copies *,
-			   class avail_exprs_stack *,
 			   class evrp_range_analyzer *,
 			   jump_threader_simplifier &simplify);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:40520f62c8b61417c0a712fe18ab0df9402112e7

commit 40520f62c8b61417c0a712fe18ab0df9402112e7
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:31:30 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 27 ++++++++++-----------------
 gcc/tree-ssa-threadedge.h |  2 --
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 70669925f3c..6c7e3467b4f 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -419,15 +419,12 @@ record_temporary_equivalences_from_stmts_at_dest (edge e,
 
    Return the simplified condition or NULL if simplification could
    not be performed.  When simplifying a GIMPLE_SWITCH, we may return
-   the CASE_LABEL_EXPR that will be taken.
-
-   The available expression table is referenced via AVAIL_EXPRS_STACK.  */
+   the CASE_LABEL_EXPR that will be taken.  */
 
 tree
 jump_threader::simplify_control_stmt_condition
 			(edge e,
 			 gimple *stmt,
-			 avail_exprs_stack *avail_exprs_stack,
 			 jump_threader_simplifier &simplify)
 {
   tree cond, cached_lhs;
@@ -472,7 +469,7 @@ jump_threader::simplify_control_stmt_condition
       const unsigned recursion_limit = 4;
 
       cached_lhs
-	= simplify_control_stmt_condition_1 (e, stmt, avail_exprs_stack,
+	= simplify_control_stmt_condition_1 (e, stmt,
 					     op0, cond_code, op1,
 					     simplify,
 					     recursion_limit);
@@ -545,11 +542,11 @@ jump_threader::simplify_control_stmt_condition
 	      gswitch *dummy_switch = as_a<gswitch *> (gimple_copy (stmt));
 	      gimple_switch_set_index (dummy_switch, cached_lhs);
 	      cached_lhs = simplify.simplify (dummy_switch, stmt,
-					      avail_exprs_stack, e->src);
+					      m_avail_exprs_stack, e->src);
 	      ggc_free (dummy_switch);
 	    }
 	  else
-	    cached_lhs = simplify.simplify (stmt, stmt, avail_exprs_stack,
+	    cached_lhs = simplify.simplify (stmt, stmt, m_avail_exprs_stack,
 					    e->src);
 	}
 
@@ -571,7 +568,6 @@ tree
 jump_threader::simplify_control_stmt_condition_1
 					(edge e,
 					 gimple *stmt,
-					 avail_exprs_stack *avail_exprs_stack,
 					 tree op0,
 					 enum tree_code cond_code,
 					 tree op1,
@@ -611,7 +607,7 @@ jump_threader::simplify_control_stmt_condition_1
 
 	  /* Is A != 0 ?  */
 	  const tree res1
-	    = simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
+	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs1, NE_EXPR, op1,
 						 simplify, limit - 1);
 	  if (res1 == NULL_TREE)
@@ -637,7 +633,7 @@ jump_threader::simplify_control_stmt_condition_1
 
 	  /* Is B != 0 ?  */
 	  const tree res2
-	    = simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
+	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs2, NE_EXPR, op1,
 						 simplify, limit - 1);
 	  if (res2 == NULL_TREE)
@@ -701,7 +697,7 @@ jump_threader::simplify_control_stmt_condition_1
 	    new_cond = invert_tree_comparison (new_cond, false);
 
 	  tree res
-	    = simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
+	    = simplify_control_stmt_condition_1 (e, def_stmt,
 						 rhs1, new_cond, rhs2,
 						 simplify, limit - 1);
 	  if (res != NULL_TREE && is_gimple_min_invariant (res))
@@ -729,7 +725,7 @@ jump_threader::simplify_control_stmt_condition_1
      then use the pass specific callback to simplify the condition.  */
   if (!res
       || !is_gimple_min_invariant (res))
-    res = simplify.simplify (dummy_cond, stmt, avail_exprs_stack, e->src);
+    res = simplify.simplify (dummy_cond, stmt, m_avail_exprs_stack, e->src);
 
   return res;
 }
@@ -952,9 +948,7 @@ jump_threader::thread_around_empty_blocks
     return false;
 
   /* Extract and simplify the condition.  */
-  cond = simplify_control_stmt_condition (taken_edge, stmt,
-					  avail_exprs_stack,
-					  simplify);
+  cond = simplify_control_stmt_condition (taken_edge, stmt, simplify);
 
   /* If the condition can be statically computed and we have not already
      visited the destination edge, then add the taken edge to our thread
@@ -1081,8 +1075,7 @@ jump_threader::thread_through_normal_block
       tree cond;
 
       /* Extract and simplify the condition.  */
-      cond = simplify_control_stmt_condition (e, stmt, avail_exprs_stack,
-					      simplify);
+      cond = simplify_control_stmt_condition (e, stmt, simplify);
 
       if (!cond)
 	return 0;
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 8ff0110450e..0409b132e81 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -50,11 +50,9 @@ public:
 
 private:
   tree simplify_control_stmt_condition (edge, gimple *,
-					class avail_exprs_stack *,
 					jump_threader_simplifier &);
   tree simplify_control_stmt_condition_1 (edge,
 					  gimple *,
-					  class avail_exprs_stack *,
 					  tree op0,
 					  tree_code cond_code,
 					  tree op1,


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2df124a33b125b297ad6b064792d15f31c725d4b

commit 2df124a33b125b297ad6b064792d15f31c725d4b
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:27:45 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c        |  6 +++---
 gcc/tree-ssa-threadedge.c | 14 ++++++++------
 gcc/tree-ssa-threadedge.h |  9 +++++----
 gcc/tree-vrp.c            |  9 +++++----
 4 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 7ce80e99d58..6937a11bfc6 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -595,7 +595,8 @@ public:
     : dom_walker (direction, REACHABLE_BLOCKS),
       m_const_and_copies (const_and_copies),
       m_avail_exprs_stack (avail_exprs_stack),
-      evrp_range_analyzer (true)
+      evrp_range_analyzer (true),
+      threader (const_and_copies, avail_exprs_stack)
     {
       m_dummy_cond = gimple_build_cond (NE_EXPR, integer_zero_node,
 					integer_zero_node, NULL, NULL);
@@ -1456,8 +1457,7 @@ void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
   dom_jump_threader_simplifier jthread_simplifier (&evrp_range_analyzer);
-  threader.thread_outgoing_edges (bb, m_const_and_copies,
-				  m_avail_exprs_stack,
+  threader.thread_outgoing_edges (bb,
 				  &evrp_range_analyzer,
 				  jthread_simplifier);
 
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 4197bd01e07..70669925f3c 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -61,7 +61,8 @@ set_ssa_name_value (tree name, tree value)
   ssa_name_values[SSA_NAME_VERSION (name)] = value;
 }
 
-jump_threader::jump_threader ()
+jump_threader::jump_threader (const_and_copies *copies,
+			      avail_exprs_stack *avails)
 {
   /* Initialize the per SSA_NAME value-handles array.  */
   gcc_assert (!ssa_name_values.exists ());
@@ -69,6 +70,9 @@ jump_threader::jump_threader ()
 
   dummy_cond = gimple_build_cond (NE_EXPR, integer_zero_node,
 				  integer_zero_node, NULL, NULL);
+
+  m_const_and_copies = copies;
+  m_avail_exprs_stack = avails;
 }
 
 jump_threader::~jump_threader (void)
@@ -1389,8 +1393,6 @@ jump_threader::thread_across_edge (edge e,
 
 void
 jump_threader::thread_outgoing_edges (basic_block bb,
-				      const_and_copies *const_and_copies,
-				      avail_exprs_stack *avail_exprs_stack,
 				      evrp_range_analyzer *evrp_range_analyzer,
 				      jump_threader_simplifier &simplify)
 {
@@ -1406,7 +1408,7 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       && potentially_threadable_block (single_succ (bb)))
     {
       thread_across_edge (single_succ_edge (bb),
-			  const_and_copies, avail_exprs_stack,
+			  m_const_and_copies, m_avail_exprs_stack,
 			  evrp_range_analyzer, simplify);
     }
   else if ((last = last_stmt (bb))
@@ -1423,13 +1425,13 @@ jump_threader::thread_outgoing_edges (basic_block bb,
 	 more than one predecessor and more than one successor.  */
       if (potentially_threadable_block (true_edge->dest))
 	thread_across_edge (true_edge,
-			    const_and_copies, avail_exprs_stack,
+			    m_const_and_copies, m_avail_exprs_stack,
 			    evrp_range_analyzer, simplify);
 
       /* Similarly for the ELSE arm.  */
       if (potentially_threadable_block (false_edge->dest))
 	thread_across_edge (false_edge,
-			    const_and_copies, avail_exprs_stack,
+			    m_const_and_copies, m_avail_exprs_stack,
 			    evrp_range_analyzer, simplify);
     }
 }
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 4ae6b486e1b..8ff0110450e 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -41,11 +41,10 @@ extern void propagate_threaded_block_debug_into (basic_block, basic_block);
 class jump_threader
 {
 public:
-  jump_threader ();
+  jump_threader (class const_and_copies *,
+		 class avail_exprs_stack *);
   ~jump_threader ();
   void thread_outgoing_edges (basic_block,
-			      const_and_copies *,
-			      avail_exprs_stack *,
 			      class evrp_range_analyzer *,
 			      jump_threader_simplifier &);
 
@@ -82,7 +81,9 @@ private:
 
   // Dummy condition to avoid creating lots of throw away statements.
   gcond *dummy_cond;
-  class jump_thread_paths *blah_blah_m_paths;
+
+  class const_and_copies *m_const_and_copies;
+  class avail_exprs_stack *m_avail_exprs_stack;
 };
 
 #endif /* GCC_TREE_SSA_THREADEDGE_H */
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index db11546e134..158d74f3a27 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4192,7 +4192,7 @@ private:
   const_and_copies *m_const_and_copies;
   avail_exprs_stack *m_avail_exprs_stack;
   hash_table<expr_elt_hasher> *m_avail_exprs;
-  jump_threader threader;
+  jump_threader *m_threader;
 };
 
 vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
@@ -4218,6 +4218,8 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
   m_vr_values = v;
   m_avail_exprs = new hash_table<expr_elt_hasher> (1024);
   m_avail_exprs_stack = new avail_exprs_stack (m_avail_exprs);
+
+  m_threader = new jump_threader (m_const_and_copies, m_avail_exprs_stack);
 }
 
 vrp_jump_threader::~vrp_jump_threader ()
@@ -4228,6 +4230,7 @@ vrp_jump_threader::~vrp_jump_threader ()
   delete m_const_and_copies;
   delete m_avail_exprs;
   delete m_avail_exprs_stack;
+  delete m_threader;
 }
 
 /* Called before processing dominator children of BB.  We want to look
@@ -4326,9 +4329,7 @@ void
 vrp_jump_threader::after_dom_children (basic_block bb)
 {
   vrp_jump_threader_simplifier jthread_simplifier (m_vr_values);
-  threader.thread_outgoing_edges (bb, m_const_and_copies,
-				  m_avail_exprs_stack, NULL,
-				  jthread_simplifier);
+  m_threader->thread_outgoing_edges (bb, NULL, jthread_simplifier);
 
   m_avail_exprs_stack->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:48 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:48 UTC (permalink / raw)
  To: gcc-cvs

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

commit a9be7396424d40517562edbedea0ba229e72ff25
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:15:47 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 50 +++++++++++++----------------------------------
 gcc/tree-ssa-threadedge.h |  9 +++++++++
 2 files changed, 23 insertions(+), 36 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index ccebf9ba264..4197bd01e07 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -408,18 +408,8 @@ record_temporary_equivalences_from_stmts_at_dest (edge e,
   return stmt;
 }
 
-static tree simplify_control_stmt_condition_1 (edge, gimple *,
-					       class avail_exprs_stack *,
-					       tree, enum tree_code, tree,
-					       gcond *,
-					       jump_threader_simplifier &,
-					       unsigned);
-
 /* Simplify the control statement at the end of the block E->dest.
 
-   To avoid allocating memory unnecessarily, a scratch GIMPLE_COND
-   is available to use/clobber in DUMMY_COND.
-
    Use SIMPLIFY (a pointer to a callback function) to further simplify
    a condition using pass specific information.
 
@@ -480,7 +470,7 @@ jump_threader::simplify_control_stmt_condition
       cached_lhs
 	= simplify_control_stmt_condition_1 (e, stmt, avail_exprs_stack,
 					     op0, cond_code, op1,
-					     dummy_cond, simplify,
+					     simplify,
 					     recursion_limit);
 
       /* If we were testing an integer/pointer against a constant, then
@@ -573,16 +563,16 @@ jump_threader::simplify_control_stmt_condition
 
 /* Recursive helper for simplify_control_stmt_condition.  */
 
-static tree
-simplify_control_stmt_condition_1 (edge e,
-				   gimple *stmt,
-				   class avail_exprs_stack *avail_exprs_stack,
-				   tree op0,
-				   enum tree_code cond_code,
-				   tree op1,
-				   gcond *dummy_cond,
-				   jump_threader_simplifier &simplify,
-				   unsigned limit)
+tree
+jump_threader::simplify_control_stmt_condition_1
+					(edge e,
+					 gimple *stmt,
+					 avail_exprs_stack *avail_exprs_stack,
+					 tree op0,
+					 enum tree_code cond_code,
+					 tree op1,
+					 jump_threader_simplifier &simplify,
+					 unsigned limit)
 {
   if (limit == 0)
     return NULL_TREE;
@@ -619,8 +609,7 @@ simplify_control_stmt_condition_1 (edge e,
 	  const tree res1
 	    = simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
 						 rhs1, NE_EXPR, op1,
-						 dummy_cond, simplify,
-						 limit - 1);
+						 simplify, limit - 1);
 	  if (res1 == NULL_TREE)
 	    ;
 	  else if (rhs_code == BIT_AND_EXPR && integer_zerop (res1))
@@ -646,8 +635,7 @@ simplify_control_stmt_condition_1 (edge e,
 	  const tree res2
 	    = simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
 						 rhs2, NE_EXPR, op1,
-						 dummy_cond, simplify,
-						 limit - 1);
+						 simplify, limit - 1);
 	  if (res2 == NULL_TREE)
 	    ;
 	  else if (rhs_code == BIT_AND_EXPR && integer_zerop (res2))
@@ -711,8 +699,7 @@ simplify_control_stmt_condition_1 (edge e,
 	  tree res
 	    = simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
 						 rhs1, new_cond, rhs2,
-						 dummy_cond, simplify,
-						 limit - 1);
+						 simplify, limit - 1);
 	  if (res != NULL_TREE && is_gimple_min_invariant (res))
 	    return res;
 	}
@@ -887,9 +874,6 @@ propagate_threaded_block_debug_into (basic_block dest, basic_block src)
    returning TRUE from the toplevel call.   Otherwise do nothing and
    return false.
 
-   DUMMY_COND, SIMPLIFY are used to try and simplify the condition at the
-   end of TAKEN_EDGE->dest.
-
    The available expression table is referenced via AVAIL_EXPRS_STACK.  */
 
 bool
@@ -1016,9 +1000,6 @@ jump_threader::thread_around_empty_blocks
    limited in that case to avoid short-circuiting the loop
    incorrectly.
 
-   DUMMY_COND is a shared cond_expr used by condition simplification as scratch,
-   to avoid allocating memory.
-
    STACK is used to undo temporary equivalences created during the walk of
    E->dest.
 
@@ -1219,9 +1200,6 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e)
 /* We are exiting E->src, see if E->dest ends with a conditional
    jump which has a known value when reached via E.
 
-   DUMMY_COND is a shared cond_expr used by condition simplification as scratch,
-   to avoid allocating memory.
-
    CONST_AND_COPIES is used to undo temporary equivalences created during the
    walk of E->dest.
 
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 99dd51239af..4ae6b486e1b 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -53,6 +53,15 @@ private:
   tree simplify_control_stmt_condition (edge, gimple *,
 					class avail_exprs_stack *,
 					jump_threader_simplifier &);
+  tree simplify_control_stmt_condition_1 (edge,
+					  gimple *,
+					  class avail_exprs_stack *,
+					  tree op0,
+					  tree_code cond_code,
+					  tree op1,
+					  jump_threader_simplifier &simplify,
+					  unsigned limit);
+
   bool thread_around_empty_blocks (edge,
 				   class avail_exprs_stack *,
 				   jump_threader_simplifier &,


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:47 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0e5a372ec4f8dfe7a3c011c07535a03475fda20d

commit 0e5a372ec4f8dfe7a3c011c07535a03475fda20d
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:10:49 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 75 ++++++++++++++++++++++-------------------------
 gcc/tree-ssa-threadedge.h | 21 +++++++++++++
 2 files changed, 56 insertions(+), 40 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index bc40a5e77d1..ccebf9ba264 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -429,12 +429,12 @@ static tree simplify_control_stmt_condition_1 (edge, gimple *,
 
    The available expression table is referenced via AVAIL_EXPRS_STACK.  */
 
-static tree
-simplify_control_stmt_condition (edge e,
-				 gimple *stmt,
-				 class avail_exprs_stack *avail_exprs_stack,
-				 gcond *dummy_cond,
-				 jump_threader_simplifier &simplify)
+tree
+jump_threader::simplify_control_stmt_condition
+			(edge e,
+			 gimple *stmt,
+			 avail_exprs_stack *avail_exprs_stack,
+			 jump_threader_simplifier &simplify)
 {
   tree cond, cached_lhs;
   enum gimple_code code = gimple_code (stmt);
@@ -892,13 +892,13 @@ propagate_threaded_block_debug_into (basic_block dest, basic_block src)
 
    The available expression table is referenced via AVAIL_EXPRS_STACK.  */
 
-static bool
-thread_around_empty_blocks (edge taken_edge,
-			    gcond *dummy_cond,
-			    class avail_exprs_stack *avail_exprs_stack,
-			    jump_threader_simplifier &simplify,
-			    bitmap visited,
-			    vec<jump_thread_edge *> *path)
+bool
+jump_threader::thread_around_empty_blocks
+			(edge taken_edge,
+			 avail_exprs_stack *avail_exprs_stack,
+			 jump_threader_simplifier &simplify,
+			 bitmap visited,
+			 vec<jump_thread_edge *> *path)
 {
   basic_block bb = taken_edge->dest;
   gimple_stmt_iterator gsi;
@@ -944,7 +944,6 @@ thread_around_empty_blocks (edge taken_edge,
 	      path->safe_push (x);
 	      bitmap_set_bit (visited, taken_edge->dest->index);
 	      return thread_around_empty_blocks (taken_edge,
-						 dummy_cond,
 						 avail_exprs_stack,
 						 simplify,
 						 visited,
@@ -966,7 +965,7 @@ thread_around_empty_blocks (edge taken_edge,
 
   /* Extract and simplify the condition.  */
   cond = simplify_control_stmt_condition (taken_edge, stmt,
-					  avail_exprs_stack, dummy_cond,
+					  avail_exprs_stack,
 					  simplify);
 
   /* If the condition can be statically computed and we have not already
@@ -994,7 +993,6 @@ thread_around_empty_blocks (edge taken_edge,
       path->safe_push (x);
 
       thread_around_empty_blocks (taken_edge,
-				  dummy_cond,
 				  avail_exprs_stack,
 				  simplify,
 				  visited,
@@ -1034,15 +1032,15 @@ thread_around_empty_blocks (edge taken_edge,
    negative indicates the block should not be duplicated and thus is not
    suitable for a joiner in a jump threading path.  */
 
-static int
-thread_through_normal_block (edge e,
-			     gcond *dummy_cond,
-			     const_and_copies *const_and_copies,
-			     avail_exprs_stack *avail_exprs_stack,
-			     evrp_range_analyzer *evrp_range_analyzer,
-			     jump_threader_simplifier &simplify,
-			     vec<jump_thread_edge *> *path,
-			     bitmap visited)
+int
+jump_threader::thread_through_normal_block
+				(edge e,
+				 const_and_copies *const_and_copies,
+				 avail_exprs_stack *avail_exprs_stack,
+				 evrp_range_analyzer *evrp_range_analyzer,
+				 jump_threader_simplifier &simplify,
+				 vec<jump_thread_edge *> *path,
+				 bitmap visited)
 {
   /* We want to record any equivalences created by traversing E.  */
   record_temporary_equivalences (e, const_and_copies, avail_exprs_stack);
@@ -1099,7 +1097,7 @@ thread_through_normal_block (edge e,
 
       /* Extract and simplify the condition.  */
       cond = simplify_control_stmt_condition (e, stmt, avail_exprs_stack,
-					      dummy_cond, simplify);
+					      simplify);
 
       if (!cond)
 	return 0;
@@ -1146,7 +1144,6 @@ thread_through_normal_block (edge e,
 	  bitmap_set_bit (visited, dest->index);
 	  bitmap_set_bit (visited, e->dest->index);
 	  thread_around_empty_blocks (taken_edge,
-				      dummy_cond,
 				      avail_exprs_stack,
 				      simplify,
 				      visited,
@@ -1232,13 +1229,12 @@ edge_forwards_cmp_to_conditional_jump_through_empty_bb_p (edge e)
 
    SIMPLIFY is a pass-specific function used to simplify statements.  */
 
-static void
-thread_across_edge (gcond *dummy_cond,
-		    edge e,
-		    class const_and_copies *const_and_copies,
-		    class avail_exprs_stack *avail_exprs_stack,
-		    class evrp_range_analyzer *evrp_range_analyzer,
-		    jump_threader_simplifier &simplify)
+void
+jump_threader::thread_across_edge (edge e,
+				   const_and_copies *const_and_copies,
+				   avail_exprs_stack *avail_exprs_stack,
+				   evrp_range_analyzer *evrp_range_analyzer,
+				   jump_threader_simplifier &simplify)
 {
   bitmap visited = BITMAP_ALLOC (NULL);
 
@@ -1256,7 +1252,7 @@ thread_across_edge (gcond *dummy_cond,
 
   int threaded;
   if ((e->flags & EDGE_DFS_BACK) == 0)
-    threaded = thread_through_normal_block (e, dummy_cond,
+    threaded = thread_through_normal_block (e,
 					    const_and_copies,
 					    avail_exprs_stack,
 					    evrp_range_analyzer,
@@ -1362,14 +1358,13 @@ thread_across_edge (gcond *dummy_cond,
         x = new jump_thread_edge (taken_edge, EDGE_COPY_SRC_JOINER_BLOCK);
 	path->safe_push (x);
 	found = thread_around_empty_blocks (taken_edge,
-					    dummy_cond,
 					    avail_exprs_stack,
 					    simplify,
 					    visited,
 					    path);
 
 	if (!found)
-	  found = thread_through_normal_block (path->last ()->e, dummy_cond,
+	  found = thread_through_normal_block (path->last ()->e,
 					       const_and_copies,
 					       avail_exprs_stack,
 					       evrp_range_analyzer,
@@ -1432,7 +1427,7 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       && (single_succ_edge (bb)->flags & flags) == 0
       && potentially_threadable_block (single_succ (bb)))
     {
-      thread_across_edge (dummy_cond, single_succ_edge (bb),
+      thread_across_edge (single_succ_edge (bb),
 			  const_and_copies, avail_exprs_stack,
 			  evrp_range_analyzer, simplify);
     }
@@ -1449,13 +1444,13 @@ jump_threader::thread_outgoing_edges (basic_block bb,
       /* Only try to thread the edge if it reaches a target block with
 	 more than one predecessor and more than one successor.  */
       if (potentially_threadable_block (true_edge->dest))
-	thread_across_edge (dummy_cond, true_edge,
+	thread_across_edge (true_edge,
 			    const_and_copies, avail_exprs_stack,
 			    evrp_range_analyzer, simplify);
 
       /* Similarly for the ELSE arm.  */
       if (potentially_threadable_block (false_edge->dest))
-	thread_across_edge (dummy_cond, false_edge,
+	thread_across_edge (false_edge,
 			    const_and_copies, avail_exprs_stack,
 			    evrp_range_analyzer, simplify);
     }
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 851170a5c90..99dd51239af 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -50,6 +50,27 @@ public:
 			      jump_threader_simplifier &);
 
 private:
+  tree simplify_control_stmt_condition (edge, gimple *,
+					class avail_exprs_stack *,
+					jump_threader_simplifier &);
+  bool thread_around_empty_blocks (edge,
+				   class avail_exprs_stack *,
+				   jump_threader_simplifier &,
+				   bitmap visited,
+				   vec<class jump_thread_edge *> *path);
+  int thread_through_normal_block (edge,
+				   class const_and_copies *,
+				   class avail_exprs_stack *,
+				   class evrp_range_analyzer *,
+				   jump_threader_simplifier &,
+				   vec<class jump_thread_edge *> *path,
+				   bitmap visited);
+  void thread_across_edge (edge,
+			   class const_and_copies *,
+			   class avail_exprs_stack *,
+			   class evrp_range_analyzer *,
+			   jump_threader_simplifier &simplify);
+
   // Dummy condition to avoid creating lots of throw away statements.
   gcond *dummy_cond;
   class jump_thread_paths *blah_blah_m_paths;


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:47 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:66bfa4466295ad524b03ff3ba53cbdada0bfe774

commit 66bfa4466295ad524b03ff3ba53cbdada0bfe774
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 14:00:35 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c        | 37 ++++++++++++++++++++-----------------
 gcc/tree-ssa-threadedge.c | 10 +++++-----
 gcc/tree-ssa-threadedge.h |  4 +++-
 gcc/tree-vrp.c            |  9 +--------
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 5d240131afe..7ce80e99d58 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -591,13 +591,15 @@ class dom_opt_dom_walker : public dom_walker
 public:
   dom_opt_dom_walker (cdi_direction direction,
 		      class const_and_copies *const_and_copies,
-		      class avail_exprs_stack *avail_exprs_stack,
-		      gcond *dummy_cond)
+		      class avail_exprs_stack *avail_exprs_stack)
     : dom_walker (direction, REACHABLE_BLOCKS),
       m_const_and_copies (const_and_copies),
       m_avail_exprs_stack (avail_exprs_stack),
-      evrp_range_analyzer (true),
-      m_dummy_cond (dummy_cond) { }
+      evrp_range_analyzer (true)
+    {
+      m_dummy_cond = gimple_build_cond (NE_EXPR, integer_zero_node,
+					integer_zero_node, NULL, NULL);
+    }
 
   virtual edge before_dom_children (basic_block);
   virtual void after_dom_children (basic_block);
@@ -620,6 +622,9 @@ private:
      value.  */
   edge optimize_stmt (basic_block, gimple_stmt_iterator *, bool *);
 
+
+  void test_for_singularity (gimple *, avail_exprs_stack *);
+
   jump_threader threader;
 };
 
@@ -714,12 +719,9 @@ pass_dominator::execute (function *fun)
   FOR_EACH_BB_FN (bb, fun)
     record_edge_info (bb);
 
-  gcond *dummy_cond = gimple_build_cond (NE_EXPR, integer_zero_node,
-					 integer_zero_node, NULL, NULL);
-
   /* Recursively walk the dominator tree optimizing statements.  */
   dom_opt_dom_walker walker (CDI_DOMINATORS, const_and_copies,
-			     avail_exprs_stack, dummy_cond);
+			     avail_exprs_stack);
   walker.walk (fun->cfg->x_entry_block_ptr);
 
   /* Look for blocks where we cleared EDGE_EXECUTABLE on an outgoing
@@ -1454,7 +1456,7 @@ void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
   dom_jump_threader_simplifier jthread_simplifier (&evrp_range_analyzer);
-  threader.thread_outgoing_edges (bb, m_dummy_cond, m_const_and_copies,
+  threader.thread_outgoing_edges (bb, m_const_and_copies,
 				  m_avail_exprs_stack,
 				  &evrp_range_analyzer,
 				  jthread_simplifier);
@@ -1801,9 +1803,9 @@ cprop_into_stmt (gimple *stmt, vr_values *vr_values)
 
    This is similar to code in VRP.  */
 
-static void
-test_for_singularity (gimple *stmt, gcond *dummy_cond,
-		      avail_exprs_stack *avail_exprs_stack)
+void
+dom_opt_dom_walker::test_for_singularity (gimple *stmt,
+					  avail_exprs_stack *avail_exprs_stack)
 {
   /* We want to support gimple conditionals as well as assignments
      where the RHS contains a conditional.  */
@@ -1849,11 +1851,12 @@ test_for_singularity (gimple *stmt, gcond *dummy_cond,
 	    test_code = GE_EXPR;
 
 	  /* Update the dummy statement so we can query the hash tables.  */
-	  gimple_cond_set_code (dummy_cond, test_code);
-	  gimple_cond_set_lhs (dummy_cond, lhs);
-	  gimple_cond_set_rhs (dummy_cond, rhs);
+	  gimple_cond_set_code (m_dummy_cond, test_code);
+	  gimple_cond_set_lhs (m_dummy_cond, lhs);
+	  gimple_cond_set_rhs (m_dummy_cond, rhs);
 	  tree cached_lhs
-	    = avail_exprs_stack->lookup_avail_expr (dummy_cond, false, false);
+	    = avail_exprs_stack->lookup_avail_expr (m_dummy_cond,
+						    false, false);
 
 	  /* If the lookup returned 1 (true), then the expression we
 	     queried was in the hash table.  As a result there is only
@@ -2088,7 +2091,7 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si,
       /* If this statement was not redundant, we may still be able to simplify
 	 it, which may in turn allow other part of DOM or other passes to do
 	 a better job.  */
-      test_for_singularity (stmt, m_dummy_cond, m_avail_exprs_stack);
+      test_for_singularity (stmt, m_avail_exprs_stack);
     }
 
   /* Record any additional equivalences created by this statement.  */
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 54e76c7b369..bc40a5e77d1 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -63,9 +63,12 @@ set_ssa_name_value (tree name, tree value)
 
 jump_threader::jump_threader ()
 {
-  /* Initialize the per SSA_NAME value-handles array.  Returns it.  */
+  /* Initialize the per SSA_NAME value-handles array.  */
   gcc_assert (!ssa_name_values.exists ());
   ssa_name_values.create (num_ssa_names);
+
+  dummy_cond = gimple_build_cond (NE_EXPR, integer_zero_node,
+				  integer_zero_node, NULL, NULL);
 }
 
 jump_threader::~jump_threader (void)
@@ -1404,9 +1407,6 @@ thread_across_edge (gcond *dummy_cond,
 /* Examine the outgoing edges from BB and conditionally
    try to thread them.
 
-   DUMMY_COND is a shared cond_expr used by condition simplification as scratch,
-   to avoid allocating memory.
-
    CONST_AND_COPIES is used to undo temporary equivalences created during the
    walk of E->dest.
 
@@ -1415,7 +1415,7 @@ thread_across_edge (gcond *dummy_cond,
    SIMPLIFY is a pass-specific function used to simplify statements.  */
 
 void
-jump_threader::thread_outgoing_edges (basic_block bb, gcond *dummy_cond,
+jump_threader::thread_outgoing_edges (basic_block bb,
 				      const_and_copies *const_and_copies,
 				      avail_exprs_stack *avail_exprs_stack,
 				      evrp_range_analyzer *evrp_range_analyzer,
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index a5e572ee30e..851170a5c90 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -43,13 +43,15 @@ class jump_threader
 public:
   jump_threader ();
   ~jump_threader ();
-  void thread_outgoing_edges (basic_block, gcond *,
+  void thread_outgoing_edges (basic_block,
 			      const_and_copies *,
 			      avail_exprs_stack *,
 			      class evrp_range_analyzer *,
 			      jump_threader_simplifier &);
 
 private:
+  // Dummy condition to avoid creating lots of throw away statements.
+  gcond *dummy_cond;
   class jump_thread_paths *blah_blah_m_paths;
 };
 
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 6ac178ed97f..db11546e134 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4192,7 +4192,6 @@ private:
   const_and_copies *m_const_and_copies;
   avail_exprs_stack *m_avail_exprs_stack;
   hash_table<expr_elt_hasher> *m_avail_exprs;
-  gcond *m_dummy_cond;
   jump_threader threader;
 };
 
@@ -4215,7 +4214,6 @@ vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
      that might be recorded.  */
   m_const_and_copies = new const_and_copies ();
 
-  m_dummy_cond = NULL;
   m_fun = fun;
   m_vr_values = v;
   m_avail_exprs = new hash_table<expr_elt_hasher> (1024);
@@ -4327,13 +4325,8 @@ vrp_jump_threader_simplifier::simplify (gimple *stmt,
 void
 vrp_jump_threader::after_dom_children (basic_block bb)
 {
-  if (!m_dummy_cond)
-    m_dummy_cond = gimple_build_cond (NE_EXPR,
-				      integer_zero_node, integer_zero_node,
-				      NULL, NULL);
-
   vrp_jump_threader_simplifier jthread_simplifier (m_vr_values);
-  threader.thread_outgoing_edges (bb, m_dummy_cond, m_const_and_copies,
+  threader.thread_outgoing_edges (bb, m_const_and_copies,
 				  m_avail_exprs_stack, NULL,
 				  jthread_simplifier);


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:47 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:47 UTC (permalink / raw)
  To: gcc-cvs

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

commit aed808bebe75e964ac5e3888777417dad097299f
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 13:34:45 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-threadedge.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 2e7055e31b9..54e76c7b369 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -61,18 +61,16 @@ set_ssa_name_value (tree name, tree value)
   ssa_name_values[SSA_NAME_VERSION (name)] = value;
 }
 
-/* Initialize the per SSA_NAME value-handles array.  Returns it.  */
-static void
-threadedge_initialize_values (void)
+jump_threader::jump_threader ()
 {
+  /* Initialize the per SSA_NAME value-handles array.  Returns it.  */
   gcc_assert (!ssa_name_values.exists ());
   ssa_name_values.create (num_ssa_names);
 }
 
-/* Free the per SSA_NAME value-handle array.  */
-static void
-threadedge_finalize_values (void)
+jump_threader::~jump_threader (void)
 {
+  /* Free the per SSA_NAME value-handle array.  */
   ssa_name_values.release ();
 }
 
@@ -1506,13 +1504,3 @@ jump_threader_simplifier::simplify (gimple *stmt,
     }
    return NULL;
 }
-
-jump_threader::jump_threader ()
-{
-  threadedge_initialize_values ();
-}
-
-jump_threader::~jump_threader ()
-{
-  threadedge_finalize_values ();
-}


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

* [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip
@ 2020-11-25 14:47 Aldy Hernandez
  0 siblings, 0 replies; 61+ messages in thread
From: Aldy Hernandez @ 2020-11-25 14:47 UTC (permalink / raw)
  To: gcc-cvs

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

commit bcf094387c9f2a66a11447dd378c01c8728d3545
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 23 13:30:13 2020 +0100

    wip wip

Diff:
---
 gcc/tree-ssa-dom.c        | 16 ++++++----------
 gcc/tree-ssa-threadedge.c | 24 +++++++++++++++++-------
 gcc/tree-ssa-threadedge.h | 14 +++-----------
 gcc/tree-vrp.c            | 11 ++++-------
 4 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 8a5e96b2c29..5d240131afe 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -619,6 +619,8 @@ private:
      the statement is a conditional with a statically determined
      value.  */
   edge optimize_stmt (basic_block, gimple_stmt_iterator *, bool *);
+
+  jump_threader threader;
 };
 
 /* Jump threading, redundancy elimination and const/copy propagation.
@@ -697,9 +699,6 @@ pass_dominator::execute (function *fun)
      LOOPS_HAVE_PREHEADERS won't be needed here.  */
   loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES);
 
-  /* Initialize the value-handle array.  */
-  threadedge_initialize_values ();
-
   /* We need accurate information regarding back edges in the CFG
      for jump threading; this may include back edges that are not part of
      a single loop.  */
@@ -849,9 +848,6 @@ pass_dominator::execute (function *fun)
   delete avail_exprs_stack;
   delete const_and_copies;
 
-  /* Free the value-handle array.  */
-  threadedge_finalize_values ();
-
   return 0;
 }
 
@@ -1458,10 +1454,10 @@ void
 dom_opt_dom_walker::after_dom_children (basic_block bb)
 {
   dom_jump_threader_simplifier jthread_simplifier (&evrp_range_analyzer);
-  thread_outgoing_edges (bb, m_dummy_cond, m_const_and_copies,
-			 m_avail_exprs_stack,
-			 &evrp_range_analyzer,
-			 jthread_simplifier);
+  threader.thread_outgoing_edges (bb, m_dummy_cond, m_const_and_copies,
+				  m_avail_exprs_stack,
+				  &evrp_range_analyzer,
+				  jthread_simplifier);
 
   /* These remove expressions local to BB from the tables.  */
   m_avail_exprs_stack->pop_to_marker ();
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 49062f9cf04..2e7055e31b9 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -62,7 +62,7 @@ set_ssa_name_value (tree name, tree value)
 }
 
 /* Initialize the per SSA_NAME value-handles array.  Returns it.  */
-void
+static void
 threadedge_initialize_values (void)
 {
   gcc_assert (!ssa_name_values.exists ());
@@ -70,7 +70,7 @@ threadedge_initialize_values (void)
 }
 
 /* Free the per SSA_NAME value-handle array.  */
-void
+static void
 threadedge_finalize_values (void)
 {
   ssa_name_values.release ();
@@ -1417,11 +1417,11 @@ thread_across_edge (gcond *dummy_cond,
    SIMPLIFY is a pass-specific function used to simplify statements.  */
 
 void
-thread_outgoing_edges (basic_block bb, gcond *dummy_cond,
-		       class const_and_copies *const_and_copies,
-		       class avail_exprs_stack *avail_exprs_stack,
-		       class evrp_range_analyzer *evrp_range_analyzer,
-		       jump_threader_simplifier &simplify)
+jump_threader::thread_outgoing_edges (basic_block bb, gcond *dummy_cond,
+				      const_and_copies *const_and_copies,
+				      avail_exprs_stack *avail_exprs_stack,
+				      evrp_range_analyzer *evrp_range_analyzer,
+				      jump_threader_simplifier &simplify)
 {
   int flags = (EDGE_IGNORE | EDGE_COMPLEX | EDGE_ABNORMAL);
   gimple *last;
@@ -1506,3 +1506,13 @@ jump_threader_simplifier::simplify (gimple *stmt,
     }
    return NULL;
 }
+
+jump_threader::jump_threader ()
+{
+  threadedge_initialize_values ();
+}
+
+jump_threader::~jump_threader ()
+{
+  threadedge_finalize_values ();
+}
diff --git a/gcc/tree-ssa-threadedge.h b/gcc/tree-ssa-threadedge.h
index 0bd73306784..a5e572ee30e 100644
--- a/gcc/tree-ssa-threadedge.h
+++ b/gcc/tree-ssa-threadedge.h
@@ -36,21 +36,13 @@ extern vec<tree> ssa_name_values;
      ? ssa_name_values[SSA_NAME_VERSION (x)] \
      : NULL_TREE)
 extern void set_ssa_name_value (tree, tree);
-extern void threadedge_initialize_values (void);
-extern void threadedge_finalize_values (void);
 extern void propagate_threaded_block_debug_into (basic_block, basic_block);
-extern void thread_outgoing_edges (basic_block, gcond *,
-				   const_and_copies *,
-				   avail_exprs_stack *,
-				   class evrp_range_analyzer *,
-				   jump_threader_simplifier &);
 
-// Step 0.
 class jump_threader
 {
 public:
-  jump_threader () { threadedge_initialize_values (); }
-  ~jump_threader () { threadedge_finalize_values (); }
+  jump_threader ();
+  ~jump_threader ();
   void thread_outgoing_edges (basic_block, gcond *,
 			      const_and_copies *,
 			      avail_exprs_stack *,
@@ -58,7 +50,7 @@ public:
 			      jump_threader_simplifier &);
 
 private:
-  class jump_thread_paths *m_paths;
+  class jump_thread_paths *blah_blah_m_paths;
 };
 
 #endif /* GCC_TREE_SSA_THREADEDGE_H */
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index c640233fcae..6ac178ed97f 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4193,6 +4193,7 @@ private:
   avail_exprs_stack *m_avail_exprs_stack;
   hash_table<expr_elt_hasher> *m_avail_exprs;
   gcond *m_dummy_cond;
+  jump_threader threader;
 };
 
 vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
@@ -4332,9 +4333,9 @@ vrp_jump_threader::after_dom_children (basic_block bb)
 				      NULL, NULL);
 
   vrp_jump_threader_simplifier jthread_simplifier (m_vr_values);
-  thread_outgoing_edges (bb, m_dummy_cond, m_const_and_copies,
-			 m_avail_exprs_stack, NULL,
-			 jthread_simplifier);
+  threader.thread_outgoing_edges (bb, m_dummy_cond, m_const_and_copies,
+				  m_avail_exprs_stack, NULL,
+				  jthread_simplifier);
 
   m_avail_exprs_stack->pop_to_marker ();
   m_const_and_copies->pop_to_marker ();
@@ -4458,8 +4459,6 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
   vrp_asserts assert_engine (fun);
   assert_engine.insert_range_assertions ();
 
-  threadedge_initialize_values ();
-
   /* For visiting PHI nodes we need EDGE_DFS_BACK computed.  */
   mark_dfs_back_edges ();
 
@@ -4537,8 +4536,6 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
      processing by the pass manager.  */
   thread_through_all_blocks (false);
 
-  threadedge_finalize_values ();
-
   scev_finalize ();
   loop_optimizer_finalize ();
   return 0;


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

end of thread, other threads:[~2020-11-25 14:52 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 14:49 [gcc(refs/users/aldyh/heads/threader-refactor)] wip wip Aldy Hernandez
  -- strict thread matches above, loose matches on Subject: below --
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:52 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:51 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:50 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:49 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:48 Aldy Hernandez
2020-11-25 14:47 Aldy Hernandez
2020-11-25 14:47 Aldy Hernandez
2020-11-25 14:47 Aldy Hernandez
2020-11-25 14:47 Aldy Hernandez

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