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