2013-09-13 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / basic-block.h
blobad04d4de83e42f970c78dffd630e3166fb867176
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
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_BASIC_BLOCK_H
21 #define GCC_BASIC_BLOCK_H
23 #include "predict.h"
24 #include "vec.h"
25 #include "function.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. */
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. */
51 location_t goto_locus;
53 /* The index number corresponding to this edge in the edge vector
54 dest->preds. */
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
60 in profile.c */
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 ,
71 enum cfg_edge_flags {
72 #include "cfg-flags.def"
73 LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */
75 #undef DEF_EDGE_FLAG
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
87 profile.c. */
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. */
114 gcov_type time[2];
115 /* A weighted cost of the size of the function body. */
116 int size[2];
117 /* True iff this pass actually was run. */
118 bool run;
121 /* Declared in cfgloop.h. */
122 struct loop;
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. */
127 rtx end_;
129 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
130 and after the block. */
131 rtx header_;
132 rtx footer_;
135 struct GTY(()) gimple_bb_info {
136 /* Sequence of statements in this block. */
137 gimple_seq seq;
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
162 the labels.
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
166 basic blocks. */
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. */
184 basic_block prev_bb;
185 basic_block next_bb;
187 union basic_block_il_dependent {
188 struct gimple_bb_info GTY ((tag ("0"))) gimple;
189 struct {
190 rtx head_;
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. */
196 int flags;
198 /* The index of this block. */
199 int index;
201 /* Expected number of executions: calculated in profile.c. */
202 gcov_type count;
204 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
205 int frequency;
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. */
210 int discriminator;
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 ,
225 enum cfg_bb_flags
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)) \
250 | (part)); \
251 } while (0)
253 #define BB_COPY_PARTITION(dstbb, srcbb) \
254 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
256 /* State of dominance information. */
258 enum dom_state
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
268 PROFILE_ABSENT,
269 PROFILE_GUESSED,
270 PROFILE_READ,
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. */
291 int x_n_edges;
293 /* The first free basic block number. */
294 int x_last_basic_block;
296 /* UIDs for LABEL_DECLs. */
297 int last_label_uid;
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
365 current insn. */
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
382 exit block). */
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,
436 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. */
458 } ce_if_block_t;
460 /* This structure maintains an edge list vector. */
461 /* FIXME: Make this a vec<edge>. */
462 struct edge_list
464 int num_edges;
465 edge *index_to_edge;
468 /* Class to compute and manage control dependences on an edge-list. */
469 class control_dependences
471 public:
472 control_dependences (edge_list *);
473 ~control_dependences ();
474 bitmap get_edges_dependent_on (int);
475 edge get_edge (int);
477 private:
478 void set_control_dependence_map_bit (basic_block, int);
479 void clear_control_dependence_bitmap (basic_block);
480 void find_control_dependence (int);
481 vec<bitmap> control_dependence_map;
482 edge_list *el;
485 /* The base value for branch probability notes and edge probabilities. */
486 #define REG_BR_PROB_BASE 10000
488 /* This is the value which indicates no edge is present. */
489 #define EDGE_INDEX_NO_EDGE -1
491 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
492 if there is no edge between the 2 basic blocks. */
493 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
495 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
496 block which is either the pred or succ end of the indexed edge. */
497 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
498 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
500 /* INDEX_EDGE returns a pointer to the edge. */
501 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
503 /* Number of edges in the compressed edge list. */
504 #define NUM_EDGES(el) ((el)->num_edges)
506 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
507 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
508 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
510 /* BB is assumed to contain conditional jump. Return the branch edge. */
511 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
512 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
514 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
515 /* Return expected execution frequency of the edge E. */
516 #define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \
517 REG_BR_PROB_BASE)
519 /* Compute a scale factor (or probability) suitable for scaling of
520 gcov_type values via apply_probability() and apply_scale(). */
521 #define GCOV_COMPUTE_SCALE(num,den) \
522 ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
524 /* Return nonzero if edge is critical. */
525 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
526 && EDGE_COUNT ((e)->dest->preds) >= 2)
528 #define EDGE_COUNT(ev) vec_safe_length (ev)
529 #define EDGE_I(ev,i) (*ev)[(i)]
530 #define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
531 #define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
533 /* Returns true if BB has precisely one successor. */
535 static inline bool
536 single_succ_p (const_basic_block bb)
538 return EDGE_COUNT (bb->succs) == 1;
541 /* Returns true if BB has precisely one predecessor. */
543 static inline bool
544 single_pred_p (const_basic_block bb)
546 return EDGE_COUNT (bb->preds) == 1;
549 /* Returns the single successor edge of basic block BB. Aborts if
550 BB does not have exactly one successor. */
552 static inline edge
553 single_succ_edge (const_basic_block bb)
555 gcc_checking_assert (single_succ_p (bb));
556 return EDGE_SUCC (bb, 0);
559 /* Returns the single predecessor edge of basic block BB. Aborts
560 if BB does not have exactly one predecessor. */
562 static inline edge
563 single_pred_edge (const_basic_block bb)
565 gcc_checking_assert (single_pred_p (bb));
566 return EDGE_PRED (bb, 0);
569 /* Returns the single successor block of basic block BB. Aborts
570 if BB does not have exactly one successor. */
572 static inline basic_block
573 single_succ (const_basic_block bb)
575 return single_succ_edge (bb)->dest;
578 /* Returns the single predecessor block of basic block BB. Aborts
579 if BB does not have exactly one predecessor.*/
581 static inline basic_block
582 single_pred (const_basic_block bb)
584 return single_pred_edge (bb)->src;
587 /* Iterator object for edges. */
589 typedef struct {
590 unsigned index;
591 vec<edge, va_gc> **container;
592 } edge_iterator;
594 static inline vec<edge, va_gc> *
595 ei_container (edge_iterator i)
597 gcc_checking_assert (i.container);
598 return *i.container;
601 #define ei_start(iter) ei_start_1 (&(iter))
602 #define ei_last(iter) ei_last_1 (&(iter))
604 /* Return an iterator pointing to the start of an edge vector. */
605 static inline edge_iterator
606 ei_start_1 (vec<edge, va_gc> **ev)
608 edge_iterator i;
610 i.index = 0;
611 i.container = ev;
613 return i;
616 /* Return an iterator pointing to the last element of an edge
617 vector. */
618 static inline edge_iterator
619 ei_last_1 (vec<edge, va_gc> **ev)
621 edge_iterator i;
623 i.index = EDGE_COUNT (*ev) - 1;
624 i.container = ev;
626 return i;
629 /* Is the iterator `i' at the end of the sequence? */
630 static inline bool
631 ei_end_p (edge_iterator i)
633 return (i.index == EDGE_COUNT (ei_container (i)));
636 /* Is the iterator `i' at one position before the end of the
637 sequence? */
638 static inline bool
639 ei_one_before_end_p (edge_iterator i)
641 return (i.index + 1 == EDGE_COUNT (ei_container (i)));
644 /* Advance the iterator to the next element. */
645 static inline void
646 ei_next (edge_iterator *i)
648 gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
649 i->index++;
652 /* Move the iterator to the previous element. */
653 static inline void
654 ei_prev (edge_iterator *i)
656 gcc_checking_assert (i->index > 0);
657 i->index--;
660 /* Return the edge pointed to by the iterator `i'. */
661 static inline edge
662 ei_edge (edge_iterator i)
664 return EDGE_I (ei_container (i), i.index);
667 /* Return an edge pointed to by the iterator. Do it safely so that
668 NULL is returned when the iterator is pointing at the end of the
669 sequence. */
670 static inline edge
671 ei_safe_edge (edge_iterator i)
673 return !ei_end_p (i) ? ei_edge (i) : NULL;
676 /* Return 1 if we should continue to iterate. Return 0 otherwise.
677 *Edge P is set to the next edge if we are to continue to iterate
678 and NULL otherwise. */
680 static inline bool
681 ei_cond (edge_iterator ei, edge *p)
683 if (!ei_end_p (ei))
685 *p = ei_edge (ei);
686 return 1;
688 else
690 *p = NULL;
691 return 0;
695 /* This macro serves as a convenient way to iterate each edge in a
696 vector of predecessor or successor edges. It must not be used when
697 an element might be removed during the traversal, otherwise
698 elements will be missed. Instead, use a for-loop like that shown
699 in the following pseudo-code:
701 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
703 IF (e != taken_edge)
704 remove_edge (e);
705 ELSE
706 ei_next (&ei);
710 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
711 for ((ITER) = ei_start ((EDGE_VEC)); \
712 ei_cond ((ITER), &(EDGE)); \
713 ei_next (&(ITER)))
715 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
716 except for edge forwarding */
717 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
718 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
719 to care REG_DEAD notes. */
720 #define CLEANUP_THREADING 8 /* Do jump threading. */
721 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
722 insns. */
723 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
724 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
726 /* In cfganal.c */
727 extern void bitmap_intersection_of_succs (sbitmap, sbitmap *, basic_block);
728 extern void bitmap_intersection_of_preds (sbitmap, sbitmap *, basic_block);
729 extern void bitmap_union_of_succs (sbitmap, sbitmap *, basic_block);
730 extern void bitmap_union_of_preds (sbitmap, sbitmap *, basic_block);
732 /* In lcm.c */
733 extern struct edge_list *pre_edge_lcm (int, sbitmap *, sbitmap *,
734 sbitmap *, sbitmap *, sbitmap **,
735 sbitmap **);
736 extern struct edge_list *pre_edge_rev_lcm (int, sbitmap *,
737 sbitmap *, sbitmap *,
738 sbitmap *, sbitmap **,
739 sbitmap **);
740 extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
742 /* In predict.c */
743 extern bool maybe_hot_bb_p (struct function *, const_basic_block);
744 extern bool maybe_hot_edge_p (edge);
745 extern bool probably_never_executed_bb_p (struct function *, const_basic_block);
746 extern bool probably_never_executed_edge_p (struct function *, edge);
747 extern bool optimize_bb_for_size_p (const_basic_block);
748 extern bool optimize_bb_for_speed_p (const_basic_block);
749 extern bool optimize_edge_for_size_p (edge);
750 extern bool optimize_edge_for_speed_p (edge);
751 extern bool optimize_loop_for_size_p (struct loop *);
752 extern bool optimize_loop_for_speed_p (struct loop *);
753 extern bool optimize_loop_nest_for_size_p (struct loop *);
754 extern bool optimize_loop_nest_for_speed_p (struct loop *);
755 extern bool gimple_predicted_by_p (const_basic_block, enum br_predictor);
756 extern bool rtl_predicted_by_p (const_basic_block, enum br_predictor);
757 extern void gimple_predict_edge (edge, enum br_predictor, int);
758 extern void rtl_predict_edge (edge, enum br_predictor, int);
759 extern void predict_edge_def (edge, enum br_predictor, enum prediction);
760 extern void guess_outgoing_edge_probabilities (basic_block);
761 extern void remove_predictions_associated_with_edge (edge);
762 extern bool edge_probability_reliable_p (const_edge);
763 extern bool br_prob_note_reliable_p (const_rtx);
764 extern bool predictable_edge_p (edge);
766 /* In cfg.c */
767 extern void init_flow (struct function *);
768 extern void debug_bb (basic_block);
769 extern basic_block debug_bb_n (int);
770 extern void dump_flow_info (FILE *, int);
771 extern void expunge_block (basic_block);
772 extern void link_block (basic_block, basic_block);
773 extern void unlink_block (basic_block);
774 extern void compact_blocks (void);
775 extern basic_block alloc_block (void);
776 extern void alloc_aux_for_blocks (int);
777 extern void clear_aux_for_blocks (void);
778 extern void free_aux_for_blocks (void);
779 extern void alloc_aux_for_edge (edge, int);
780 extern void alloc_aux_for_edges (int);
781 extern void clear_aux_for_edges (void);
782 extern void free_aux_for_edges (void);
784 /* In cfganal.c */
785 extern void find_unreachable_blocks (void);
786 extern bool mark_dfs_back_edges (void);
787 struct edge_list * create_edge_list (void);
788 void free_edge_list (struct edge_list *);
789 void print_edge_list (FILE *, struct edge_list *);
790 void verify_edge_list (FILE *, struct edge_list *);
791 int find_edge_index (struct edge_list *, basic_block, basic_block);
792 edge find_edge (basic_block, basic_block);
793 extern void remove_fake_edges (void);
794 extern void remove_fake_exit_edges (void);
795 extern void add_noreturn_fake_exit_edges (void);
796 extern void connect_infinite_loops_to_exit (void);
797 extern int post_order_compute (int *, bool, bool);
798 extern basic_block dfs_find_deadend (basic_block);
799 extern int inverted_post_order_compute (int *);
800 extern int pre_and_rev_post_order_compute (int *, int *, bool);
801 extern int dfs_enumerate_from (basic_block, int,
802 bool (*)(const_basic_block, const void *),
803 basic_block *, int, const void *);
804 extern void compute_dominance_frontiers (struct bitmap_head_def *);
805 extern bitmap compute_idf (bitmap, struct bitmap_head_def *);
807 /* In cfgrtl.c */
808 extern rtx block_label (basic_block);
809 extern rtx bb_note (basic_block);
810 extern bool purge_all_dead_edges (void);
811 extern bool purge_dead_edges (basic_block);
812 extern bool fixup_abnormal_edges (void);
813 extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx);
814 extern bool contains_no_active_insn_p (const_basic_block);
815 extern bool forwarder_block_p (const_basic_block);
816 extern bool can_fallthru (basic_block, basic_block);
817 extern void emit_barrier_after_bb (basic_block bb);
818 extern void fixup_partitions (void);
820 /* In cfgbuild.c. */
821 extern void find_many_sub_basic_blocks (sbitmap);
822 extern void rtl_make_eh_edge (sbitmap, basic_block, rtx);
824 enum replace_direction { dir_none, dir_forward, dir_backward, dir_both };
826 /* In cfgcleanup.c. */
827 extern bool cleanup_cfg (int);
828 extern int flow_find_cross_jump (basic_block, basic_block, rtx *, rtx *,
829 enum replace_direction*);
830 extern int flow_find_head_matching_sequence (basic_block, basic_block,
831 rtx *, rtx *, int);
833 extern bool delete_unreachable_blocks (void);
835 extern void update_br_prob_note (basic_block);
836 extern bool inside_basic_block_p (const_rtx);
837 extern bool control_flow_insn_p (const_rtx);
838 extern rtx get_last_bb_insn (basic_block);
840 /* In dominance.c */
842 enum cdi_direction
844 CDI_DOMINATORS = 1,
845 CDI_POST_DOMINATORS = 2
848 extern enum dom_state dom_info_state (enum cdi_direction);
849 extern void set_dom_info_availability (enum cdi_direction, enum dom_state);
850 extern bool dom_info_available_p (enum cdi_direction);
851 extern void calculate_dominance_info (enum cdi_direction);
852 extern void free_dominance_info (enum cdi_direction);
853 extern basic_block nearest_common_dominator (enum cdi_direction,
854 basic_block, basic_block);
855 extern basic_block nearest_common_dominator_for_set (enum cdi_direction,
856 bitmap);
857 extern void set_immediate_dominator (enum cdi_direction, basic_block,
858 basic_block);
859 extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
860 extern bool dominated_by_p (enum cdi_direction, const_basic_block, const_basic_block);
861 extern vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);
862 extern vec<basic_block> get_dominated_by_region (enum cdi_direction,
863 basic_block *,
864 unsigned);
865 extern vec<basic_block> get_dominated_to_depth (enum cdi_direction,
866 basic_block, int);
867 extern vec<basic_block> get_all_dominated_blocks (enum cdi_direction,
868 basic_block);
869 extern void add_to_dominance_info (enum cdi_direction, basic_block);
870 extern void delete_from_dominance_info (enum cdi_direction, basic_block);
871 basic_block recompute_dominator (enum cdi_direction, basic_block);
872 extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
873 basic_block);
874 extern void iterate_fix_dominators (enum cdi_direction,
875 vec<basic_block> , bool);
876 extern void verify_dominators (enum cdi_direction);
877 extern basic_block first_dom_son (enum cdi_direction, basic_block);
878 extern basic_block next_dom_son (enum cdi_direction, basic_block);
879 unsigned bb_dom_dfs_in (enum cdi_direction, basic_block);
880 unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
882 extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
883 extern void break_superblocks (void);
884 extern void relink_block_chain (bool);
885 extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
886 extern void init_rtl_bb_info (basic_block);
888 extern void initialize_original_copy_tables (void);
889 extern void free_original_copy_tables (void);
890 extern void set_bb_original (basic_block, basic_block);
891 extern basic_block get_bb_original (basic_block);
892 extern void set_bb_copy (basic_block, basic_block);
893 extern basic_block get_bb_copy (basic_block);
894 void set_loop_copy (struct loop *, struct loop *);
895 struct loop *get_loop_copy (struct loop *);
897 #include "cfghooks.h"
899 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
900 static inline bool
901 bb_has_eh_pred (basic_block bb)
903 edge e;
904 edge_iterator ei;
906 FOR_EACH_EDGE (e, ei, bb->preds)
908 if (e->flags & EDGE_EH)
909 return true;
911 return false;
914 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
915 static inline bool
916 bb_has_abnormal_pred (basic_block bb)
918 edge e;
919 edge_iterator ei;
921 FOR_EACH_EDGE (e, ei, bb->preds)
923 if (e->flags & EDGE_ABNORMAL)
924 return true;
926 return false;
929 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
930 static inline edge
931 find_fallthru_edge (vec<edge, va_gc> *edges)
933 edge e;
934 edge_iterator ei;
936 FOR_EACH_EDGE (e, ei, edges)
937 if (e->flags & EDGE_FALLTHRU)
938 break;
940 return e;
943 /* In cfgloopmanip.c. */
944 extern edge mfb_kj_edge;
945 extern bool mfb_keep_just (edge);
947 /* In cfgexpand.c. */
948 extern void rtl_profile_for_bb (basic_block);
949 extern void rtl_profile_for_edge (edge);
950 extern void default_rtl_profile (void);
952 /* In profile.c. */
953 typedef struct gcov_working_set_info gcov_working_set_t;
954 extern gcov_working_set_t *find_working_set(unsigned pct_times_10);
956 /* Check tha probability is sane. */
958 static inline void
959 check_probability (int prob)
961 gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
964 /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
965 Used to combine BB probabilities. */
967 static inline int
968 combine_probabilities (int prob1, int prob2)
970 check_probability (prob1);
971 check_probability (prob2);
972 return RDIV (prob1 * prob2, REG_BR_PROB_BASE);
975 /* Apply scale factor SCALE on frequency or count FREQ. Use this
976 interface when potentially scaling up, so that SCALE is not
977 constrained to be < REG_BR_PROB_BASE. */
979 static inline gcov_type
980 apply_scale (gcov_type freq, gcov_type scale)
982 return RDIV (freq * scale, REG_BR_PROB_BASE);
985 /* Apply probability PROB on frequency or count FREQ. */
987 static inline gcov_type
988 apply_probability (gcov_type freq, int prob)
990 check_probability (prob);
991 return apply_scale (freq, prob);
994 /* Return inverse probability for PROB. */
996 static inline int
997 inverse_probability (int prob1)
999 check_probability (prob1);
1000 return REG_BR_PROB_BASE - prob1;
1002 #endif /* GCC_BASIC_BLOCK_H */