]>
Commit | Line | Data |
---|---|---|
9ee634e3 | 1 | /* Hooks for cfg representation specific functions. |
8d9254fc | 2 | Copyright (C) 2003-2020 Free Software Foundation, Inc. |
9ee634e3 JH |
3 | Contributed by Sebastian Pop <s.pop@laposte.net> |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9dcd6f09 | 9 | the Free Software Foundation; either version 3, or (at your option) |
9ee634e3 JH |
10 | any later version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
9ee634e3 | 20 | |
f1717f8d KC |
21 | #ifndef GCC_CFGHOOKS_H |
22 | #define GCC_CFGHOOKS_H | |
23 | ||
9fdcd34e | 24 | #include "predict.h" |
9ee634e3 | 25 | |
893479de AM |
26 | /* Structure to gather statistic about profile consistency, per pass. |
27 | An array of this structure, indexed by pass static number, is allocated | |
28 | in passes.c. The structure is defined here so that different CFG modes | |
29 | can do their book-keeping via CFG hooks. | |
30 | ||
31 | For every field[2], field[0] is the count before the pass runs, and | |
32 | field[1] is the post-pass count. This allows us to monitor the effect | |
33 | of each individual pass on the profile consistency. | |
34 | ||
35 | This structure is not supposed to be used by anything other than passes.c | |
36 | and one CFG hook per CFG mode. */ | |
37 | struct profile_record | |
38 | { | |
39 | /* The number of basic blocks where sum(freq) of the block's predecessors | |
40 | doesn't match reasonably well with the incoming frequency. */ | |
160576e1 | 41 | int num_mismatched_freq_in; |
893479de | 42 | /* Likewise for a basic block's successors. */ |
160576e1 | 43 | int num_mismatched_freq_out; |
893479de AM |
44 | /* The number of basic blocks where sum(count) of the block's predecessors |
45 | doesn't match reasonably well with the incoming frequency. */ | |
160576e1 | 46 | int num_mismatched_count_in; |
893479de | 47 | /* Likewise for a basic block's successors. */ |
160576e1 | 48 | int num_mismatched_count_out; |
893479de | 49 | /* A weighted cost of the run-time of the function body. */ |
160576e1 | 50 | gcov_type_unsigned time; |
893479de | 51 | /* A weighted cost of the size of the function body. */ |
160576e1 | 52 | int size; |
893479de AM |
53 | /* True iff this pass actually was run. */ |
54 | bool run; | |
55 | }; | |
56 | ||
229d576c RB |
57 | typedef int_hash <unsigned short, 0> dependence_hash; |
58 | ||
59 | /* Optional data for duplicate_block. */ | |
60 | ||
6c1dae73 | 61 | class copy_bb_data |
229d576c | 62 | { |
6c1dae73 | 63 | public: |
229d576c RB |
64 | copy_bb_data() : dependence_map (NULL) {} |
65 | ~copy_bb_data () { delete dependence_map; } | |
66 | ||
67 | /* A map from the copied BBs dependence info cliques to | |
68 | equivalents in the BBs duplicated to. */ | |
69 | hash_map<dependence_hash, unsigned short> *dependence_map; | |
70 | }; | |
893479de | 71 | |
9ee634e3 JH |
72 | struct cfg_hooks |
73 | { | |
f470c378 ZD |
74 | /* Name of the corresponding ir. */ |
75 | const char *name; | |
76 | ||
77 | /* Debugging. */ | |
78 | int (*verify_flow_info) (void); | |
1a817418 | 79 | void (*dump_bb) (FILE *, basic_block, int, dump_flags_t); |
2c895bd1 | 80 | void (*dump_bb_for_graph) (pretty_printer *, basic_block); |
9ee634e3 JH |
81 | |
82 | /* Basic CFG manipulation. */ | |
83 | ||
6614fd40 | 84 | /* Return new basic block. */ |
f55ade6e | 85 | basic_block (*create_basic_block) (void *head, void *end, basic_block after); |
bc35512f | 86 | |
9ee634e3 | 87 | /* Redirect edge E to the given basic block B and update underlying program |
6de9cd9a DN |
88 | representation. Returns edge representing redirected branch (that may not |
89 | be equivalent to E in the case of duplicate edges being removed) or NULL | |
90 | if edge is not easily redirectable for whatever reason. */ | |
91 | edge (*redirect_edge_and_branch) (edge e, basic_block b); | |
9ee634e3 JH |
92 | |
93 | /* Same as the above but allows redirecting of fallthru edges. In that case | |
0e61db61 NS |
94 | newly created forwarder basic block is returned. The edge must |
95 | not be abnormal. */ | |
d329e058 | 96 | basic_block (*redirect_edge_and_branch_force) (edge, basic_block); |
9ee634e3 | 97 | |
14fa2cc0 ZD |
98 | /* Returns true if it is possible to remove the edge by redirecting it |
99 | to the destination of the other edge going from its source. */ | |
9678086d | 100 | bool (*can_remove_branch_p) (const_edge); |
14fa2cc0 | 101 | |
f470c378 ZD |
102 | /* Remove statements corresponding to a given basic block. */ |
103 | void (*delete_basic_block) (basic_block); | |
104 | ||
105 | /* Creates a new basic block just after basic block B by splitting | |
106 | everything after specified instruction I. */ | |
107 | basic_block (*split_block) (basic_block b, void * i); | |
b8698a0f | 108 | |
f470c378 ZD |
109 | /* Move block B immediately after block A. */ |
110 | bool (*move_block_after) (basic_block b, basic_block a); | |
9ee634e3 | 111 | |
bc35512f | 112 | /* Return true when blocks A and B can be merged into single basic block. */ |
b48d0358 | 113 | bool (*can_merge_blocks_p) (basic_block a, basic_block b); |
bc35512f JH |
114 | |
115 | /* Merge blocks A and B. */ | |
f55ade6e | 116 | void (*merge_blocks) (basic_block a, basic_block b); |
bc35512f | 117 | |
6de9cd9a DN |
118 | /* Predict edge E using PREDICTOR to given PROBABILITY. */ |
119 | void (*predict_edge) (edge e, enum br_predictor predictor, int probability); | |
120 | ||
121 | /* Return true if the one of outgoing edges is already predicted by | |
122 | PREDICTOR. */ | |
9678086d | 123 | bool (*predicted_by_p) (const_basic_block bb, enum br_predictor predictor); |
6de9cd9a DN |
124 | |
125 | /* Return true when block A can be duplicated. */ | |
9678086d | 126 | bool (*can_duplicate_block_p) (const_basic_block a); |
6de9cd9a DN |
127 | |
128 | /* Duplicate block A. */ | |
229d576c | 129 | basic_block (*duplicate_block) (basic_block a, copy_bb_data *); |
6de9cd9a | 130 | |
9ee634e3 JH |
131 | /* Higher level functions representable by primitive operations above if |
132 | we didn't have some oddities in RTL and Tree representations. */ | |
f470c378 ZD |
133 | basic_block (*split_edge) (edge); |
134 | void (*make_forwarder_block) (edge); | |
135 | ||
cf103ca4 | 136 | /* Try to make the edge fallthru. */ |
f470c378 | 137 | void (*tidy_fallthru_edge) (edge); |
6de9cd9a | 138 | |
cf103ca4 EB |
139 | /* Make the edge non-fallthru. */ |
140 | basic_block (*force_nonfallthru) (edge); | |
141 | ||
6de9cd9a DN |
142 | /* Say whether a block ends with a call, possibly followed by some |
143 | other code that must stay with the call. */ | |
b48d0358 | 144 | bool (*block_ends_with_call_p) (basic_block); |
6de9cd9a DN |
145 | |
146 | /* Say whether a block ends with a conditional branch. Switches | |
147 | and unconditional branches do not qualify. */ | |
9678086d | 148 | bool (*block_ends_with_condjump_p) (const_basic_block); |
6de9cd9a DN |
149 | |
150 | /* Add fake edges to the function exit for any non constant and non noreturn | |
151 | calls, volatile inline assembly in the bitmap of blocks specified by | |
152 | BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks | |
153 | that were split. | |
154 | ||
155 | The goal is to expose cases in which entering a basic block does not imply | |
156 | that all subsequent instructions must be executed. */ | |
157 | int (*flow_call_edges_add) (sbitmap); | |
d9d4706f KH |
158 | |
159 | /* This function is called immediately after edge E is added to the | |
160 | edge vector E->dest->preds. */ | |
161 | void (*execute_on_growing_pred) (edge); | |
162 | ||
163 | /* This function is called immediately before edge E is removed from | |
164 | the edge vector E->dest->preds. */ | |
165 | void (*execute_on_shrinking_pred) (edge); | |
1cb7dfc3 MH |
166 | |
167 | /* A hook for duplicating loop in CFG, currently this is used | |
168 | in loop versioning. */ | |
99b1c316 | 169 | bool (*cfg_hook_duplicate_loop_to_header_edge) (class loop *, edge, |
ee8c1b05 | 170 | unsigned, sbitmap, |
9771b263 | 171 | edge, vec<edge> *, |
ee8c1b05 | 172 | int); |
1cb7dfc3 | 173 | |
0fa2e4df | 174 | /* Add condition to new basic block and update CFG used in loop |
1cb7dfc3 MH |
175 | versioning. */ |
176 | void (*lv_add_condition_to_bb) (basic_block, basic_block, basic_block, | |
c22cacf3 | 177 | void *); |
1cb7dfc3 MH |
178 | /* Update the PHI nodes in case of loop versioning. */ |
179 | void (*lv_adjust_loop_header_phi) (basic_block, basic_block, | |
180 | basic_block, edge); | |
c22cacf3 | 181 | |
1cb7dfc3 MH |
182 | /* Given a condition BB extract the true/false taken/not taken edges |
183 | (depending if we are on tree's or RTL). */ | |
184 | void (*extract_cond_bb_edges) (basic_block, edge *, edge *); | |
185 | ||
c22cacf3 | 186 | |
1cb7dfc3 MH |
187 | /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge |
188 | E->dest (only in tree-ssa loop versioning. */ | |
189 | void (*flush_pending_stmts) (edge); | |
df92c640 SB |
190 | |
191 | /* True if a block contains no executable instructions. */ | |
192 | bool (*empty_block_p) (basic_block); | |
193 | ||
194 | /* Split a basic block if it ends with a conditional branch and if | |
195 | the other part of the block is not empty. */ | |
196 | basic_block (*split_block_before_cond_jump) (basic_block); | |
aa4723d7 SB |
197 | |
198 | /* Do book-keeping of a basic block for the profile consistency checker. */ | |
160576e1 | 199 | void (*account_profile_record) (basic_block, struct profile_record *); |
9ee634e3 JH |
200 | }; |
201 | ||
f470c378 | 202 | extern void verify_flow_info (void); |
b2b29377 MM |
203 | |
204 | /* Check control flow invariants, if internal consistency checks are | |
205 | enabled. */ | |
206 | ||
207 | static inline void | |
208 | checking_verify_flow_info (void) | |
209 | { | |
210 | /* TODO: Add a separate option for -fchecking=cfg. */ | |
211 | if (flag_checking) | |
212 | verify_flow_info (); | |
213 | } | |
214 | ||
1a817418 | 215 | extern void dump_bb (FILE *, basic_block, int, dump_flags_t); |
2c895bd1 | 216 | extern void dump_bb_for_graph (pretty_printer *, basic_block); |
1a817418 | 217 | extern void dump_flow_info (FILE *, dump_flags_t); |
2c895bd1 | 218 | |
6de9cd9a | 219 | extern edge redirect_edge_and_branch (edge, basic_block); |
f470c378 | 220 | extern basic_block redirect_edge_and_branch_force (edge, basic_block); |
893479de | 221 | extern edge redirect_edge_succ_nodup (edge, basic_block); |
9678086d | 222 | extern bool can_remove_branch_p (const_edge); |
14fa2cc0 | 223 | extern void remove_branch (edge); |
452ba14d | 224 | extern void remove_edge (edge); |
c4d281b2 | 225 | extern edge split_block (basic_block, rtx); |
355fe088 | 226 | extern edge split_block (basic_block, gimple *); |
f470c378 ZD |
227 | extern edge split_block_after_labels (basic_block); |
228 | extern bool move_block_after (basic_block, basic_block); | |
229 | extern void delete_basic_block (basic_block); | |
230 | extern basic_block split_edge (edge); | |
c4d281b2 RB |
231 | extern basic_block create_basic_block (rtx, rtx, basic_block); |
232 | extern basic_block create_basic_block (gimple_seq, basic_block); | |
f470c378 | 233 | extern basic_block create_empty_bb (basic_block); |
b48d0358 | 234 | extern bool can_merge_blocks_p (basic_block, basic_block); |
f470c378 ZD |
235 | extern void merge_blocks (basic_block, basic_block); |
236 | extern edge make_forwarder_block (basic_block, bool (*)(edge), | |
237 | void (*) (basic_block)); | |
cf103ca4 | 238 | extern basic_block force_nonfallthru (edge); |
f470c378 ZD |
239 | extern void tidy_fallthru_edge (edge); |
240 | extern void tidy_fallthru_edges (void); | |
6de9cd9a | 241 | extern void predict_edge (edge e, enum br_predictor predictor, int probability); |
9678086d KG |
242 | extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor); |
243 | extern bool can_duplicate_block_p (const_basic_block); | |
229d576c RB |
244 | extern basic_block duplicate_block (basic_block, edge, basic_block, |
245 | copy_bb_data * = NULL); | |
b48d0358 | 246 | extern bool block_ends_with_call_p (basic_block bb); |
df92c640 SB |
247 | extern bool empty_block_p (basic_block); |
248 | extern basic_block split_block_before_cond_jump (basic_block); | |
9678086d | 249 | extern bool block_ends_with_condjump_p (const_basic_block bb); |
6de9cd9a | 250 | extern int flow_call_edges_add (sbitmap); |
d9d4706f KH |
251 | extern void execute_on_growing_pred (edge); |
252 | extern void execute_on_shrinking_pred (edge); | |
99b1c316 | 253 | extern bool cfg_hook_duplicate_loop_to_header_edge (class loop *loop, edge, |
1cb7dfc3 MH |
254 | unsigned int ndupl, |
255 | sbitmap wont_exit, | |
ee8c1b05 | 256 | edge orig, |
9771b263 | 257 | vec<edge> *to_remove, |
1cb7dfc3 MH |
258 | int flags); |
259 | ||
260 | extern void lv_flush_pending_stmts (edge); | |
261 | extern void extract_cond_bb_edges (basic_block, edge *, edge*); | |
262 | extern void lv_adjust_loop_header_phi (basic_block, basic_block, basic_block, | |
263 | edge); | |
264 | extern void lv_add_condition_to_bb (basic_block, basic_block, basic_block, | |
265 | void *); | |
9ee634e3 | 266 | |
78bde837 SB |
267 | extern bool can_copy_bbs_p (basic_block *, unsigned); |
268 | extern void copy_bbs (basic_block *, unsigned, basic_block *, | |
99b1c316 | 269 | edge *, unsigned, edge *, class loop *, |
f14540b6 | 270 | basic_block, bool); |
78bde837 | 271 | |
160576e1 ML |
272 | void profile_record_check_consistency (profile_record *); |
273 | void profile_record_account_profile (profile_record *); | |
aa4723d7 | 274 | |
9ee634e3 | 275 | /* Hooks containers. */ |
726a989a | 276 | extern struct cfg_hooks gimple_cfg_hooks; |
9ee634e3 | 277 | extern struct cfg_hooks rtl_cfg_hooks; |
f470c378 | 278 | extern struct cfg_hooks cfg_layout_rtl_cfg_hooks; |
9ee634e3 JH |
279 | |
280 | /* Declarations. */ | |
52bca999 | 281 | extern enum ir_type current_ir_type (void); |
d329e058 AJ |
282 | extern void rtl_register_cfg_hooks (void); |
283 | extern void cfg_layout_rtl_register_cfg_hooks (void); | |
726a989a | 284 | extern void gimple_register_cfg_hooks (void); |
e855c69d AB |
285 | extern struct cfg_hooks get_cfg_hooks (void); |
286 | extern void set_cfg_hooks (struct cfg_hooks); | |
9ee634e3 | 287 | |
f1717f8d | 288 | #endif /* GCC_CFGHOOKS_H */ |