OSDN Git Service

PR c++/43890
[pf3gnuchains/gcc-fork.git] / gcc / basic-block.h
1 /* Define control and data flow tables, and regsets.
2    Copyright (C) 1987, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3    2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #ifndef GCC_BASIC_BLOCK_H
22 #define GCC_BASIC_BLOCK_H
23
24 #include "bitmap.h"
25 #include "sbitmap.h"
26 #include "partition.h"
27 #include "hard-reg-set.h"
28 #include "predict.h"
29 #include "vec.h"
30 #include "function.h"
31
32 /* Head of register set linked list.  */
33 typedef bitmap_head regset_head;
34
35 /* A pointer to a regset_head.  */
36 typedef bitmap regset;
37
38 /* Allocate a register set with oballoc.  */
39 #define ALLOC_REG_SET(OBSTACK) BITMAP_ALLOC (OBSTACK)
40
41 /* Do any cleanup needed on a regset when it is no longer used.  */
42 #define FREE_REG_SET(REGSET) BITMAP_FREE (REGSET)
43
44 /* Initialize a new regset.  */
45 #define INIT_REG_SET(HEAD) bitmap_initialize (HEAD, &reg_obstack)
46
47 /* Clear a register set by freeing up the linked list.  */
48 #define CLEAR_REG_SET(HEAD) bitmap_clear (HEAD)
49
50 /* Copy a register set to another register set.  */
51 #define COPY_REG_SET(TO, FROM) bitmap_copy (TO, FROM)
52
53 /* Compare two register sets.  */
54 #define REG_SET_EQUAL_P(A, B) bitmap_equal_p (A, B)
55
56 /* `and' a register set with a second register set.  */
57 #define AND_REG_SET(TO, FROM) bitmap_and_into (TO, FROM)
58
59 /* `and' the complement of a register set with a register set.  */
60 #define AND_COMPL_REG_SET(TO, FROM) bitmap_and_compl_into (TO, FROM)
61
62 /* Inclusive or a register set with a second register set.  */
63 #define IOR_REG_SET(TO, FROM) bitmap_ior_into (TO, FROM)
64
65 /* Exclusive or a register set with a second register set.  */
66 #define XOR_REG_SET(TO, FROM) bitmap_xor_into (TO, FROM)
67
68 /* Or into TO the register set FROM1 `and'ed with the complement of FROM2.  */
69 #define IOR_AND_COMPL_REG_SET(TO, FROM1, FROM2) \
70   bitmap_ior_and_compl_into (TO, FROM1, FROM2)
71
72 /* Clear a single register in a register set.  */
73 #define CLEAR_REGNO_REG_SET(HEAD, REG) bitmap_clear_bit (HEAD, REG)
74
75 /* Set a single register in a register set.  */
76 #define SET_REGNO_REG_SET(HEAD, REG) bitmap_set_bit (HEAD, REG)
77
78 /* Return true if a register is set in a register set.  */
79 #define REGNO_REG_SET_P(TO, REG) bitmap_bit_p (TO, REG)
80
81 /* Copy the hard registers in a register set to the hard register set.  */
82 extern void reg_set_to_hard_reg_set (HARD_REG_SET *, const_bitmap);
83 #define REG_SET_TO_HARD_REG_SET(TO, FROM)                               \
84 do {                                                                    \
85   CLEAR_HARD_REG_SET (TO);                                              \
86   reg_set_to_hard_reg_set (&TO, FROM);                                  \
87 } while (0)
88
89 typedef bitmap_iterator reg_set_iterator;
90
91 /* Loop over all registers in REGSET, starting with MIN, setting REGNUM to the
92    register number and executing CODE for all registers that are set.  */
93 #define EXECUTE_IF_SET_IN_REG_SET(REGSET, MIN, REGNUM, RSI)     \
94   EXECUTE_IF_SET_IN_BITMAP (REGSET, MIN, REGNUM, RSI)
95
96 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
97    REGNUM to the register number and executing CODE for all registers that are
98    set in the first regset and not set in the second.  */
99 #define EXECUTE_IF_AND_COMPL_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, RSI) \
100   EXECUTE_IF_AND_COMPL_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, RSI)
101
102 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
103    REGNUM to the register number and executing CODE for all registers that are
104    set in both regsets.  */
105 #define EXECUTE_IF_AND_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, RSI) \
106   EXECUTE_IF_AND_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, RSI) \
107
108 /* Same information as REGS_INVALIDATED_BY_CALL but in regset form to be used
109    in dataflow more conveniently.  */
110
111 extern regset regs_invalidated_by_call_regset;
112
113 /* Type we use to hold basic block counters.  Should be at least
114    64bit.  Although a counter cannot be negative, we use a signed
115    type, because erroneous negative counts can be generated when the
116    flow graph is manipulated by various optimizations.  A signed type
117    makes those easy to detect.  */
118 typedef HOST_WIDEST_INT gcov_type;
119
120 /* Control flow edge information.  */
121 struct GTY(()) edge_def {
122   /* The two blocks at the ends of the edge.  */
123   struct basic_block_def *src;
124   struct basic_block_def *dest;
125
126   /* Instructions queued on the edge.  */
127   union edge_def_insns {
128     gimple_seq GTY ((tag ("true"))) g;
129     rtx GTY ((tag ("false"))) r;
130   } GTY ((desc ("current_ir_type () == IR_GIMPLE"))) insns;
131
132   /* Auxiliary info specific to a pass.  */
133   PTR GTY ((skip (""))) aux;
134
135   /* Location of any goto implicit in the edge and associated BLOCK.  */
136   tree goto_block;
137   location_t goto_locus;
138
139   /* The index number corresponding to this edge in the edge vector
140      dest->preds.  */
141   unsigned int dest_idx;
142
143   int flags;                    /* see EDGE_* below  */
144   int probability;              /* biased by REG_BR_PROB_BASE */
145   gcov_type count;              /* Expected number of executions calculated
146                                    in profile.c  */
147 };
148
149 DEF_VEC_P(edge);
150 DEF_VEC_ALLOC_P(edge,gc);
151 DEF_VEC_ALLOC_P(edge,heap);
152
153 #define EDGE_FALLTHRU           1       /* 'Straight line' flow */
154 #define EDGE_ABNORMAL           2       /* Strange flow, like computed
155                                            label, or eh */
156 #define EDGE_ABNORMAL_CALL      4       /* Call with abnormal exit
157                                            like an exception, or sibcall */
158 #define EDGE_EH                 8       /* Exception throw */
159 #define EDGE_FAKE               16      /* Not a real edge (profile.c) */
160 #define EDGE_DFS_BACK           32      /* A backwards edge */
161 #define EDGE_CAN_FALLTHRU       64      /* Candidate for straight line
162                                            flow.  */
163 #define EDGE_IRREDUCIBLE_LOOP   128     /* Part of irreducible loop.  */
164 #define EDGE_SIBCALL            256     /* Edge from sibcall to exit.  */
165 #define EDGE_LOOP_EXIT          512     /* Exit of a loop.  */
166 #define EDGE_TRUE_VALUE         1024    /* Edge taken when controlling
167                                            predicate is nonzero.  */
168 #define EDGE_FALSE_VALUE        2048    /* Edge taken when controlling
169                                            predicate is zero.  */
170 #define EDGE_EXECUTABLE         4096    /* Edge is executable.  Only
171                                            valid during SSA-CCP.  */
172 #define EDGE_CROSSING           8192    /* Edge crosses between hot
173                                            and cold sections, when we
174                                            do partitioning.  */
175 #define EDGE_ALL_FLAGS         16383
176
177 #define EDGE_COMPLEX    (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH)
178
179 /* Counter summary from the last set of coverage counts read by
180    profile.c.  */
181 extern const struct gcov_ctr_summary *profile_info;
182
183 /* Declared in cfgloop.h.  */
184 struct loop;
185
186 /* Declared in tree-flow.h.  */
187 struct edge_prediction;
188 struct rtl_bb_info;
189
190 /* A basic block is a sequence of instructions with only entry and
191    only one exit.  If any one of the instructions are executed, they
192    will all be executed, and in sequence from first to last.
193
194    There may be COND_EXEC instructions in the basic block.  The
195    COND_EXEC *instructions* will be executed -- but if the condition
196    is false the conditionally executed *expressions* will of course
197    not be executed.  We don't consider the conditionally executed
198    expression (which might have side-effects) to be in a separate
199    basic block because the program counter will always be at the same
200    location after the COND_EXEC instruction, regardless of whether the
201    condition is true or not.
202
203    Basic blocks need not start with a label nor end with a jump insn.
204    For example, a previous basic block may just "conditionally fall"
205    into the succeeding basic block, and the last basic block need not
206    end with a jump insn.  Block 0 is a descendant of the entry block.
207
208    A basic block beginning with two labels cannot have notes between
209    the labels.
210
211    Data for jump tables are stored in jump_insns that occur in no
212    basic block even though these insns can follow or precede insns in
213    basic blocks.  */
214
215 /* Basic block information indexed by block number.  */
216 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
217   /* The edges into and out of the block.  */
218   VEC(edge,gc) *preds;
219   VEC(edge,gc) *succs;
220
221   /* Auxiliary info specific to a pass.  */
222   PTR GTY ((skip (""))) aux;
223
224   /* Innermost loop containing the block.  */
225   struct loop *loop_father;
226
227   /* The dominance and postdominance information node.  */
228   struct et_node * GTY ((skip (""))) dom[2];
229
230   /* Previous and next blocks in the chain.  */
231   struct basic_block_def *prev_bb;
232   struct basic_block_def *next_bb;
233
234   union basic_block_il_dependent {
235       struct gimple_bb_info * GTY ((tag ("0"))) gimple;
236       struct rtl_bb_info * GTY ((tag ("1"))) rtl;
237     } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
238
239   /* Expected number of executions: calculated in profile.c.  */
240   gcov_type count;
241
242   /* The index of this block.  */
243   int index;
244
245   /* The loop depth of this block.  */
246   int loop_depth;
247
248   /* Expected frequency.  Normalized to be in range 0 to BB_FREQ_MAX.  */
249   int frequency;
250
251   /* The discriminator for this block.  */
252   int discriminator;
253
254   /* Various flags.  See BB_* below.  */
255   int flags;
256 };
257
258 struct GTY(()) rtl_bb_info {
259   /* The first and last insns of the block.  */
260   rtx head_;
261   rtx end_;
262
263   /* In CFGlayout mode points to insn notes/jumptables to be placed just before
264      and after the block.   */
265   rtx header;
266   rtx footer;
267
268   /* This field is used by the bb-reorder and tracer passes.  */
269   int visited;
270 };
271
272 struct GTY(()) gimple_bb_info {
273   /* Sequence of statements in this block.  */
274   gimple_seq seq;
275
276   /* PHI nodes for this block.  */
277   gimple_seq phi_nodes;
278 };
279
280 DEF_VEC_P(basic_block);
281 DEF_VEC_ALLOC_P(basic_block,gc);
282 DEF_VEC_ALLOC_P(basic_block,heap);
283
284 #define BB_FREQ_MAX 10000
285
286 /* Masks for basic_block.flags.
287
288    BB_HOT_PARTITION and BB_COLD_PARTITION should be preserved throughout
289    the compilation, so they are never cleared.
290
291    All other flags may be cleared by clear_bb_flags().  It is generally
292    a bad idea to rely on any flags being up-to-date.  */
293
294 enum bb_flags
295 {
296   /* Only set on blocks that have just been created by create_bb.  */
297   BB_NEW = 1 << 0,
298
299   /* Set by find_unreachable_blocks.  Do not rely on this being set in any
300      pass.  */
301   BB_REACHABLE = 1 << 1,
302
303   /* Set for blocks in an irreducible loop by loop analysis.  */
304   BB_IRREDUCIBLE_LOOP = 1 << 2,
305
306   /* Set on blocks that may actually not be single-entry single-exit block.  */
307   BB_SUPERBLOCK = 1 << 3,
308
309   /* Set on basic blocks that the scheduler should not touch.  This is used
310      by SMS to prevent other schedulers from messing with the loop schedule.  */
311   BB_DISABLE_SCHEDULE = 1 << 4,
312
313   /* Set on blocks that should be put in a hot section.  */
314   BB_HOT_PARTITION = 1 << 5,
315
316   /* Set on blocks that should be put in a cold section.  */
317   BB_COLD_PARTITION = 1 << 6,
318
319   /* Set on block that was duplicated.  */
320   BB_DUPLICATED = 1 << 7,
321
322   /* Set if the label at the top of this block is the target of a non-local goto.  */
323   BB_NON_LOCAL_GOTO_TARGET = 1 << 8,
324
325   /* Set on blocks that are in RTL format.  */
326   BB_RTL = 1 << 9 ,
327
328   /* Set on blocks that are forwarder blocks.
329      Only used in cfgcleanup.c.  */
330   BB_FORWARDER_BLOCK = 1 << 10,
331
332   /* Set on blocks that cannot be threaded through.
333      Only used in cfgcleanup.c.  */
334   BB_NONTHREADABLE_BLOCK = 1 << 11
335 };
336
337 /* Dummy flag for convenience in the hot/cold partitioning code.  */
338 #define BB_UNPARTITIONED        0
339
340 /* Partitions, to be used when partitioning hot and cold basic blocks into
341    separate sections.  */
342 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
343 #define BB_SET_PARTITION(bb, part) do {                                 \
344   basic_block bb_ = (bb);                                               \
345   bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION))    \
346                 | (part));                                              \
347 } while (0)
348
349 #define BB_COPY_PARTITION(dstbb, srcbb) \
350   BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
351
352 /* State of dominance information.  */
353
354 enum dom_state
355 {
356   DOM_NONE,             /* Not computed at all.  */
357   DOM_NO_FAST_QUERY,    /* The data is OK, but the fast query data are not usable.  */
358   DOM_OK                /* Everything is ok.  */
359 };
360
361 /* What sort of profiling information we have.  */
362 enum profile_status_d
363 {
364   PROFILE_ABSENT,
365   PROFILE_GUESSED,
366   PROFILE_READ
367 };
368
369 /* A structure to group all the per-function control flow graph data.
370    The x_* prefixing is necessary because otherwise references to the
371    fields of this struct are interpreted as the defines for backward
372    source compatibility following the definition of this struct.  */
373 struct GTY(()) control_flow_graph {
374   /* Block pointers for the exit and entry of a function.
375      These are always the head and tail of the basic block list.  */
376   basic_block x_entry_block_ptr;
377   basic_block x_exit_block_ptr;
378
379   /* Index by basic block number, get basic block struct info.  */
380   VEC(basic_block,gc) *x_basic_block_info;
381
382   /* Number of basic blocks in this flow graph.  */
383   int x_n_basic_blocks;
384
385   /* Number of edges in this flow graph.  */
386   int x_n_edges;
387
388   /* The first free basic block number.  */
389   int x_last_basic_block;
390
391   /* Mapping of labels to their associated blocks.  At present
392      only used for the gimple CFG.  */
393   VEC(basic_block,gc) *x_label_to_block_map;
394
395   enum profile_status_d x_profile_status;
396
397   /* Whether the dominators and the postdominators are available.  */
398   enum dom_state x_dom_computed[2];
399
400   /* Number of basic blocks in the dominance tree.  */
401   unsigned x_n_bbs_in_dom_tree[2];
402
403   /* Maximal number of entities in the single jumptable.  Used to estimate
404      final flowgraph size.  */
405   int max_jumptable_ents;
406
407   /* UIDs for LABEL_DECLs.  */
408   int last_label_uid;
409 };
410
411 /* Defines for accessing the fields of the CFG structure for function FN.  */
412 #define ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)     ((FN)->cfg->x_entry_block_ptr)
413 #define EXIT_BLOCK_PTR_FOR_FUNCTION(FN)      ((FN)->cfg->x_exit_block_ptr)
414 #define basic_block_info_for_function(FN)    ((FN)->cfg->x_basic_block_info)
415 #define n_basic_blocks_for_function(FN)      ((FN)->cfg->x_n_basic_blocks)
416 #define n_edges_for_function(FN)             ((FN)->cfg->x_n_edges)
417 #define last_basic_block_for_function(FN)    ((FN)->cfg->x_last_basic_block)
418 #define label_to_block_map_for_function(FN)  ((FN)->cfg->x_label_to_block_map)
419 #define profile_status_for_function(FN)      ((FN)->cfg->x_profile_status)
420
421 #define BASIC_BLOCK_FOR_FUNCTION(FN,N) \
422   (VEC_index (basic_block, basic_block_info_for_function(FN), (N)))
423 #define SET_BASIC_BLOCK_FOR_FUNCTION(FN,N,BB) \
424   (VEC_replace (basic_block, basic_block_info_for_function(FN), (N), (BB)))
425
426 /* Defines for textual backward source compatibility.  */
427 #define ENTRY_BLOCK_PTR         (cfun->cfg->x_entry_block_ptr)
428 #define EXIT_BLOCK_PTR          (cfun->cfg->x_exit_block_ptr)
429 #define basic_block_info        (cfun->cfg->x_basic_block_info)
430 #define n_basic_blocks          (cfun->cfg->x_n_basic_blocks)
431 #define n_edges                 (cfun->cfg->x_n_edges)
432 #define last_basic_block        (cfun->cfg->x_last_basic_block)
433 #define label_to_block_map      (cfun->cfg->x_label_to_block_map)
434 #define profile_status          (cfun->cfg->x_profile_status)
435
436 #define BASIC_BLOCK(N)          (VEC_index (basic_block, basic_block_info, (N)))
437 #define SET_BASIC_BLOCK(N,BB)   (VEC_replace (basic_block, basic_block_info, (N), (BB)))
438
439 /* For iterating over basic blocks.  */
440 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
441   for (BB = FROM; BB != TO; BB = BB->DIR)
442
443 #define FOR_EACH_BB_FN(BB, FN) \
444   FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
445
446 #define FOR_EACH_BB(BB) FOR_EACH_BB_FN (BB, cfun)
447
448 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
449   FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
450
451 #define FOR_EACH_BB_REVERSE(BB) FOR_EACH_BB_REVERSE_FN(BB, cfun)
452
453 /* For iterating over insns in basic block.  */
454 #define FOR_BB_INSNS(BB, INSN)                  \
455   for ((INSN) = BB_HEAD (BB);                   \
456        (INSN) && (INSN) != NEXT_INSN (BB_END (BB));     \
457        (INSN) = NEXT_INSN (INSN))
458
459 /* For iterating over insns in basic block when we might remove the
460    current insn.  */
461 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR)                       \
462   for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL;       \
463        (INSN) && (INSN) != NEXT_INSN (BB_END (BB));     \
464        (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
465
466 #define FOR_BB_INSNS_REVERSE(BB, INSN)          \
467   for ((INSN) = BB_END (BB);                    \
468        (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB));    \
469        (INSN) = PREV_INSN (INSN))
470
471 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR)       \
472   for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL;        \
473        (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB));    \
474        (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
475
476 /* Cycles through _all_ basic blocks, even the fake ones (entry and
477    exit block).  */
478
479 #define FOR_ALL_BB(BB) \
480   for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
481
482 #define FOR_ALL_BB_FN(BB, FN) \
483   for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
484
485 extern bitmap_obstack reg_obstack;
486
487 \f
488 /* Stuff for recording basic block info.  */
489
490 #define BB_HEAD(B)      (B)->il.rtl->head_
491 #define BB_END(B)       (B)->il.rtl->end_
492
493 /* Special block numbers [markers] for entry and exit.
494    Neither of them is supposed to hold actual statements.  */
495 #define ENTRY_BLOCK (0)
496 #define EXIT_BLOCK (1)
497
498 /* The two blocks that are always in the cfg.  */
499 #define NUM_FIXED_BLOCKS (2)
500
501 #define set_block_for_insn(INSN, BB)  (BLOCK_FOR_INSN (INSN) = BB)
502
503 extern void compute_bb_for_insn (void);
504 extern unsigned int free_bb_for_insn (void);
505 extern void update_bb_for_insn (basic_block);
506
507 extern void insert_insn_on_edge (rtx, edge);
508 basic_block split_edge_and_insert (edge, rtx);
509
510 extern void commit_one_edge_insertion (edge e);
511 extern void commit_edge_insertions (void);
512
513 extern void remove_fake_edges (void);
514 extern void remove_fake_exit_edges (void);
515 extern void add_noreturn_fake_exit_edges (void);
516 extern void connect_infinite_loops_to_exit (void);
517 extern edge unchecked_make_edge (basic_block, basic_block, int);
518 extern edge cached_make_edge (sbitmap, basic_block, basic_block, int);
519 extern edge make_edge (basic_block, basic_block, int);
520 extern edge make_single_succ_edge (basic_block, basic_block, int);
521 extern void remove_edge_raw (edge);
522 extern void redirect_edge_succ (edge, basic_block);
523 extern edge redirect_edge_succ_nodup (edge, basic_block);
524 extern void redirect_edge_pred (edge, basic_block);
525 extern basic_block create_basic_block_structure (rtx, rtx, rtx, basic_block);
526 extern void clear_bb_flags (void);
527 extern int post_order_compute (int *, bool, bool);
528 extern int inverted_post_order_compute (int *);
529 extern int pre_and_rev_post_order_compute (int *, int *, bool);
530 extern int dfs_enumerate_from (basic_block, int,
531                                bool (*)(const_basic_block, const void *),
532                                basic_block *, int, const void *);
533 extern void compute_dominance_frontiers (bitmap *);
534 extern bitmap compute_idf (bitmap, bitmap *);
535 extern void dump_bb_info (basic_block, bool, bool, int, const char *, FILE *);
536 extern void dump_edge_info (FILE *, edge, int);
537 extern void brief_dump_cfg (FILE *);
538 extern void clear_edges (void);
539 extern void scale_bbs_frequencies_int (basic_block *, int, int, int);
540 extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,
541                                              gcov_type);
542
543 /* Structure to group all of the information to process IF-THEN and
544    IF-THEN-ELSE blocks for the conditional execution support.  This
545    needs to be in a public file in case the IFCVT macros call
546    functions passing the ce_if_block data structure.  */
547
548 typedef struct ce_if_block
549 {
550   basic_block test_bb;                  /* First test block.  */
551   basic_block then_bb;                  /* THEN block.  */
552   basic_block else_bb;                  /* ELSE block or NULL.  */
553   basic_block join_bb;                  /* Join THEN/ELSE blocks.  */
554   basic_block last_test_bb;             /* Last bb to hold && or || tests.  */
555   int num_multiple_test_blocks;         /* # of && and || basic blocks.  */
556   int num_and_and_blocks;               /* # of && blocks.  */
557   int num_or_or_blocks;                 /* # of || blocks.  */
558   int num_multiple_test_insns;          /* # of insns in && and || blocks.  */
559   int and_and_p;                        /* Complex test is &&.  */
560   int num_then_insns;                   /* # of insns in THEN block.  */
561   int num_else_insns;                   /* # of insns in ELSE block.  */
562   int pass;                             /* Pass number.  */
563
564 #ifdef IFCVT_EXTRA_FIELDS
565   IFCVT_EXTRA_FIELDS                    /* Any machine dependent fields.  */
566 #endif
567
568 } ce_if_block_t;
569
570 /* This structure maintains an edge list vector.  */
571 struct edge_list
572 {
573   int num_blocks;
574   int num_edges;
575   edge *index_to_edge;
576 };
577
578 /* The base value for branch probability notes and edge probabilities.  */
579 #define REG_BR_PROB_BASE  10000
580
581 /* This is the value which indicates no edge is present.  */
582 #define EDGE_INDEX_NO_EDGE      -1
583
584 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
585    if there is no edge between the 2 basic blocks.  */
586 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
587
588 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
589    block which is either the pred or succ end of the indexed edge.  */
590 #define INDEX_EDGE_PRED_BB(el, index)   ((el)->index_to_edge[(index)]->src)
591 #define INDEX_EDGE_SUCC_BB(el, index)   ((el)->index_to_edge[(index)]->dest)
592
593 /* INDEX_EDGE returns a pointer to the edge.  */
594 #define INDEX_EDGE(el, index)           ((el)->index_to_edge[(index)])
595
596 /* Number of edges in the compressed edge list.  */
597 #define NUM_EDGES(el)                   ((el)->num_edges)
598
599 /* BB is assumed to contain conditional jump.  Return the fallthru edge.  */
600 #define FALLTHRU_EDGE(bb)               (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
601                                          ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
602
603 /* BB is assumed to contain conditional jump.  Return the branch edge.  */
604 #define BRANCH_EDGE(bb)                 (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
605                                          ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
606
607 /* Return expected execution frequency of the edge E.  */
608 #define EDGE_FREQUENCY(e)               (((e)->src->frequency \
609                                           * (e)->probability \
610                                           + REG_BR_PROB_BASE / 2) \
611                                          / REG_BR_PROB_BASE)
612
613 /* Return nonzero if edge is critical.  */
614 #define EDGE_CRITICAL_P(e)              (EDGE_COUNT ((e)->src->succs) >= 2 \
615                                          && EDGE_COUNT ((e)->dest->preds) >= 2)
616
617 #define EDGE_COUNT(ev)                  VEC_length (edge, (ev))
618 #define EDGE_I(ev,i)                    VEC_index  (edge, (ev), (i))
619 #define EDGE_PRED(bb,i)                 VEC_index  (edge, (bb)->preds, (i))
620 #define EDGE_SUCC(bb,i)                 VEC_index  (edge, (bb)->succs, (i))
621
622 /* Returns true if BB has precisely one successor.  */
623
624 static inline bool
625 single_succ_p (const_basic_block bb)
626 {
627   return EDGE_COUNT (bb->succs) == 1;
628 }
629
630 /* Returns true if BB has precisely one predecessor.  */
631
632 static inline bool
633 single_pred_p (const_basic_block bb)
634 {
635   return EDGE_COUNT (bb->preds) == 1;
636 }
637
638 /* Returns the single successor edge of basic block BB.  Aborts if
639    BB does not have exactly one successor.  */
640
641 static inline edge
642 single_succ_edge (const_basic_block bb)
643 {
644   gcc_assert (single_succ_p (bb));
645   return EDGE_SUCC (bb, 0);
646 }
647
648 /* Returns the single predecessor edge of basic block BB.  Aborts
649    if BB does not have exactly one predecessor.  */
650
651 static inline edge
652 single_pred_edge (const_basic_block bb)
653 {
654   gcc_assert (single_pred_p (bb));
655   return EDGE_PRED (bb, 0);
656 }
657
658 /* Returns the single successor block of basic block BB.  Aborts
659    if BB does not have exactly one successor.  */
660
661 static inline basic_block
662 single_succ (const_basic_block bb)
663 {
664   return single_succ_edge (bb)->dest;
665 }
666
667 /* Returns the single predecessor block of basic block BB.  Aborts
668    if BB does not have exactly one predecessor.*/
669
670 static inline basic_block
671 single_pred (const_basic_block bb)
672 {
673   return single_pred_edge (bb)->src;
674 }
675
676 /* Iterator object for edges.  */
677
678 typedef struct {
679   unsigned index;
680   VEC(edge,gc) **container;
681 } edge_iterator;
682
683 static inline VEC(edge,gc) *
684 ei_container (edge_iterator i)
685 {
686   gcc_assert (i.container);
687   return *i.container;
688 }
689
690 #define ei_start(iter) ei_start_1 (&(iter))
691 #define ei_last(iter) ei_last_1 (&(iter))
692
693 /* Return an iterator pointing to the start of an edge vector.  */
694 static inline edge_iterator
695 ei_start_1 (VEC(edge,gc) **ev)
696 {
697   edge_iterator i;
698
699   i.index = 0;
700   i.container = ev;
701
702   return i;
703 }
704
705 /* Return an iterator pointing to the last element of an edge
706    vector.  */
707 static inline edge_iterator
708 ei_last_1 (VEC(edge,gc) **ev)
709 {
710   edge_iterator i;
711
712   i.index = EDGE_COUNT (*ev) - 1;
713   i.container = ev;
714
715   return i;
716 }
717
718 /* Is the iterator `i' at the end of the sequence?  */
719 static inline bool
720 ei_end_p (edge_iterator i)
721 {
722   return (i.index == EDGE_COUNT (ei_container (i)));
723 }
724
725 /* Is the iterator `i' at one position before the end of the
726    sequence?  */
727 static inline bool
728 ei_one_before_end_p (edge_iterator i)
729 {
730   return (i.index + 1 == EDGE_COUNT (ei_container (i)));
731 }
732
733 /* Advance the iterator to the next element.  */
734 static inline void
735 ei_next (edge_iterator *i)
736 {
737   gcc_assert (i->index < EDGE_COUNT (ei_container (*i)));
738   i->index++;
739 }
740
741 /* Move the iterator to the previous element.  */
742 static inline void
743 ei_prev (edge_iterator *i)
744 {
745   gcc_assert (i->index > 0);
746   i->index--;
747 }
748
749 /* Return the edge pointed to by the iterator `i'.  */
750 static inline edge
751 ei_edge (edge_iterator i)
752 {
753   return EDGE_I (ei_container (i), i.index);
754 }
755
756 /* Return an edge pointed to by the iterator.  Do it safely so that
757    NULL is returned when the iterator is pointing at the end of the
758    sequence.  */
759 static inline edge
760 ei_safe_edge (edge_iterator i)
761 {
762   return !ei_end_p (i) ? ei_edge (i) : NULL;
763 }
764
765 /* Return 1 if we should continue to iterate.  Return 0 otherwise.
766    *Edge P is set to the next edge if we are to continue to iterate
767    and NULL otherwise.  */
768
769 static inline bool
770 ei_cond (edge_iterator ei, edge *p)
771 {
772   if (!ei_end_p (ei))
773     {
774       *p = ei_edge (ei);
775       return 1;
776     }
777   else
778     {
779       *p = NULL;
780       return 0;
781     }
782 }
783
784 /* This macro serves as a convenient way to iterate each edge in a
785    vector of predecessor or successor edges.  It must not be used when
786    an element might be removed during the traversal, otherwise
787    elements will be missed.  Instead, use a for-loop like that shown
788    in the following pseudo-code:
789
790    FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
791      {
792         IF (e != taken_edge)
793           remove_edge (e);
794         ELSE
795           ei_next (&ei);
796      }
797 */
798
799 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC)       \
800   for ((ITER) = ei_start ((EDGE_VEC));          \
801        ei_cond ((ITER), &(EDGE));               \
802        ei_next (&(ITER)))
803
804 struct edge_list * create_edge_list (void);
805 void free_edge_list (struct edge_list *);
806 void print_edge_list (FILE *, struct edge_list *);
807 void verify_edge_list (FILE *, struct edge_list *);
808 int find_edge_index (struct edge_list *, basic_block, basic_block);
809 edge find_edge (basic_block, basic_block);
810
811 #define CLEANUP_EXPENSIVE       1       /* Do relatively expensive optimizations
812                                            except for edge forwarding */
813 #define CLEANUP_CROSSJUMP       2       /* Do crossjumping.  */
814 #define CLEANUP_POST_REGSTACK   4       /* We run after reg-stack and need
815                                            to care REG_DEAD notes.  */
816 #define CLEANUP_THREADING       8       /* Do jump threading.  */
817 #define CLEANUP_NO_INSN_DEL     16      /* Do not try to delete trivially dead
818                                            insns.  */
819 #define CLEANUP_CFGLAYOUT       32      /* Do cleanup in cfglayout mode.  */
820
821 /* In lcm.c */
822 extern struct edge_list *pre_edge_lcm (int, sbitmap *, sbitmap *,
823                                        sbitmap *, sbitmap *, sbitmap **,
824                                        sbitmap **);
825 extern struct edge_list *pre_edge_rev_lcm (int, sbitmap *,
826                                            sbitmap *, sbitmap *,
827                                            sbitmap *, sbitmap **,
828                                            sbitmap **);
829 extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
830
831 /* In predict.c */
832 extern bool maybe_hot_bb_p (const_basic_block);
833 extern bool maybe_hot_edge_p (edge);
834 extern bool probably_never_executed_bb_p (const_basic_block);
835 extern bool optimize_bb_for_size_p (const_basic_block);
836 extern bool optimize_bb_for_speed_p (const_basic_block);
837 extern bool optimize_edge_for_size_p (edge);
838 extern bool optimize_edge_for_speed_p (edge);
839 extern bool optimize_function_for_size_p (struct function *);
840 extern bool optimize_function_for_speed_p (struct function *);
841 extern bool optimize_loop_for_size_p (struct loop *);
842 extern bool optimize_loop_for_speed_p (struct loop *);
843 extern bool optimize_loop_nest_for_size_p (struct loop *);
844 extern bool optimize_loop_nest_for_speed_p (struct loop *);
845 extern bool gimple_predicted_by_p (const_basic_block, enum br_predictor);
846 extern bool rtl_predicted_by_p (const_basic_block, enum br_predictor);
847 extern void gimple_predict_edge (edge, enum br_predictor, int);
848 extern void rtl_predict_edge (edge, enum br_predictor, int);
849 extern void predict_edge_def (edge, enum br_predictor, enum prediction);
850 extern void guess_outgoing_edge_probabilities (basic_block);
851 extern void remove_predictions_associated_with_edge (edge);
852 extern bool edge_probability_reliable_p (const_edge);
853 extern bool br_prob_note_reliable_p (const_rtx);
854 extern bool predictable_edge_p (edge);
855
856 /* In cfg.c  */
857 extern void init_flow (struct function *);
858 extern void debug_bb (basic_block);
859 extern basic_block debug_bb_n (int);
860 extern void dump_regset (regset, FILE *);
861 extern void debug_regset (regset);
862 extern void expunge_block (basic_block);
863 extern void link_block (basic_block, basic_block);
864 extern void unlink_block (basic_block);
865 extern void compact_blocks (void);
866 extern basic_block alloc_block (void);
867 extern void alloc_aux_for_block (basic_block, int);
868 extern void alloc_aux_for_blocks (int);
869 extern void clear_aux_for_blocks (void);
870 extern void free_aux_for_blocks (void);
871 extern void alloc_aux_for_edge (edge, int);
872 extern void alloc_aux_for_edges (int);
873 extern void clear_aux_for_edges (void);
874 extern void free_aux_for_edges (void);
875
876 /* In cfganal.c  */
877 extern void find_unreachable_blocks (void);
878 extern bool forwarder_block_p (const_basic_block);
879 extern bool can_fallthru (basic_block, basic_block);
880 extern bool could_fall_through (basic_block, basic_block);
881 extern void flow_nodes_print (const char *, const_sbitmap, FILE *);
882 extern void flow_edge_list_print (const char *, const edge *, int, FILE *);
883
884 /* In cfgrtl.c  */
885 extern basic_block force_nonfallthru (edge);
886 extern rtx block_label (basic_block);
887 extern bool purge_all_dead_edges (void);
888 extern bool purge_dead_edges (basic_block);
889
890 /* In cfgbuild.c.  */
891 extern void find_many_sub_basic_blocks (sbitmap);
892 extern void rtl_make_eh_edge (sbitmap, basic_block, rtx);
893
894 /* In cfgcleanup.c.  */
895 extern bool cleanup_cfg (int);
896 extern int flow_find_cross_jump (basic_block, basic_block, rtx *, rtx *);
897 extern int flow_find_head_matching_sequence (basic_block, basic_block,
898                                              rtx *, rtx *, int);
899
900 extern bool delete_unreachable_blocks (void);
901
902 extern bool mark_dfs_back_edges (void);
903 extern void set_edge_can_fallthru_flag (void);
904 extern void update_br_prob_note (basic_block);
905 extern void fixup_abnormal_edges (void);
906 extern bool inside_basic_block_p (const_rtx);
907 extern bool control_flow_insn_p (const_rtx);
908 extern rtx get_last_bb_insn (basic_block);
909
910 /* In bb-reorder.c */
911 extern void reorder_basic_blocks (void);
912
913 /* In dominance.c */
914
915 enum cdi_direction
916 {
917   CDI_DOMINATORS = 1,
918   CDI_POST_DOMINATORS = 2
919 };
920
921 extern enum dom_state dom_info_state (enum cdi_direction);
922 extern void set_dom_info_availability (enum cdi_direction, enum dom_state);
923 extern bool dom_info_available_p (enum cdi_direction);
924 extern void calculate_dominance_info (enum cdi_direction);
925 extern void free_dominance_info (enum cdi_direction);
926 extern basic_block nearest_common_dominator (enum cdi_direction,
927                                              basic_block, basic_block);
928 extern basic_block nearest_common_dominator_for_set (enum cdi_direction,
929                                                      bitmap);
930 extern void set_immediate_dominator (enum cdi_direction, basic_block,
931                                      basic_block);
932 extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
933 extern bool dominated_by_p (enum cdi_direction, const_basic_block, const_basic_block);
934 extern VEC (basic_block, heap) *get_dominated_by (enum cdi_direction, basic_block);
935 extern VEC (basic_block, heap) *get_dominated_by_region (enum cdi_direction,
936                                                          basic_block *,
937                                                          unsigned);
938 extern VEC (basic_block, heap) *get_all_dominated_blocks (enum cdi_direction,
939                                                           basic_block);
940 extern void add_to_dominance_info (enum cdi_direction, basic_block);
941 extern void delete_from_dominance_info (enum cdi_direction, basic_block);
942 basic_block recompute_dominator (enum cdi_direction, basic_block);
943 extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
944                                            basic_block);
945 extern void iterate_fix_dominators (enum cdi_direction,
946                                     VEC (basic_block, heap) *, bool);
947 extern void verify_dominators (enum cdi_direction);
948 extern basic_block first_dom_son (enum cdi_direction, basic_block);
949 extern basic_block next_dom_son (enum cdi_direction, basic_block);
950 unsigned bb_dom_dfs_in (enum cdi_direction, basic_block);
951 unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
952
953 extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
954 extern void break_superblocks (void);
955 extern void relink_block_chain (bool);
956 extern void check_bb_profile (basic_block, FILE *);
957 extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
958 extern void init_rtl_bb_info (basic_block);
959
960 extern void initialize_original_copy_tables (void);
961 extern void free_original_copy_tables (void);
962 extern void set_bb_original (basic_block, basic_block);
963 extern basic_block get_bb_original (basic_block);
964 extern void set_bb_copy (basic_block, basic_block);
965 extern basic_block get_bb_copy (basic_block);
966 void set_loop_copy (struct loop *, struct loop *);
967 struct loop *get_loop_copy (struct loop *);
968
969
970 extern rtx insert_insn_end_bb_new (rtx, basic_block);
971
972 #include "cfghooks.h"
973
974 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH.  */
975 static inline bool
976 bb_has_eh_pred (basic_block bb)
977 {
978   edge e;
979   edge_iterator ei;
980
981   FOR_EACH_EDGE (e, ei, bb->preds)
982     {
983       if (e->flags & EDGE_EH)
984         return true;
985     }
986   return false;
987 }
988
989 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL.  */
990 static inline bool
991 bb_has_abnormal_pred (basic_block bb)
992 {
993   edge e;
994   edge_iterator ei;
995
996   FOR_EACH_EDGE (e, ei, bb->preds)
997     {
998       if (e->flags & EDGE_ABNORMAL)
999         return true;
1000     }
1001   return false;
1002 }
1003
1004 /* In cfgloopmanip.c.  */
1005 extern edge mfb_kj_edge;
1006 extern bool mfb_keep_just (edge);
1007
1008 /* In cfgexpand.c.  */
1009 extern void rtl_profile_for_bb (basic_block);
1010 extern void rtl_profile_for_edge (edge);
1011 extern void default_rtl_profile (void);
1012
1013 #endif /* GCC_BASIC_BLOCK_H */