1 /* Define control flow data structures for the CFG.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_BASIC_BLOCK_H
21 #define GCC_BASIC_BLOCK_H
27 /* Type we use to hold basic block counters. Should be at least
28 64bit. Although a counter cannot be negative, we use a signed
29 type, because erroneous negative counts can be generated when the
30 flow graph is manipulated by various optimizations. A signed type
31 makes those easy to detect. */
32 typedef HOST_WIDEST_INT gcov_type
;
33 typedef unsigned HOST_WIDEST_INT gcov_type_unsigned
;
35 /* Control flow edge information. */
36 struct GTY((user
)) edge_def
{
37 /* The two blocks at the ends of the edge. */
41 /* Instructions queued on the edge. */
42 union edge_def_insns
{
47 /* Auxiliary info specific to a pass. */
50 /* Location of any goto implicit in the edge. */
51 location_t goto_locus
;
53 /* The index number corresponding to this edge in the edge vector
55 unsigned int dest_idx
;
57 int flags
; /* see cfg-flags.def */
58 int probability
; /* biased by REG_BR_PROB_BASE */
59 gcov_type count
; /* Expected number of executions calculated
64 /* Garbage collection and PCH support for edge_def. */
65 extern void gt_ggc_mx (edge_def
*e
);
66 extern void gt_pch_nx (edge_def
*e
);
67 extern void gt_pch_nx (edge_def
*e
, gt_pointer_operator
, void *);
69 /* Masks for edge.flags. */
70 #define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
72 #include "cfg-flags.def"
73 LAST_CFG_EDGE_FLAG
/* this is only used for EDGE_ALL_FLAGS */
77 /* Bit mask for all edge flags. */
78 #define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
80 /* The following four flags all indicate something special about an edge.
81 Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
82 control flow transfers. */
83 #define EDGE_COMPLEX \
84 (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
86 /* Counter summary from the last set of coverage counts read by
88 extern const struct gcov_ctr_summary
*profile_info
;
90 /* Structure to gather statistic about profile consistency, per pass.
91 An array of this structure, indexed by pass static number, is allocated
92 in passes.c. The structure is defined here so that different CFG modes
93 can do their book-keeping via CFG hooks.
95 For every field[2], field[0] is the count before the pass runs, and
96 field[1] is the post-pass count. This allows us to monitor the effect
97 of each individual pass on the profile consistency.
99 This structure is not supposed to be used by anything other than passes.c
100 and one CFG hook per CFG mode. */
101 struct profile_record
103 /* The number of basic blocks where sum(freq) of the block's predecessors
104 doesn't match reasonably well with the incoming frequency. */
105 int num_mismatched_freq_in
[2];
106 /* Likewise for a basic block's successors. */
107 int num_mismatched_freq_out
[2];
108 /* The number of basic blocks where sum(count) of the block's predecessors
109 doesn't match reasonably well with the incoming frequency. */
110 int num_mismatched_count_in
[2];
111 /* Likewise for a basic block's successors. */
112 int num_mismatched_count_out
[2];
113 /* A weighted cost of the run-time of the function body. */
115 /* A weighted cost of the size of the function body. */
117 /* True iff this pass actually was run. */
121 /* Declared in cfgloop.h. */
124 struct GTY(()) rtl_bb_info
{
125 /* The first insn of the block is embedded into bb->il.x. */
126 /* The last insn of the block. */
129 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
130 and after the block. */
135 struct GTY(()) gimple_bb_info
{
136 /* Sequence of statements in this block. */
139 /* PHI nodes for this block. */
140 gimple_seq phi_nodes
;
143 /* A basic block is a sequence of instructions with only one entry and
144 only one exit. If any one of the instructions are executed, they
145 will all be executed, and in sequence from first to last.
147 There may be COND_EXEC instructions in the basic block. The
148 COND_EXEC *instructions* will be executed -- but if the condition
149 is false the conditionally executed *expressions* will of course
150 not be executed. We don't consider the conditionally executed
151 expression (which might have side-effects) to be in a separate
152 basic block because the program counter will always be at the same
153 location after the COND_EXEC instruction, regardless of whether the
154 condition is true or not.
156 Basic blocks need not start with a label nor end with a jump insn.
157 For example, a previous basic block may just "conditionally fall"
158 into the succeeding basic block, and the last basic block need not
159 end with a jump insn. Block 0 is a descendant of the entry block.
161 A basic block beginning with two labels cannot have notes between
164 Data for jump tables are stored in jump_insns that occur in no
165 basic block even though these insns can follow or precede insns in
168 /* Basic block information indexed by block number. */
169 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def
{
170 /* The edges into and out of the block. */
171 vec
<edge
, va_gc
> *preds
;
172 vec
<edge
, va_gc
> *succs
;
174 /* Auxiliary info specific to a pass. */
175 PTR
GTY ((skip (""))) aux
;
177 /* Innermost loop containing the block. */
178 struct loop
*loop_father
;
180 /* The dominance and postdominance information node. */
181 struct et_node
* GTY ((skip (""))) dom
[2];
183 /* Previous and next blocks in the chain. */
187 union basic_block_il_dependent
{
188 struct gimple_bb_info
GTY ((tag ("0"))) gimple
;
191 struct rtl_bb_info
* rtl
;
192 } GTY ((tag ("1"))) x
;
193 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il
;
195 /* Various flags. See cfg-flags.def. */
198 /* The index of this block. */
201 /* Expected number of executions: calculated in profile.c. */
204 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
207 /* The discriminator for this block. The discriminator distinguishes
208 among several basic blocks that share a common locus, allowing for
209 more accurate sample-based profiling. */
213 /* This ensures that struct gimple_bb_info is smaller than
214 struct rtl_bb_info, so that inlining the former into basic_block_def
215 is the better choice. */
216 typedef int __assert_gimple_bb_smaller_rtl_bb
217 [(int)sizeof(struct rtl_bb_info
)
218 - (int)sizeof (struct gimple_bb_info
)];
221 #define BB_FREQ_MAX 10000
223 /* Masks for basic_block.flags. */
224 #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
227 #include "cfg-flags.def"
228 LAST_CFG_BB_FLAG
/* this is only used for BB_ALL_FLAGS */
230 #undef DEF_BASIC_BLOCK_FLAG
232 /* Bit mask for all basic block flags. */
233 #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
235 /* Bit mask for all basic block flags that must be preserved. These are
236 the bit masks that are *not* cleared by clear_bb_flags. */
237 #define BB_FLAGS_TO_PRESERVE \
238 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
239 | BB_HOT_PARTITION | BB_COLD_PARTITION)
241 /* Dummy bitmask for convenience in the hot/cold partitioning code. */
242 #define BB_UNPARTITIONED 0
244 /* Partitions, to be used when partitioning hot and cold basic blocks into
245 separate sections. */
246 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
247 #define BB_SET_PARTITION(bb, part) do { \
248 basic_block bb_ = (bb); \
249 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
253 #define BB_COPY_PARTITION(dstbb, srcbb) \
254 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
256 /* State of dominance information. */
260 DOM_NONE
, /* Not computed at all. */
261 DOM_NO_FAST_QUERY
, /* The data is OK, but the fast query data are not usable. */
262 DOM_OK
/* Everything is ok. */
265 /* What sort of profiling information we have. */
266 enum profile_status_d
271 PROFILE_LAST
/* Last value, used by profile streaming. */
274 /* A structure to group all the per-function control flow graph data.
275 The x_* prefixing is necessary because otherwise references to the
276 fields of this struct are interpreted as the defines for backward
277 source compatibility following the definition of this struct. */
278 struct GTY(()) control_flow_graph
{
279 /* Block pointers for the exit and entry of a function.
280 These are always the head and tail of the basic block list. */
281 basic_block x_entry_block_ptr
;
282 basic_block x_exit_block_ptr
;
284 /* Index by basic block number, get basic block struct info. */
285 vec
<basic_block
, va_gc
> *x_basic_block_info
;
287 /* Number of basic blocks in this flow graph. */
288 int x_n_basic_blocks
;
290 /* Number of edges in this flow graph. */
293 /* The first free basic block number. */
294 int x_last_basic_block
;
296 /* UIDs for LABEL_DECLs. */
299 /* Mapping of labels to their associated blocks. At present
300 only used for the gimple CFG. */
301 vec
<basic_block
, va_gc
> *x_label_to_block_map
;
303 enum profile_status_d x_profile_status
;
305 /* Whether the dominators and the postdominators are available. */
306 enum dom_state x_dom_computed
[2];
308 /* Number of basic blocks in the dominance tree. */
309 unsigned x_n_bbs_in_dom_tree
[2];
311 /* Maximal number of entities in the single jumptable. Used to estimate
312 final flowgraph size. */
313 int max_jumptable_ents
;
316 /* Defines for accessing the fields of the CFG structure for function FN. */
317 #define ENTRY_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_entry_block_ptr)
318 #define EXIT_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_exit_block_ptr)
319 #define basic_block_info_for_function(FN) ((FN)->cfg->x_basic_block_info)
320 #define n_basic_blocks_for_function(FN) ((FN)->cfg->x_n_basic_blocks)
321 #define n_edges_for_function(FN) ((FN)->cfg->x_n_edges)
322 #define last_basic_block_for_function(FN) ((FN)->cfg->x_last_basic_block)
323 #define label_to_block_map_for_function(FN) ((FN)->cfg->x_label_to_block_map)
324 #define profile_status_for_function(FN) ((FN)->cfg->x_profile_status)
326 #define BASIC_BLOCK_FOR_FUNCTION(FN,N) \
327 ((*basic_block_info_for_function(FN))[(N)])
328 #define SET_BASIC_BLOCK_FOR_FUNCTION(FN,N,BB) \
329 ((*basic_block_info_for_function(FN))[(N)] = (BB))
331 /* Defines for textual backward source compatibility. */
332 #define ENTRY_BLOCK_PTR (cfun->cfg->x_entry_block_ptr)
333 #define EXIT_BLOCK_PTR (cfun->cfg->x_exit_block_ptr)
334 #define basic_block_info (cfun->cfg->x_basic_block_info)
335 #define n_basic_blocks (cfun->cfg->x_n_basic_blocks)
336 #define n_edges (cfun->cfg->x_n_edges)
337 #define last_basic_block (cfun->cfg->x_last_basic_block)
338 #define label_to_block_map (cfun->cfg->x_label_to_block_map)
339 #define profile_status (cfun->cfg->x_profile_status)
341 #define BASIC_BLOCK(N) ((*basic_block_info)[(N)])
342 #define SET_BASIC_BLOCK(N,BB) ((*basic_block_info)[(N)] = (BB))
344 /* For iterating over basic blocks. */
345 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
346 for (BB = FROM; BB != TO; BB = BB->DIR)
348 #define FOR_EACH_BB_FN(BB, FN) \
349 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
351 #define FOR_EACH_BB(BB) FOR_EACH_BB_FN (BB, cfun)
353 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
354 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
356 #define FOR_EACH_BB_REVERSE(BB) FOR_EACH_BB_REVERSE_FN(BB, cfun)
358 /* For iterating over insns in basic block. */
359 #define FOR_BB_INSNS(BB, INSN) \
360 for ((INSN) = BB_HEAD (BB); \
361 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
362 (INSN) = NEXT_INSN (INSN))
364 /* For iterating over insns in basic block when we might remove the
366 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
367 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
368 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
369 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
371 #define FOR_BB_INSNS_REVERSE(BB, INSN) \
372 for ((INSN) = BB_END (BB); \
373 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
374 (INSN) = PREV_INSN (INSN))
376 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
377 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
378 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
379 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
381 /* Cycles through _all_ basic blocks, even the fake ones (entry and
384 #define FOR_ALL_BB(BB) \
385 for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
387 #define FOR_ALL_BB_FN(BB, FN) \
388 for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
391 /* Stuff for recording basic block info. */
393 #define BB_HEAD(B) (B)->il.x.head_
394 #define BB_END(B) (B)->il.x.rtl->end_
395 #define BB_HEADER(B) (B)->il.x.rtl->header_
396 #define BB_FOOTER(B) (B)->il.x.rtl->footer_
398 /* Special block numbers [markers] for entry and exit.
399 Neither of them is supposed to hold actual statements. */
400 #define ENTRY_BLOCK (0)
401 #define EXIT_BLOCK (1)
403 /* The two blocks that are always in the cfg. */
404 #define NUM_FIXED_BLOCKS (2)
406 #define set_block_for_insn(INSN, BB) (BLOCK_FOR_INSN (INSN) = BB)
408 extern void compute_bb_for_insn (void);
409 extern unsigned int free_bb_for_insn (void);
410 extern void update_bb_for_insn (basic_block
);
412 extern void insert_insn_on_edge (rtx
, edge
);
413 basic_block
split_edge_and_insert (edge
, rtx
);
415 extern void commit_one_edge_insertion (edge e
);
416 extern void commit_edge_insertions (void);
418 extern edge
unchecked_make_edge (basic_block
, basic_block
, int);
419 extern edge
cached_make_edge (sbitmap
, basic_block
, basic_block
, int);
420 extern edge
make_edge (basic_block
, basic_block
, int);
421 extern edge
make_single_succ_edge (basic_block
, basic_block
, int);
422 extern void remove_edge_raw (edge
);
423 extern void redirect_edge_succ (edge
, basic_block
);
424 extern edge
redirect_edge_succ_nodup (edge
, basic_block
);
425 extern void redirect_edge_pred (edge
, basic_block
);
426 extern basic_block
create_basic_block_structure (rtx
, rtx
, rtx
, basic_block
);
427 extern void clear_bb_flags (void);
428 extern void dump_bb_info (FILE *, basic_block
, int, int, bool, bool);
429 extern void dump_edge_info (FILE *, edge
, int, int);
430 extern void debug (edge_def
&ref
);
431 extern void debug (edge_def
*ptr
);
432 extern void brief_dump_cfg (FILE *, int);
433 extern void clear_edges (void);
434 extern void scale_bbs_frequencies_int (basic_block
*, int, int, int);
435 extern void scale_bbs_frequencies_gcov_type (basic_block
*, int, gcov_type
,
438 /* Structure to group all of the information to process IF-THEN and
439 IF-THEN-ELSE blocks for the conditional execution support. This
440 needs to be in a public file in case the IFCVT macros call
441 functions passing the ce_if_block data structure. */
443 typedef struct ce_if_block
445 basic_block test_bb
; /* First test block. */
446 basic_block then_bb
; /* THEN block. */
447 basic_block else_bb
; /* ELSE block or NULL. */
448 basic_block join_bb
; /* Join THEN/ELSE blocks. */
449 basic_block last_test_bb
; /* Last bb to hold && or || tests. */
450 int num_multiple_test_blocks
; /* # of && and || basic blocks. */
451 int num_and_and_blocks
; /* # of && blocks. */
452 int num_or_or_blocks
; /* # of || blocks. */
453 int num_multiple_test_insns
; /* # of insns in && and || blocks. */
454 int and_and_p
; /* Complex test is &&. */
455 int num_then_insns
; /* # of insns in THEN block. */
456 int num_else_insns
; /* # of insns in ELSE block. */
457 int pass
; /* Pass number. */
460 /* This structure maintains an edge list vector. */
461 /* FIXME: Make this a vec<edge>. */
468 /* The base value for branch probability notes and edge probabilities. */
469 #define REG_BR_PROB_BASE 10000
471 /* This is the value which indicates no edge is present. */
472 #define EDGE_INDEX_NO_EDGE -1
474 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
475 if there is no edge between the 2 basic blocks. */
476 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
478 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
479 block which is either the pred or succ end of the indexed edge. */
480 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
481 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
483 /* INDEX_EDGE returns a pointer to the edge. */
484 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
486 /* Number of edges in the compressed edge list. */
487 #define NUM_EDGES(el) ((el)->num_edges)
489 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
490 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
491 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
493 /* BB is assumed to contain conditional jump. Return the branch edge. */
494 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
495 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
497 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
498 /* Return expected execution frequency of the edge E. */
499 #define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \
502 /* Compute a scale factor (or probability) suitable for scaling of
503 gcov_type values via apply_probability() and apply_scale(). */
504 #define GCOV_COMPUTE_SCALE(num,den) \
505 ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
507 /* Return nonzero if edge is critical. */
508 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
509 && EDGE_COUNT ((e)->dest->preds) >= 2)
511 #define EDGE_COUNT(ev) vec_safe_length (ev)
512 #define EDGE_I(ev,i) (*ev)[(i)]
513 #define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
514 #define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
516 /* Returns true if BB has precisely one successor. */
519 single_succ_p (const_basic_block bb
)
521 return EDGE_COUNT (bb
->succs
) == 1;
524 /* Returns true if BB has precisely one predecessor. */
527 single_pred_p (const_basic_block bb
)
529 return EDGE_COUNT (bb
->preds
) == 1;
532 /* Returns the single successor edge of basic block BB. Aborts if
533 BB does not have exactly one successor. */
536 single_succ_edge (const_basic_block bb
)
538 gcc_checking_assert (single_succ_p (bb
));
539 return EDGE_SUCC (bb
, 0);
542 /* Returns the single predecessor edge of basic block BB. Aborts
543 if BB does not have exactly one predecessor. */
546 single_pred_edge (const_basic_block bb
)
548 gcc_checking_assert (single_pred_p (bb
));
549 return EDGE_PRED (bb
, 0);
552 /* Returns the single successor block of basic block BB. Aborts
553 if BB does not have exactly one successor. */
555 static inline basic_block
556 single_succ (const_basic_block bb
)
558 return single_succ_edge (bb
)->dest
;
561 /* Returns the single predecessor block of basic block BB. Aborts
562 if BB does not have exactly one predecessor.*/
564 static inline basic_block
565 single_pred (const_basic_block bb
)
567 return single_pred_edge (bb
)->src
;
570 /* Iterator object for edges. */
574 vec
<edge
, va_gc
> **container
;
577 static inline vec
<edge
, va_gc
> *
578 ei_container (edge_iterator i
)
580 gcc_checking_assert (i
.container
);
584 #define ei_start(iter) ei_start_1 (&(iter))
585 #define ei_last(iter) ei_last_1 (&(iter))
587 /* Return an iterator pointing to the start of an edge vector. */
588 static inline edge_iterator
589 ei_start_1 (vec
<edge
, va_gc
> **ev
)
599 /* Return an iterator pointing to the last element of an edge
601 static inline edge_iterator
602 ei_last_1 (vec
<edge
, va_gc
> **ev
)
606 i
.index
= EDGE_COUNT (*ev
) - 1;
612 /* Is the iterator `i' at the end of the sequence? */
614 ei_end_p (edge_iterator i
)
616 return (i
.index
== EDGE_COUNT (ei_container (i
)));
619 /* Is the iterator `i' at one position before the end of the
622 ei_one_before_end_p (edge_iterator i
)
624 return (i
.index
+ 1 == EDGE_COUNT (ei_container (i
)));
627 /* Advance the iterator to the next element. */
629 ei_next (edge_iterator
*i
)
631 gcc_checking_assert (i
->index
< EDGE_COUNT (ei_container (*i
)));
635 /* Move the iterator to the previous element. */
637 ei_prev (edge_iterator
*i
)
639 gcc_checking_assert (i
->index
> 0);
643 /* Return the edge pointed to by the iterator `i'. */
645 ei_edge (edge_iterator i
)
647 return EDGE_I (ei_container (i
), i
.index
);
650 /* Return an edge pointed to by the iterator. Do it safely so that
651 NULL is returned when the iterator is pointing at the end of the
654 ei_safe_edge (edge_iterator i
)
656 return !ei_end_p (i
) ? ei_edge (i
) : NULL
;
659 /* Return 1 if we should continue to iterate. Return 0 otherwise.
660 *Edge P is set to the next edge if we are to continue to iterate
661 and NULL otherwise. */
664 ei_cond (edge_iterator ei
, edge
*p
)
678 /* This macro serves as a convenient way to iterate each edge in a
679 vector of predecessor or successor edges. It must not be used when
680 an element might be removed during the traversal, otherwise
681 elements will be missed. Instead, use a for-loop like that shown
682 in the following pseudo-code:
684 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
693 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
694 for ((ITER) = ei_start ((EDGE_VEC)); \
695 ei_cond ((ITER), &(EDGE)); \
698 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
699 except for edge forwarding */
700 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
701 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
702 to care REG_DEAD notes. */
703 #define CLEANUP_THREADING 8 /* Do jump threading. */
704 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
706 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
707 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
710 extern void bitmap_intersection_of_succs (sbitmap
, sbitmap
*, basic_block
);
711 extern void bitmap_intersection_of_preds (sbitmap
, sbitmap
*, basic_block
);
712 extern void bitmap_union_of_succs (sbitmap
, sbitmap
*, basic_block
);
713 extern void bitmap_union_of_preds (sbitmap
, sbitmap
*, basic_block
);
716 extern struct edge_list
*pre_edge_lcm (int, sbitmap
*, sbitmap
*,
717 sbitmap
*, sbitmap
*, sbitmap
**,
719 extern struct edge_list
*pre_edge_rev_lcm (int, sbitmap
*,
720 sbitmap
*, sbitmap
*,
721 sbitmap
*, sbitmap
**,
723 extern void compute_available (sbitmap
*, sbitmap
*, sbitmap
*, sbitmap
*);
726 extern bool maybe_hot_bb_p (struct function
*, const_basic_block
);
727 extern bool maybe_hot_edge_p (edge
);
728 extern bool probably_never_executed_bb_p (struct function
*, const_basic_block
);
729 extern bool optimize_bb_for_size_p (const_basic_block
);
730 extern bool optimize_bb_for_speed_p (const_basic_block
);
731 extern bool optimize_edge_for_size_p (edge
);
732 extern bool optimize_edge_for_speed_p (edge
);
733 extern bool optimize_loop_for_size_p (struct loop
*);
734 extern bool optimize_loop_for_speed_p (struct loop
*);
735 extern bool optimize_loop_nest_for_size_p (struct loop
*);
736 extern bool optimize_loop_nest_for_speed_p (struct loop
*);
737 extern bool gimple_predicted_by_p (const_basic_block
, enum br_predictor
);
738 extern bool rtl_predicted_by_p (const_basic_block
, enum br_predictor
);
739 extern void gimple_predict_edge (edge
, enum br_predictor
, int);
740 extern void rtl_predict_edge (edge
, enum br_predictor
, int);
741 extern void predict_edge_def (edge
, enum br_predictor
, enum prediction
);
742 extern void guess_outgoing_edge_probabilities (basic_block
);
743 extern void remove_predictions_associated_with_edge (edge
);
744 extern bool edge_probability_reliable_p (const_edge
);
745 extern bool br_prob_note_reliable_p (const_rtx
);
746 extern bool predictable_edge_p (edge
);
749 extern void init_flow (struct function
*);
750 extern void debug_bb (basic_block
);
751 extern basic_block
debug_bb_n (int);
752 extern void dump_flow_info (FILE *, int);
753 extern void expunge_block (basic_block
);
754 extern void link_block (basic_block
, basic_block
);
755 extern void unlink_block (basic_block
);
756 extern void compact_blocks (void);
757 extern basic_block
alloc_block (void);
758 extern void alloc_aux_for_blocks (int);
759 extern void clear_aux_for_blocks (void);
760 extern void free_aux_for_blocks (void);
761 extern void alloc_aux_for_edge (edge
, int);
762 extern void alloc_aux_for_edges (int);
763 extern void clear_aux_for_edges (void);
764 extern void free_aux_for_edges (void);
767 extern void find_unreachable_blocks (void);
768 extern bool mark_dfs_back_edges (void);
769 struct edge_list
* create_edge_list (void);
770 void free_edge_list (struct edge_list
*);
771 void print_edge_list (FILE *, struct edge_list
*);
772 void verify_edge_list (FILE *, struct edge_list
*);
773 int find_edge_index (struct edge_list
*, basic_block
, basic_block
);
774 edge
find_edge (basic_block
, basic_block
);
775 extern void remove_fake_edges (void);
776 extern void remove_fake_exit_edges (void);
777 extern void add_noreturn_fake_exit_edges (void);
778 extern void connect_infinite_loops_to_exit (void);
779 extern int post_order_compute (int *, bool, bool);
780 extern basic_block
dfs_find_deadend (basic_block
);
781 extern int inverted_post_order_compute (int *);
782 extern int pre_and_rev_post_order_compute (int *, int *, bool);
783 extern int dfs_enumerate_from (basic_block
, int,
784 bool (*)(const_basic_block
, const void *),
785 basic_block
*, int, const void *);
786 extern void compute_dominance_frontiers (struct bitmap_head_def
*);
787 extern bitmap
compute_idf (bitmap
, struct bitmap_head_def
*);
790 extern rtx
block_label (basic_block
);
791 extern rtx
bb_note (basic_block
);
792 extern bool purge_all_dead_edges (void);
793 extern bool purge_dead_edges (basic_block
);
794 extern bool fixup_abnormal_edges (void);
795 extern basic_block
force_nonfallthru_and_redirect (edge
, basic_block
, rtx
);
796 extern bool contains_no_active_insn_p (const_basic_block
);
797 extern bool forwarder_block_p (const_basic_block
);
798 extern bool can_fallthru (basic_block
, basic_block
);
799 extern void emit_barrier_after_bb (basic_block bb
);
802 extern void find_many_sub_basic_blocks (sbitmap
);
803 extern void rtl_make_eh_edge (sbitmap
, basic_block
, rtx
);
805 enum replace_direction
{ dir_none
, dir_forward
, dir_backward
, dir_both
};
807 /* In cfgcleanup.c. */
808 extern bool cleanup_cfg (int);
809 extern int flow_find_cross_jump (basic_block
, basic_block
, rtx
*, rtx
*,
810 enum replace_direction
*);
811 extern int flow_find_head_matching_sequence (basic_block
, basic_block
,
814 extern bool delete_unreachable_blocks (void);
816 extern void update_br_prob_note (basic_block
);
817 extern bool inside_basic_block_p (const_rtx
);
818 extern bool control_flow_insn_p (const_rtx
);
819 extern rtx
get_last_bb_insn (basic_block
);
826 CDI_POST_DOMINATORS
= 2
829 extern enum dom_state
dom_info_state (enum cdi_direction
);
830 extern void set_dom_info_availability (enum cdi_direction
, enum dom_state
);
831 extern bool dom_info_available_p (enum cdi_direction
);
832 extern void calculate_dominance_info (enum cdi_direction
);
833 extern void free_dominance_info (enum cdi_direction
);
834 extern basic_block
nearest_common_dominator (enum cdi_direction
,
835 basic_block
, basic_block
);
836 extern basic_block
nearest_common_dominator_for_set (enum cdi_direction
,
838 extern void set_immediate_dominator (enum cdi_direction
, basic_block
,
840 extern basic_block
get_immediate_dominator (enum cdi_direction
, basic_block
);
841 extern bool dominated_by_p (enum cdi_direction
, const_basic_block
, const_basic_block
);
842 extern vec
<basic_block
> get_dominated_by (enum cdi_direction
, basic_block
);
843 extern vec
<basic_block
> get_dominated_by_region (enum cdi_direction
,
846 extern vec
<basic_block
> get_dominated_to_depth (enum cdi_direction
,
848 extern vec
<basic_block
> get_all_dominated_blocks (enum cdi_direction
,
850 extern void add_to_dominance_info (enum cdi_direction
, basic_block
);
851 extern void delete_from_dominance_info (enum cdi_direction
, basic_block
);
852 basic_block
recompute_dominator (enum cdi_direction
, basic_block
);
853 extern void redirect_immediate_dominators (enum cdi_direction
, basic_block
,
855 extern void iterate_fix_dominators (enum cdi_direction
,
856 vec
<basic_block
> , bool);
857 extern void verify_dominators (enum cdi_direction
);
858 extern basic_block
first_dom_son (enum cdi_direction
, basic_block
);
859 extern basic_block
next_dom_son (enum cdi_direction
, basic_block
);
860 unsigned bb_dom_dfs_in (enum cdi_direction
, basic_block
);
861 unsigned bb_dom_dfs_out (enum cdi_direction
, basic_block
);
863 extern edge
try_redirect_by_replacing_jump (edge
, basic_block
, bool);
864 extern void break_superblocks (void);
865 extern void relink_block_chain (bool);
866 extern void update_bb_profile_for_threading (basic_block
, int, gcov_type
, edge
);
867 extern void init_rtl_bb_info (basic_block
);
869 extern void initialize_original_copy_tables (void);
870 extern void free_original_copy_tables (void);
871 extern void set_bb_original (basic_block
, basic_block
);
872 extern basic_block
get_bb_original (basic_block
);
873 extern void set_bb_copy (basic_block
, basic_block
);
874 extern basic_block
get_bb_copy (basic_block
);
875 void set_loop_copy (struct loop
*, struct loop
*);
876 struct loop
*get_loop_copy (struct loop
*);
878 #include "cfghooks.h"
880 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
882 bb_has_eh_pred (basic_block bb
)
887 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
889 if (e
->flags
& EDGE_EH
)
895 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
897 bb_has_abnormal_pred (basic_block bb
)
902 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
904 if (e
->flags
& EDGE_ABNORMAL
)
910 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
912 find_fallthru_edge (vec
<edge
, va_gc
> *edges
)
917 FOR_EACH_EDGE (e
, ei
, edges
)
918 if (e
->flags
& EDGE_FALLTHRU
)
924 /* In cfgloopmanip.c. */
925 extern edge mfb_kj_edge
;
926 extern bool mfb_keep_just (edge
);
928 /* In cfgexpand.c. */
929 extern void rtl_profile_for_bb (basic_block
);
930 extern void rtl_profile_for_edge (edge
);
931 extern void default_rtl_profile (void);
934 typedef struct gcov_working_set_info gcov_working_set_t
;
935 extern gcov_working_set_t
*find_working_set(unsigned pct_times_10
);
937 /* Check tha probability is sane. */
940 check_probability (int prob
)
942 gcc_checking_assert (prob
>= 0 && prob
<= REG_BR_PROB_BASE
);
945 /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
946 Used to combine BB probabilities. */
949 combine_probabilities (int prob1
, int prob2
)
951 check_probability (prob1
);
952 check_probability (prob2
);
953 return RDIV (prob1
* prob2
, REG_BR_PROB_BASE
);
956 /* Apply scale factor SCALE on frequency or count FREQ. Use this
957 interface when potentially scaling up, so that SCALE is not
958 constrained to be < REG_BR_PROB_BASE. */
960 static inline gcov_type
961 apply_scale (gcov_type freq
, int scale
)
963 return RDIV (freq
* scale
, REG_BR_PROB_BASE
);
966 /* Apply probability PROB on frequency or count FREQ. */
968 static inline gcov_type
969 apply_probability (gcov_type freq
, int prob
)
971 check_probability (prob
);
972 return apply_scale (freq
, prob
);
975 /* Return inverse probability for PROB. */
978 inverse_probability (int prob1
)
980 check_probability (prob1
);
981 return REG_BR_PROB_BASE
- prob1
;
983 #endif /* GCC_BASIC_BLOCK_H */