2012-09-04 Janus Weil <janus@gcc.gnu.org>
[official-gcc.git] / gcc / basic-block.h
blob09b5eb0a77cab2a7fa5b68b272959b8e4ba9cf1b
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;
35 /* Control flow edge information. */
36 struct GTY((user)) edge_def {
37 /* The two blocks at the ends of the edge. */
38 basic_block src;
39 basic_block dest;
41 /* Instructions queued on the edge. */
42 union edge_def_insns {
43 gimple_seq g;
44 rtx r;
45 } insns;
47 /* Auxiliary info specific to a pass. */
48 PTR aux;
50 /* Location of any goto implicit in the edge and associated BLOCK. */
51 tree goto_block;
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 /* Declared in cfgloop.h. */
95 struct loop;
97 struct GTY(()) rtl_bb_info {
98 /* The first insn of the block is embedded into bb->il.x. */
99 /* The last insn of the block. */
100 rtx end_;
102 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
103 and after the block. */
104 rtx header_;
105 rtx footer_;
108 struct GTY(()) gimple_bb_info {
109 /* Sequence of statements in this block. */
110 gimple_seq seq;
112 /* PHI nodes for this block. */
113 gimple_seq phi_nodes;
116 /* A basic block is a sequence of instructions with only one entry and
117 only one exit. If any one of the instructions are executed, they
118 will all be executed, and in sequence from first to last.
120 There may be COND_EXEC instructions in the basic block. The
121 COND_EXEC *instructions* will be executed -- but if the condition
122 is false the conditionally executed *expressions* will of course
123 not be executed. We don't consider the conditionally executed
124 expression (which might have side-effects) to be in a separate
125 basic block because the program counter will always be at the same
126 location after the COND_EXEC instruction, regardless of whether the
127 condition is true or not.
129 Basic blocks need not start with a label nor end with a jump insn.
130 For example, a previous basic block may just "conditionally fall"
131 into the succeeding basic block, and the last basic block need not
132 end with a jump insn. Block 0 is a descendant of the entry block.
134 A basic block beginning with two labels cannot have notes between
135 the labels.
137 Data for jump tables are stored in jump_insns that occur in no
138 basic block even though these insns can follow or precede insns in
139 basic blocks. */
141 /* Basic block information indexed by block number. */
142 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
143 /* The edges into and out of the block. */
144 VEC(edge,gc) *preds;
145 VEC(edge,gc) *succs;
147 /* Auxiliary info specific to a pass. */
148 PTR GTY ((skip (""))) aux;
150 /* Innermost loop containing the block. */
151 struct loop *loop_father;
153 /* The dominance and postdominance information node. */
154 struct et_node * GTY ((skip (""))) dom[2];
156 /* Previous and next blocks in the chain. */
157 basic_block prev_bb;
158 basic_block next_bb;
160 union basic_block_il_dependent {
161 struct gimple_bb_info GTY ((tag ("0"))) gimple;
162 struct {
163 rtx head_;
164 struct rtl_bb_info * rtl;
165 } GTY ((tag ("1"))) x;
166 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
168 /* Various flags. See cfg-flags.def. */
169 int flags;
171 /* The index of this block. */
172 int index;
174 /* Expected number of executions: calculated in profile.c. */
175 gcov_type count;
177 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
178 int frequency;
180 /* The discriminator for this block. The discriminator distinguishes
181 among several basic blocks that share a common locus, allowing for
182 more accurate sample-based profiling. */
183 int discriminator;
186 /* This ensures that struct gimple_bb_info is smaller than
187 struct rtl_bb_info, so that inlining the former into basic_block_def
188 is the better choice. */
189 typedef int __assert_gimple_bb_smaller_rtl_bb
190 [(int)sizeof(struct rtl_bb_info)
191 - (int)sizeof (struct gimple_bb_info)];
193 DEF_VEC_P(basic_block);
194 DEF_VEC_ALLOC_P(basic_block,gc);
195 DEF_VEC_ALLOC_P(basic_block,heap);
197 #define BB_FREQ_MAX 10000
199 /* Masks for basic_block.flags. */
200 #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
201 enum cfg_bb_flags
203 #include "cfg-flags.def"
204 LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
206 #undef DEF_BASIC_BLOCK_FLAG
208 /* Bit mask for all basic block flags. */
209 #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
211 /* Bit mask for all basic block flags that must be preserved. These are
212 the bit masks that are *not* cleared by clear_bb_flags. */
213 #define BB_FLAGS_TO_PRESERVE \
214 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
215 | BB_HOT_PARTITION | BB_COLD_PARTITION)
217 /* Dummy bitmask for convenience in the hot/cold partitioning code. */
218 #define BB_UNPARTITIONED 0
220 /* Partitions, to be used when partitioning hot and cold basic blocks into
221 separate sections. */
222 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
223 #define BB_SET_PARTITION(bb, part) do { \
224 basic_block bb_ = (bb); \
225 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
226 | (part)); \
227 } while (0)
229 #define BB_COPY_PARTITION(dstbb, srcbb) \
230 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
232 /* State of dominance information. */
234 enum dom_state
236 DOM_NONE, /* Not computed at all. */
237 DOM_NO_FAST_QUERY, /* The data is OK, but the fast query data are not usable. */
238 DOM_OK /* Everything is ok. */
241 /* What sort of profiling information we have. */
242 enum profile_status_d
244 PROFILE_ABSENT,
245 PROFILE_GUESSED,
246 PROFILE_READ,
247 PROFILE_LAST /* Last value, used by profile streaming. */
250 /* A structure to group all the per-function control flow graph data.
251 The x_* prefixing is necessary because otherwise references to the
252 fields of this struct are interpreted as the defines for backward
253 source compatibility following the definition of this struct. */
254 struct GTY(()) control_flow_graph {
255 /* Block pointers for the exit and entry of a function.
256 These are always the head and tail of the basic block list. */
257 basic_block x_entry_block_ptr;
258 basic_block x_exit_block_ptr;
260 /* Index by basic block number, get basic block struct info. */
261 VEC(basic_block,gc) *x_basic_block_info;
263 /* Number of basic blocks in this flow graph. */
264 int x_n_basic_blocks;
266 /* Number of edges in this flow graph. */
267 int x_n_edges;
269 /* The first free basic block number. */
270 int x_last_basic_block;
272 /* UIDs for LABEL_DECLs. */
273 int last_label_uid;
275 /* Mapping of labels to their associated blocks. At present
276 only used for the gimple CFG. */
277 VEC(basic_block,gc) *x_label_to_block_map;
279 enum profile_status_d x_profile_status;
281 /* Whether the dominators and the postdominators are available. */
282 enum dom_state x_dom_computed[2];
284 /* Number of basic blocks in the dominance tree. */
285 unsigned x_n_bbs_in_dom_tree[2];
287 /* Maximal number of entities in the single jumptable. Used to estimate
288 final flowgraph size. */
289 int max_jumptable_ents;
292 /* Defines for accessing the fields of the CFG structure for function FN. */
293 #define ENTRY_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_entry_block_ptr)
294 #define EXIT_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_exit_block_ptr)
295 #define basic_block_info_for_function(FN) ((FN)->cfg->x_basic_block_info)
296 #define n_basic_blocks_for_function(FN) ((FN)->cfg->x_n_basic_blocks)
297 #define n_edges_for_function(FN) ((FN)->cfg->x_n_edges)
298 #define last_basic_block_for_function(FN) ((FN)->cfg->x_last_basic_block)
299 #define label_to_block_map_for_function(FN) ((FN)->cfg->x_label_to_block_map)
300 #define profile_status_for_function(FN) ((FN)->cfg->x_profile_status)
302 #define BASIC_BLOCK_FOR_FUNCTION(FN,N) \
303 (VEC_index (basic_block, basic_block_info_for_function(FN), (N)))
304 #define SET_BASIC_BLOCK_FOR_FUNCTION(FN,N,BB) \
305 (VEC_replace (basic_block, basic_block_info_for_function(FN), (N), (BB)))
307 /* Defines for textual backward source compatibility. */
308 #define ENTRY_BLOCK_PTR (cfun->cfg->x_entry_block_ptr)
309 #define EXIT_BLOCK_PTR (cfun->cfg->x_exit_block_ptr)
310 #define basic_block_info (cfun->cfg->x_basic_block_info)
311 #define n_basic_blocks (cfun->cfg->x_n_basic_blocks)
312 #define n_edges (cfun->cfg->x_n_edges)
313 #define last_basic_block (cfun->cfg->x_last_basic_block)
314 #define label_to_block_map (cfun->cfg->x_label_to_block_map)
315 #define profile_status (cfun->cfg->x_profile_status)
317 #define BASIC_BLOCK(N) (VEC_index (basic_block, basic_block_info, (N)))
318 #define SET_BASIC_BLOCK(N,BB) (VEC_replace (basic_block, basic_block_info, (N), (BB)))
320 /* For iterating over basic blocks. */
321 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
322 for (BB = FROM; BB != TO; BB = BB->DIR)
324 #define FOR_EACH_BB_FN(BB, FN) \
325 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
327 #define FOR_EACH_BB(BB) FOR_EACH_BB_FN (BB, cfun)
329 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
330 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
332 #define FOR_EACH_BB_REVERSE(BB) FOR_EACH_BB_REVERSE_FN(BB, cfun)
334 /* For iterating over insns in basic block. */
335 #define FOR_BB_INSNS(BB, INSN) \
336 for ((INSN) = BB_HEAD (BB); \
337 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
338 (INSN) = NEXT_INSN (INSN))
340 /* For iterating over insns in basic block when we might remove the
341 current insn. */
342 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
343 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
344 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
345 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
347 #define FOR_BB_INSNS_REVERSE(BB, INSN) \
348 for ((INSN) = BB_END (BB); \
349 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
350 (INSN) = PREV_INSN (INSN))
352 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
353 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
354 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
355 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
357 /* Cycles through _all_ basic blocks, even the fake ones (entry and
358 exit block). */
360 #define FOR_ALL_BB(BB) \
361 for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
363 #define FOR_ALL_BB_FN(BB, FN) \
364 for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
367 /* Stuff for recording basic block info. */
369 #define BB_HEAD(B) (B)->il.x.head_
370 #define BB_END(B) (B)->il.x.rtl->end_
371 #define BB_HEADER(B) (B)->il.x.rtl->header_
372 #define BB_FOOTER(B) (B)->il.x.rtl->footer_
374 /* Special block numbers [markers] for entry and exit.
375 Neither of them is supposed to hold actual statements. */
376 #define ENTRY_BLOCK (0)
377 #define EXIT_BLOCK (1)
379 /* The two blocks that are always in the cfg. */
380 #define NUM_FIXED_BLOCKS (2)
382 #define set_block_for_insn(INSN, BB) (BLOCK_FOR_INSN (INSN) = BB)
384 extern void compute_bb_for_insn (void);
385 extern unsigned int free_bb_for_insn (void);
386 extern void update_bb_for_insn (basic_block);
388 extern void insert_insn_on_edge (rtx, edge);
389 basic_block split_edge_and_insert (edge, rtx);
391 extern void commit_one_edge_insertion (edge e);
392 extern void commit_edge_insertions (void);
394 extern edge unchecked_make_edge (basic_block, basic_block, int);
395 extern edge cached_make_edge (sbitmap, basic_block, basic_block, int);
396 extern edge make_edge (basic_block, basic_block, int);
397 extern edge make_single_succ_edge (basic_block, basic_block, int);
398 extern void remove_edge_raw (edge);
399 extern void redirect_edge_succ (edge, basic_block);
400 extern edge redirect_edge_succ_nodup (edge, basic_block);
401 extern void redirect_edge_pred (edge, basic_block);
402 extern basic_block create_basic_block_structure (rtx, rtx, rtx, basic_block);
403 extern void clear_bb_flags (void);
404 extern void dump_bb_info (FILE *, basic_block, int, int, bool, bool);
405 extern void dump_edge_info (FILE *, edge, int, int);
406 extern void brief_dump_cfg (FILE *, int);
407 extern void clear_edges (void);
408 extern void scale_bbs_frequencies_int (basic_block *, int, int, int);
409 extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,
410 gcov_type);
412 /* Structure to group all of the information to process IF-THEN and
413 IF-THEN-ELSE blocks for the conditional execution support. This
414 needs to be in a public file in case the IFCVT macros call
415 functions passing the ce_if_block data structure. */
417 typedef struct ce_if_block
419 basic_block test_bb; /* First test block. */
420 basic_block then_bb; /* THEN block. */
421 basic_block else_bb; /* ELSE block or NULL. */
422 basic_block join_bb; /* Join THEN/ELSE blocks. */
423 basic_block last_test_bb; /* Last bb to hold && or || tests. */
424 int num_multiple_test_blocks; /* # of && and || basic blocks. */
425 int num_and_and_blocks; /* # of && blocks. */
426 int num_or_or_blocks; /* # of || blocks. */
427 int num_multiple_test_insns; /* # of insns in && and || blocks. */
428 int and_and_p; /* Complex test is &&. */
429 int num_then_insns; /* # of insns in THEN block. */
430 int num_else_insns; /* # of insns in ELSE block. */
431 int pass; /* Pass number. */
432 } ce_if_block_t;
434 /* This structure maintains an edge list vector. */
435 /* FIXME: Make this a VEC(edge). */
436 struct edge_list
438 int num_edges;
439 edge *index_to_edge;
442 /* The base value for branch probability notes and edge probabilities. */
443 #define REG_BR_PROB_BASE 10000
445 /* This is the value which indicates no edge is present. */
446 #define EDGE_INDEX_NO_EDGE -1
448 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
449 if there is no edge between the 2 basic blocks. */
450 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
452 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
453 block which is either the pred or succ end of the indexed edge. */
454 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
455 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
457 /* INDEX_EDGE returns a pointer to the edge. */
458 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
460 /* Number of edges in the compressed edge list. */
461 #define NUM_EDGES(el) ((el)->num_edges)
463 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
464 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
465 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
467 /* BB is assumed to contain conditional jump. Return the branch edge. */
468 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
469 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
471 /* Return expected execution frequency of the edge E. */
472 #define EDGE_FREQUENCY(e) (((e)->src->frequency \
473 * (e)->probability \
474 + REG_BR_PROB_BASE / 2) \
475 / REG_BR_PROB_BASE)
477 /* Return nonzero if edge is critical. */
478 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
479 && EDGE_COUNT ((e)->dest->preds) >= 2)
481 #define EDGE_COUNT(ev) VEC_length (edge, (ev))
482 #define EDGE_I(ev,i) VEC_index (edge, (ev), (i))
483 #define EDGE_PRED(bb,i) VEC_index (edge, (bb)->preds, (i))
484 #define EDGE_SUCC(bb,i) VEC_index (edge, (bb)->succs, (i))
486 /* Returns true if BB has precisely one successor. */
488 static inline bool
489 single_succ_p (const_basic_block bb)
491 return EDGE_COUNT (bb->succs) == 1;
494 /* Returns true if BB has precisely one predecessor. */
496 static inline bool
497 single_pred_p (const_basic_block bb)
499 return EDGE_COUNT (bb->preds) == 1;
502 /* Returns the single successor edge of basic block BB. Aborts if
503 BB does not have exactly one successor. */
505 static inline edge
506 single_succ_edge (const_basic_block bb)
508 gcc_checking_assert (single_succ_p (bb));
509 return EDGE_SUCC (bb, 0);
512 /* Returns the single predecessor edge of basic block BB. Aborts
513 if BB does not have exactly one predecessor. */
515 static inline edge
516 single_pred_edge (const_basic_block bb)
518 gcc_checking_assert (single_pred_p (bb));
519 return EDGE_PRED (bb, 0);
522 /* Returns the single successor block of basic block BB. Aborts
523 if BB does not have exactly one successor. */
525 static inline basic_block
526 single_succ (const_basic_block bb)
528 return single_succ_edge (bb)->dest;
531 /* Returns the single predecessor block of basic block BB. Aborts
532 if BB does not have exactly one predecessor.*/
534 static inline basic_block
535 single_pred (const_basic_block bb)
537 return single_pred_edge (bb)->src;
540 /* Iterator object for edges. */
542 typedef struct {
543 unsigned index;
544 VEC(edge,gc) **container;
545 } edge_iterator;
547 static inline VEC(edge,gc) *
548 ei_container (edge_iterator i)
550 gcc_checking_assert (i.container);
551 return *i.container;
554 #define ei_start(iter) ei_start_1 (&(iter))
555 #define ei_last(iter) ei_last_1 (&(iter))
557 /* Return an iterator pointing to the start of an edge vector. */
558 static inline edge_iterator
559 ei_start_1 (VEC(edge,gc) **ev)
561 edge_iterator i;
563 i.index = 0;
564 i.container = ev;
566 return i;
569 /* Return an iterator pointing to the last element of an edge
570 vector. */
571 static inline edge_iterator
572 ei_last_1 (VEC(edge,gc) **ev)
574 edge_iterator i;
576 i.index = EDGE_COUNT (*ev) - 1;
577 i.container = ev;
579 return i;
582 /* Is the iterator `i' at the end of the sequence? */
583 static inline bool
584 ei_end_p (edge_iterator i)
586 return (i.index == EDGE_COUNT (ei_container (i)));
589 /* Is the iterator `i' at one position before the end of the
590 sequence? */
591 static inline bool
592 ei_one_before_end_p (edge_iterator i)
594 return (i.index + 1 == EDGE_COUNT (ei_container (i)));
597 /* Advance the iterator to the next element. */
598 static inline void
599 ei_next (edge_iterator *i)
601 gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
602 i->index++;
605 /* Move the iterator to the previous element. */
606 static inline void
607 ei_prev (edge_iterator *i)
609 gcc_checking_assert (i->index > 0);
610 i->index--;
613 /* Return the edge pointed to by the iterator `i'. */
614 static inline edge
615 ei_edge (edge_iterator i)
617 return EDGE_I (ei_container (i), i.index);
620 /* Return an edge pointed to by the iterator. Do it safely so that
621 NULL is returned when the iterator is pointing at the end of the
622 sequence. */
623 static inline edge
624 ei_safe_edge (edge_iterator i)
626 return !ei_end_p (i) ? ei_edge (i) : NULL;
629 /* Return 1 if we should continue to iterate. Return 0 otherwise.
630 *Edge P is set to the next edge if we are to continue to iterate
631 and NULL otherwise. */
633 static inline bool
634 ei_cond (edge_iterator ei, edge *p)
636 if (!ei_end_p (ei))
638 *p = ei_edge (ei);
639 return 1;
641 else
643 *p = NULL;
644 return 0;
648 /* This macro serves as a convenient way to iterate each edge in a
649 vector of predecessor or successor edges. It must not be used when
650 an element might be removed during the traversal, otherwise
651 elements will be missed. Instead, use a for-loop like that shown
652 in the following pseudo-code:
654 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
656 IF (e != taken_edge)
657 remove_edge (e);
658 ELSE
659 ei_next (&ei);
663 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
664 for ((ITER) = ei_start ((EDGE_VEC)); \
665 ei_cond ((ITER), &(EDGE)); \
666 ei_next (&(ITER)))
668 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
669 except for edge forwarding */
670 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
671 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
672 to care REG_DEAD notes. */
673 #define CLEANUP_THREADING 8 /* Do jump threading. */
674 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
675 insns. */
676 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
677 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
679 /* In cfganal.c */
680 extern void sbitmap_intersection_of_succs (sbitmap, sbitmap *, basic_block);
681 extern void sbitmap_intersection_of_preds (sbitmap, sbitmap *, basic_block);
682 extern void sbitmap_union_of_succs (sbitmap, sbitmap *, basic_block);
683 extern void sbitmap_union_of_preds (sbitmap, sbitmap *, basic_block);
685 /* In lcm.c */
686 extern struct edge_list *pre_edge_lcm (int, sbitmap *, sbitmap *,
687 sbitmap *, sbitmap *, sbitmap **,
688 sbitmap **);
689 extern struct edge_list *pre_edge_rev_lcm (int, sbitmap *,
690 sbitmap *, sbitmap *,
691 sbitmap *, sbitmap **,
692 sbitmap **);
693 extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
695 /* In predict.c */
696 extern bool maybe_hot_bb_p (struct function *, const_basic_block);
697 extern bool maybe_hot_edge_p (edge);
698 extern bool probably_never_executed_bb_p (struct function *, const_basic_block);
699 extern bool optimize_bb_for_size_p (const_basic_block);
700 extern bool optimize_bb_for_speed_p (const_basic_block);
701 extern bool optimize_edge_for_size_p (edge);
702 extern bool optimize_edge_for_speed_p (edge);
703 extern bool optimize_loop_for_size_p (struct loop *);
704 extern bool optimize_loop_for_speed_p (struct loop *);
705 extern bool optimize_loop_nest_for_size_p (struct loop *);
706 extern bool optimize_loop_nest_for_speed_p (struct loop *);
707 extern bool gimple_predicted_by_p (const_basic_block, enum br_predictor);
708 extern bool rtl_predicted_by_p (const_basic_block, enum br_predictor);
709 extern void gimple_predict_edge (edge, enum br_predictor, int);
710 extern void rtl_predict_edge (edge, enum br_predictor, int);
711 extern void predict_edge_def (edge, enum br_predictor, enum prediction);
712 extern void guess_outgoing_edge_probabilities (basic_block);
713 extern void remove_predictions_associated_with_edge (edge);
714 extern bool edge_probability_reliable_p (const_edge);
715 extern bool br_prob_note_reliable_p (const_rtx);
716 extern bool predictable_edge_p (edge);
718 /* In cfg.c */
719 extern void init_flow (struct function *);
720 extern void debug_bb (basic_block);
721 extern basic_block debug_bb_n (int);
722 extern void dump_flow_info (FILE *, int);
723 extern void expunge_block (basic_block);
724 extern void link_block (basic_block, basic_block);
725 extern void unlink_block (basic_block);
726 extern void compact_blocks (void);
727 extern basic_block alloc_block (void);
728 extern void alloc_aux_for_blocks (int);
729 extern void clear_aux_for_blocks (void);
730 extern void free_aux_for_blocks (void);
731 extern void alloc_aux_for_edge (edge, int);
732 extern void alloc_aux_for_edges (int);
733 extern void clear_aux_for_edges (void);
734 extern void free_aux_for_edges (void);
736 /* In cfganal.c */
737 extern void find_unreachable_blocks (void);
738 extern bool mark_dfs_back_edges (void);
739 struct edge_list * create_edge_list (void);
740 void free_edge_list (struct edge_list *);
741 void print_edge_list (FILE *, struct edge_list *);
742 void verify_edge_list (FILE *, struct edge_list *);
743 int find_edge_index (struct edge_list *, basic_block, basic_block);
744 edge find_edge (basic_block, basic_block);
745 extern void remove_fake_edges (void);
746 extern void remove_fake_exit_edges (void);
747 extern void add_noreturn_fake_exit_edges (void);
748 extern void connect_infinite_loops_to_exit (void);
749 extern int post_order_compute (int *, bool, bool);
750 extern int inverted_post_order_compute (int *);
751 extern int pre_and_rev_post_order_compute (int *, int *, bool);
752 extern int dfs_enumerate_from (basic_block, int,
753 bool (*)(const_basic_block, const void *),
754 basic_block *, int, const void *);
755 extern void compute_dominance_frontiers (struct bitmap_head_def *);
756 extern bitmap compute_idf (bitmap, struct bitmap_head_def *);
758 /* In cfgrtl.c */
759 extern rtx block_label (basic_block);
760 extern rtx bb_note (basic_block);
761 extern bool purge_all_dead_edges (void);
762 extern bool purge_dead_edges (basic_block);
763 extern bool fixup_abnormal_edges (void);
764 extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx);
765 extern bool forwarder_block_p (const_basic_block);
766 extern bool can_fallthru (basic_block, basic_block);
768 /* In cfgbuild.c. */
769 extern void find_many_sub_basic_blocks (sbitmap);
770 extern void rtl_make_eh_edge (sbitmap, basic_block, rtx);
772 enum replace_direction { dir_none, dir_forward, dir_backward, dir_both };
774 /* In cfgcleanup.c. */
775 extern bool cleanup_cfg (int);
776 extern int flow_find_cross_jump (basic_block, basic_block, rtx *, rtx *,
777 enum replace_direction*);
778 extern int flow_find_head_matching_sequence (basic_block, basic_block,
779 rtx *, rtx *, int);
781 extern bool delete_unreachable_blocks (void);
783 extern void update_br_prob_note (basic_block);
784 extern bool inside_basic_block_p (const_rtx);
785 extern bool control_flow_insn_p (const_rtx);
786 extern rtx get_last_bb_insn (basic_block);
788 /* In dominance.c */
790 enum cdi_direction
792 CDI_DOMINATORS = 1,
793 CDI_POST_DOMINATORS = 2
796 extern enum dom_state dom_info_state (enum cdi_direction);
797 extern void set_dom_info_availability (enum cdi_direction, enum dom_state);
798 extern bool dom_info_available_p (enum cdi_direction);
799 extern void calculate_dominance_info (enum cdi_direction);
800 extern void free_dominance_info (enum cdi_direction);
801 extern basic_block nearest_common_dominator (enum cdi_direction,
802 basic_block, basic_block);
803 extern basic_block nearest_common_dominator_for_set (enum cdi_direction,
804 bitmap);
805 extern void set_immediate_dominator (enum cdi_direction, basic_block,
806 basic_block);
807 extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
808 extern bool dominated_by_p (enum cdi_direction, const_basic_block, const_basic_block);
809 extern VEC (basic_block, heap) *get_dominated_by (enum cdi_direction, basic_block);
810 extern VEC (basic_block, heap) *get_dominated_by_region (enum cdi_direction,
811 basic_block *,
812 unsigned);
813 extern VEC (basic_block, heap) *get_dominated_to_depth (enum cdi_direction,
814 basic_block, int);
815 extern VEC (basic_block, heap) *get_all_dominated_blocks (enum cdi_direction,
816 basic_block);
817 extern void add_to_dominance_info (enum cdi_direction, basic_block);
818 extern void delete_from_dominance_info (enum cdi_direction, basic_block);
819 basic_block recompute_dominator (enum cdi_direction, basic_block);
820 extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
821 basic_block);
822 extern void iterate_fix_dominators (enum cdi_direction,
823 VEC (basic_block, heap) *, bool);
824 extern void verify_dominators (enum cdi_direction);
825 extern basic_block first_dom_son (enum cdi_direction, basic_block);
826 extern basic_block next_dom_son (enum cdi_direction, basic_block);
827 unsigned bb_dom_dfs_in (enum cdi_direction, basic_block);
828 unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
830 extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
831 extern void break_superblocks (void);
832 extern void relink_block_chain (bool);
833 extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
834 extern void init_rtl_bb_info (basic_block);
836 extern void initialize_original_copy_tables (void);
837 extern void free_original_copy_tables (void);
838 extern void set_bb_original (basic_block, basic_block);
839 extern basic_block get_bb_original (basic_block);
840 extern void set_bb_copy (basic_block, basic_block);
841 extern basic_block get_bb_copy (basic_block);
842 void set_loop_copy (struct loop *, struct loop *);
843 struct loop *get_loop_copy (struct loop *);
845 #include "cfghooks.h"
847 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
848 static inline bool
849 bb_has_eh_pred (basic_block bb)
851 edge e;
852 edge_iterator ei;
854 FOR_EACH_EDGE (e, ei, bb->preds)
856 if (e->flags & EDGE_EH)
857 return true;
859 return false;
862 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
863 static inline bool
864 bb_has_abnormal_pred (basic_block bb)
866 edge e;
867 edge_iterator ei;
869 FOR_EACH_EDGE (e, ei, bb->preds)
871 if (e->flags & EDGE_ABNORMAL)
872 return true;
874 return false;
877 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
878 static inline edge
879 find_fallthru_edge (VEC(edge,gc) *edges)
881 edge e;
882 edge_iterator ei;
884 FOR_EACH_EDGE (e, ei, edges)
885 if (e->flags & EDGE_FALLTHRU)
886 break;
888 return e;
891 /* In cfgloopmanip.c. */
892 extern edge mfb_kj_edge;
893 extern bool mfb_keep_just (edge);
895 /* In cfgexpand.c. */
896 extern void rtl_profile_for_bb (basic_block);
897 extern void rtl_profile_for_edge (edge);
898 extern void default_rtl_profile (void);
900 #endif /* GCC_BASIC_BLOCK_H */