]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/basic-block.h
i386.c (make_resolver_func): Update.
[thirdparty/gcc.git] / gcc / basic-block.h
CommitLineData
7a8cba34 1/* Define control flow data structures for the CFG.
cbe34bb5 2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
3245eea0 3
1322177d 4This file is part of GCC.
3245eea0 5
1322177d
LB
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
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
1322177d 9version.
3245eea0 10
1322177d
LB
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.
3245eea0
CH
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
3245eea0 19
88657302 20#ifndef GCC_BASIC_BLOCK_H
7f8a2125 21#define GCC_BASIC_BLOCK_H
3245eea0 22
3995f3a2 23#include <profile-count.h>
b2aec5c0 24
e881bb1b 25/* Control flow edge information. */
0823efed 26struct GTY((user)) edge_def {
e881bb1b 27 /* The two blocks at the ends of the edge. */
b8244d74
SB
28 basic_block src;
29 basic_block dest;
e881bb1b
RH
30
31 /* Instructions queued on the edge. */
6de9cd9a 32 union edge_def_insns {
0823efed 33 gimple_seq g;
3ffa95c2 34 rtx_insn *r;
0823efed 35 } insns;
e881bb1b
RH
36
37 /* Auxiliary info specific to a pass. */
0823efed 38 PTR aux;
3245eea0 39
5368224f 40 /* Location of any goto implicit in the edge. */
2d593c86 41 location_t goto_locus;
62b857ea 42
2eac9a76
RG
43 /* The index number corresponding to this edge in the edge vector
44 dest->preds. */
45 unsigned int dest_idx;
46
a315c44c 47 int flags; /* see cfg-flags.def */
e881bb1b 48 int probability; /* biased by REG_BR_PROB_BASE */
3995f3a2 49 profile_count count; /* Expected number of executions calculated
51891abe 50 in profile.c */
6de9cd9a
DN
51};
52
a315c44c
SB
53/* Masks for edge.flags. */
54#define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
55enum cfg_edge_flags {
56#include "cfg-flags.def"
57 LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */
58};
59#undef DEF_EDGE_FLAG
60
61/* Bit mask for all edge flags. */
62#define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
3245eea0 63
a315c44c
SB
64/* The following four flags all indicate something special about an edge.
65 Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
66 control flow transfers. */
0be7e7a6
RH
67#define EDGE_COMPLEX \
68 (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
65b98a02 69
3e8b732e 70struct GTY(()) rtl_bb_info {
bcc708fc
MM
71 /* The first insn of the block is embedded into bb->il.x. */
72 /* The last insn of the block. */
1130d5e3 73 rtx_insn *end_;
3e8b732e
MM
74
75 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
76 and after the block. */
1130d5e3 77 rtx_insn *header_;
d8ce2eae 78 rtx_insn *footer_;
3e8b732e
MM
79};
80
81struct GTY(()) gimple_bb_info {
82 /* Sequence of statements in this block. */
83 gimple_seq seq;
84
85 /* PHI nodes for this block. */
86 gimple_seq phi_nodes;
87};
4aab792d 88
229ecb89 89/* A basic block is a sequence of instructions with only one entry and
e68e3108
MM
90 only one exit. If any one of the instructions are executed, they
91 will all be executed, and in sequence from first to last.
92
93 There may be COND_EXEC instructions in the basic block. The
94 COND_EXEC *instructions* will be executed -- but if the condition
95 is false the conditionally executed *expressions* will of course
96 not be executed. We don't consider the conditionally executed
97 expression (which might have side-effects) to be in a separate
98 basic block because the program counter will always be at the same
99 location after the COND_EXEC instruction, regardless of whether the
100 condition is true or not.
101
102 Basic blocks need not start with a label nor end with a jump insn.
b53978a3
JO
103 For example, a previous basic block may just "conditionally fall"
104 into the succeeding basic block, and the last basic block need not
105 end with a jump insn. Block 0 is a descendant of the entry block.
106
107 A basic block beginning with two labels cannot have notes between
108 the labels.
109
110 Data for jump tables are stored in jump_insns that occur in no
111 basic block even though these insns can follow or precede insns in
112 basic blocks. */
113
e881bb1b 114/* Basic block information indexed by block number. */
d1b38208 115struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
e881bb1b 116 /* The edges into and out of the block. */
9771b263
DN
117 vec<edge, va_gc> *preds;
118 vec<edge, va_gc> *succs;
4d1d8045 119
e881bb1b 120 /* Auxiliary info specific to a pass. */
6de9cd9a 121 PTR GTY ((skip (""))) aux;
3245eea0 122
076c7ab8 123 /* Innermost loop containing the block. */
9e2f83a5 124 struct loop *loop_father;
076c7ab8
ZW
125
126 /* The dominance and postdominance information node. */
127 struct et_node * GTY ((skip (""))) dom[2];
336a6399 128
918ed612 129 /* Previous and next blocks in the chain. */
b8244d74
SB
130 basic_block prev_bb;
131 basic_block next_bb;
918ed612 132
5e2d947c 133 union basic_block_il_dependent {
3e8b732e 134 struct gimple_bb_info GTY ((tag ("0"))) gimple;
bcc708fc 135 struct {
1130d5e3 136 rtx_insn *head_;
bcc708fc
MM
137 struct rtl_bb_info * rtl;
138 } GTY ((tag ("1"))) x;
5e2d947c
JH
139 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
140
391886c8
RG
141 /* Various flags. See cfg-flags.def. */
142 int flags;
7f8a2125 143
076c7ab8
ZW
144 /* The index of this block. */
145 int index;
146
391886c8 147 /* Expected number of executions: calculated in profile.c. */
3995f3a2 148 profile_count count;
076c7ab8 149
861f9cd0
JH
150 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
151 int frequency;
006844a3 152
a315c44c
SB
153 /* The discriminator for this block. The discriminator distinguishes
154 among several basic blocks that share a common locus, allowing for
155 more accurate sample-based profiling. */
6c52e687 156 int discriminator;
6de9cd9a
DN
157};
158
3e8b732e
MM
159/* This ensures that struct gimple_bb_info is smaller than
160 struct rtl_bb_info, so that inlining the former into basic_block_def
161 is the better choice. */
162typedef int __assert_gimple_bb_smaller_rtl_bb
c3284718
RS
163 [(int) sizeof (struct rtl_bb_info)
164 - (int) sizeof (struct gimple_bb_info)];
7506e1cb 165
c71070ab 166
861f9cd0 167#define BB_FREQ_MAX 10000
e881bb1b 168
a315c44c
SB
169/* Masks for basic_block.flags. */
170#define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
171enum cfg_bb_flags
9e32d2be 172{
a315c44c
SB
173#include "cfg-flags.def"
174 LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
9e32d2be 175};
a315c44c
SB
176#undef DEF_BASIC_BLOCK_FLAG
177
c4669594 178/* Bit mask for all basic block flags. */
a315c44c 179#define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
740ce53d 180
c4669594
SB
181/* Bit mask for all basic block flags that must be preserved. These are
182 the bit masks that are *not* cleared by clear_bb_flags. */
183#define BB_FLAGS_TO_PRESERVE \
184 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
185 | BB_HOT_PARTITION | BB_COLD_PARTITION)
186
a315c44c 187/* Dummy bitmask for convenience in the hot/cold partitioning code. */
076c7ab8 188#define BB_UNPARTITIONED 0
006844a3 189
750054a2
CT
190/* Partitions, to be used when partitioning hot and cold basic blocks into
191 separate sections. */
076c7ab8 192#define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
51a904c9
ZW
193#define BB_SET_PARTITION(bb, part) do { \
194 basic_block bb_ = (bb); \
195 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
196 | (part)); \
197} while (0)
198
076c7ab8
ZW
199#define BB_COPY_PARTITION(dstbb, srcbb) \
200 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
750054a2 201
997de8ed 202/* Defines for accessing the fields of the CFG structure for function FN. */
fefa31b5
DM
203#define ENTRY_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_entry_block_ptr)
204#define EXIT_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_exit_block_ptr)
bbd79259 205#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
0cae8d31 206#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
dc936fb2 207#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
3986e690 208#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
3e248e06 209#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
ea19eb9f 210#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
997de8ed 211
bbd79259
DM
212#define BASIC_BLOCK_FOR_FN(FN,N) \
213 ((*basic_block_info_for_fn (FN))[(N)])
214#define SET_BASIC_BLOCK_FOR_FN(FN,N,BB) \
215 ((*basic_block_info_for_fn (FN))[(N)] = (BB))
997de8ed 216
918ed612
ZD
217/* For iterating over basic blocks. */
218#define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
219 for (BB = FROM; BB != TO; BB = BB->DIR)
220
997de8ed
SB
221#define FOR_EACH_BB_FN(BB, FN) \
222 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
223
997de8ed
SB
224#define FOR_EACH_BB_REVERSE_FN(BB, FN) \
225 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
226
50654f6c
ZD
227/* For iterating over insns in basic block. */
228#define FOR_BB_INSNS(BB, INSN) \
229 for ((INSN) = BB_HEAD (BB); \
24bd1a0b 230 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
50654f6c
ZD
231 (INSN) = NEXT_INSN (INSN))
232
6fb5fa3c
DB
233/* For iterating over insns in basic block when we might remove the
234 current insn. */
235#define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
236 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
237 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
238 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
b8698a0f 239
50654f6c
ZD
240#define FOR_BB_INSNS_REVERSE(BB, INSN) \
241 for ((INSN) = BB_END (BB); \
24bd1a0b 242 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
50654f6c
ZD
243 (INSN) = PREV_INSN (INSN))
244
6fb5fa3c
DB
245#define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
246 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
247 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
248 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
249
ed8d2920
MM
250/* Cycles through _all_ basic blocks, even the fake ones (entry and
251 exit block). */
252
a930a4ef 253#define FOR_ALL_BB_FN(BB, FN) \
fefa31b5 254 for (BB = ENTRY_BLOCK_PTR_FOR_FN (FN); BB; BB = BB->next_bb)
a930a4ef 255
5ece9746
JL
256\f
257/* Stuff for recording basic block info. */
258
ef0fe503
DM
259/* For now, these will be functions (so that they can include checked casts
260 to rtx_insn. Once the underlying fields are converted from rtx
261 to rtx_insn, these can be converted back to macros. */
262
1130d5e3
DM
263#define BB_HEAD(B) (B)->il.x.head_
264#define BB_END(B) (B)->il.x.rtl->end_
265#define BB_HEADER(B) (B)->il.x.rtl->header_
d8ce2eae 266#define BB_FOOTER(B) (B)->il.x.rtl->footer_
2b1d9dc0 267
95bca6b0
BRF
268/* Special block numbers [markers] for entry and exit.
269 Neither of them is supposed to hold actual statements. */
24bd1a0b
DB
270#define ENTRY_BLOCK (0)
271#define EXIT_BLOCK (1)
272
273/* The two blocks that are always in the cfg. */
274#define NUM_FIXED_BLOCKS (2)
5ece9746 275
410538ea
AM
276/* This is the value which indicates no edge is present. */
277#define EDGE_INDEX_NO_EDGE -1
278
279/* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
280 if there is no edge between the 2 basic blocks. */
281#define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
282
283/* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
284 block which is either the pred or succ end of the indexed edge. */
285#define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
286#define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
287
288/* INDEX_EDGE returns a pointer to the edge. */
289#define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
290
291/* Number of edges in the compressed edge list. */
292#define NUM_EDGES(el) ((el)->num_edges)
293
7a442791 294/* BB is assumed to contain conditional jump. Return the fallthru edge. */
628f6a4e
BE
295#define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
296 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
7a442791
JH
297
298/* BB is assumed to contain conditional jump. Return the branch edge. */
628f6a4e
BE
299#define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
300 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
7a442791 301
134d3a2e 302/* Return expected execution frequency of the edge E. */
e78410bf
JH
303#define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \
304 REG_BR_PROB_BASE)
134d3a2e 305
8ddb5a29 306/* Compute a scale factor (or probability) suitable for scaling of
f41f80f9 307 gcov_type values via apply_probability() and apply_scale(). */
8ddb5a29
TJ
308#define GCOV_COMPUTE_SCALE(num,den) \
309 ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
310
4262e623 311/* Return nonzero if edge is critical. */
628f6a4e
BE
312#define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
313 && EDGE_COUNT ((e)->dest->preds) >= 2)
314
9771b263
DN
315#define EDGE_COUNT(ev) vec_safe_length (ev)
316#define EDGE_I(ev,i) (*ev)[(i)]
317#define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
318#define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
628f6a4e 319
c5cbcccf
ZD
320/* Returns true if BB has precisely one successor. */
321
322static inline bool
ed7a4b4b 323single_succ_p (const_basic_block bb)
c5cbcccf
ZD
324{
325 return EDGE_COUNT (bb->succs) == 1;
326}
327
328/* Returns true if BB has precisely one predecessor. */
329
330static inline bool
ed7a4b4b 331single_pred_p (const_basic_block bb)
c5cbcccf
ZD
332{
333 return EDGE_COUNT (bb->preds) == 1;
334}
335
81b29e2f
ZD
336/* Returns the single successor edge of basic block BB. Aborts if
337 BB does not have exactly one successor. */
c5cbcccf
ZD
338
339static inline edge
ed7a4b4b 340single_succ_edge (const_basic_block bb)
c5cbcccf 341{
77a74ed7 342 gcc_checking_assert (single_succ_p (bb));
c5cbcccf
ZD
343 return EDGE_SUCC (bb, 0);
344}
345
81b29e2f
ZD
346/* Returns the single predecessor edge of basic block BB. Aborts
347 if BB does not have exactly one predecessor. */
c5cbcccf
ZD
348
349static inline edge
ed7a4b4b 350single_pred_edge (const_basic_block bb)
c5cbcccf 351{
77a74ed7 352 gcc_checking_assert (single_pred_p (bb));
c5cbcccf
ZD
353 return EDGE_PRED (bb, 0);
354}
355
81b29e2f
ZD
356/* Returns the single successor block of basic block BB. Aborts
357 if BB does not have exactly one successor. */
c5cbcccf
ZD
358
359static inline basic_block
ed7a4b4b 360single_succ (const_basic_block bb)
c5cbcccf
ZD
361{
362 return single_succ_edge (bb)->dest;
363}
364
81b29e2f
ZD
365/* Returns the single predecessor block of basic block BB. Aborts
366 if BB does not have exactly one predecessor.*/
c5cbcccf
ZD
367
368static inline basic_block
ed7a4b4b 369single_pred (const_basic_block bb)
c5cbcccf
ZD
370{
371 return single_pred_edge (bb)->src;
372}
373
628f6a4e
BE
374/* Iterator object for edges. */
375
84562394 376struct edge_iterator {
628f6a4e 377 unsigned index;
9771b263 378 vec<edge, va_gc> **container;
84562394 379};
628f6a4e 380
9771b263 381static inline vec<edge, va_gc> *
f76ccf60
BE
382ei_container (edge_iterator i)
383{
77a74ed7 384 gcc_checking_assert (i.container);
f76ccf60
BE
385 return *i.container;
386}
387
388#define ei_start(iter) ei_start_1 (&(iter))
389#define ei_last(iter) ei_last_1 (&(iter))
390
628f6a4e
BE
391/* Return an iterator pointing to the start of an edge vector. */
392static inline edge_iterator
9771b263 393ei_start_1 (vec<edge, va_gc> **ev)
628f6a4e
BE
394{
395 edge_iterator i;
396
397 i.index = 0;
398 i.container = ev;
399
400 return i;
401}
402
403/* Return an iterator pointing to the last element of an edge
471854f8 404 vector. */
628f6a4e 405static inline edge_iterator
9771b263 406ei_last_1 (vec<edge, va_gc> **ev)
628f6a4e
BE
407{
408 edge_iterator i;
409
f76ccf60 410 i.index = EDGE_COUNT (*ev) - 1;
628f6a4e
BE
411 i.container = ev;
412
413 return i;
414}
415
416/* Is the iterator `i' at the end of the sequence? */
417static inline bool
418ei_end_p (edge_iterator i)
419{
f76ccf60 420 return (i.index == EDGE_COUNT (ei_container (i)));
628f6a4e
BE
421}
422
423/* Is the iterator `i' at one position before the end of the
424 sequence? */
425static inline bool
426ei_one_before_end_p (edge_iterator i)
427{
f76ccf60 428 return (i.index + 1 == EDGE_COUNT (ei_container (i)));
628f6a4e
BE
429}
430
431/* Advance the iterator to the next element. */
432static inline void
433ei_next (edge_iterator *i)
434{
77a74ed7 435 gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
628f6a4e
BE
436 i->index++;
437}
438
439/* Move the iterator to the previous element. */
440static inline void
441ei_prev (edge_iterator *i)
442{
77a74ed7 443 gcc_checking_assert (i->index > 0);
628f6a4e
BE
444 i->index--;
445}
446
447/* Return the edge pointed to by the iterator `i'. */
448static inline edge
449ei_edge (edge_iterator i)
450{
f76ccf60 451 return EDGE_I (ei_container (i), i.index);
628f6a4e
BE
452}
453
454/* Return an edge pointed to by the iterator. Do it safely so that
455 NULL is returned when the iterator is pointing at the end of the
456 sequence. */
457static inline edge
458ei_safe_edge (edge_iterator i)
459{
460 return !ei_end_p (i) ? ei_edge (i) : NULL;
461}
462
f3522a84
KH
463/* Return 1 if we should continue to iterate. Return 0 otherwise.
464 *Edge P is set to the next edge if we are to continue to iterate
465 and NULL otherwise. */
466
467static inline bool
468ei_cond (edge_iterator ei, edge *p)
469{
470 if (!ei_end_p (ei))
471 {
472 *p = ei_edge (ei);
473 return 1;
474 }
475 else
476 {
477 *p = NULL;
478 return 0;
479 }
480}
481
628f6a4e 482/* This macro serves as a convenient way to iterate each edge in a
c2b7c2d8 483 vector of predecessor or successor edges. It must not be used when
628f6a4e
BE
484 an element might be removed during the traversal, otherwise
485 elements will be missed. Instead, use a for-loop like that shown
486 in the following pseudo-code:
c22cacf3 487
628f6a4e
BE
488 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
489 {
490 IF (e != taken_edge)
d0d2cc21 491 remove_edge (e);
628f6a4e
BE
492 ELSE
493 ei_next (&ei);
494 }
495*/
496
f3522a84
KH
497#define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
498 for ((ITER) = ei_start ((EDGE_VEC)); \
499 ei_cond ((ITER), &(EDGE)); \
628f6a4e 500 ei_next (&(ITER)))
4262e623 501
e0bb17a8 502#define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
46fac664
JH
503 except for edge forwarding */
504#define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
505#define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
506 to care REG_DEAD notes. */
6fb5fa3c
DB
507#define CLEANUP_THREADING 8 /* Do jump threading. */
508#define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
95479831 509 insns. */
6fb5fa3c 510#define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
7d776ee2 511#define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
6ce2bcb7 512
7783daa7
AM
513/* Return true if BB is in a transaction. */
514
515static inline bool
516bb_in_transaction (basic_block bb)
517{
518 return bb->flags & BB_IN_TRANSACTION;
519}
520
f66fd328 521/* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
bae8b6b2
SB
522static inline bool
523bb_has_eh_pred (basic_block bb)
fcc42bca
AK
524{
525 edge e;
526 edge_iterator ei;
527
528 FOR_EACH_EDGE (e, ei, bb->preds)
529 {
530 if (e->flags & EDGE_EH)
531 return true;
532 }
533 return false;
534}
535
ba49cb7b
KZ
536/* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
537static inline bool
538bb_has_abnormal_pred (basic_block bb)
539{
540 edge e;
541 edge_iterator ei;
542
543 FOR_EACH_EDGE (e, ei, bb->preds)
544 {
545 if (e->flags & EDGE_ABNORMAL)
546 return true;
547 }
548 return false;
549}
550
0fd4b31d
NF
551/* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
552static inline edge
9771b263 553find_fallthru_edge (vec<edge, va_gc> *edges)
0fd4b31d
NF
554{
555 edge e;
556 edge_iterator ei;
557
558 FOR_EACH_EDGE (e, ei, edges)
559 if (e->flags & EDGE_FALLTHRU)
560 break;
561
562 return e;
563}
564
e78410bf
JH
565/* Check tha probability is sane. */
566
567static inline void
568check_probability (int prob)
569{
570 gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
571}
572
573/* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
574 Used to combine BB probabilities. */
575
576static inline int
577combine_probabilities (int prob1, int prob2)
578{
579 check_probability (prob1);
580 check_probability (prob2);
581 return RDIV (prob1 * prob2, REG_BR_PROB_BASE);
582}
583
f41f80f9
TJ
584/* Apply scale factor SCALE on frequency or count FREQ. Use this
585 interface when potentially scaling up, so that SCALE is not
586 constrained to be < REG_BR_PROB_BASE. */
587
588static inline gcov_type
b9cbfeeb 589apply_scale (gcov_type freq, gcov_type scale)
f41f80f9
TJ
590{
591 return RDIV (freq * scale, REG_BR_PROB_BASE);
592}
593
e78410bf
JH
594/* Apply probability PROB on frequency or count FREQ. */
595
596static inline gcov_type
597apply_probability (gcov_type freq, int prob)
598{
599 check_probability (prob);
f41f80f9 600 return apply_scale (freq, prob);
e78410bf
JH
601}
602
603/* Return inverse probability for PROB. */
604
605static inline int
606inverse_probability (int prob1)
607{
608 check_probability (prob1);
609 return REG_BR_PROB_BASE - prob1;
610}
5e94175f
JL
611
612/* Return true if BB has at least one abnormal outgoing edge. */
613
614static inline bool
6efe83b2 615has_abnormal_or_eh_outgoing_edge_p (basic_block bb)
5e94175f
JL
616{
617 edge e;
618 edge_iterator ei;
619
620 FOR_EACH_EDGE (e, ei, bb->succs)
6efe83b2 621 if (e->flags & (EDGE_ABNORMAL | EDGE_EH))
5e94175f
JL
622 return true;
623
624 return false;
625}
f1544089
MP
626
627/* Return true when one of the predecessor edges of BB is marked with
628 EDGE_ABNORMAL_CALL or EDGE_EH. */
629
630static inline bool
631has_abnormal_call_or_eh_pred_edge_p (basic_block bb)
632{
633 edge e;
634 edge_iterator ei;
635
636 FOR_EACH_EDGE (e, ei, bb->preds)
637 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
638 return true;
639
640 return false;
641}
642
88657302 643#endif /* GCC_BASIC_BLOCK_H */