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