domwalk.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Generic dominator tree walker
  2. Copyright (C) 2003-2019 Free Software Foundation, Inc.
  3. Contributed by Diego Novillo <dnovillo@redhat.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_DOM_WALK_H
  17. #define GCC_DOM_WALK_H
  18. /**
  19. * This is the main class for the dominator walker. It is expected that
  20. * consumers will have a custom class inheriting from it, which will over ride
  21. * at least one of before_dom_children and after_dom_children to implement the
  22. * custom behavior.
  23. */
  24. class dom_walker
  25. {
  26. public:
  27. static const edge STOP;
  28. /* An enum for determining whether the dom walk should be constrained to
  29. blocks reachable by executable edges. */
  30. enum reachability
  31. {
  32. /* Walk all blocks within the CFG. */
  33. ALL_BLOCKS,
  34. /* Use REACHABLE_BLOCKS when your subclass can discover that some edges
  35. are not executable.
  36. If a subclass can discover that a COND, SWITCH or GOTO has a static
  37. target in the before_dom_children callback, the taken edge should
  38. be returned. The generic walker will clear EDGE_EXECUTABLE on all
  39. edges it can determine are not executable.
  40. With REACHABLE_BLOCKS, EDGE_EXECUTABLE will be set on every edge in
  41. the dom_walker ctor; the flag will then be cleared on edges that are
  42. determined to be not executable. */
  43. REACHABLE_BLOCKS,
  44. /* Identical to REACHABLE_BLOCKS, but the initial state of EDGE_EXECUTABLE
  45. will instead be preserved in the ctor, allowing for information about
  46. non-executable edges to be merged in from an earlier analysis (and
  47. potentially for additional edges to be marked as non-executable). */
  48. REACHABLE_BLOCKS_PRESERVING_FLAGS
  49. };
  50. /* You can provide a mapping of basic-block index to RPO if you
  51. have that readily available or you do multiple walks. If you
  52. specify NULL as BB_INDEX_TO_RPO dominator children will not be
  53. walked in RPO order. */
  54. dom_walker (cdi_direction direction, enum reachability = ALL_BLOCKS,
  55. int *bb_index_to_rpo = NULL);
  56. ~dom_walker ();
  57. /* Walk the dominator tree. */
  58. void walk (basic_block);
  59. /* Function to call before the recursive walk of the dominator children.
  60. Return value is the always taken edge if the block has multiple outgoing
  61. edges, NULL otherwise. When skipping unreachable blocks, the walker
  62. uses the taken edge information to clear EDGE_EXECUTABLE on the other
  63. edges, exposing unreachable blocks. A NULL return value means all
  64. outgoing edges should still be considered executable. A return value
  65. of STOP means to stop the domwalk from processing dominated blocks from
  66. here. This can be used to process a SEME region only (note domwalk
  67. will still do work linear in function size). */
  68. virtual edge before_dom_children (basic_block) { return NULL; }
  69. /* Function to call after the recursive walk of the dominator children. */
  70. virtual void after_dom_children (basic_block) {}
  71. private:
  72. /* This is the direction of the dominator tree we want to walk. i.e.,
  73. if it is set to CDI_DOMINATORS, then we walk the dominator tree,
  74. if it is set to CDI_POST_DOMINATORS, then we walk the post
  75. dominator tree. */
  76. const ENUM_BITFIELD (cdi_direction) m_dom_direction : 2;
  77. const ENUM_BITFIELD (reachability) m_reachability : 2;
  78. bool m_user_bb_to_rpo;
  79. basic_block m_unreachable_dom;
  80. int *m_bb_to_rpo;
  81. /* Query whether or not the given block is reachable or not. */
  82. bool bb_reachable (struct function *, basic_block);
  83. /* Given an unreachable block, propagate that property to outgoing
  84. and possibly incoming edges for the block. Typically called after
  85. determining a block is unreachable in the before_dom_children
  86. callback. */
  87. void propagate_unreachable_to_edges (basic_block, FILE *, dump_flags_t);
  88. };
  89. extern void set_all_edges_as_executable (function *fn);
  90. #endif