* config/i386/cpuid.h (__cpuid): Remove definitions that handle %ebx
[official-gcc.git] / gcc / basic-block.h
bloba2b31275e02ebb6b07d0c27bc2f3917c0c57037d
1 /* Define control flow data structures for the CFG.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #ifndef GCC_BASIC_BLOCK_H
21 #define GCC_BASIC_BLOCK_H
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"
33 /* Use gcov_type to hold basic block counters. Should be at least
34 64bit. Although a counter cannot be negative, we use a signed
35 type, because erroneous negative counts can be generated when the
36 flow graph is manipulated by various optimizations. A signed type
37 makes those easy to detect. */
39 /* Control flow edge information. */
40 struct GTY((user)) edge_def {
41 /* The two blocks at the ends of the edge. */
42 basic_block src;
43 basic_block dest;
45 /* Instructions queued on the edge. */
46 union edge_def_insns {
47 gimple_seq g;
48 rtx_insn *r;
49 } insns;
51 /* Auxiliary info specific to a pass. */
52 PTR aux;
54 /* Location of any goto implicit in the edge. */
55 location_t goto_locus;
57 /* The index number corresponding to this edge in the edge vector
58 dest->preds. */
59 unsigned int dest_idx;
61 int flags; /* see cfg-flags.def */
62 int probability; /* biased by REG_BR_PROB_BASE */
63 gcov_type count; /* Expected number of executions calculated
64 in profile.c */
68 /* Garbage collection and PCH support for edge_def. */
69 extern void gt_ggc_mx (edge_def *e);
70 extern void gt_pch_nx (edge_def *e);
71 extern void gt_pch_nx (edge_def *e, gt_pointer_operator, void *);
73 /* Masks for edge.flags. */
74 #define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
75 enum cfg_edge_flags {
76 #include "cfg-flags.def"
77 LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */
79 #undef DEF_EDGE_FLAG
81 /* Bit mask for all edge flags. */
82 #define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
84 /* The following four flags all indicate something special about an edge.
85 Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
86 control flow transfers. */
87 #define EDGE_COMPLEX \
88 (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
90 /* Counter summary from the last set of coverage counts read by
91 profile.c. */
92 extern const struct gcov_ctr_summary *profile_info;
94 /* Structure to gather statistic about profile consistency, per pass.
95 An array of this structure, indexed by pass static number, is allocated
96 in passes.c. The structure is defined here so that different CFG modes
97 can do their book-keeping via CFG hooks.
99 For every field[2], field[0] is the count before the pass runs, and
100 field[1] is the post-pass count. This allows us to monitor the effect
101 of each individual pass on the profile consistency.
103 This structure is not supposed to be used by anything other than passes.c
104 and one CFG hook per CFG mode. */
105 struct profile_record
107 /* The number of basic blocks where sum(freq) of the block's predecessors
108 doesn't match reasonably well with the incoming frequency. */
109 int num_mismatched_freq_in[2];
110 /* Likewise for a basic block's successors. */
111 int num_mismatched_freq_out[2];
112 /* The number of basic blocks where sum(count) of the block's predecessors
113 doesn't match reasonably well with the incoming frequency. */
114 int num_mismatched_count_in[2];
115 /* Likewise for a basic block's successors. */
116 int num_mismatched_count_out[2];
117 /* A weighted cost of the run-time of the function body. */
118 gcov_type time[2];
119 /* A weighted cost of the size of the function body. */
120 int size[2];
121 /* True iff this pass actually was run. */
122 bool run;
125 /* Declared in cfgloop.h. */
126 struct loop;
128 struct GTY(()) rtl_bb_info {
129 /* The first insn of the block is embedded into bb->il.x. */
130 /* The last insn of the block. */
131 rtx_insn *end_;
133 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
134 and after the block. */
135 rtx_insn *header_;
136 rtx_insn *footer_;
139 struct GTY(()) gimple_bb_info {
140 /* Sequence of statements in this block. */
141 gimple_seq seq;
143 /* PHI nodes for this block. */
144 gimple_seq phi_nodes;
147 /* A basic block is a sequence of instructions with only one entry and
148 only one exit. If any one of the instructions are executed, they
149 will all be executed, and in sequence from first to last.
151 There may be COND_EXEC instructions in the basic block. The
152 COND_EXEC *instructions* will be executed -- but if the condition
153 is false the conditionally executed *expressions* will of course
154 not be executed. We don't consider the conditionally executed
155 expression (which might have side-effects) to be in a separate
156 basic block because the program counter will always be at the same
157 location after the COND_EXEC instruction, regardless of whether the
158 condition is true or not.
160 Basic blocks need not start with a label nor end with a jump insn.
161 For example, a previous basic block may just "conditionally fall"
162 into the succeeding basic block, and the last basic block need not
163 end with a jump insn. Block 0 is a descendant of the entry block.
165 A basic block beginning with two labels cannot have notes between
166 the labels.
168 Data for jump tables are stored in jump_insns that occur in no
169 basic block even though these insns can follow or precede insns in
170 basic blocks. */
172 /* Basic block information indexed by block number. */
173 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
174 /* The edges into and out of the block. */
175 vec<edge, va_gc> *preds;
176 vec<edge, va_gc> *succs;
178 /* Auxiliary info specific to a pass. */
179 PTR GTY ((skip (""))) aux;
181 /* Innermost loop containing the block. */
182 struct loop *loop_father;
184 /* The dominance and postdominance information node. */
185 struct et_node * GTY ((skip (""))) dom[2];
187 /* Previous and next blocks in the chain. */
188 basic_block prev_bb;
189 basic_block next_bb;
191 union basic_block_il_dependent {
192 struct gimple_bb_info GTY ((tag ("0"))) gimple;
193 struct {
194 rtx_insn *head_;
195 struct rtl_bb_info * rtl;
196 } GTY ((tag ("1"))) x;
197 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
199 /* Various flags. See cfg-flags.def. */
200 int flags;
202 /* The index of this block. */
203 int index;
205 /* Expected number of executions: calculated in profile.c. */
206 gcov_type count;
208 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
209 int frequency;
211 /* The discriminator for this block. The discriminator distinguishes
212 among several basic blocks that share a common locus, allowing for
213 more accurate sample-based profiling. */
214 int discriminator;
217 /* This ensures that struct gimple_bb_info is smaller than
218 struct rtl_bb_info, so that inlining the former into basic_block_def
219 is the better choice. */
220 typedef int __assert_gimple_bb_smaller_rtl_bb
221 [(int) sizeof (struct rtl_bb_info)
222 - (int) sizeof (struct gimple_bb_info)];
225 #define BB_FREQ_MAX 10000
227 /* Masks for basic_block.flags. */
228 #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
229 enum cfg_bb_flags
231 #include "cfg-flags.def"
232 LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
234 #undef DEF_BASIC_BLOCK_FLAG
236 /* Bit mask for all basic block flags. */
237 #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
239 /* Bit mask for all basic block flags that must be preserved. These are
240 the bit masks that are *not* cleared by clear_bb_flags. */
241 #define BB_FLAGS_TO_PRESERVE \
242 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
243 | BB_HOT_PARTITION | BB_COLD_PARTITION)
245 /* Dummy bitmask for convenience in the hot/cold partitioning code. */
246 #define BB_UNPARTITIONED 0
248 /* Partitions, to be used when partitioning hot and cold basic blocks into
249 separate sections. */
250 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
251 #define BB_SET_PARTITION(bb, part) do { \
252 basic_block bb_ = (bb); \
253 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
254 | (part)); \
255 } while (0)
257 #define BB_COPY_PARTITION(dstbb, srcbb) \
258 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
260 /* State of dominance information. */
262 enum dom_state
264 DOM_NONE, /* Not computed at all. */
265 DOM_NO_FAST_QUERY, /* The data is OK, but the fast query data are not usable. */
266 DOM_OK /* Everything is ok. */
269 /* What sort of profiling information we have. */
270 enum profile_status_d
272 PROFILE_ABSENT,
273 PROFILE_GUESSED,
274 PROFILE_READ,
275 PROFILE_LAST /* Last value, used by profile streaming. */
278 /* A structure to group all the per-function control flow graph data.
279 The x_* prefixing is necessary because otherwise references to the
280 fields of this struct are interpreted as the defines for backward
281 source compatibility following the definition of this struct. */
282 struct GTY(()) control_flow_graph {
283 /* Block pointers for the exit and entry of a function.
284 These are always the head and tail of the basic block list. */
285 basic_block x_entry_block_ptr;
286 basic_block x_exit_block_ptr;
288 /* Index by basic block number, get basic block struct info. */
289 vec<basic_block, va_gc> *x_basic_block_info;
291 /* Number of basic blocks in this flow graph. */
292 int x_n_basic_blocks;
294 /* Number of edges in this flow graph. */
295 int x_n_edges;
297 /* The first free basic block number. */
298 int x_last_basic_block;
300 /* UIDs for LABEL_DECLs. */
301 int last_label_uid;
303 /* Mapping of labels to their associated blocks. At present
304 only used for the gimple CFG. */
305 vec<basic_block, va_gc> *x_label_to_block_map;
307 enum profile_status_d x_profile_status;
309 /* Whether the dominators and the postdominators are available. */
310 enum dom_state x_dom_computed[2];
312 /* Number of basic blocks in the dominance tree. */
313 unsigned x_n_bbs_in_dom_tree[2];
315 /* Maximal number of entities in the single jumptable. Used to estimate
316 final flowgraph size. */
317 int max_jumptable_ents;
320 /* Defines for accessing the fields of the CFG structure for function FN. */
321 #define ENTRY_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_entry_block_ptr)
322 #define EXIT_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_exit_block_ptr)
323 #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
324 #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
325 #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
326 #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
327 #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
328 #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
330 #define BASIC_BLOCK_FOR_FN(FN,N) \
331 ((*basic_block_info_for_fn (FN))[(N)])
332 #define SET_BASIC_BLOCK_FOR_FN(FN,N,BB) \
333 ((*basic_block_info_for_fn (FN))[(N)] = (BB))
335 /* For iterating over basic blocks. */
336 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
337 for (BB = FROM; BB != TO; BB = BB->DIR)
339 #define FOR_EACH_BB_FN(BB, FN) \
340 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
342 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
343 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
345 /* For iterating over insns in basic block. */
346 #define FOR_BB_INSNS(BB, INSN) \
347 for ((INSN) = BB_HEAD (BB); \
348 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
349 (INSN) = NEXT_INSN (INSN))
351 /* For iterating over insns in basic block when we might remove the
352 current insn. */
353 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
354 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
355 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
356 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
358 #define FOR_BB_INSNS_REVERSE(BB, INSN) \
359 for ((INSN) = BB_END (BB); \
360 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
361 (INSN) = PREV_INSN (INSN))
363 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
364 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
365 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
366 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
368 /* Cycles through _all_ basic blocks, even the fake ones (entry and
369 exit block). */
371 #define FOR_ALL_BB_FN(BB, FN) \
372 for (BB = ENTRY_BLOCK_PTR_FOR_FN (FN); BB; BB = BB->next_bb)
375 /* Stuff for recording basic block info. */
377 /* For now, these will be functions (so that they can include checked casts
378 to rtx_insn. Once the underlying fields are converted from rtx
379 to rtx_insn, these can be converted back to macros. */
381 #define BB_HEAD(B) (B)->il.x.head_
382 #define BB_END(B) (B)->il.x.rtl->end_
383 #define BB_HEADER(B) (B)->il.x.rtl->header_
384 #define BB_FOOTER(B) (B)->il.x.rtl->footer_
386 /* Special block numbers [markers] for entry and exit.
387 Neither of them is supposed to hold actual statements. */
388 #define ENTRY_BLOCK (0)
389 #define EXIT_BLOCK (1)
391 /* The two blocks that are always in the cfg. */
392 #define NUM_FIXED_BLOCKS (2)
394 extern void compute_bb_for_insn (void);
395 extern unsigned int free_bb_for_insn (void);
396 extern void update_bb_for_insn (basic_block);
398 extern void insert_insn_on_edge (rtx, edge);
399 basic_block split_edge_and_insert (edge, rtx_insn *);
401 extern void commit_one_edge_insertion (edge e);
402 extern void commit_edge_insertions (void);
404 extern edge unchecked_make_edge (basic_block, basic_block, int);
405 extern edge cached_make_edge (sbitmap, basic_block, basic_block, int);
406 extern edge make_edge (basic_block, basic_block, int);
407 extern edge make_single_succ_edge (basic_block, basic_block, int);
408 extern void remove_edge_raw (edge);
409 extern void redirect_edge_succ (edge, basic_block);
410 extern edge redirect_edge_succ_nodup (edge, basic_block);
411 extern void redirect_edge_pred (edge, basic_block);
412 extern basic_block create_basic_block_structure (rtx_insn *, rtx_insn *,
413 rtx_note *, basic_block);
414 extern void clear_bb_flags (void);
415 extern void dump_bb_info (FILE *, basic_block, int, int, bool, bool);
416 extern void dump_edge_info (FILE *, edge, int, int);
417 extern void debug (edge_def &ref);
418 extern void debug (edge_def *ptr);
419 extern void brief_dump_cfg (FILE *, int);
420 extern void clear_edges (void);
421 extern void scale_bbs_frequencies_int (basic_block *, int, int, int);
422 extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,
423 gcov_type);
425 /* Structure to group all of the information to process IF-THEN and
426 IF-THEN-ELSE blocks for the conditional execution support. This
427 needs to be in a public file in case the IFCVT macros call
428 functions passing the ce_if_block data structure. */
430 struct ce_if_block
432 basic_block test_bb; /* First test block. */
433 basic_block then_bb; /* THEN block. */
434 basic_block else_bb; /* ELSE block or NULL. */
435 basic_block join_bb; /* Join THEN/ELSE blocks. */
436 basic_block last_test_bb; /* Last bb to hold && or || tests. */
437 int num_multiple_test_blocks; /* # of && and || basic blocks. */
438 int num_and_and_blocks; /* # of && blocks. */
439 int num_or_or_blocks; /* # of || blocks. */
440 int num_multiple_test_insns; /* # of insns in && and || blocks. */
441 int and_and_p; /* Complex test is &&. */
442 int num_then_insns; /* # of insns in THEN block. */
443 int num_else_insns; /* # of insns in ELSE block. */
444 int pass; /* Pass number. */
447 /* This structure maintains an edge list vector. */
448 /* FIXME: Make this a vec<edge>. */
449 struct edge_list
451 int num_edges;
452 edge *index_to_edge;
455 /* Class to compute and manage control dependences on an edge-list. */
456 class control_dependences
458 public:
459 control_dependences (edge_list *);
460 ~control_dependences ();
461 bitmap get_edges_dependent_on (int);
462 edge get_edge (int);
464 private:
465 void set_control_dependence_map_bit (basic_block, int);
466 void clear_control_dependence_bitmap (basic_block);
467 void find_control_dependence (int);
468 vec<bitmap> control_dependence_map;
469 edge_list *m_el;
472 /* The base value for branch probability notes and edge probabilities. */
473 #define REG_BR_PROB_BASE 10000
475 /* This is the value which indicates no edge is present. */
476 #define EDGE_INDEX_NO_EDGE -1
478 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
479 if there is no edge between the 2 basic blocks. */
480 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
482 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
483 block which is either the pred or succ end of the indexed edge. */
484 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
485 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
487 /* INDEX_EDGE returns a pointer to the edge. */
488 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
490 /* Number of edges in the compressed edge list. */
491 #define NUM_EDGES(el) ((el)->num_edges)
493 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
494 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
495 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
497 /* BB is assumed to contain conditional jump. Return the branch edge. */
498 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
499 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
501 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
502 /* Return expected execution frequency of the edge E. */
503 #define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \
504 REG_BR_PROB_BASE)
506 /* Compute a scale factor (or probability) suitable for scaling of
507 gcov_type values via apply_probability() and apply_scale(). */
508 #define GCOV_COMPUTE_SCALE(num,den) \
509 ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
511 /* Return nonzero if edge is critical. */
512 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
513 && EDGE_COUNT ((e)->dest->preds) >= 2)
515 #define EDGE_COUNT(ev) vec_safe_length (ev)
516 #define EDGE_I(ev,i) (*ev)[(i)]
517 #define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
518 #define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
520 /* Returns true if BB has precisely one successor. */
522 static inline bool
523 single_succ_p (const_basic_block bb)
525 return EDGE_COUNT (bb->succs) == 1;
528 /* Returns true if BB has precisely one predecessor. */
530 static inline bool
531 single_pred_p (const_basic_block bb)
533 return EDGE_COUNT (bb->preds) == 1;
536 /* Returns the single successor edge of basic block BB. Aborts if
537 BB does not have exactly one successor. */
539 static inline edge
540 single_succ_edge (const_basic_block bb)
542 gcc_checking_assert (single_succ_p (bb));
543 return EDGE_SUCC (bb, 0);
546 /* Returns the single predecessor edge of basic block BB. Aborts
547 if BB does not have exactly one predecessor. */
549 static inline edge
550 single_pred_edge (const_basic_block bb)
552 gcc_checking_assert (single_pred_p (bb));
553 return EDGE_PRED (bb, 0);
556 /* Returns the single successor block of basic block BB. Aborts
557 if BB does not have exactly one successor. */
559 static inline basic_block
560 single_succ (const_basic_block bb)
562 return single_succ_edge (bb)->dest;
565 /* Returns the single predecessor block of basic block BB. Aborts
566 if BB does not have exactly one predecessor.*/
568 static inline basic_block
569 single_pred (const_basic_block bb)
571 return single_pred_edge (bb)->src;
574 /* Iterator object for edges. */
576 struct edge_iterator {
577 unsigned index;
578 vec<edge, va_gc> **container;
581 static inline vec<edge, va_gc> *
582 ei_container (edge_iterator i)
584 gcc_checking_assert (i.container);
585 return *i.container;
588 #define ei_start(iter) ei_start_1 (&(iter))
589 #define ei_last(iter) ei_last_1 (&(iter))
591 /* Return an iterator pointing to the start of an edge vector. */
592 static inline edge_iterator
593 ei_start_1 (vec<edge, va_gc> **ev)
595 edge_iterator i;
597 i.index = 0;
598 i.container = ev;
600 return i;
603 /* Return an iterator pointing to the last element of an edge
604 vector. */
605 static inline edge_iterator
606 ei_last_1 (vec<edge, va_gc> **ev)
608 edge_iterator i;
610 i.index = EDGE_COUNT (*ev) - 1;
611 i.container = ev;
613 return i;
616 /* Is the iterator `i' at the end of the sequence? */
617 static inline bool
618 ei_end_p (edge_iterator i)
620 return (i.index == EDGE_COUNT (ei_container (i)));
623 /* Is the iterator `i' at one position before the end of the
624 sequence? */
625 static inline bool
626 ei_one_before_end_p (edge_iterator i)
628 return (i.index + 1 == EDGE_COUNT (ei_container (i)));
631 /* Advance the iterator to the next element. */
632 static inline void
633 ei_next (edge_iterator *i)
635 gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
636 i->index++;
639 /* Move the iterator to the previous element. */
640 static inline void
641 ei_prev (edge_iterator *i)
643 gcc_checking_assert (i->index > 0);
644 i->index--;
647 /* Return the edge pointed to by the iterator `i'. */
648 static inline edge
649 ei_edge (edge_iterator i)
651 return EDGE_I (ei_container (i), i.index);
654 /* Return an edge pointed to by the iterator. Do it safely so that
655 NULL is returned when the iterator is pointing at the end of the
656 sequence. */
657 static inline edge
658 ei_safe_edge (edge_iterator i)
660 return !ei_end_p (i) ? ei_edge (i) : NULL;
663 /* Return 1 if we should continue to iterate. Return 0 otherwise.
664 *Edge P is set to the next edge if we are to continue to iterate
665 and NULL otherwise. */
667 static inline bool
668 ei_cond (edge_iterator ei, edge *p)
670 if (!ei_end_p (ei))
672 *p = ei_edge (ei);
673 return 1;
675 else
677 *p = NULL;
678 return 0;
682 /* This macro serves as a convenient way to iterate each edge in a
683 vector of predecessor or successor edges. It must not be used when
684 an element might be removed during the traversal, otherwise
685 elements will be missed. Instead, use a for-loop like that shown
686 in the following pseudo-code:
688 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
690 IF (e != taken_edge)
691 remove_edge (e);
692 ELSE
693 ei_next (&ei);
697 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
698 for ((ITER) = ei_start ((EDGE_VEC)); \
699 ei_cond ((ITER), &(EDGE)); \
700 ei_next (&(ITER)))
702 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
703 except for edge forwarding */
704 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
705 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
706 to care REG_DEAD notes. */
707 #define CLEANUP_THREADING 8 /* Do jump threading. */
708 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
709 insns. */
710 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
711 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
713 /* In cfganal.c */
714 extern void bitmap_intersection_of_succs (sbitmap, sbitmap *, basic_block);
715 extern void bitmap_intersection_of_preds (sbitmap, sbitmap *, basic_block);
716 extern void bitmap_union_of_succs (sbitmap, sbitmap *, basic_block);
717 extern void bitmap_union_of_preds (sbitmap, sbitmap *, basic_block);
719 /* In lcm.c */
720 extern struct edge_list *pre_edge_lcm (int, sbitmap *, sbitmap *,
721 sbitmap *, sbitmap *, sbitmap **,
722 sbitmap **);
723 extern struct edge_list *pre_edge_lcm_avs (int, sbitmap *, sbitmap *,
724 sbitmap *, sbitmap *, sbitmap *,
725 sbitmap *, sbitmap **, sbitmap **);
726 extern struct edge_list *pre_edge_rev_lcm (int, sbitmap *,
727 sbitmap *, sbitmap *,
728 sbitmap *, sbitmap **,
729 sbitmap **);
730 extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
732 /* In predict.c */
733 extern bool maybe_hot_bb_p (struct function *, const_basic_block);
734 extern bool maybe_hot_edge_p (edge);
735 extern bool probably_never_executed_bb_p (struct function *, const_basic_block);
736 extern bool probably_never_executed_edge_p (struct function *, edge);
737 extern bool optimize_bb_for_size_p (const_basic_block);
738 extern bool optimize_bb_for_speed_p (const_basic_block);
739 extern bool optimize_edge_for_size_p (edge);
740 extern bool optimize_edge_for_speed_p (edge);
741 extern bool optimize_loop_for_size_p (struct loop *);
742 extern bool optimize_loop_for_speed_p (struct loop *);
743 extern bool optimize_loop_nest_for_size_p (struct loop *);
744 extern bool optimize_loop_nest_for_speed_p (struct loop *);
745 extern bool gimple_predicted_by_p (const_basic_block, enum br_predictor);
746 extern bool rtl_predicted_by_p (const_basic_block, enum br_predictor);
747 extern void gimple_predict_edge (edge, enum br_predictor, int);
748 extern void rtl_predict_edge (edge, enum br_predictor, int);
749 extern void predict_edge_def (edge, enum br_predictor, enum prediction);
750 extern void guess_outgoing_edge_probabilities (basic_block);
751 extern void remove_predictions_associated_with_edge (edge);
752 extern bool edge_probability_reliable_p (const_edge);
753 extern bool br_prob_note_reliable_p (const_rtx);
754 extern bool predictable_edge_p (edge);
756 /* In cfg.c */
757 extern void init_flow (struct function *);
758 extern void debug_bb (basic_block);
759 extern basic_block debug_bb_n (int);
760 extern void dump_flow_info (FILE *, int);
761 extern void expunge_block (basic_block);
762 extern void link_block (basic_block, basic_block);
763 extern void unlink_block (basic_block);
764 extern void compact_blocks (void);
765 extern basic_block alloc_block (void);
766 extern void alloc_aux_for_blocks (int);
767 extern void clear_aux_for_blocks (void);
768 extern void free_aux_for_blocks (void);
769 extern void alloc_aux_for_edge (edge, int);
770 extern void alloc_aux_for_edges (int);
771 extern void clear_aux_for_edges (void);
772 extern void free_aux_for_edges (void);
774 /* In cfganal.c */
775 extern void find_unreachable_blocks (void);
776 extern bool mark_dfs_back_edges (void);
777 struct edge_list * create_edge_list (void);
778 void free_edge_list (struct edge_list *);
779 void print_edge_list (FILE *, struct edge_list *);
780 void verify_edge_list (FILE *, struct edge_list *);
781 int find_edge_index (struct edge_list *, basic_block, basic_block);
782 edge find_edge (basic_block, basic_block);
783 extern void remove_fake_edges (void);
784 extern void remove_fake_exit_edges (void);
785 extern void add_noreturn_fake_exit_edges (void);
786 extern void connect_infinite_loops_to_exit (void);
787 extern int post_order_compute (int *, bool, bool);
788 extern basic_block dfs_find_deadend (basic_block);
789 extern int inverted_post_order_compute (int *);
790 extern int pre_and_rev_post_order_compute_fn (struct function *,
791 int *, int *, bool);
792 extern int pre_and_rev_post_order_compute (int *, int *, bool);
793 extern int dfs_enumerate_from (basic_block, int,
794 bool (*)(const_basic_block, const void *),
795 basic_block *, int, const void *);
796 extern void compute_dominance_frontiers (struct bitmap_head *);
797 extern bitmap compute_idf (bitmap, struct bitmap_head *);
798 extern basic_block * single_pred_before_succ_order (void);
800 /* In cfgrtl.c */
801 extern rtx block_label (basic_block);
802 extern rtx_note *bb_note (basic_block);
803 extern bool purge_all_dead_edges (void);
804 extern bool purge_dead_edges (basic_block);
805 extern bool fixup_abnormal_edges (void);
806 extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx);
807 extern bool contains_no_active_insn_p (const_basic_block);
808 extern bool forwarder_block_p (const_basic_block);
809 extern bool can_fallthru (basic_block, basic_block);
810 extern void emit_barrier_after_bb (basic_block bb);
811 extern void fixup_partitions (void);
813 /* In cfgbuild.c. */
814 extern void find_many_sub_basic_blocks (sbitmap);
815 extern void rtl_make_eh_edge (sbitmap, basic_block, rtx);
817 enum replace_direction { dir_none, dir_forward, dir_backward, dir_both };
819 /* In cfgcleanup.c. */
820 extern bool cleanup_cfg (int);
821 extern int flow_find_cross_jump (basic_block, basic_block, rtx_insn **,
822 rtx_insn **, enum replace_direction*);
823 extern int flow_find_head_matching_sequence (basic_block, basic_block,
824 rtx_insn **, rtx_insn **, int);
826 extern bool delete_unreachable_blocks (void);
828 extern void update_br_prob_note (basic_block);
829 extern bool inside_basic_block_p (const rtx_insn *);
830 extern bool control_flow_insn_p (const rtx_insn *);
831 extern rtx_insn *get_last_bb_insn (basic_block);
833 /* In dominance.c */
835 enum cdi_direction
837 CDI_DOMINATORS = 1,
838 CDI_POST_DOMINATORS = 2
841 extern enum dom_state dom_info_state (function *, enum cdi_direction);
842 extern enum dom_state dom_info_state (enum cdi_direction);
843 extern void set_dom_info_availability (enum cdi_direction, enum dom_state);
844 extern bool dom_info_available_p (function *, enum cdi_direction);
845 extern bool dom_info_available_p (enum cdi_direction);
846 extern void calculate_dominance_info (enum cdi_direction);
847 extern void free_dominance_info (function *, enum cdi_direction);
848 extern void free_dominance_info (enum cdi_direction);
849 extern basic_block nearest_common_dominator (enum cdi_direction,
850 basic_block, basic_block);
851 extern basic_block nearest_common_dominator_for_set (enum cdi_direction,
852 bitmap);
853 extern void set_immediate_dominator (enum cdi_direction, basic_block,
854 basic_block);
855 extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
856 extern bool dominated_by_p (enum cdi_direction, const_basic_block, const_basic_block);
857 extern vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);
858 extern vec<basic_block> get_dominated_by_region (enum cdi_direction,
859 basic_block *,
860 unsigned);
861 extern vec<basic_block> get_dominated_to_depth (enum cdi_direction,
862 basic_block, int);
863 extern vec<basic_block> get_all_dominated_blocks (enum cdi_direction,
864 basic_block);
865 extern void add_to_dominance_info (enum cdi_direction, basic_block);
866 extern void delete_from_dominance_info (enum cdi_direction, basic_block);
867 basic_block recompute_dominator (enum cdi_direction, basic_block);
868 extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
869 basic_block);
870 extern void iterate_fix_dominators (enum cdi_direction,
871 vec<basic_block> , bool);
872 extern void verify_dominators (enum cdi_direction);
873 extern basic_block first_dom_son (enum cdi_direction, basic_block);
874 extern basic_block next_dom_son (enum cdi_direction, basic_block);
875 unsigned bb_dom_dfs_in (enum cdi_direction, basic_block);
876 unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
878 extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
879 extern void break_superblocks (void);
880 extern void relink_block_chain (bool);
881 extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
882 extern void init_rtl_bb_info (basic_block);
884 extern void initialize_original_copy_tables (void);
885 extern void free_original_copy_tables (void);
886 extern void set_bb_original (basic_block, basic_block);
887 extern basic_block get_bb_original (basic_block);
888 extern void set_bb_copy (basic_block, basic_block);
889 extern basic_block get_bb_copy (basic_block);
890 void set_loop_copy (struct loop *, struct loop *);
891 struct loop *get_loop_copy (struct loop *);
893 #include "cfghooks.h"
895 /* Return true if BB is in a transaction. */
897 static inline bool
898 bb_in_transaction (basic_block bb)
900 return bb->flags & BB_IN_TRANSACTION;
903 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
904 static inline bool
905 bb_has_eh_pred (basic_block bb)
907 edge e;
908 edge_iterator ei;
910 FOR_EACH_EDGE (e, ei, bb->preds)
912 if (e->flags & EDGE_EH)
913 return true;
915 return false;
918 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
919 static inline bool
920 bb_has_abnormal_pred (basic_block bb)
922 edge e;
923 edge_iterator ei;
925 FOR_EACH_EDGE (e, ei, bb->preds)
927 if (e->flags & EDGE_ABNORMAL)
928 return true;
930 return false;
933 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
934 static inline edge
935 find_fallthru_edge (vec<edge, va_gc> *edges)
937 edge e;
938 edge_iterator ei;
940 FOR_EACH_EDGE (e, ei, edges)
941 if (e->flags & EDGE_FALLTHRU)
942 break;
944 return e;
947 /* In cfgloopmanip.c. */
948 extern edge mfb_kj_edge;
949 extern bool mfb_keep_just (edge);
951 /* In cfgexpand.c. */
952 extern void rtl_profile_for_bb (basic_block);
953 extern void rtl_profile_for_edge (edge);
954 extern void default_rtl_profile (void);
956 /* In profile.c. */
957 typedef struct gcov_working_set_info gcov_working_set_t;
958 extern gcov_working_set_t *find_working_set (unsigned pct_times_10);
960 /* Check tha probability is sane. */
962 static inline void
963 check_probability (int prob)
965 gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
968 /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
969 Used to combine BB probabilities. */
971 static inline int
972 combine_probabilities (int prob1, int prob2)
974 check_probability (prob1);
975 check_probability (prob2);
976 return RDIV (prob1 * prob2, REG_BR_PROB_BASE);
979 /* Apply scale factor SCALE on frequency or count FREQ. Use this
980 interface when potentially scaling up, so that SCALE is not
981 constrained to be < REG_BR_PROB_BASE. */
983 static inline gcov_type
984 apply_scale (gcov_type freq, gcov_type scale)
986 return RDIV (freq * scale, REG_BR_PROB_BASE);
989 /* Apply probability PROB on frequency or count FREQ. */
991 static inline gcov_type
992 apply_probability (gcov_type freq, int prob)
994 check_probability (prob);
995 return apply_scale (freq, prob);
998 /* Return inverse probability for PROB. */
1000 static inline int
1001 inverse_probability (int prob1)
1003 check_probability (prob1);
1004 return REG_BR_PROB_BASE - prob1;
1007 /* Return true if BB has at least one abnormal outgoing edge. */
1009 static inline bool
1010 has_abnormal_or_eh_outgoing_edge_p (basic_block bb)
1012 edge e;
1013 edge_iterator ei;
1015 FOR_EACH_EDGE (e, ei, bb->succs)
1016 if (e->flags & (EDGE_ABNORMAL | EDGE_EH))
1017 return true;
1019 return false;
1021 #endif /* GCC_BASIC_BLOCK_H */