]>
Commit | Line | Data |
---|---|---|
0f71a633 | 1 | /* Define control flow data structures for the CFG. |
f1717362 | 2 | Copyright (C) 1987-2016 Free Software Foundation, Inc. |
6207bd2c | 3 | |
f12b58b3 | 4 | This file is part of GCC. |
6207bd2c | 5 | |
f12b58b3 | 6 | GCC is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU General Public License as published by the Free | |
8c4c00c1 | 8 | Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 9 | version. |
6207bd2c | 10 | |
f12b58b3 | 11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
6207bd2c | 15 | |
16 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
6207bd2c | 19 | |
2a281353 | 20 | #ifndef GCC_BASIC_BLOCK_H |
ddc63996 | 21 | #define GCC_BASIC_BLOCK_H |
6207bd2c | 22 | |
7e0b0820 | 23 | |
424a4a92 | 24 | /* Use gcov_type to hold basic block counters. Should be at least |
805e22b2 | 25 | 64bit. Although a counter cannot be negative, we use a signed |
26 | type, because erroneous negative counts can be generated when the | |
27 | flow graph is manipulated by various optimizations. A signed type | |
6a8fa8e2 | 28 | makes those easy to detect. */ |
63f23608 | 29 | |
71caadc0 | 30 | /* Control flow edge information. */ |
2b15d2ba | 31 | struct GTY((user)) edge_def { |
71caadc0 | 32 | /* The two blocks at the ends of the edge. */ |
161dfa6e | 33 | basic_block src; |
34 | basic_block dest; | |
71caadc0 | 35 | |
36 | /* Instructions queued on the edge. */ | |
4ee9c684 | 37 | union edge_def_insns { |
2b15d2ba | 38 | gimple_seq g; |
ae5e6486 | 39 | rtx_insn *r; |
2b15d2ba | 40 | } insns; |
71caadc0 | 41 | |
42 | /* Auxiliary info specific to a pass. */ | |
2b15d2ba | 43 | PTR aux; |
6207bd2c | 44 | |
5169661d | 45 | /* Location of any goto implicit in the edge. */ |
9c85a98a | 46 | location_t goto_locus; |
815540dd | 47 | |
b041d147 | 48 | /* The index number corresponding to this edge in the edge vector |
49 | dest->preds. */ | |
50 | unsigned int dest_idx; | |
51 | ||
5147ec07 | 52 | int flags; /* see cfg-flags.def */ |
71caadc0 | 53 | int probability; /* biased by REG_BR_PROB_BASE */ |
63f23608 | 54 | gcov_type count; /* Expected number of executions calculated |
86d4af74 | 55 | in profile.c */ |
4ee9c684 | 56 | }; |
57 | ||
5147ec07 | 58 | /* Masks for edge.flags. */ |
59 | #define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX , | |
60 | enum cfg_edge_flags { | |
61 | #include "cfg-flags.def" | |
62 | LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */ | |
63 | }; | |
64 | #undef DEF_EDGE_FLAG | |
65 | ||
66 | /* Bit mask for all edge flags. */ | |
67 | #define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1) | |
6207bd2c | 68 | |
5147ec07 | 69 | /* The following four flags all indicate something special about an edge. |
70 | Test the edge flags on EDGE_COMPLEX to detect all forms of "strange" | |
71 | control flow transfers. */ | |
f59cbcbf | 72 | #define EDGE_COMPLEX \ |
73 | (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE) | |
2102d800 | 74 | |
924c4c71 | 75 | struct GTY(()) rtl_bb_info { |
43e94e51 | 76 | /* The first insn of the block is embedded into bb->il.x. */ |
77 | /* The last insn of the block. */ | |
26bb3cb2 | 78 | rtx_insn *end_; |
924c4c71 | 79 | |
80 | /* In CFGlayout mode points to insn notes/jumptables to be placed just before | |
81 | and after the block. */ | |
26bb3cb2 | 82 | rtx_insn *header_; |
943ea6fa | 83 | rtx_insn *footer_; |
924c4c71 | 84 | }; |
85 | ||
86 | struct GTY(()) gimple_bb_info { | |
87 | /* Sequence of statements in this block. */ | |
88 | gimple_seq seq; | |
89 | ||
90 | /* PHI nodes for this block. */ | |
91 | gimple_seq phi_nodes; | |
92 | }; | |
7ea47fbd | 93 | |
1496fdb4 | 94 | /* A basic block is a sequence of instructions with only one entry and |
997af237 | 95 | only one exit. If any one of the instructions are executed, they |
96 | will all be executed, and in sequence from first to last. | |
97 | ||
98 | There may be COND_EXEC instructions in the basic block. The | |
99 | COND_EXEC *instructions* will be executed -- but if the condition | |
100 | is false the conditionally executed *expressions* will of course | |
101 | not be executed. We don't consider the conditionally executed | |
102 | expression (which might have side-effects) to be in a separate | |
103 | basic block because the program counter will always be at the same | |
104 | location after the COND_EXEC instruction, regardless of whether the | |
105 | condition is true or not. | |
106 | ||
107 | Basic blocks need not start with a label nor end with a jump insn. | |
1deb248e | 108 | For example, a previous basic block may just "conditionally fall" |
109 | into the succeeding basic block, and the last basic block need not | |
110 | end with a jump insn. Block 0 is a descendant of the entry block. | |
111 | ||
112 | A basic block beginning with two labels cannot have notes between | |
113 | the labels. | |
114 | ||
115 | Data for jump tables are stored in jump_insns that occur in no | |
116 | basic block even though these insns can follow or precede insns in | |
117 | basic blocks. */ | |
118 | ||
71caadc0 | 119 | /* Basic block information indexed by block number. */ |
fb1e4f4a | 120 | struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def { |
71caadc0 | 121 | /* The edges into and out of the block. */ |
f1f41a6c | 122 | vec<edge, va_gc> *preds; |
123 | vec<edge, va_gc> *succs; | |
f24e9d92 | 124 | |
71caadc0 | 125 | /* Auxiliary info specific to a pass. */ |
4ee9c684 | 126 | PTR GTY ((skip (""))) aux; |
6207bd2c | 127 | |
7562ed74 | 128 | /* Innermost loop containing the block. */ |
ccae4f9f | 129 | struct loop *loop_father; |
7562ed74 | 130 | |
131 | /* The dominance and postdominance information node. */ | |
132 | struct et_node * GTY ((skip (""))) dom[2]; | |
0e21c32a | 133 | |
7fa55aef | 134 | /* Previous and next blocks in the chain. */ |
161dfa6e | 135 | basic_block prev_bb; |
136 | basic_block next_bb; | |
7fa55aef | 137 | |
e0dde8f8 | 138 | union basic_block_il_dependent { |
924c4c71 | 139 | struct gimple_bb_info GTY ((tag ("0"))) gimple; |
43e94e51 | 140 | struct { |
26bb3cb2 | 141 | rtx_insn *head_; |
43e94e51 | 142 | struct rtl_bb_info * rtl; |
143 | } GTY ((tag ("1"))) x; | |
e0dde8f8 | 144 | } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il; |
145 | ||
6b42039a | 146 | /* Various flags. See cfg-flags.def. */ |
147 | int flags; | |
ddc63996 | 148 | |
7562ed74 | 149 | /* The index of this block. */ |
150 | int index; | |
151 | ||
6b42039a | 152 | /* Expected number of executions: calculated in profile.c. */ |
153 | gcov_type count; | |
7562ed74 | 154 | |
f81d9f78 | 155 | /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */ |
156 | int frequency; | |
a6a1b9be | 157 | |
5147ec07 | 158 | /* The discriminator for this block. The discriminator distinguishes |
159 | among several basic blocks that share a common locus, allowing for | |
160 | more accurate sample-based profiling. */ | |
d01c707b | 161 | int discriminator; |
4ee9c684 | 162 | }; |
163 | ||
924c4c71 | 164 | /* This ensures that struct gimple_bb_info is smaller than |
165 | struct rtl_bb_info, so that inlining the former into basic_block_def | |
166 | is the better choice. */ | |
167 | typedef int __assert_gimple_bb_smaller_rtl_bb | |
9af5ce0c | 168 | [(int) sizeof (struct rtl_bb_info) |
169 | - (int) sizeof (struct gimple_bb_info)]; | |
c23dad79 | 170 | |
ba2c9526 | 171 | |
f81d9f78 | 172 | #define BB_FREQ_MAX 10000 |
71caadc0 | 173 | |
5147ec07 | 174 | /* Masks for basic_block.flags. */ |
175 | #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX , | |
176 | enum cfg_bb_flags | |
0f69b266 | 177 | { |
5147ec07 | 178 | #include "cfg-flags.def" |
179 | LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */ | |
0f69b266 | 180 | }; |
5147ec07 | 181 | #undef DEF_BASIC_BLOCK_FLAG |
182 | ||
bec2cf98 | 183 | /* Bit mask for all basic block flags. */ |
5147ec07 | 184 | #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1) |
d3129ae7 | 185 | |
bec2cf98 | 186 | /* Bit mask for all basic block flags that must be preserved. These are |
187 | the bit masks that are *not* cleared by clear_bb_flags. */ | |
188 | #define BB_FLAGS_TO_PRESERVE \ | |
189 | (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \ | |
190 | | BB_HOT_PARTITION | BB_COLD_PARTITION) | |
191 | ||
5147ec07 | 192 | /* Dummy bitmask for convenience in the hot/cold partitioning code. */ |
7562ed74 | 193 | #define BB_UNPARTITIONED 0 |
a6a1b9be | 194 | |
4f18499c | 195 | /* Partitions, to be used when partitioning hot and cold basic blocks into |
196 | separate sections. */ | |
7562ed74 | 197 | #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION)) |
91ef7ecb | 198 | #define BB_SET_PARTITION(bb, part) do { \ |
199 | basic_block bb_ = (bb); \ | |
200 | bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \ | |
201 | | (part)); \ | |
202 | } while (0) | |
203 | ||
7562ed74 | 204 | #define BB_COPY_PARTITION(dstbb, srcbb) \ |
205 | BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb)) | |
4f18499c | 206 | |
7a22afab | 207 | /* Defines for accessing the fields of the CFG structure for function FN. */ |
34154e27 | 208 | #define ENTRY_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_entry_block_ptr) |
209 | #define EXIT_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_exit_block_ptr) | |
98e6ab47 | 210 | #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info) |
a28770e1 | 211 | #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks) |
f1955b22 | 212 | #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges) |
776b0663 | 213 | #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block) |
dbd64d47 | 214 | #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map) |
3bedbae3 | 215 | #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status) |
7a22afab | 216 | |
98e6ab47 | 217 | #define BASIC_BLOCK_FOR_FN(FN,N) \ |
218 | ((*basic_block_info_for_fn (FN))[(N)]) | |
219 | #define SET_BASIC_BLOCK_FOR_FN(FN,N,BB) \ | |
220 | ((*basic_block_info_for_fn (FN))[(N)] = (BB)) | |
7a22afab | 221 | |
7fa55aef | 222 | /* For iterating over basic blocks. */ |
223 | #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \ | |
224 | for (BB = FROM; BB != TO; BB = BB->DIR) | |
225 | ||
7a22afab | 226 | #define FOR_EACH_BB_FN(BB, FN) \ |
227 | FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb) | |
228 | ||
7a22afab | 229 | #define FOR_EACH_BB_REVERSE_FN(BB, FN) \ |
230 | FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb) | |
231 | ||
f9cce2dc | 232 | /* For iterating over insns in basic block. */ |
233 | #define FOR_BB_INSNS(BB, INSN) \ | |
234 | for ((INSN) = BB_HEAD (BB); \ | |
4d2e5d52 | 235 | (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \ |
f9cce2dc | 236 | (INSN) = NEXT_INSN (INSN)) |
237 | ||
3072d30e | 238 | /* For iterating over insns in basic block when we might remove the |
239 | current insn. */ | |
240 | #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \ | |
241 | for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \ | |
242 | (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \ | |
243 | (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL) | |
48e1416a | 244 | |
f9cce2dc | 245 | #define FOR_BB_INSNS_REVERSE(BB, INSN) \ |
246 | for ((INSN) = BB_END (BB); \ | |
4d2e5d52 | 247 | (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \ |
f9cce2dc | 248 | (INSN) = PREV_INSN (INSN)) |
249 | ||
3072d30e | 250 | #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \ |
251 | for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \ | |
252 | (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \ | |
253 | (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL) | |
254 | ||
cb5c5698 | 255 | /* Cycles through _all_ basic blocks, even the fake ones (entry and |
256 | exit block). */ | |
257 | ||
4f217f69 | 258 | #define FOR_ALL_BB_FN(BB, FN) \ |
34154e27 | 259 | for (BB = ENTRY_BLOCK_PTR_FOR_FN (FN); BB; BB = BB->next_bb) |
4f217f69 | 260 | |
61e82936 | 261 | \f |
262 | /* Stuff for recording basic block info. */ | |
263 | ||
060ce583 | 264 | /* For now, these will be functions (so that they can include checked casts |
265 | to rtx_insn. Once the underlying fields are converted from rtx | |
266 | to rtx_insn, these can be converted back to macros. */ | |
267 | ||
26bb3cb2 | 268 | #define BB_HEAD(B) (B)->il.x.head_ |
269 | #define BB_END(B) (B)->il.x.rtl->end_ | |
270 | #define BB_HEADER(B) (B)->il.x.rtl->header_ | |
943ea6fa | 271 | #define BB_FOOTER(B) (B)->il.x.rtl->footer_ |
fac55a46 | 272 | |
dd24d1a6 | 273 | /* Special block numbers [markers] for entry and exit. |
274 | Neither of them is supposed to hold actual statements. */ | |
4d2e5d52 | 275 | #define ENTRY_BLOCK (0) |
276 | #define EXIT_BLOCK (1) | |
277 | ||
278 | /* The two blocks that are always in the cfg. */ | |
279 | #define NUM_FIXED_BLOCKS (2) | |
61e82936 | 280 | |
edc6a4c0 | 281 | /* The base value for branch probability notes and edge probabilities. */ |
282 | #define REG_BR_PROB_BASE 10000 | |
283 | ||
26d63a15 | 284 | /* This is the value which indicates no edge is present. */ |
285 | #define EDGE_INDEX_NO_EDGE -1 | |
286 | ||
287 | /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE | |
288 | if there is no edge between the 2 basic blocks. */ | |
289 | #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ))) | |
290 | ||
291 | /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic | |
292 | block which is either the pred or succ end of the indexed edge. */ | |
293 | #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src) | |
294 | #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest) | |
295 | ||
296 | /* INDEX_EDGE returns a pointer to the edge. */ | |
297 | #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)]) | |
298 | ||
299 | /* Number of edges in the compressed edge list. */ | |
300 | #define NUM_EDGES(el) ((el)->num_edges) | |
301 | ||
b1e17e10 | 302 | /* BB is assumed to contain conditional jump. Return the fallthru edge. */ |
cd665a06 | 303 | #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \ |
304 | ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1)) | |
b1e17e10 | 305 | |
306 | /* BB is assumed to contain conditional jump. Return the branch edge. */ | |
cd665a06 | 307 | #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \ |
308 | ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0)) | |
b1e17e10 | 309 | |
877584e4 | 310 | #define RDIV(X,Y) (((X) + (Y) / 2) / (Y)) |
eb429644 | 311 | /* Return expected execution frequency of the edge E. */ |
877584e4 | 312 | #define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \ |
313 | REG_BR_PROB_BASE) | |
eb429644 | 314 | |
f9d4b7f4 | 315 | /* Compute a scale factor (or probability) suitable for scaling of |
e2bc4ec8 | 316 | gcov_type values via apply_probability() and apply_scale(). */ |
f9d4b7f4 | 317 | #define GCOV_COMPUTE_SCALE(num,den) \ |
318 | ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE) | |
319 | ||
e76f35e8 | 320 | /* Return nonzero if edge is critical. */ |
cd665a06 | 321 | #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \ |
322 | && EDGE_COUNT ((e)->dest->preds) >= 2) | |
323 | ||
f1f41a6c | 324 | #define EDGE_COUNT(ev) vec_safe_length (ev) |
325 | #define EDGE_I(ev,i) (*ev)[(i)] | |
326 | #define EDGE_PRED(bb,i) (*(bb)->preds)[(i)] | |
327 | #define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)] | |
cd665a06 | 328 | |
ea091dfd | 329 | /* Returns true if BB has precisely one successor. */ |
330 | ||
331 | static inline bool | |
7ecb5bb2 | 332 | single_succ_p (const_basic_block bb) |
ea091dfd | 333 | { |
334 | return EDGE_COUNT (bb->succs) == 1; | |
335 | } | |
336 | ||
337 | /* Returns true if BB has precisely one predecessor. */ | |
338 | ||
339 | static inline bool | |
7ecb5bb2 | 340 | single_pred_p (const_basic_block bb) |
ea091dfd | 341 | { |
342 | return EDGE_COUNT (bb->preds) == 1; | |
343 | } | |
344 | ||
c843a183 | 345 | /* Returns the single successor edge of basic block BB. Aborts if |
346 | BB does not have exactly one successor. */ | |
ea091dfd | 347 | |
348 | static inline edge | |
7ecb5bb2 | 349 | single_succ_edge (const_basic_block bb) |
ea091dfd | 350 | { |
1b4345f7 | 351 | gcc_checking_assert (single_succ_p (bb)); |
ea091dfd | 352 | return EDGE_SUCC (bb, 0); |
353 | } | |
354 | ||
c843a183 | 355 | /* Returns the single predecessor edge of basic block BB. Aborts |
356 | if BB does not have exactly one predecessor. */ | |
ea091dfd | 357 | |
358 | static inline edge | |
7ecb5bb2 | 359 | single_pred_edge (const_basic_block bb) |
ea091dfd | 360 | { |
1b4345f7 | 361 | gcc_checking_assert (single_pred_p (bb)); |
ea091dfd | 362 | return EDGE_PRED (bb, 0); |
363 | } | |
364 | ||
c843a183 | 365 | /* Returns the single successor block of basic block BB. Aborts |
366 | if BB does not have exactly one successor. */ | |
ea091dfd | 367 | |
368 | static inline basic_block | |
7ecb5bb2 | 369 | single_succ (const_basic_block bb) |
ea091dfd | 370 | { |
371 | return single_succ_edge (bb)->dest; | |
372 | } | |
373 | ||
c843a183 | 374 | /* Returns the single predecessor block of basic block BB. Aborts |
375 | if BB does not have exactly one predecessor.*/ | |
ea091dfd | 376 | |
377 | static inline basic_block | |
7ecb5bb2 | 378 | single_pred (const_basic_block bb) |
ea091dfd | 379 | { |
380 | return single_pred_edge (bb)->src; | |
381 | } | |
382 | ||
cd665a06 | 383 | /* Iterator object for edges. */ |
384 | ||
b3e7c666 | 385 | struct edge_iterator { |
cd665a06 | 386 | unsigned index; |
f1f41a6c | 387 | vec<edge, va_gc> **container; |
b3e7c666 | 388 | }; |
cd665a06 | 389 | |
f1f41a6c | 390 | static inline vec<edge, va_gc> * |
56ff961b | 391 | ei_container (edge_iterator i) |
392 | { | |
1b4345f7 | 393 | gcc_checking_assert (i.container); |
56ff961b | 394 | return *i.container; |
395 | } | |
396 | ||
397 | #define ei_start(iter) ei_start_1 (&(iter)) | |
398 | #define ei_last(iter) ei_last_1 (&(iter)) | |
399 | ||
cd665a06 | 400 | /* Return an iterator pointing to the start of an edge vector. */ |
401 | static inline edge_iterator | |
f1f41a6c | 402 | ei_start_1 (vec<edge, va_gc> **ev) |
cd665a06 | 403 | { |
404 | edge_iterator i; | |
405 | ||
406 | i.index = 0; | |
407 | i.container = ev; | |
408 | ||
409 | return i; | |
410 | } | |
411 | ||
412 | /* Return an iterator pointing to the last element of an edge | |
dac49aa5 | 413 | vector. */ |
cd665a06 | 414 | static inline edge_iterator |
f1f41a6c | 415 | ei_last_1 (vec<edge, va_gc> **ev) |
cd665a06 | 416 | { |
417 | edge_iterator i; | |
418 | ||
56ff961b | 419 | i.index = EDGE_COUNT (*ev) - 1; |
cd665a06 | 420 | i.container = ev; |
421 | ||
422 | return i; | |
423 | } | |
424 | ||
425 | /* Is the iterator `i' at the end of the sequence? */ | |
426 | static inline bool | |
427 | ei_end_p (edge_iterator i) | |
428 | { | |
56ff961b | 429 | return (i.index == EDGE_COUNT (ei_container (i))); |
cd665a06 | 430 | } |
431 | ||
432 | /* Is the iterator `i' at one position before the end of the | |
433 | sequence? */ | |
434 | static inline bool | |
435 | ei_one_before_end_p (edge_iterator i) | |
436 | { | |
56ff961b | 437 | return (i.index + 1 == EDGE_COUNT (ei_container (i))); |
cd665a06 | 438 | } |
439 | ||
440 | /* Advance the iterator to the next element. */ | |
441 | static inline void | |
442 | ei_next (edge_iterator *i) | |
443 | { | |
1b4345f7 | 444 | gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i))); |
cd665a06 | 445 | i->index++; |
446 | } | |
447 | ||
448 | /* Move the iterator to the previous element. */ | |
449 | static inline void | |
450 | ei_prev (edge_iterator *i) | |
451 | { | |
1b4345f7 | 452 | gcc_checking_assert (i->index > 0); |
cd665a06 | 453 | i->index--; |
454 | } | |
455 | ||
456 | /* Return the edge pointed to by the iterator `i'. */ | |
457 | static inline edge | |
458 | ei_edge (edge_iterator i) | |
459 | { | |
56ff961b | 460 | return EDGE_I (ei_container (i), i.index); |
cd665a06 | 461 | } |
462 | ||
463 | /* Return an edge pointed to by the iterator. Do it safely so that | |
464 | NULL is returned when the iterator is pointing at the end of the | |
465 | sequence. */ | |
466 | static inline edge | |
467 | ei_safe_edge (edge_iterator i) | |
468 | { | |
469 | return !ei_end_p (i) ? ei_edge (i) : NULL; | |
470 | } | |
471 | ||
3df28fc8 | 472 | /* Return 1 if we should continue to iterate. Return 0 otherwise. |
473 | *Edge P is set to the next edge if we are to continue to iterate | |
474 | and NULL otherwise. */ | |
475 | ||
476 | static inline bool | |
477 | ei_cond (edge_iterator ei, edge *p) | |
478 | { | |
479 | if (!ei_end_p (ei)) | |
480 | { | |
481 | *p = ei_edge (ei); | |
482 | return 1; | |
483 | } | |
484 | else | |
485 | { | |
486 | *p = NULL; | |
487 | return 0; | |
488 | } | |
489 | } | |
490 | ||
cd665a06 | 491 | /* This macro serves as a convenient way to iterate each edge in a |
cfd459fc | 492 | vector of predecessor or successor edges. It must not be used when |
cd665a06 | 493 | an element might be removed during the traversal, otherwise |
494 | elements will be missed. Instead, use a for-loop like that shown | |
495 | in the following pseudo-code: | |
a0c938f0 | 496 | |
cd665a06 | 497 | FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) |
498 | { | |
499 | IF (e != taken_edge) | |
0891994d | 500 | remove_edge (e); |
cd665a06 | 501 | ELSE |
502 | ei_next (&ei); | |
503 | } | |
504 | */ | |
505 | ||
3df28fc8 | 506 | #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \ |
507 | for ((ITER) = ei_start ((EDGE_VEC)); \ | |
508 | ei_cond ((ITER), &(EDGE)); \ | |
cd665a06 | 509 | ei_next (&(ITER))) |
e76f35e8 | 510 | |
d01481af | 511 | #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations |
a0d79d69 | 512 | except for edge forwarding */ |
513 | #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */ | |
514 | #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need | |
515 | to care REG_DEAD notes. */ | |
3072d30e | 516 | #define CLEANUP_THREADING 8 /* Do jump threading. */ |
517 | #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead | |
43a852ea | 518 | insns. */ |
3072d30e | 519 | #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */ |
79f958cb | 520 | #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */ |
fbac255a | 521 | |
c927329e | 522 | /* Return true if BB is in a transaction. */ |
523 | ||
524 | static inline bool | |
525 | bb_in_transaction (basic_block bb) | |
526 | { | |
527 | return bb->flags & BB_IN_TRANSACTION; | |
528 | } | |
529 | ||
a5517fc0 | 530 | /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */ |
ec028b54 | 531 | static inline bool |
532 | bb_has_eh_pred (basic_block bb) | |
467b5d37 | 533 | { |
534 | edge e; | |
535 | edge_iterator ei; | |
536 | ||
537 | FOR_EACH_EDGE (e, ei, bb->preds) | |
538 | { | |
539 | if (e->flags & EDGE_EH) | |
540 | return true; | |
541 | } | |
542 | return false; | |
543 | } | |
544 | ||
dea7b504 | 545 | /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */ |
546 | static inline bool | |
547 | bb_has_abnormal_pred (basic_block bb) | |
548 | { | |
549 | edge e; | |
550 | edge_iterator ei; | |
551 | ||
552 | FOR_EACH_EDGE (e, ei, bb->preds) | |
553 | { | |
554 | if (e->flags & EDGE_ABNORMAL) | |
555 | return true; | |
556 | } | |
557 | return false; | |
558 | } | |
559 | ||
7f58c05e | 560 | /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */ |
561 | static inline edge | |
f1f41a6c | 562 | find_fallthru_edge (vec<edge, va_gc> *edges) |
7f58c05e | 563 | { |
564 | edge e; | |
565 | edge_iterator ei; | |
566 | ||
567 | FOR_EACH_EDGE (e, ei, edges) | |
568 | if (e->flags & EDGE_FALLTHRU) | |
569 | break; | |
570 | ||
571 | return e; | |
572 | } | |
573 | ||
877584e4 | 574 | /* Check tha probability is sane. */ |
575 | ||
576 | static inline void | |
577 | check_probability (int prob) | |
578 | { | |
579 | gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE); | |
580 | } | |
581 | ||
582 | /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE. | |
583 | Used to combine BB probabilities. */ | |
584 | ||
585 | static inline int | |
586 | combine_probabilities (int prob1, int prob2) | |
587 | { | |
588 | check_probability (prob1); | |
589 | check_probability (prob2); | |
590 | return RDIV (prob1 * prob2, REG_BR_PROB_BASE); | |
591 | } | |
592 | ||
e2bc4ec8 | 593 | /* Apply scale factor SCALE on frequency or count FREQ. Use this |
594 | interface when potentially scaling up, so that SCALE is not | |
595 | constrained to be < REG_BR_PROB_BASE. */ | |
596 | ||
597 | static inline gcov_type | |
acdafb9d | 598 | apply_scale (gcov_type freq, gcov_type scale) |
e2bc4ec8 | 599 | { |
600 | return RDIV (freq * scale, REG_BR_PROB_BASE); | |
601 | } | |
602 | ||
877584e4 | 603 | /* Apply probability PROB on frequency or count FREQ. */ |
604 | ||
605 | static inline gcov_type | |
606 | apply_probability (gcov_type freq, int prob) | |
607 | { | |
608 | check_probability (prob); | |
e2bc4ec8 | 609 | return apply_scale (freq, prob); |
877584e4 | 610 | } |
611 | ||
612 | /* Return inverse probability for PROB. */ | |
613 | ||
614 | static inline int | |
615 | inverse_probability (int prob1) | |
616 | { | |
617 | check_probability (prob1); | |
618 | return REG_BR_PROB_BASE - prob1; | |
619 | } | |
b61383dd | 620 | |
621 | /* Return true if BB has at least one abnormal outgoing edge. */ | |
622 | ||
623 | static inline bool | |
cb287480 | 624 | has_abnormal_or_eh_outgoing_edge_p (basic_block bb) |
b61383dd | 625 | { |
626 | edge e; | |
627 | edge_iterator ei; | |
628 | ||
629 | FOR_EACH_EDGE (e, ei, bb->succs) | |
cb287480 | 630 | if (e->flags & (EDGE_ABNORMAL | EDGE_EH)) |
b61383dd | 631 | return true; |
632 | ||
633 | return false; | |
634 | } | |
a0a565a9 | 635 | |
636 | /* Return true when one of the predecessor edges of BB is marked with | |
637 | EDGE_ABNORMAL_CALL or EDGE_EH. */ | |
638 | ||
639 | static inline bool | |
640 | has_abnormal_call_or_eh_pred_edge_p (basic_block bb) | |
641 | { | |
642 | edge e; | |
643 | edge_iterator ei; | |
644 | ||
645 | FOR_EACH_EDGE (e, ei, bb->preds) | |
646 | if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH)) | |
647 | return true; | |
648 | ||
649 | return false; | |
650 | } | |
651 | ||
2a281353 | 652 | #endif /* GCC_BASIC_BLOCK_H */ |