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, 2011, 2012
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_BASIC_BLOCK_H
23 #define GCC_BASIC_BLOCK_H
29 /* Type we use to hold basic block counters. Should be at least
30 64bit. Although a counter cannot be negative, we use a signed
31 type, because erroneous negative counts can be generated when the
32 flow graph is manipulated by various optimizations. A signed type
33 makes those easy to detect. */
34 typedef HOST_WIDEST_INT gcov_type
;
35 typedef unsigned HOST_WIDEST_INT gcov_type_unsigned
;
37 /* Control flow edge information. */
38 struct GTY((user
)) edge_def
{
39 /* The two blocks at the ends of the edge. */
43 /* Instructions queued on the edge. */
44 union edge_def_insns
{
49 /* Auxiliary info specific to a pass. */
52 /* Location of any goto implicit in the edge. */
53 location_t goto_locus
;
55 /* The index number corresponding to this edge in the edge vector
57 unsigned int dest_idx
;
59 int flags
; /* see cfg-flags.def */
60 int probability
; /* biased by REG_BR_PROB_BASE */
61 gcov_type count
; /* Expected number of executions calculated
66 /* Garbage collection and PCH support for edge_def. */
67 extern void gt_ggc_mx (edge_def
*e
);
68 extern void gt_pch_nx (edge_def
*e
);
69 extern void gt_pch_nx (edge_def
*e
, gt_pointer_operator
, void *);
71 /* Masks for edge.flags. */
72 #define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
74 #include "cfg-flags.def"
75 LAST_CFG_EDGE_FLAG
/* this is only used for EDGE_ALL_FLAGS */
79 /* Bit mask for all edge flags. */
80 #define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
82 /* The following four flags all indicate something special about an edge.
83 Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
84 control flow transfers. */
85 #define EDGE_COMPLEX \
86 (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
88 /* Counter summary from the last set of coverage counts read by
90 extern const struct gcov_ctr_summary
*profile_info
;
92 /* Working set size statistics for a given percentage of the entire
93 profile (sum_all from the counter summary). */
94 typedef struct gcov_working_set_info
96 /* Number of hot counters included in this working set. */
97 unsigned num_counters
;
98 /* Smallest counter included in this working set. */
99 gcov_type min_counter
;
100 } gcov_working_set_t
;
102 /* Structure to gather statistic about profile consistency, per pass.
103 An array of this structure, indexed by pass static number, is allocated
104 in passes.c. The structure is defined here so that different CFG modes
105 can do their book-keeping via CFG hooks.
107 For every field[2], field[0] is the count before the pass runs, and
108 field[1] is the post-pass count. This allows us to monitor the effect
109 of each individual pass on the profile consistency.
111 This structure is not supposed to be used by anything other than passes.c
112 and one CFG hook per CFG mode. */
113 struct profile_record
115 /* The number of basic blocks where sum(freq) of the block's predecessors
116 doesn't match reasonably well with the incoming frequency. */
117 int num_mismatched_freq_in
[2];
118 /* Likewise for a basic block's successors. */
119 int num_mismatched_freq_out
[2];
120 /* The number of basic blocks where sum(count) of the block's predecessors
121 doesn't match reasonably well with the incoming frequency. */
122 int num_mismatched_count_in
[2];
123 /* Likewise for a basic block's successors. */
124 int num_mismatched_count_out
[2];
125 /* A weighted cost of the run-time of the function body. */
127 /* A weighted cost of the size of the function body. */
129 /* True iff this pass actually was run. */
133 /* Declared in cfgloop.h. */
136 struct GTY(()) rtl_bb_info
{
137 /* The first insn of the block is embedded into bb->il.x. */
138 /* The last insn of the block. */
141 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
142 and after the block. */
147 struct GTY(()) gimple_bb_info
{
148 /* Sequence of statements in this block. */
151 /* PHI nodes for this block. */
152 gimple_seq phi_nodes
;
155 /* A basic block is a sequence of instructions with only one entry and
156 only one exit. If any one of the instructions are executed, they
157 will all be executed, and in sequence from first to last.
159 There may be COND_EXEC instructions in the basic block. The
160 COND_EXEC *instructions* will be executed -- but if the condition
161 is false the conditionally executed *expressions* will of course
162 not be executed. We don't consider the conditionally executed
163 expression (which might have side-effects) to be in a separate
164 basic block because the program counter will always be at the same
165 location after the COND_EXEC instruction, regardless of whether the
166 condition is true or not.
168 Basic blocks need not start with a label nor end with a jump insn.
169 For example, a previous basic block may just "conditionally fall"
170 into the succeeding basic block, and the last basic block need not
171 end with a jump insn. Block 0 is a descendant of the entry block.
173 A basic block beginning with two labels cannot have notes between
176 Data for jump tables are stored in jump_insns that occur in no
177 basic block even though these insns can follow or precede insns in
180 /* Basic block information indexed by block number. */
181 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def
{
182 /* The edges into and out of the block. */
183 vec
<edge
, va_gc
> *preds
;
184 vec
<edge
, va_gc
> *succs
;
186 /* Auxiliary info specific to a pass. */
187 PTR
GTY ((skip (""))) aux
;
189 /* Innermost loop containing the block. */
190 struct loop
*loop_father
;
192 /* The dominance and postdominance information node. */
193 struct et_node
* GTY ((skip (""))) dom
[2];
195 /* Previous and next blocks in the chain. */
199 union basic_block_il_dependent
{
200 struct gimple_bb_info
GTY ((tag ("0"))) gimple
;
203 struct rtl_bb_info
* rtl
;
204 } GTY ((tag ("1"))) x
;
205 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il
;
207 /* Various flags. See cfg-flags.def. */
210 /* The index of this block. */
213 /* Expected number of executions: calculated in profile.c. */
216 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
219 /* The discriminator for this block. The discriminator distinguishes
220 among several basic blocks that share a common locus, allowing for
221 more accurate sample-based profiling. */
225 /* This ensures that struct gimple_bb_info is smaller than
226 struct rtl_bb_info, so that inlining the former into basic_block_def
227 is the better choice. */
228 typedef int __assert_gimple_bb_smaller_rtl_bb
229 [(int)sizeof(struct rtl_bb_info
)
230 - (int)sizeof (struct gimple_bb_info
)];
233 #define BB_FREQ_MAX 10000
235 /* Masks for basic_block.flags. */
236 #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
239 #include "cfg-flags.def"
240 LAST_CFG_BB_FLAG
/* this is only used for BB_ALL_FLAGS */
242 #undef DEF_BASIC_BLOCK_FLAG
244 /* Bit mask for all basic block flags. */
245 #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
247 /* Bit mask for all basic block flags that must be preserved. These are
248 the bit masks that are *not* cleared by clear_bb_flags. */
249 #define BB_FLAGS_TO_PRESERVE \
250 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
251 | BB_HOT_PARTITION | BB_COLD_PARTITION)
253 /* Dummy bitmask for convenience in the hot/cold partitioning code. */
254 #define BB_UNPARTITIONED 0
256 /* Partitions, to be used when partitioning hot and cold basic blocks into
257 separate sections. */
258 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
259 #define BB_SET_PARTITION(bb, part) do { \
260 basic_block bb_ = (bb); \
261 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
265 #define BB_COPY_PARTITION(dstbb, srcbb) \
266 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
268 /* State of dominance information. */
272 DOM_NONE
, /* Not computed at all. */
273 DOM_NO_FAST_QUERY
, /* The data is OK, but the fast query data are not usable. */
274 DOM_OK
/* Everything is ok. */
277 /* What sort of profiling information we have. */
278 enum profile_status_d
283 PROFILE_LAST
/* Last value, used by profile streaming. */
286 /* A structure to group all the per-function control flow graph data.
287 The x_* prefixing is necessary because otherwise references to the
288 fields of this struct are interpreted as the defines for backward
289 source compatibility following the definition of this struct. */
290 struct GTY(()) control_flow_graph
{
291 /* Block pointers for the exit and entry of a function.
292 These are always the head and tail of the basic block list. */
293 basic_block x_entry_block_ptr
;
294 basic_block x_exit_block_ptr
;
296 /* Index by basic block number, get basic block struct info. */
297 vec
<basic_block
, va_gc
> *x_basic_block_info
;
299 /* Number of basic blocks in this flow graph. */
300 int x_n_basic_blocks
;
302 /* Number of edges in this flow graph. */
305 /* The first free basic block number. */
306 int x_last_basic_block
;
308 /* UIDs for LABEL_DECLs. */
311 /* Mapping of labels to their associated blocks. At present
312 only used for the gimple CFG. */
313 vec
<basic_block
, va_gc
> *x_label_to_block_map
;
315 enum profile_status_d x_profile_status
;
317 /* Whether the dominators and the postdominators are available. */
318 enum dom_state x_dom_computed
[2];
320 /* Number of basic blocks in the dominance tree. */
321 unsigned x_n_bbs_in_dom_tree
[2];
323 /* Maximal number of entities in the single jumptable. Used to estimate
324 final flowgraph size. */
325 int max_jumptable_ents
;
328 /* Defines for accessing the fields of the CFG structure for function FN. */
329 #define ENTRY_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_entry_block_ptr)
330 #define EXIT_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_exit_block_ptr)
331 #define basic_block_info_for_function(FN) ((FN)->cfg->x_basic_block_info)
332 #define n_basic_blocks_for_function(FN) ((FN)->cfg->x_n_basic_blocks)
333 #define n_edges_for_function(FN) ((FN)->cfg->x_n_edges)
334 #define last_basic_block_for_function(FN) ((FN)->cfg->x_last_basic_block)
335 #define label_to_block_map_for_function(FN) ((FN)->cfg->x_label_to_block_map)
336 #define profile_status_for_function(FN) ((FN)->cfg->x_profile_status)
338 #define BASIC_BLOCK_FOR_FUNCTION(FN,N) \
339 ((*basic_block_info_for_function(FN))[(N)])
340 #define SET_BASIC_BLOCK_FOR_FUNCTION(FN,N,BB) \
341 ((*basic_block_info_for_function(FN))[(N)] = (BB))
343 /* Defines for textual backward source compatibility. */
344 #define ENTRY_BLOCK_PTR (cfun->cfg->x_entry_block_ptr)
345 #define EXIT_BLOCK_PTR (cfun->cfg->x_exit_block_ptr)
346 #define basic_block_info (cfun->cfg->x_basic_block_info)
347 #define n_basic_blocks (cfun->cfg->x_n_basic_blocks)
348 #define n_edges (cfun->cfg->x_n_edges)
349 #define last_basic_block (cfun->cfg->x_last_basic_block)
350 #define label_to_block_map (cfun->cfg->x_label_to_block_map)
351 #define profile_status (cfun->cfg->x_profile_status)
353 #define BASIC_BLOCK(N) ((*basic_block_info)[(N)])
354 #define SET_BASIC_BLOCK(N,BB) ((*basic_block_info)[(N)] = (BB))
356 /* For iterating over basic blocks. */
357 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
358 for (BB = FROM; BB != TO; BB = BB->DIR)
360 #define FOR_EACH_BB_FN(BB, FN) \
361 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
363 #define FOR_EACH_BB(BB) FOR_EACH_BB_FN (BB, cfun)
365 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
366 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
368 #define FOR_EACH_BB_REVERSE(BB) FOR_EACH_BB_REVERSE_FN(BB, cfun)
370 /* For iterating over insns in basic block. */
371 #define FOR_BB_INSNS(BB, INSN) \
372 for ((INSN) = BB_HEAD (BB); \
373 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
374 (INSN) = NEXT_INSN (INSN))
376 /* For iterating over insns in basic block when we might remove the
378 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
379 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
380 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
381 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
383 #define FOR_BB_INSNS_REVERSE(BB, INSN) \
384 for ((INSN) = BB_END (BB); \
385 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
386 (INSN) = PREV_INSN (INSN))
388 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
389 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
390 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
391 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
393 /* Cycles through _all_ basic blocks, even the fake ones (entry and
396 #define FOR_ALL_BB(BB) \
397 for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
399 #define FOR_ALL_BB_FN(BB, FN) \
400 for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
403 /* Stuff for recording basic block info. */
405 #define BB_HEAD(B) (B)->il.x.head_
406 #define BB_END(B) (B)->il.x.rtl->end_
407 #define BB_HEADER(B) (B)->il.x.rtl->header_
408 #define BB_FOOTER(B) (B)->il.x.rtl->footer_
410 /* Special block numbers [markers] for entry and exit.
411 Neither of them is supposed to hold actual statements. */
412 #define ENTRY_BLOCK (0)
413 #define EXIT_BLOCK (1)
415 /* The two blocks that are always in the cfg. */
416 #define NUM_FIXED_BLOCKS (2)
418 #define set_block_for_insn(INSN, BB) (BLOCK_FOR_INSN (INSN) = BB)
420 extern void compute_bb_for_insn (void);
421 extern unsigned int free_bb_for_insn (void);
422 extern void update_bb_for_insn (basic_block
);
424 extern void insert_insn_on_edge (rtx
, edge
);
425 basic_block
split_edge_and_insert (edge
, rtx
);
427 extern void commit_one_edge_insertion (edge e
);
428 extern void commit_edge_insertions (void);
430 extern edge
unchecked_make_edge (basic_block
, basic_block
, int);
431 extern edge
cached_make_edge (sbitmap
, basic_block
, basic_block
, int);
432 extern edge
make_edge (basic_block
, basic_block
, int);
433 extern edge
make_single_succ_edge (basic_block
, basic_block
, int);
434 extern void remove_edge_raw (edge
);
435 extern void redirect_edge_succ (edge
, basic_block
);
436 extern edge
redirect_edge_succ_nodup (edge
, basic_block
);
437 extern void redirect_edge_pred (edge
, basic_block
);
438 extern basic_block
create_basic_block_structure (rtx
, rtx
, rtx
, basic_block
);
439 extern void clear_bb_flags (void);
440 extern void dump_bb_info (FILE *, basic_block
, int, int, bool, bool);
441 extern void dump_edge_info (FILE *, edge
, int, int);
442 extern void brief_dump_cfg (FILE *, int);
443 extern void clear_edges (void);
444 extern void scale_bbs_frequencies_int (basic_block
*, int, int, int);
445 extern void scale_bbs_frequencies_gcov_type (basic_block
*, int, gcov_type
,
448 /* Structure to group all of the information to process IF-THEN and
449 IF-THEN-ELSE blocks for the conditional execution support. This
450 needs to be in a public file in case the IFCVT macros call
451 functions passing the ce_if_block data structure. */
453 typedef struct ce_if_block
455 basic_block test_bb
; /* First test block. */
456 basic_block then_bb
; /* THEN block. */
457 basic_block else_bb
; /* ELSE block or NULL. */
458 basic_block join_bb
; /* Join THEN/ELSE blocks. */
459 basic_block last_test_bb
; /* Last bb to hold && or || tests. */
460 int num_multiple_test_blocks
; /* # of && and || basic blocks. */
461 int num_and_and_blocks
; /* # of && blocks. */
462 int num_or_or_blocks
; /* # of || blocks. */
463 int num_multiple_test_insns
; /* # of insns in && and || blocks. */
464 int and_and_p
; /* Complex test is &&. */
465 int num_then_insns
; /* # of insns in THEN block. */
466 int num_else_insns
; /* # of insns in ELSE block. */
467 int pass
; /* Pass number. */
470 /* This structure maintains an edge list vector. */
471 /* FIXME: Make this a vec<edge>. */
478 /* The base value for branch probability notes and edge probabilities. */
479 #define REG_BR_PROB_BASE 10000
481 /* This is the value which indicates no edge is present. */
482 #define EDGE_INDEX_NO_EDGE -1
484 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
485 if there is no edge between the 2 basic blocks. */
486 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
488 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
489 block which is either the pred or succ end of the indexed edge. */
490 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
491 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
493 /* INDEX_EDGE returns a pointer to the edge. */
494 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
496 /* Number of edges in the compressed edge list. */
497 #define NUM_EDGES(el) ((el)->num_edges)
499 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
500 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
501 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
503 /* BB is assumed to contain conditional jump. Return the branch edge. */
504 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
505 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
507 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
508 /* Return expected execution frequency of the edge E. */
509 #define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \
512 /* Return nonzero if edge is critical. */
513 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
514 && EDGE_COUNT ((e)->dest->preds) >= 2)
516 #define EDGE_COUNT(ev) vec_safe_length (ev)
517 #define EDGE_I(ev,i) (*ev)[(i)]
518 #define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
519 #define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
521 /* Returns true if BB has precisely one successor. */
524 single_succ_p (const_basic_block bb
)
526 return EDGE_COUNT (bb
->succs
) == 1;
529 /* Returns true if BB has precisely one predecessor. */
532 single_pred_p (const_basic_block bb
)
534 return EDGE_COUNT (bb
->preds
) == 1;
537 /* Returns the single successor edge of basic block BB. Aborts if
538 BB does not have exactly one successor. */
541 single_succ_edge (const_basic_block bb
)
543 gcc_checking_assert (single_succ_p (bb
));
544 return EDGE_SUCC (bb
, 0);
547 /* Returns the single predecessor edge of basic block BB. Aborts
548 if BB does not have exactly one predecessor. */
551 single_pred_edge (const_basic_block bb
)
553 gcc_checking_assert (single_pred_p (bb
));
554 return EDGE_PRED (bb
, 0);
557 /* Returns the single successor block of basic block BB. Aborts
558 if BB does not have exactly one successor. */
560 static inline basic_block
561 single_succ (const_basic_block bb
)
563 return single_succ_edge (bb
)->dest
;
566 /* Returns the single predecessor block of basic block BB. Aborts
567 if BB does not have exactly one predecessor.*/
569 static inline basic_block
570 single_pred (const_basic_block bb
)
572 return single_pred_edge (bb
)->src
;
575 /* Iterator object for edges. */
579 vec
<edge
, va_gc
> **container
;
582 static inline vec
<edge
, va_gc
> *
583 ei_container (edge_iterator i
)
585 gcc_checking_assert (i
.container
);
589 #define ei_start(iter) ei_start_1 (&(iter))
590 #define ei_last(iter) ei_last_1 (&(iter))
592 /* Return an iterator pointing to the start of an edge vector. */
593 static inline edge_iterator
594 ei_start_1 (vec
<edge
, va_gc
> **ev
)
604 /* Return an iterator pointing to the last element of an edge
606 static inline edge_iterator
607 ei_last_1 (vec
<edge
, va_gc
> **ev
)
611 i
.index
= EDGE_COUNT (*ev
) - 1;
617 /* Is the iterator `i' at the end of the sequence? */
619 ei_end_p (edge_iterator i
)
621 return (i
.index
== EDGE_COUNT (ei_container (i
)));
624 /* Is the iterator `i' at one position before the end of the
627 ei_one_before_end_p (edge_iterator i
)
629 return (i
.index
+ 1 == EDGE_COUNT (ei_container (i
)));
632 /* Advance the iterator to the next element. */
634 ei_next (edge_iterator
*i
)
636 gcc_checking_assert (i
->index
< EDGE_COUNT (ei_container (*i
)));
640 /* Move the iterator to the previous element. */
642 ei_prev (edge_iterator
*i
)
644 gcc_checking_assert (i
->index
> 0);
648 /* Return the edge pointed to by the iterator `i'. */
650 ei_edge (edge_iterator i
)
652 return EDGE_I (ei_container (i
), i
.index
);
655 /* Return an edge pointed to by the iterator. Do it safely so that
656 NULL is returned when the iterator is pointing at the end of the
659 ei_safe_edge (edge_iterator i
)
661 return !ei_end_p (i
) ? ei_edge (i
) : NULL
;
664 /* Return 1 if we should continue to iterate. Return 0 otherwise.
665 *Edge P is set to the next edge if we are to continue to iterate
666 and NULL otherwise. */
669 ei_cond (edge_iterator ei
, edge
*p
)
683 /* This macro serves as a convenient way to iterate each edge in a
684 vector of predecessor or successor edges. It must not be used when
685 an element might be removed during the traversal, otherwise
686 elements will be missed. Instead, use a for-loop like that shown
687 in the following pseudo-code:
689 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
698 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
699 for ((ITER) = ei_start ((EDGE_VEC)); \
700 ei_cond ((ITER), &(EDGE)); \
703 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
704 except for edge forwarding */
705 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
706 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
707 to care REG_DEAD notes. */
708 #define CLEANUP_THREADING 8 /* Do jump threading. */
709 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
711 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
712 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
715 extern void bitmap_intersection_of_succs (sbitmap
, sbitmap
*, basic_block
);
716 extern void bitmap_intersection_of_preds (sbitmap
, sbitmap
*, basic_block
);
717 extern void bitmap_union_of_succs (sbitmap
, sbitmap
*, basic_block
);
718 extern void bitmap_union_of_preds (sbitmap
, sbitmap
*, basic_block
);
721 extern struct edge_list
*pre_edge_lcm (int, sbitmap
*, sbitmap
*,
722 sbitmap
*, sbitmap
*, sbitmap
**,
724 extern struct edge_list
*pre_edge_rev_lcm (int, sbitmap
*,
725 sbitmap
*, sbitmap
*,
726 sbitmap
*, sbitmap
**,
728 extern void compute_available (sbitmap
*, sbitmap
*, sbitmap
*, sbitmap
*);
731 extern bool maybe_hot_bb_p (struct function
*, const_basic_block
);
732 extern bool maybe_hot_edge_p (edge
);
733 extern bool probably_never_executed_bb_p (struct function
*, const_basic_block
);
734 extern bool optimize_bb_for_size_p (const_basic_block
);
735 extern bool optimize_bb_for_speed_p (const_basic_block
);
736 extern bool optimize_edge_for_size_p (edge
);
737 extern bool optimize_edge_for_speed_p (edge
);
738 extern bool optimize_loop_for_size_p (struct loop
*);
739 extern bool optimize_loop_for_speed_p (struct loop
*);
740 extern bool optimize_loop_nest_for_size_p (struct loop
*);
741 extern bool optimize_loop_nest_for_speed_p (struct loop
*);
742 extern bool gimple_predicted_by_p (const_basic_block
, enum br_predictor
);
743 extern bool rtl_predicted_by_p (const_basic_block
, enum br_predictor
);
744 extern void gimple_predict_edge (edge
, enum br_predictor
, int);
745 extern void rtl_predict_edge (edge
, enum br_predictor
, int);
746 extern void predict_edge_def (edge
, enum br_predictor
, enum prediction
);
747 extern void guess_outgoing_edge_probabilities (basic_block
);
748 extern void remove_predictions_associated_with_edge (edge
);
749 extern bool edge_probability_reliable_p (const_edge
);
750 extern bool br_prob_note_reliable_p (const_rtx
);
751 extern bool predictable_edge_p (edge
);
754 extern void init_flow (struct function
*);
755 extern void debug_bb (basic_block
);
756 extern basic_block
debug_bb_n (int);
757 extern void dump_flow_info (FILE *, int);
758 extern void expunge_block (basic_block
);
759 extern void link_block (basic_block
, basic_block
);
760 extern void unlink_block (basic_block
);
761 extern void compact_blocks (void);
762 extern basic_block
alloc_block (void);
763 extern void alloc_aux_for_blocks (int);
764 extern void clear_aux_for_blocks (void);
765 extern void free_aux_for_blocks (void);
766 extern void alloc_aux_for_edge (edge
, int);
767 extern void alloc_aux_for_edges (int);
768 extern void clear_aux_for_edges (void);
769 extern void free_aux_for_edges (void);
772 extern void find_unreachable_blocks (void);
773 extern bool mark_dfs_back_edges (void);
774 struct edge_list
* create_edge_list (void);
775 void free_edge_list (struct edge_list
*);
776 void print_edge_list (FILE *, struct edge_list
*);
777 void verify_edge_list (FILE *, struct edge_list
*);
778 int find_edge_index (struct edge_list
*, basic_block
, basic_block
);
779 edge
find_edge (basic_block
, basic_block
);
780 extern void remove_fake_edges (void);
781 extern void remove_fake_exit_edges (void);
782 extern void add_noreturn_fake_exit_edges (void);
783 extern void connect_infinite_loops_to_exit (void);
784 extern int post_order_compute (int *, bool, bool);
785 extern basic_block
dfs_find_deadend (basic_block
);
786 extern int inverted_post_order_compute (int *);
787 extern int pre_and_rev_post_order_compute (int *, int *, bool);
788 extern int dfs_enumerate_from (basic_block
, int,
789 bool (*)(const_basic_block
, const void *),
790 basic_block
*, int, const void *);
791 extern void compute_dominance_frontiers (struct bitmap_head_def
*);
792 extern bitmap
compute_idf (bitmap
, struct bitmap_head_def
*);
795 extern rtx
block_label (basic_block
);
796 extern rtx
bb_note (basic_block
);
797 extern bool purge_all_dead_edges (void);
798 extern bool purge_dead_edges (basic_block
);
799 extern bool fixup_abnormal_edges (void);
800 extern basic_block
force_nonfallthru_and_redirect (edge
, basic_block
, rtx
);
801 extern bool contains_no_active_insn_p (const_basic_block
);
802 extern bool forwarder_block_p (const_basic_block
);
803 extern bool can_fallthru (basic_block
, basic_block
);
806 extern void find_many_sub_basic_blocks (sbitmap
);
807 extern void rtl_make_eh_edge (sbitmap
, basic_block
, rtx
);
809 enum replace_direction
{ dir_none
, dir_forward
, dir_backward
, dir_both
};
811 /* In cfgcleanup.c. */
812 extern bool cleanup_cfg (int);
813 extern int flow_find_cross_jump (basic_block
, basic_block
, rtx
*, rtx
*,
814 enum replace_direction
*);
815 extern int flow_find_head_matching_sequence (basic_block
, basic_block
,
818 extern bool delete_unreachable_blocks (void);
820 extern void update_br_prob_note (basic_block
);
821 extern bool inside_basic_block_p (const_rtx
);
822 extern bool control_flow_insn_p (const_rtx
);
823 extern rtx
get_last_bb_insn (basic_block
);
830 CDI_POST_DOMINATORS
= 2
833 extern enum dom_state
dom_info_state (enum cdi_direction
);
834 extern void set_dom_info_availability (enum cdi_direction
, enum dom_state
);
835 extern bool dom_info_available_p (enum cdi_direction
);
836 extern void calculate_dominance_info (enum cdi_direction
);
837 extern void free_dominance_info (enum cdi_direction
);
838 extern basic_block
nearest_common_dominator (enum cdi_direction
,
839 basic_block
, basic_block
);
840 extern basic_block
nearest_common_dominator_for_set (enum cdi_direction
,
842 extern void set_immediate_dominator (enum cdi_direction
, basic_block
,
844 extern basic_block
get_immediate_dominator (enum cdi_direction
, basic_block
);
845 extern bool dominated_by_p (enum cdi_direction
, const_basic_block
, const_basic_block
);
846 extern vec
<basic_block
> get_dominated_by (enum cdi_direction
, basic_block
);
847 extern vec
<basic_block
> get_dominated_by_region (enum cdi_direction
,
850 extern vec
<basic_block
> get_dominated_to_depth (enum cdi_direction
,
852 extern vec
<basic_block
> get_all_dominated_blocks (enum cdi_direction
,
854 extern void add_to_dominance_info (enum cdi_direction
, basic_block
);
855 extern void delete_from_dominance_info (enum cdi_direction
, basic_block
);
856 basic_block
recompute_dominator (enum cdi_direction
, basic_block
);
857 extern void redirect_immediate_dominators (enum cdi_direction
, basic_block
,
859 extern void iterate_fix_dominators (enum cdi_direction
,
860 vec
<basic_block
> , bool);
861 extern void verify_dominators (enum cdi_direction
);
862 extern basic_block
first_dom_son (enum cdi_direction
, basic_block
);
863 extern basic_block
next_dom_son (enum cdi_direction
, basic_block
);
864 unsigned bb_dom_dfs_in (enum cdi_direction
, basic_block
);
865 unsigned bb_dom_dfs_out (enum cdi_direction
, basic_block
);
867 extern edge
try_redirect_by_replacing_jump (edge
, basic_block
, bool);
868 extern void break_superblocks (void);
869 extern void relink_block_chain (bool);
870 extern void update_bb_profile_for_threading (basic_block
, int, gcov_type
, edge
);
871 extern void init_rtl_bb_info (basic_block
);
873 extern void initialize_original_copy_tables (void);
874 extern void free_original_copy_tables (void);
875 extern void set_bb_original (basic_block
, basic_block
);
876 extern basic_block
get_bb_original (basic_block
);
877 extern void set_bb_copy (basic_block
, basic_block
);
878 extern basic_block
get_bb_copy (basic_block
);
879 void set_loop_copy (struct loop
*, struct loop
*);
880 struct loop
*get_loop_copy (struct loop
*);
882 #include "cfghooks.h"
884 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
886 bb_has_eh_pred (basic_block bb
)
891 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
893 if (e
->flags
& EDGE_EH
)
899 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
901 bb_has_abnormal_pred (basic_block bb
)
906 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
908 if (e
->flags
& EDGE_ABNORMAL
)
914 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
916 find_fallthru_edge (vec
<edge
, va_gc
> *edges
)
921 FOR_EACH_EDGE (e
, ei
, edges
)
922 if (e
->flags
& EDGE_FALLTHRU
)
928 /* In cfgloopmanip.c. */
929 extern edge mfb_kj_edge
;
930 extern bool mfb_keep_just (edge
);
932 /* In cfgexpand.c. */
933 extern void rtl_profile_for_bb (basic_block
);
934 extern void rtl_profile_for_edge (edge
);
935 extern void default_rtl_profile (void);
938 extern gcov_working_set_t
*find_working_set(unsigned pct_times_10
);
940 /* Check tha probability is sane. */
943 check_probability (int prob
)
945 gcc_checking_assert (prob
>= 0 && prob
<= REG_BR_PROB_BASE
);
948 /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
949 Used to combine BB probabilities. */
952 combine_probabilities (int prob1
, int prob2
)
954 check_probability (prob1
);
955 check_probability (prob2
);
956 return RDIV (prob1
* prob2
, REG_BR_PROB_BASE
);
959 /* Apply probability PROB on frequency or count FREQ. */
961 static inline gcov_type
962 apply_probability (gcov_type freq
, int prob
)
964 check_probability (prob
);
965 return RDIV (freq
* prob
, REG_BR_PROB_BASE
);
968 /* Return inverse probability for PROB. */
971 inverse_probability (int prob1
)
973 check_probability (prob1
);
974 return REG_BR_PROB_BASE
- prob1
;
976 #endif /* GCC_BASIC_BLOCK_H */