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