c-family/
[official-gcc.git] / gcc / basic-block.h
blobd9bd3b7e550d7f0c5254ce030a9ded75ab7fc63e
1 /* Define control flow data structures for the CFG.
2 Copyright (C) 1987, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_BASIC_BLOCK_H
22 #define GCC_BASIC_BLOCK_H
24 #include "predict.h"
25 #include "vec.h"
26 #include "function.h"
28 /* Type we use to hold basic block counters. Should be at least
29 64bit. Although a counter cannot be negative, we use a signed
30 type, because erroneous negative counts can be generated when the
31 flow graph is manipulated by various optimizations. A signed type
32 makes those easy to detect. */
33 typedef HOST_WIDEST_INT gcov_type;
34 typedef unsigned HOST_WIDEST_INT gcov_type_unsigned;
36 /* Control flow edge information. */
37 struct GTY((user)) edge_def {
38 /* The two blocks at the ends of the edge. */
39 basic_block src;
40 basic_block dest;
42 /* Instructions queued on the edge. */
43 union edge_def_insns {
44 gimple_seq g;
45 rtx r;
46 } insns;
48 /* Auxiliary info specific to a pass. */
49 PTR aux;
51 /* Location of any goto implicit in the edge. */
52 location_t goto_locus;
54 /* The index number corresponding to this edge in the edge vector
55 dest->preds. */
56 unsigned int dest_idx;
58 int flags; /* see cfg-flags.def */
59 int probability; /* biased by REG_BR_PROB_BASE */
60 gcov_type count; /* Expected number of executions calculated
61 in profile.c */
64 DEF_VEC_P(edge);
65 DEF_VEC_ALLOC_P(edge,gc);
66 DEF_VEC_ALLOC_P(edge,heap);
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 /* Working set size statistics for a given percentage of the entire
95 profile (sum_all from the counter summary). */
96 typedef struct gcov_working_set_info
98 /* Number of hot counters included in this working set. */
99 unsigned num_counters;
100 /* Smallest counter included in this working set. */
101 gcov_type min_counter;
102 } gcov_working_set_t;
104 /* Structure to gather statistic about profile consistency, per pass.
105 An array of this structure, indexed by pass static number, is allocated
106 in passes.c. The structure is defined here so that different CFG modes
107 can do their book-keeping via CFG hooks.
109 For every field[2], field[0] is the count before the pass runs, and
110 field[1] is the post-pass count. This allows us to monitor the effect
111 of each individual pass on the profile consistency.
113 This structure is not supposed to be used by anything other than passes.c
114 and one CFG hook per CFG mode. */
115 struct profile_record
117 /* The number of basic blocks where sum(freq) of the block's predecessors
118 doesn't match reasonably well with the incoming frequency. */
119 int num_mismatched_freq_in[2];
120 /* Likewise for a basic block's successors. */
121 int num_mismatched_freq_out[2];
122 /* The number of basic blocks where sum(count) of the block's predecessors
123 doesn't match reasonably well with the incoming frequency. */
124 int num_mismatched_count_in[2];
125 /* Likewise for a basic block's successors. */
126 int num_mismatched_count_out[2];
127 /* A weighted cost of the run-time of the function body. */
128 gcov_type time[2];
129 /* A weighted cost of the size of the function body. */
130 int size[2];
131 /* True iff this pass actually was run. */
132 bool run;
135 /* Declared in cfgloop.h. */
136 struct loop;
138 struct GTY(()) rtl_bb_info {
139 /* The first insn of the block is embedded into bb->il.x. */
140 /* The last insn of the block. */
141 rtx end_;
143 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
144 and after the block. */
145 rtx header_;
146 rtx footer_;
149 struct GTY(()) gimple_bb_info {
150 /* Sequence of statements in this block. */
151 gimple_seq seq;
153 /* PHI nodes for this block. */
154 gimple_seq phi_nodes;
157 /* A basic block is a sequence of instructions with only one entry and
158 only one exit. If any one of the instructions are executed, they
159 will all be executed, and in sequence from first to last.
161 There may be COND_EXEC instructions in the basic block. The
162 COND_EXEC *instructions* will be executed -- but if the condition
163 is false the conditionally executed *expressions* will of course
164 not be executed. We don't consider the conditionally executed
165 expression (which might have side-effects) to be in a separate
166 basic block because the program counter will always be at the same
167 location after the COND_EXEC instruction, regardless of whether the
168 condition is true or not.
170 Basic blocks need not start with a label nor end with a jump insn.
171 For example, a previous basic block may just "conditionally fall"
172 into the succeeding basic block, and the last basic block need not
173 end with a jump insn. Block 0 is a descendant of the entry block.
175 A basic block beginning with two labels cannot have notes between
176 the labels.
178 Data for jump tables are stored in jump_insns that occur in no
179 basic block even though these insns can follow or precede insns in
180 basic blocks. */
182 /* Basic block information indexed by block number. */
183 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
184 /* The edges into and out of the block. */
185 VEC(edge,gc) *preds;
186 VEC(edge,gc) *succs;
188 /* Auxiliary info specific to a pass. */
189 PTR GTY ((skip (""))) aux;
191 /* Innermost loop containing the block. */
192 struct loop *loop_father;
194 /* The dominance and postdominance information node. */
195 struct et_node * GTY ((skip (""))) dom[2];
197 /* Previous and next blocks in the chain. */
198 basic_block prev_bb;
199 basic_block next_bb;
201 union basic_block_il_dependent {
202 struct gimple_bb_info GTY ((tag ("0"))) gimple;
203 struct {
204 rtx head_;
205 struct rtl_bb_info * rtl;
206 } GTY ((tag ("1"))) x;
207 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
209 /* Various flags. See cfg-flags.def. */
210 int flags;
212 /* The index of this block. */
213 int index;
215 /* Expected number of executions: calculated in profile.c. */
216 gcov_type count;
218 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
219 int frequency;
221 /* The discriminator for this block. The discriminator distinguishes
222 among several basic blocks that share a common locus, allowing for
223 more accurate sample-based profiling. */
224 int discriminator;
227 /* This ensures that struct gimple_bb_info is smaller than
228 struct rtl_bb_info, so that inlining the former into basic_block_def
229 is the better choice. */
230 typedef int __assert_gimple_bb_smaller_rtl_bb
231 [(int)sizeof(struct rtl_bb_info)
232 - (int)sizeof (struct gimple_bb_info)];
234 DEF_VEC_P(basic_block);
235 DEF_VEC_ALLOC_P(basic_block,gc);
236 DEF_VEC_ALLOC_P(basic_block,heap);
238 #define BB_FREQ_MAX 10000
240 /* Masks for basic_block.flags. */
241 #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
242 enum cfg_bb_flags
244 #include "cfg-flags.def"
245 LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
247 #undef DEF_BASIC_BLOCK_FLAG
249 /* Bit mask for all basic block flags. */
250 #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
252 /* Bit mask for all basic block flags that must be preserved. These are
253 the bit masks that are *not* cleared by clear_bb_flags. */
254 #define BB_FLAGS_TO_PRESERVE \
255 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
256 | BB_HOT_PARTITION | BB_COLD_PARTITION)
258 /* Dummy bitmask for convenience in the hot/cold partitioning code. */
259 #define BB_UNPARTITIONED 0
261 /* Partitions, to be used when partitioning hot and cold basic blocks into
262 separate sections. */
263 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
264 #define BB_SET_PARTITION(bb, part) do { \
265 basic_block bb_ = (bb); \
266 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
267 | (part)); \
268 } while (0)
270 #define BB_COPY_PARTITION(dstbb, srcbb) \
271 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
273 /* State of dominance information. */
275 enum dom_state
277 DOM_NONE, /* Not computed at all. */
278 DOM_NO_FAST_QUERY, /* The data is OK, but the fast query data are not usable. */
279 DOM_OK /* Everything is ok. */
282 /* What sort of profiling information we have. */
283 enum profile_status_d
285 PROFILE_ABSENT,
286 PROFILE_GUESSED,
287 PROFILE_READ,
288 PROFILE_LAST /* Last value, used by profile streaming. */
291 /* A structure to group all the per-function control flow graph data.
292 The x_* prefixing is necessary because otherwise references to the
293 fields of this struct are interpreted as the defines for backward
294 source compatibility following the definition of this struct. */
295 struct GTY(()) control_flow_graph {
296 /* Block pointers for the exit and entry of a function.
297 These are always the head and tail of the basic block list. */
298 basic_block x_entry_block_ptr;
299 basic_block x_exit_block_ptr;
301 /* Index by basic block number, get basic block struct info. */
302 VEC(basic_block,gc) *x_basic_block_info;
304 /* Number of basic blocks in this flow graph. */
305 int x_n_basic_blocks;
307 /* Number of edges in this flow graph. */
308 int x_n_edges;
310 /* The first free basic block number. */
311 int x_last_basic_block;
313 /* UIDs for LABEL_DECLs. */
314 int last_label_uid;
316 /* Mapping of labels to their associated blocks. At present
317 only used for the gimple CFG. */
318 VEC(basic_block,gc) *x_label_to_block_map;
320 enum profile_status_d x_profile_status;
322 /* Whether the dominators and the postdominators are available. */
323 enum dom_state x_dom_computed[2];
325 /* Number of basic blocks in the dominance tree. */
326 unsigned x_n_bbs_in_dom_tree[2];
328 /* Maximal number of entities in the single jumptable. Used to estimate
329 final flowgraph size. */
330 int max_jumptable_ents;
333 /* Defines for accessing the fields of the CFG structure for function FN. */
334 #define ENTRY_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_entry_block_ptr)
335 #define EXIT_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_exit_block_ptr)
336 #define basic_block_info_for_function(FN) ((FN)->cfg->x_basic_block_info)
337 #define n_basic_blocks_for_function(FN) ((FN)->cfg->x_n_basic_blocks)
338 #define n_edges_for_function(FN) ((FN)->cfg->x_n_edges)
339 #define last_basic_block_for_function(FN) ((FN)->cfg->x_last_basic_block)
340 #define label_to_block_map_for_function(FN) ((FN)->cfg->x_label_to_block_map)
341 #define profile_status_for_function(FN) ((FN)->cfg->x_profile_status)
343 #define BASIC_BLOCK_FOR_FUNCTION(FN,N) \
344 (VEC_index (basic_block, basic_block_info_for_function(FN), (N)))
345 #define SET_BASIC_BLOCK_FOR_FUNCTION(FN,N,BB) \
346 (VEC_replace (basic_block, basic_block_info_for_function(FN), (N), (BB)))
348 /* Defines for textual backward source compatibility. */
349 #define ENTRY_BLOCK_PTR (cfun->cfg->x_entry_block_ptr)
350 #define EXIT_BLOCK_PTR (cfun->cfg->x_exit_block_ptr)
351 #define basic_block_info (cfun->cfg->x_basic_block_info)
352 #define n_basic_blocks (cfun->cfg->x_n_basic_blocks)
353 #define n_edges (cfun->cfg->x_n_edges)
354 #define last_basic_block (cfun->cfg->x_last_basic_block)
355 #define label_to_block_map (cfun->cfg->x_label_to_block_map)
356 #define profile_status (cfun->cfg->x_profile_status)
358 #define BASIC_BLOCK(N) (VEC_index (basic_block, basic_block_info, (N)))
359 #define SET_BASIC_BLOCK(N,BB) (VEC_replace (basic_block, basic_block_info, (N), (BB)))
361 /* For iterating over basic blocks. */
362 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
363 for (BB = FROM; BB != TO; BB = BB->DIR)
365 #define FOR_EACH_BB_FN(BB, FN) \
366 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
368 #define FOR_EACH_BB(BB) FOR_EACH_BB_FN (BB, cfun)
370 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
371 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
373 #define FOR_EACH_BB_REVERSE(BB) FOR_EACH_BB_REVERSE_FN(BB, cfun)
375 /* For iterating over insns in basic block. */
376 #define FOR_BB_INSNS(BB, INSN) \
377 for ((INSN) = BB_HEAD (BB); \
378 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
379 (INSN) = NEXT_INSN (INSN))
381 /* For iterating over insns in basic block when we might remove the
382 current insn. */
383 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
384 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
385 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
386 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
388 #define FOR_BB_INSNS_REVERSE(BB, INSN) \
389 for ((INSN) = BB_END (BB); \
390 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
391 (INSN) = PREV_INSN (INSN))
393 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
394 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
395 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
396 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
398 /* Cycles through _all_ basic blocks, even the fake ones (entry and
399 exit block). */
401 #define FOR_ALL_BB(BB) \
402 for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
404 #define FOR_ALL_BB_FN(BB, FN) \
405 for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
408 /* Stuff for recording basic block info. */
410 #define BB_HEAD(B) (B)->il.x.head_
411 #define BB_END(B) (B)->il.x.rtl->end_
412 #define BB_HEADER(B) (B)->il.x.rtl->header_
413 #define BB_FOOTER(B) (B)->il.x.rtl->footer_
415 /* Special block numbers [markers] for entry and exit.
416 Neither of them is supposed to hold actual statements. */
417 #define ENTRY_BLOCK (0)
418 #define EXIT_BLOCK (1)
420 /* The two blocks that are always in the cfg. */
421 #define NUM_FIXED_BLOCKS (2)
423 #define set_block_for_insn(INSN, BB) (BLOCK_FOR_INSN (INSN) = BB)
425 extern void compute_bb_for_insn (void);
426 extern unsigned int free_bb_for_insn (void);
427 extern void update_bb_for_insn (basic_block);
429 extern void insert_insn_on_edge (rtx, edge);
430 basic_block split_edge_and_insert (edge, rtx);
432 extern void commit_one_edge_insertion (edge e);
433 extern void commit_edge_insertions (void);
435 extern edge unchecked_make_edge (basic_block, basic_block, int);
436 extern edge cached_make_edge (sbitmap, basic_block, basic_block, int);
437 extern edge make_edge (basic_block, basic_block, int);
438 extern edge make_single_succ_edge (basic_block, basic_block, int);
439 extern void remove_edge_raw (edge);
440 extern void redirect_edge_succ (edge, basic_block);
441 extern edge redirect_edge_succ_nodup (edge, basic_block);
442 extern void redirect_edge_pred (edge, basic_block);
443 extern basic_block create_basic_block_structure (rtx, rtx, rtx, basic_block);
444 extern void clear_bb_flags (void);
445 extern void dump_bb_info (FILE *, basic_block, int, int, bool, bool);
446 extern void dump_edge_info (FILE *, edge, int, int);
447 extern void brief_dump_cfg (FILE *, int);
448 extern void clear_edges (void);
449 extern void scale_bbs_frequencies_int (basic_block *, int, int, int);
450 extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,
451 gcov_type);
453 /* Structure to group all of the information to process IF-THEN and
454 IF-THEN-ELSE blocks for the conditional execution support. This
455 needs to be in a public file in case the IFCVT macros call
456 functions passing the ce_if_block data structure. */
458 typedef struct ce_if_block
460 basic_block test_bb; /* First test block. */
461 basic_block then_bb; /* THEN block. */
462 basic_block else_bb; /* ELSE block or NULL. */
463 basic_block join_bb; /* Join THEN/ELSE blocks. */
464 basic_block last_test_bb; /* Last bb to hold && or || tests. */
465 int num_multiple_test_blocks; /* # of && and || basic blocks. */
466 int num_and_and_blocks; /* # of && blocks. */
467 int num_or_or_blocks; /* # of || blocks. */
468 int num_multiple_test_insns; /* # of insns in && and || blocks. */
469 int and_and_p; /* Complex test is &&. */
470 int num_then_insns; /* # of insns in THEN block. */
471 int num_else_insns; /* # of insns in ELSE block. */
472 int pass; /* Pass number. */
473 } ce_if_block_t;
475 /* This structure maintains an edge list vector. */
476 /* FIXME: Make this a VEC(edge). */
477 struct edge_list
479 int num_edges;
480 edge *index_to_edge;
483 /* The base value for branch probability notes and edge probabilities. */
484 #define REG_BR_PROB_BASE 10000
486 /* This is the value which indicates no edge is present. */
487 #define EDGE_INDEX_NO_EDGE -1
489 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
490 if there is no edge between the 2 basic blocks. */
491 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
493 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
494 block which is either the pred or succ end of the indexed edge. */
495 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
496 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
498 /* INDEX_EDGE returns a pointer to the edge. */
499 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
501 /* Number of edges in the compressed edge list. */
502 #define NUM_EDGES(el) ((el)->num_edges)
504 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
505 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
506 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
508 /* BB is assumed to contain conditional jump. Return the branch edge. */
509 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
510 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
512 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
513 /* Return expected execution frequency of the edge E. */
514 #define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \
515 REG_BR_PROB_BASE)
517 /* Return nonzero if edge is critical. */
518 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
519 && EDGE_COUNT ((e)->dest->preds) >= 2)
521 #define EDGE_COUNT(ev) VEC_length (edge, (ev))
522 #define EDGE_I(ev,i) VEC_index (edge, (ev), (i))
523 #define EDGE_PRED(bb,i) VEC_index (edge, (bb)->preds, (i))
524 #define EDGE_SUCC(bb,i) VEC_index (edge, (bb)->succs, (i))
526 /* Returns true if BB has precisely one successor. */
528 static inline bool
529 single_succ_p (const_basic_block bb)
531 return EDGE_COUNT (bb->succs) == 1;
534 /* Returns true if BB has precisely one predecessor. */
536 static inline bool
537 single_pred_p (const_basic_block bb)
539 return EDGE_COUNT (bb->preds) == 1;
542 /* Returns the single successor edge of basic block BB. Aborts if
543 BB does not have exactly one successor. */
545 static inline edge
546 single_succ_edge (const_basic_block bb)
548 gcc_checking_assert (single_succ_p (bb));
549 return EDGE_SUCC (bb, 0);
552 /* Returns the single predecessor edge of basic block BB. Aborts
553 if BB does not have exactly one predecessor. */
555 static inline edge
556 single_pred_edge (const_basic_block bb)
558 gcc_checking_assert (single_pred_p (bb));
559 return EDGE_PRED (bb, 0);
562 /* Returns the single successor block of basic block BB. Aborts
563 if BB does not have exactly one successor. */
565 static inline basic_block
566 single_succ (const_basic_block bb)
568 return single_succ_edge (bb)->dest;
571 /* Returns the single predecessor block of basic block BB. Aborts
572 if BB does not have exactly one predecessor.*/
574 static inline basic_block
575 single_pred (const_basic_block bb)
577 return single_pred_edge (bb)->src;
580 /* Iterator object for edges. */
582 typedef struct {
583 unsigned index;
584 VEC(edge,gc) **container;
585 } edge_iterator;
587 static inline VEC(edge,gc) *
588 ei_container (edge_iterator i)
590 gcc_checking_assert (i.container);
591 return *i.container;
594 #define ei_start(iter) ei_start_1 (&(iter))
595 #define ei_last(iter) ei_last_1 (&(iter))
597 /* Return an iterator pointing to the start of an edge vector. */
598 static inline edge_iterator
599 ei_start_1 (VEC(edge,gc) **ev)
601 edge_iterator i;
603 i.index = 0;
604 i.container = ev;
606 return i;
609 /* Return an iterator pointing to the last element of an edge
610 vector. */
611 static inline edge_iterator
612 ei_last_1 (VEC(edge,gc) **ev)
614 edge_iterator i;
616 i.index = EDGE_COUNT (*ev) - 1;
617 i.container = ev;
619 return i;
622 /* Is the iterator `i' at the end of the sequence? */
623 static inline bool
624 ei_end_p (edge_iterator i)
626 return (i.index == EDGE_COUNT (ei_container (i)));
629 /* Is the iterator `i' at one position before the end of the
630 sequence? */
631 static inline bool
632 ei_one_before_end_p (edge_iterator i)
634 return (i.index + 1 == EDGE_COUNT (ei_container (i)));
637 /* Advance the iterator to the next element. */
638 static inline void
639 ei_next (edge_iterator *i)
641 gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
642 i->index++;
645 /* Move the iterator to the previous element. */
646 static inline void
647 ei_prev (edge_iterator *i)
649 gcc_checking_assert (i->index > 0);
650 i->index--;
653 /* Return the edge pointed to by the iterator `i'. */
654 static inline edge
655 ei_edge (edge_iterator i)
657 return EDGE_I (ei_container (i), i.index);
660 /* Return an edge pointed to by the iterator. Do it safely so that
661 NULL is returned when the iterator is pointing at the end of the
662 sequence. */
663 static inline edge
664 ei_safe_edge (edge_iterator i)
666 return !ei_end_p (i) ? ei_edge (i) : NULL;
669 /* Return 1 if we should continue to iterate. Return 0 otherwise.
670 *Edge P is set to the next edge if we are to continue to iterate
671 and NULL otherwise. */
673 static inline bool
674 ei_cond (edge_iterator ei, edge *p)
676 if (!ei_end_p (ei))
678 *p = ei_edge (ei);
679 return 1;
681 else
683 *p = NULL;
684 return 0;
688 /* This macro serves as a convenient way to iterate each edge in a
689 vector of predecessor or successor edges. It must not be used when
690 an element might be removed during the traversal, otherwise
691 elements will be missed. Instead, use a for-loop like that shown
692 in the following pseudo-code:
694 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
696 IF (e != taken_edge)
697 remove_edge (e);
698 ELSE
699 ei_next (&ei);
703 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
704 for ((ITER) = ei_start ((EDGE_VEC)); \
705 ei_cond ((ITER), &(EDGE)); \
706 ei_next (&(ITER)))
708 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
709 except for edge forwarding */
710 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
711 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
712 to care REG_DEAD notes. */
713 #define CLEANUP_THREADING 8 /* Do jump threading. */
714 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
715 insns. */
716 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
717 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
719 /* In cfganal.c */
720 extern void sbitmap_intersection_of_succs (sbitmap, sbitmap *, basic_block);
721 extern void sbitmap_intersection_of_preds (sbitmap, sbitmap *, basic_block);
722 extern void sbitmap_union_of_succs (sbitmap, sbitmap *, basic_block);
723 extern void sbitmap_union_of_preds (sbitmap, sbitmap *, basic_block);
725 /* In lcm.c */
726 extern struct edge_list *pre_edge_lcm (int, sbitmap *, sbitmap *,
727 sbitmap *, sbitmap *, sbitmap **,
728 sbitmap **);
729 extern struct edge_list *pre_edge_rev_lcm (int, sbitmap *,
730 sbitmap *, sbitmap *,
731 sbitmap *, sbitmap **,
732 sbitmap **);
733 extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
735 /* In predict.c */
736 extern bool maybe_hot_bb_p (struct function *, const_basic_block);
737 extern bool maybe_hot_edge_p (edge);
738 extern bool probably_never_executed_bb_p (struct function *, const_basic_block);
739 extern bool optimize_bb_for_size_p (const_basic_block);
740 extern bool optimize_bb_for_speed_p (const_basic_block);
741 extern bool optimize_edge_for_size_p (edge);
742 extern bool optimize_edge_for_speed_p (edge);
743 extern bool optimize_loop_for_size_p (struct loop *);
744 extern bool optimize_loop_for_speed_p (struct loop *);
745 extern bool optimize_loop_nest_for_size_p (struct loop *);
746 extern bool optimize_loop_nest_for_speed_p (struct loop *);
747 extern bool gimple_predicted_by_p (const_basic_block, enum br_predictor);
748 extern bool rtl_predicted_by_p (const_basic_block, enum br_predictor);
749 extern void gimple_predict_edge (edge, enum br_predictor, int);
750 extern void rtl_predict_edge (edge, enum br_predictor, int);
751 extern void predict_edge_def (edge, enum br_predictor, enum prediction);
752 extern void guess_outgoing_edge_probabilities (basic_block);
753 extern void remove_predictions_associated_with_edge (edge);
754 extern bool edge_probability_reliable_p (const_edge);
755 extern bool br_prob_note_reliable_p (const_rtx);
756 extern bool predictable_edge_p (edge);
758 /* In cfg.c */
759 extern void init_flow (struct function *);
760 extern void debug_bb (basic_block);
761 extern basic_block debug_bb_n (int);
762 extern void dump_flow_info (FILE *, int);
763 extern void expunge_block (basic_block);
764 extern void link_block (basic_block, basic_block);
765 extern void unlink_block (basic_block);
766 extern void compact_blocks (void);
767 extern basic_block alloc_block (void);
768 extern void alloc_aux_for_blocks (int);
769 extern void clear_aux_for_blocks (void);
770 extern void free_aux_for_blocks (void);
771 extern void alloc_aux_for_edge (edge, int);
772 extern void alloc_aux_for_edges (int);
773 extern void clear_aux_for_edges (void);
774 extern void free_aux_for_edges (void);
776 /* In cfganal.c */
777 extern void find_unreachable_blocks (void);
778 extern bool mark_dfs_back_edges (void);
779 struct edge_list * create_edge_list (void);
780 void free_edge_list (struct edge_list *);
781 void print_edge_list (FILE *, struct edge_list *);
782 void verify_edge_list (FILE *, struct edge_list *);
783 int find_edge_index (struct edge_list *, basic_block, basic_block);
784 edge find_edge (basic_block, basic_block);
785 extern void remove_fake_edges (void);
786 extern void remove_fake_exit_edges (void);
787 extern void add_noreturn_fake_exit_edges (void);
788 extern void connect_infinite_loops_to_exit (void);
789 extern int post_order_compute (int *, bool, bool);
790 extern int inverted_post_order_compute (int *);
791 extern int pre_and_rev_post_order_compute (int *, int *, bool);
792 extern int dfs_enumerate_from (basic_block, int,
793 bool (*)(const_basic_block, const void *),
794 basic_block *, int, const void *);
795 extern void compute_dominance_frontiers (struct bitmap_head_def *);
796 extern bitmap compute_idf (bitmap, struct bitmap_head_def *);
798 /* In cfgrtl.c */
799 extern rtx block_label (basic_block);
800 extern rtx bb_note (basic_block);
801 extern bool purge_all_dead_edges (void);
802 extern bool purge_dead_edges (basic_block);
803 extern bool fixup_abnormal_edges (void);
804 extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx);
805 extern bool contains_no_active_insn_p (const_basic_block);
806 extern bool forwarder_block_p (const_basic_block);
807 extern bool can_fallthru (basic_block, basic_block);
809 /* In cfgbuild.c. */
810 extern void find_many_sub_basic_blocks (sbitmap);
811 extern void rtl_make_eh_edge (sbitmap, basic_block, rtx);
813 enum replace_direction { dir_none, dir_forward, dir_backward, dir_both };
815 /* In cfgcleanup.c. */
816 extern bool cleanup_cfg (int);
817 extern int flow_find_cross_jump (basic_block, basic_block, rtx *, rtx *,
818 enum replace_direction*);
819 extern int flow_find_head_matching_sequence (basic_block, basic_block,
820 rtx *, rtx *, int);
822 extern bool delete_unreachable_blocks (void);
824 extern void update_br_prob_note (basic_block);
825 extern bool inside_basic_block_p (const_rtx);
826 extern bool control_flow_insn_p (const_rtx);
827 extern rtx get_last_bb_insn (basic_block);
829 /* In dominance.c */
831 enum cdi_direction
833 CDI_DOMINATORS = 1,
834 CDI_POST_DOMINATORS = 2
837 extern enum dom_state dom_info_state (enum cdi_direction);
838 extern void set_dom_info_availability (enum cdi_direction, enum dom_state);
839 extern bool dom_info_available_p (enum cdi_direction);
840 extern void calculate_dominance_info (enum cdi_direction);
841 extern void free_dominance_info (enum cdi_direction);
842 extern basic_block nearest_common_dominator (enum cdi_direction,
843 basic_block, basic_block);
844 extern basic_block nearest_common_dominator_for_set (enum cdi_direction,
845 bitmap);
846 extern void set_immediate_dominator (enum cdi_direction, basic_block,
847 basic_block);
848 extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
849 extern bool dominated_by_p (enum cdi_direction, const_basic_block, const_basic_block);
850 extern VEC (basic_block, heap) *get_dominated_by (enum cdi_direction, basic_block);
851 extern VEC (basic_block, heap) *get_dominated_by_region (enum cdi_direction,
852 basic_block *,
853 unsigned);
854 extern VEC (basic_block, heap) *get_dominated_to_depth (enum cdi_direction,
855 basic_block, int);
856 extern VEC (basic_block, heap) *get_all_dominated_blocks (enum cdi_direction,
857 basic_block);
858 extern void add_to_dominance_info (enum cdi_direction, basic_block);
859 extern void delete_from_dominance_info (enum cdi_direction, basic_block);
860 basic_block recompute_dominator (enum cdi_direction, basic_block);
861 extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
862 basic_block);
863 extern void iterate_fix_dominators (enum cdi_direction,
864 VEC (basic_block, heap) *, bool);
865 extern void verify_dominators (enum cdi_direction);
866 extern basic_block first_dom_son (enum cdi_direction, basic_block);
867 extern basic_block next_dom_son (enum cdi_direction, basic_block);
868 unsigned bb_dom_dfs_in (enum cdi_direction, basic_block);
869 unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
871 extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
872 extern void break_superblocks (void);
873 extern void relink_block_chain (bool);
874 extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
875 extern void init_rtl_bb_info (basic_block);
877 extern void initialize_original_copy_tables (void);
878 extern void free_original_copy_tables (void);
879 extern void set_bb_original (basic_block, basic_block);
880 extern basic_block get_bb_original (basic_block);
881 extern void set_bb_copy (basic_block, basic_block);
882 extern basic_block get_bb_copy (basic_block);
883 void set_loop_copy (struct loop *, struct loop *);
884 struct loop *get_loop_copy (struct loop *);
886 #include "cfghooks.h"
888 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
889 static inline bool
890 bb_has_eh_pred (basic_block bb)
892 edge e;
893 edge_iterator ei;
895 FOR_EACH_EDGE (e, ei, bb->preds)
897 if (e->flags & EDGE_EH)
898 return true;
900 return false;
903 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
904 static inline bool
905 bb_has_abnormal_pred (basic_block bb)
907 edge e;
908 edge_iterator ei;
910 FOR_EACH_EDGE (e, ei, bb->preds)
912 if (e->flags & EDGE_ABNORMAL)
913 return true;
915 return false;
918 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
919 static inline edge
920 find_fallthru_edge (VEC(edge,gc) *edges)
922 edge e;
923 edge_iterator ei;
925 FOR_EACH_EDGE (e, ei, edges)
926 if (e->flags & EDGE_FALLTHRU)
927 break;
929 return e;
932 /* In cfgloopmanip.c. */
933 extern edge mfb_kj_edge;
934 extern bool mfb_keep_just (edge);
936 /* In cfgexpand.c. */
937 extern void rtl_profile_for_bb (basic_block);
938 extern void rtl_profile_for_edge (edge);
939 extern void default_rtl_profile (void);
941 /* In profile.c. */
942 extern gcov_working_set_t *find_working_set(unsigned pct_times_10);
944 /* Check tha probability is sane. */
946 static inline void
947 check_probability (int prob)
949 gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
952 /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
953 Used to combine BB probabilities. */
955 static inline int
956 combine_probabilities (int prob1, int prob2)
958 check_probability (prob1);
959 check_probability (prob2);
960 return RDIV (prob1 * prob2, REG_BR_PROB_BASE);
963 /* Apply probability PROB on frequency or count FREQ. */
965 static inline gcov_type
966 apply_probability (gcov_type freq, int prob)
968 check_probability (prob);
969 return RDIV (freq * prob, REG_BR_PROB_BASE);
972 /* Return inverse probability for PROB. */
974 static inline int
975 inverse_probability (int prob1)
977 check_probability (prob1);
978 return REG_BR_PROB_BASE - prob1;
980 #endif /* GCC_BASIC_BLOCK_H */