From: Richard Biener Date: Mon, 1 Apr 2019 11:36:25 +0000 (+0000) Subject: re PR tree-optimization/46590 (long compile time with -O2 and many loops) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e37240b0b556c2bcdf94b0a84ff798cd4bd5a316;p=gcc.git re PR tree-optimization/46590 (long compile time with -O2 and many loops) 2019-04-01 Richard Biener 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e123db0fe9c..2b0a73afd58 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2019-04-01 Richard Biener + + 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 PR driver/89861 diff --git a/gcc/domwalk.c b/gcc/domwalk.c index 3849eed4944..8c0fdecb462 100644 --- a/gcc/domwalk.c +++ b/gcc/domwalk.c @@ -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); diff --git a/gcc/domwalk.h b/gcc/domwalk.h index c3bc80438a5..f865c61588f 100644 --- a/gcc/domwalk.h +++ b/gcc/domwalk.h @@ -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;