cfghooks.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* Hooks for cfg representation specific functions.
  2. Copyright (C) 2003-2015 Free Software Foundation, Inc.
  3. Contributed by Sebastian Pop <s.pop@laposte.net>
  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_CFGHOOKS_H
  17. #define GCC_CFGHOOKS_H
  18. /* Only basic-block.h includes this. */
  19. /* Structure to gather statistic about profile consistency, per pass.
  20. An array of this structure, indexed by pass static number, is allocated
  21. in passes.c. The structure is defined here so that different CFG modes
  22. can do their book-keeping via CFG hooks.
  23. For every field[2], field[0] is the count before the pass runs, and
  24. field[1] is the post-pass count. This allows us to monitor the effect
  25. of each individual pass on the profile consistency.
  26. This structure is not supposed to be used by anything other than passes.c
  27. and one CFG hook per CFG mode. */
  28. struct profile_record
  29. {
  30. /* The number of basic blocks where sum(freq) of the block's predecessors
  31. doesn't match reasonably well with the incoming frequency. */
  32. int num_mismatched_freq_in[2];
  33. /* Likewise for a basic block's successors. */
  34. int num_mismatched_freq_out[2];
  35. /* The number of basic blocks where sum(count) of the block's predecessors
  36. doesn't match reasonably well with the incoming frequency. */
  37. int num_mismatched_count_in[2];
  38. /* Likewise for a basic block's successors. */
  39. int num_mismatched_count_out[2];
  40. /* A weighted cost of the run-time of the function body. */
  41. gcov_type time[2];
  42. /* A weighted cost of the size of the function body. */
  43. int size[2];
  44. /* True iff this pass actually was run. */
  45. bool run;
  46. };
  47. struct cfg_hooks
  48. {
  49. /* Name of the corresponding ir. */
  50. const char *name;
  51. /* Debugging. */
  52. int (*verify_flow_info) (void);
  53. void (*dump_bb) (FILE *, basic_block, int, int);
  54. void (*dump_bb_for_graph) (pretty_printer *, basic_block);
  55. /* Basic CFG manipulation. */
  56. /* Return new basic block. */
  57. basic_block (*create_basic_block) (void *head, void *end, basic_block after);
  58. /* Redirect edge E to the given basic block B and update underlying program
  59. representation. Returns edge representing redirected branch (that may not
  60. be equivalent to E in the case of duplicate edges being removed) or NULL
  61. if edge is not easily redirectable for whatever reason. */
  62. edge (*redirect_edge_and_branch) (edge e, basic_block b);
  63. /* Same as the above but allows redirecting of fallthru edges. In that case
  64. newly created forwarder basic block is returned. The edge must
  65. not be abnormal. */
  66. basic_block (*redirect_edge_and_branch_force) (edge, basic_block);
  67. /* Returns true if it is possible to remove the edge by redirecting it
  68. to the destination of the other edge going from its source. */
  69. bool (*can_remove_branch_p) (const_edge);
  70. /* Remove statements corresponding to a given basic block. */
  71. void (*delete_basic_block) (basic_block);
  72. /* Creates a new basic block just after basic block B by splitting
  73. everything after specified instruction I. */
  74. basic_block (*split_block) (basic_block b, void * i);
  75. /* Move block B immediately after block A. */
  76. bool (*move_block_after) (basic_block b, basic_block a);
  77. /* Return true when blocks A and B can be merged into single basic block. */
  78. bool (*can_merge_blocks_p) (basic_block a, basic_block b);
  79. /* Merge blocks A and B. */
  80. void (*merge_blocks) (basic_block a, basic_block b);
  81. /* Predict edge E using PREDICTOR to given PROBABILITY. */
  82. void (*predict_edge) (edge e, enum br_predictor predictor, int probability);
  83. /* Return true if the one of outgoing edges is already predicted by
  84. PREDICTOR. */
  85. bool (*predicted_by_p) (const_basic_block bb, enum br_predictor predictor);
  86. /* Return true when block A can be duplicated. */
  87. bool (*can_duplicate_block_p) (const_basic_block a);
  88. /* Duplicate block A. */
  89. basic_block (*duplicate_block) (basic_block a);
  90. /* Higher level functions representable by primitive operations above if
  91. we didn't have some oddities in RTL and Tree representations. */
  92. basic_block (*split_edge) (edge);
  93. void (*make_forwarder_block) (edge);
  94. /* Try to make the edge fallthru. */
  95. void (*tidy_fallthru_edge) (edge);
  96. /* Make the edge non-fallthru. */
  97. basic_block (*force_nonfallthru) (edge);
  98. /* Say whether a block ends with a call, possibly followed by some
  99. other code that must stay with the call. */
  100. bool (*block_ends_with_call_p) (basic_block);
  101. /* Say whether a block ends with a conditional branch. Switches
  102. and unconditional branches do not qualify. */
  103. bool (*block_ends_with_condjump_p) (const_basic_block);
  104. /* Add fake edges to the function exit for any non constant and non noreturn
  105. calls, volatile inline assembly in the bitmap of blocks specified by
  106. BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks
  107. that were split.
  108. The goal is to expose cases in which entering a basic block does not imply
  109. that all subsequent instructions must be executed. */
  110. int (*flow_call_edges_add) (sbitmap);
  111. /* This function is called immediately after edge E is added to the
  112. edge vector E->dest->preds. */
  113. void (*execute_on_growing_pred) (edge);
  114. /* This function is called immediately before edge E is removed from
  115. the edge vector E->dest->preds. */
  116. void (*execute_on_shrinking_pred) (edge);
  117. /* A hook for duplicating loop in CFG, currently this is used
  118. in loop versioning. */
  119. bool (*cfg_hook_duplicate_loop_to_header_edge) (struct loop *, edge,
  120. unsigned, sbitmap,
  121. edge, vec<edge> *,
  122. int);
  123. /* Add condition to new basic block and update CFG used in loop
  124. versioning. */
  125. void (*lv_add_condition_to_bb) (basic_block, basic_block, basic_block,
  126. void *);
  127. /* Update the PHI nodes in case of loop versioning. */
  128. void (*lv_adjust_loop_header_phi) (basic_block, basic_block,
  129. basic_block, edge);
  130. /* Given a condition BB extract the true/false taken/not taken edges
  131. (depending if we are on tree's or RTL). */
  132. void (*extract_cond_bb_edges) (basic_block, edge *, edge *);
  133. /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge
  134. E->dest (only in tree-ssa loop versioning. */
  135. void (*flush_pending_stmts) (edge);
  136. /* True if a block contains no executable instructions. */
  137. bool (*empty_block_p) (basic_block);
  138. /* Split a basic block if it ends with a conditional branch and if
  139. the other part of the block is not empty. */
  140. basic_block (*split_block_before_cond_jump) (basic_block);
  141. /* Do book-keeping of a basic block for the profile consistency checker. */
  142. void (*account_profile_record) (basic_block, int, struct profile_record *);
  143. };
  144. extern void verify_flow_info (void);
  145. extern void dump_bb (FILE *, basic_block, int, int);
  146. extern void dump_bb_for_graph (pretty_printer *, basic_block);
  147. extern void dump_flow_info (FILE *, int);
  148. extern edge redirect_edge_and_branch (edge, basic_block);
  149. extern basic_block redirect_edge_and_branch_force (edge, basic_block);
  150. extern edge redirect_edge_succ_nodup (edge, basic_block);
  151. extern bool can_remove_branch_p (const_edge);
  152. extern void remove_branch (edge);
  153. extern void remove_edge (edge);
  154. extern edge split_block (basic_block, void *);
  155. extern edge split_block_after_labels (basic_block);
  156. extern bool move_block_after (basic_block, basic_block);
  157. extern void delete_basic_block (basic_block);
  158. extern basic_block split_edge (edge);
  159. extern basic_block create_basic_block (void *, void *, basic_block);
  160. extern basic_block create_empty_bb (basic_block);
  161. extern bool can_merge_blocks_p (basic_block, basic_block);
  162. extern void merge_blocks (basic_block, basic_block);
  163. extern edge make_forwarder_block (basic_block, bool (*)(edge),
  164. void (*) (basic_block));
  165. extern basic_block force_nonfallthru (edge);
  166. extern void tidy_fallthru_edge (edge);
  167. extern void tidy_fallthru_edges (void);
  168. extern void predict_edge (edge e, enum br_predictor predictor, int probability);
  169. extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor);
  170. extern bool can_duplicate_block_p (const_basic_block);
  171. extern basic_block duplicate_block (basic_block, edge, basic_block);
  172. extern bool block_ends_with_call_p (basic_block bb);
  173. extern bool empty_block_p (basic_block);
  174. extern basic_block split_block_before_cond_jump (basic_block);
  175. extern bool block_ends_with_condjump_p (const_basic_block bb);
  176. extern int flow_call_edges_add (sbitmap);
  177. extern void execute_on_growing_pred (edge);
  178. extern void execute_on_shrinking_pred (edge);
  179. extern bool cfg_hook_duplicate_loop_to_header_edge (struct loop *loop, edge,
  180. unsigned int ndupl,
  181. sbitmap wont_exit,
  182. edge orig,
  183. vec<edge> *to_remove,
  184. int flags);
  185. extern void lv_flush_pending_stmts (edge);
  186. extern void extract_cond_bb_edges (basic_block, edge *, edge*);
  187. extern void lv_adjust_loop_header_phi (basic_block, basic_block, basic_block,
  188. edge);
  189. extern void lv_add_condition_to_bb (basic_block, basic_block, basic_block,
  190. void *);
  191. extern bool can_copy_bbs_p (basic_block *, unsigned);
  192. extern void copy_bbs (basic_block *, unsigned, basic_block *,
  193. edge *, unsigned, edge *, struct loop *,
  194. basic_block, bool);
  195. void account_profile_record (struct profile_record *, int);
  196. /* Hooks containers. */
  197. extern struct cfg_hooks gimple_cfg_hooks;
  198. extern struct cfg_hooks rtl_cfg_hooks;
  199. extern struct cfg_hooks cfg_layout_rtl_cfg_hooks;
  200. /* Declarations. */
  201. extern enum ir_type current_ir_type (void);
  202. extern void rtl_register_cfg_hooks (void);
  203. extern void cfg_layout_rtl_register_cfg_hooks (void);
  204. extern void gimple_register_cfg_hooks (void);
  205. extern struct cfg_hooks get_cfg_hooks (void);
  206. extern void set_cfg_hooks (struct cfg_hooks);
  207. #endif /* GCC_CFGHOOKS_H */