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