re PR tree-optimization/46590 (long compile time with -O2 and many loops)
authorRichard Biener <rguenther@suse.de>
Mon, 1 Apr 2019 11:36:25 +0000 (11:36 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 1 Apr 2019 11:36:25 +0000 (11:36 +0000)
2019-04-01  Richard Biener  <rguenther@suse.de>

PR tree-optimization/46590
* domwalk.h (dom_walker::dom_walker): Consolidate constructors.
(dom_walker::m_reachability): Add in place of...
(dom_walker::m_skip_unreachable_blocks): ...this.
* domwalk.c (dom_walker::dom_walker): Consoliate constructors.
Move complex initialization ...
(dom_walker::walk): Here.  Especially compute m_bb_to_rpo
lazily and initialize edge flags on each invocation.
(dom_walker::bb_reachable): Use m_reachability.

From-SVN: r270055

gcc/ChangeLog
gcc/domwalk.c
gcc/domwalk.h

index e123db0fe9c013b25f6a1b40467427e3975d2a70..2b0a73afd58574907061034f527a7ac1be88fcd6 100644 (file)
@@ -1,3 +1,15 @@
+2019-04-01  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/46590
+       * domwalk.h (dom_walker::dom_walker): Consolidate constructors.
+       (dom_walker::m_reachability): Add in place of...
+       (dom_walker::m_skip_unreachable_blocks): ...this.
+       * domwalk.c (dom_walker::dom_walker): Consoliate constructors.
+       Move complex initialization ...
+       (dom_walker::walk): Here.  Especially compute m_bb_to_rpo
+       lazily and initialize edge flags on each invocation.
+       (dom_walker::bb_reachable): Use m_reachability.
+
 2019-04-01  Martin Liska  <mliska@suse.cz>
 
        PR driver/89861
index 3849eed494467bc30258b9ddf76d2fd2895280f4..8c0fdecb4621ff849aa9161e2c2f8dd10531d70d 100644 (file)
@@ -190,69 +190,11 @@ dom_walker::dom_walker (cdi_direction direction,
                        enum reachability reachability,
                        int *bb_index_to_rpo)
   : m_dom_direction (direction),
-    m_skip_unreachable_blocks (reachability != ALL_BLOCKS),
-    m_user_bb_to_rpo (true),
+    m_reachability (reachability),
+    m_user_bb_to_rpo (bb_index_to_rpo != NULL),
     m_unreachable_dom (NULL),
     m_bb_to_rpo (bb_index_to_rpo)
 {
-  /* Set up edge flags if need be.  */
-  switch (reachability)
-    {
-    default:
-      gcc_unreachable ();
-    case ALL_BLOCKS:
-      /* No need to touch edge flags.  */
-      break;
-
-    case REACHABLE_BLOCKS:
-      set_all_edges_as_executable (cfun);
-      break;
-
-    case REACHABLE_BLOCKS_PRESERVING_FLAGS:
-      /* Preserve the edge flags.  */
-      break;
-    }
-}
-
-/* Constructor for a dom walker.  */
-
-dom_walker::dom_walker (cdi_direction direction,
-                       enum reachability reachability)
-  : m_dom_direction (direction),
-    m_skip_unreachable_blocks (reachability != ALL_BLOCKS),
-    m_user_bb_to_rpo (false),
-    m_unreachable_dom (NULL),
-    m_bb_to_rpo (NULL)
-{
-  /* Compute the basic-block index to RPO mapping.  */
-  if (direction == CDI_DOMINATORS)
-    {
-      int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
-      int postorder_num = pre_and_rev_post_order_compute (NULL, postorder,
-                                                         true);
-      m_bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
-      for (int i = 0; i < postorder_num; ++i)
-       m_bb_to_rpo[postorder[i]] = i;
-      free (postorder);
-    }
-
-  /* Set up edge flags if need be.  */
-  switch (reachability)
-    {
-    default:
-      gcc_unreachable ();
-    case ALL_BLOCKS:
-      /* No need to touch edge flags.  */
-      break;
-
-    case REACHABLE_BLOCKS:
-      set_all_edges_as_executable (cfun);
-      break;
-
-    case REACHABLE_BLOCKS_PRESERVING_FLAGS:
-      /* Preserve the edge flags.  */
-      break;
-    }
 }
 
 /* Destructor.  */
@@ -270,7 +212,7 @@ dom_walker::bb_reachable (struct function *fun, basic_block bb)
 {
   /* If we're not skipping unreachable blocks, then assume everything
      is reachable.  */
-  if (!m_skip_unreachable_blocks)
+  if (m_reachability == ALL_BLOCKS)
     return true;
 
   /* If any of the predecessor edges that do not come from blocks dominated
@@ -331,6 +273,23 @@ const edge dom_walker::STOP = (edge)-1;
 void
 dom_walker::walk (basic_block bb)
 {
+  /* Compute the basic-block index to RPO mapping lazily.  */
+  if (!m_bb_to_rpo
+      && m_dom_direction == CDI_DOMINATORS)
+    {
+      int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
+      int postorder_num = pre_and_rev_post_order_compute (NULL, postorder,
+                                                         true);
+      m_bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
+      for (int i = 0; i < postorder_num; ++i)
+       m_bb_to_rpo[postorder[i]] = i;
+      free (postorder);
+    }
+
+  /* Set up edge flags if need be.  */
+  if (m_reachability == REACHABLE_BLOCKS)
+    set_all_edges_as_executable (cfun);
+
   basic_block dest;
   basic_block *worklist = XNEWVEC (basic_block,
                                   n_basic_blocks_for_fn (cfun) * 2);
index c3bc80438a51c0e3cd670f6174192d1e50351f6b..f865c61588f38762c426011f9f39544d268077cb 100644 (file)
@@ -60,13 +60,12 @@ public:
     REACHABLE_BLOCKS_PRESERVING_FLAGS
   };
 
-  dom_walker (cdi_direction direction, enum reachability = ALL_BLOCKS);
-
   /* You can provide a mapping of basic-block index to RPO if you
      have that readily available or you do multiple walks.  If you
      specify NULL as BB_INDEX_TO_RPO dominator children will not be
      walked in RPO order.  */
-  dom_walker (cdi_direction direction, enum reachability, int *bb_index_to_rpo);
+  dom_walker (cdi_direction direction, enum reachability = ALL_BLOCKS,
+             int *bb_index_to_rpo = NULL);
 
   ~dom_walker ();
 
@@ -94,7 +93,7 @@ private:
      if it is set to CDI_POST_DOMINATORS, then we walk the post
      dominator tree.  */
   const ENUM_BITFIELD (cdi_direction) m_dom_direction : 2;
-  bool m_skip_unreachable_blocks;
+  const ENUM_BITFIELD (reachability) m_reachability : 2;
   bool m_user_bb_to_rpo;
   basic_block m_unreachable_dom;
   int *m_bb_to_rpo;