cfg.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* Control flow graph manipulation code header file.
  2. Copyright (C) 2014-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_CFG_H
  16. #define GCC_CFG_H
  17. #include "dominance.h"
  18. /* What sort of profiling information we have. */
  19. enum profile_status_d
  20. {
  21. PROFILE_ABSENT,
  22. PROFILE_GUESSED,
  23. PROFILE_READ,
  24. PROFILE_LAST /* Last value, used by profile streaming. */
  25. };
  26. /* A structure to group all the per-function control flow graph data.
  27. The x_* prefixing is necessary because otherwise references to the
  28. fields of this struct are interpreted as the defines for backward
  29. source compatibility following the definition of this struct. */
  30. struct GTY(()) control_flow_graph {
  31. /* Block pointers for the exit and entry of a function.
  32. These are always the head and tail of the basic block list. */
  33. basic_block x_entry_block_ptr;
  34. basic_block x_exit_block_ptr;
  35. /* Index by basic block number, get basic block struct info. */
  36. vec<basic_block, va_gc> *x_basic_block_info;
  37. /* Number of basic blocks in this flow graph. */
  38. int x_n_basic_blocks;
  39. /* Number of edges in this flow graph. */
  40. int x_n_edges;
  41. /* The first free basic block number. */
  42. int x_last_basic_block;
  43. /* UIDs for LABEL_DECLs. */
  44. int last_label_uid;
  45. /* Mapping of labels to their associated blocks. At present
  46. only used for the gimple CFG. */
  47. vec<basic_block, va_gc> *x_label_to_block_map;
  48. enum profile_status_d x_profile_status;
  49. /* Whether the dominators and the postdominators are available. */
  50. enum dom_state x_dom_computed[2];
  51. /* Number of basic blocks in the dominance tree. */
  52. unsigned x_n_bbs_in_dom_tree[2];
  53. /* Maximal number of entities in the single jumptable. Used to estimate
  54. final flowgraph size. */
  55. int max_jumptable_ents;
  56. /* Maximal count of BB in function. */
  57. profile_count count_max;
  58. /* Dynamically allocated edge/bb flags. */
  59. int edge_flags_allocated;
  60. int bb_flags_allocated;
  61. };
  62. extern void init_flow (function *);
  63. extern void clear_edges (function *);
  64. extern basic_block alloc_block (void);
  65. extern void link_block (basic_block, basic_block);
  66. extern void unlink_block (basic_block);
  67. extern void compact_blocks (void);
  68. extern void expunge_block (basic_block);
  69. extern edge unchecked_make_edge (basic_block, basic_block, int);
  70. extern edge cached_make_edge (sbitmap, basic_block, basic_block, int);
  71. extern edge make_edge (basic_block, basic_block, int);
  72. extern edge make_single_succ_edge (basic_block, basic_block, int);
  73. extern void remove_edge_raw (edge);
  74. extern void redirect_edge_succ (edge, basic_block);
  75. extern void redirect_edge_pred (edge, basic_block);
  76. extern void clear_bb_flags (void);
  77. extern void dump_edge_info (FILE *, edge, dump_flags_t, int);
  78. extern void debug (edge_def &ref);
  79. extern void debug (edge_def *ptr);
  80. extern void alloc_aux_for_blocks (int);
  81. extern void clear_aux_for_blocks (void);
  82. extern void free_aux_for_blocks (void);
  83. extern void alloc_aux_for_edge (edge, int);
  84. extern void alloc_aux_for_edges (int);
  85. extern void clear_aux_for_edges (void);
  86. extern void free_aux_for_edges (void);
  87. extern void debug_bb (basic_block);
  88. extern basic_block debug_bb_n (int);
  89. extern void dump_bb_info (FILE *, basic_block, int, dump_flags_t, bool, bool);
  90. extern void brief_dump_cfg (FILE *, dump_flags_t);
  91. extern void update_bb_profile_for_threading (basic_block, profile_count, edge);
  92. extern void scale_bbs_frequencies_profile_count (basic_block *, int,
  93. profile_count, profile_count);
  94. extern void scale_bbs_frequencies (basic_block *, int, profile_probability);
  95. extern void initialize_original_copy_tables (void);
  96. extern void reset_original_copy_tables (void);
  97. extern void free_original_copy_tables (void);
  98. extern bool original_copy_tables_initialized_p (void);
  99. extern void set_bb_original (basic_block, basic_block);
  100. extern basic_block get_bb_original (basic_block);
  101. extern void set_bb_copy (basic_block, basic_block);
  102. extern basic_block get_bb_copy (basic_block);
  103. void set_loop_copy (struct loop *, struct loop *);
  104. struct loop *get_loop_copy (struct loop *);
  105. /* Generic RAII class to allocate a bit from storage of integer type T.
  106. The allocated bit is accessible as mask with the single bit set
  107. via the conversion operator to T. */
  108. template <class T>
  109. class auto_flag
  110. {
  111. public:
  112. /* static assert T is integer type of max HOST_WIDE_INT precision. */
  113. auto_flag (T *sptr)
  114. {
  115. m_sptr = sptr;
  116. int free_bit = ffs_hwi (~*sptr);
  117. /* If there are no unset bits... */
  118. if (free_bit == 0)
  119. gcc_unreachable ();
  120. m_flag = HOST_WIDE_INT_1U << (free_bit - 1);
  121. /* ...or if T is signed and thus the complement is sign-extended,
  122. check if we ran out of bits. We could spare us this bit
  123. if we could use C++11 std::make_unsigned<T>::type to pass
  124. ~*sptr to ffs_hwi. */
  125. if (m_flag == 0)
  126. gcc_unreachable ();
  127. gcc_checking_assert ((*sptr & m_flag) == 0);
  128. *sptr |= m_flag;
  129. }
  130. ~auto_flag ()
  131. {
  132. gcc_checking_assert ((*m_sptr & m_flag) == m_flag);
  133. *m_sptr &= ~m_flag;
  134. }
  135. operator T () const { return m_flag; }
  136. private:
  137. T *m_sptr;
  138. T m_flag;
  139. };
  140. /* RAII class to allocate an edge flag for temporary use. You have
  141. to clear the flag from all edges when you are finished using it. */
  142. class auto_edge_flag : public auto_flag<int>
  143. {
  144. public:
  145. auto_edge_flag (function *fun)
  146. : auto_flag<int> (&fun->cfg->edge_flags_allocated) {}
  147. };
  148. /* RAII class to allocate a bb flag for temporary use. You have
  149. to clear the flag from all edges when you are finished using it. */
  150. class auto_bb_flag : public auto_flag<int>
  151. {
  152. public:
  153. auto_bb_flag (function *fun)
  154. : auto_flag<int> (&fun->cfg->bb_flags_allocated) {}
  155. };
  156. #endif /* GCC_CFG_H */