Enhances the gcov program summary by adding a histogram of arc counter entries.
[gcc.git] / gcc / basic-block.h
1 /* Define control flow data structures for the CFG.
2 Copyright (C) 1987, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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 "predict.h"
25 #include "vec.h"
26 #include "function.h"
27
28 /* Type we use to hold basic block counters. Should be at least
29 64bit. Although a counter cannot be negative, we use a signed
30 type, because erroneous negative counts can be generated when the
31 flow graph is manipulated by various optimizations. A signed type
32 makes those easy to detect. */
33 typedef HOST_WIDEST_INT gcov_type;
34 typedef unsigned HOST_WIDEST_INT gcov_type_unsigned;
35
36 /* Control flow edge information. */
37 struct GTY((user)) edge_def {
38 /* The two blocks at the ends of the edge. */
39 basic_block src;
40 basic_block dest;
41
42 /* Instructions queued on the edge. */
43 union edge_def_insns {
44 gimple_seq g;
45 rtx r;
46 } insns;
47
48 /* Auxiliary info specific to a pass. */
49 PTR aux;
50
51 /* Location of any goto implicit in the edge and associated BLOCK. */
52 tree goto_block;
53 location_t goto_locus;
54
55 /* The index number corresponding to this edge in the edge vector
56 dest->preds. */
57 unsigned int dest_idx;
58
59 int flags; /* see cfg-flags.def */
60 int probability; /* biased by REG_BR_PROB_BASE */
61 gcov_type count; /* Expected number of executions calculated
62 in profile.c */
63 };
64
65 DEF_VEC_P(edge);
66 DEF_VEC_ALLOC_P(edge,gc);
67 DEF_VEC_ALLOC_P(edge,heap);
68
69 /* Garbage collection and PCH support for edge_def. */
70 extern void gt_ggc_mx (edge_def *e);
71 extern void gt_pch_nx (edge_def *e);
72 extern void gt_pch_nx (edge_def *e, gt_pointer_operator, void *);
73
74 /* Masks for edge.flags. */
75 #define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
76 enum cfg_edge_flags {
77 #include "cfg-flags.def"
78 LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */
79 };
80 #undef DEF_EDGE_FLAG
81
82 /* Bit mask for all edge flags. */
83 #define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
84
85 /* The following four flags all indicate something special about an edge.
86 Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
87 control flow transfers. */
88 #define EDGE_COMPLEX \
89 (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
90
91 /* Counter summary from the last set of coverage counts read by
92 profile.c. */
93 extern const struct gcov_ctr_summary *profile_info;
94
95 /* Working set size statistics for a given percentage of the entire
96 profile (sum_all from the counter summary). */
97 typedef struct gcov_working_set_info
98 {
99 /* Number of hot counters included in this working set. */
100 unsigned num_counters;
101 /* Smallest counter included in this working set. */
102 gcov_type min_counter;
103 } gcov_working_set_t;
104
105 /* Declared in cfgloop.h. */
106 struct loop;
107
108 struct GTY(()) rtl_bb_info {
109 /* The first insn of the block is embedded into bb->il.x. */
110 /* The last insn of the block. */
111 rtx end_;
112
113 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
114 and after the block. */
115 rtx header_;
116 rtx footer_;
117 };
118
119 struct GTY(()) gimple_bb_info {
120 /* Sequence of statements in this block. */
121 gimple_seq seq;
122
123 /* PHI nodes for this block. */
124 gimple_seq phi_nodes;
125 };
126
127 /* A basic block is a sequence of instructions with only one entry and
128 only one exit. If any one of the instructions are executed, they
129 will all be executed, and in sequence from first to last.
130
131 There may be COND_EXEC instructions in the basic block. The
132 COND_EXEC *instructions* will be executed -- but if the condition
133 is false the conditionally executed *expressions* will of course
134 not be executed. We don't consider the conditionally executed
135 expression (which might have side-effects) to be in a separate
136 basic block because the program counter will always be at the same
137 location after the COND_EXEC instruction, regardless of whether the
138 condition is true or not.
139
140 Basic blocks need not start with a label nor end with a jump insn.
141 For example, a previous basic block may just "conditionally fall"
142 into the succeeding basic block, and the last basic block need not
143 end with a jump insn. Block 0 is a descendant of the entry block.
144
145 A basic block beginning with two labels cannot have notes between
146 the labels.
147
148 Data for jump tables are stored in jump_insns that occur in no
149 basic block even though these insns can follow or precede insns in
150 basic blocks. */
151
152 /* Basic block information indexed by block number. */
153 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
154 /* The edges into and out of the block. */
155 VEC(edge,gc) *preds;
156 VEC(edge,gc) *succs;
157
158 /* Auxiliary info specific to a pass. */
159 PTR GTY ((skip (""))) aux;
160
161 /* Innermost loop containing the block. */
162 struct loop *loop_father;
163
164 /* The dominance and postdominance information node. */
165 struct et_node * GTY ((skip (""))) dom[2];
166
167 /* Previous and next blocks in the chain. */
168 basic_block prev_bb;
169 basic_block next_bb;
170
171 union basic_block_il_dependent {
172 struct gimple_bb_info GTY ((tag ("0"))) gimple;
173 struct {
174 rtx head_;
175 struct rtl_bb_info * rtl;
176 } GTY ((tag ("1"))) x;
177 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
178
179 /* Various flags. See cfg-flags.def. */
180 int flags;
181
182 /* The index of this block. */
183 int index;
184
185 /* Expected number of executions: calculated in profile.c. */
186 gcov_type count;
187
188 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
189 int frequency;
190
191 /* The discriminator for this block. The discriminator distinguishes
192 among several basic blocks that share a common locus, allowing for
193 more accurate sample-based profiling. */
194 int discriminator;
195 };
196
197 /* This ensures that struct gimple_bb_info is smaller than
198 struct rtl_bb_info, so that inlining the former into basic_block_def
199 is the better choice. */
200 typedef int __assert_gimple_bb_smaller_rtl_bb
201 [(int)sizeof(struct rtl_bb_info)
202 - (int)sizeof (struct gimple_bb_info)];
203
204 DEF_VEC_P(basic_block);
205 DEF_VEC_ALLOC_P(basic_block,gc);
206 DEF_VEC_ALLOC_P(basic_block,heap);
207
208 #define BB_FREQ_MAX 10000
209
210 /* Masks for basic_block.flags. */
211 #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
212 enum cfg_bb_flags
213 {
214 #include "cfg-flags.def"
215 LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
216 };
217 #undef DEF_BASIC_BLOCK_FLAG
218
219 /* Bit mask for all basic block flags. */
220 #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
221
222 /* Bit mask for all basic block flags that must be preserved. These are
223 the bit masks that are *not* cleared by clear_bb_flags. */
224 #define BB_FLAGS_TO_PRESERVE \
225 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
226 | BB_HOT_PARTITION | BB_COLD_PARTITION)
227
228 /* Dummy bitmask for convenience in the hot/cold partitioning code. */
229 #define BB_UNPARTITIONED 0
230
231 /* Partitions, to be used when partitioning hot and cold basic blocks into
232 separate sections. */
233 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
234 #define BB_SET_PARTITION(bb, part) do { \
235 basic_block bb_ = (bb); \
236 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
237 | (part)); \
238 } while (0)
239
240 #define BB_COPY_PARTITION(dstbb, srcbb) \
241 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
242
243 /* State of dominance information. */
244
245 enum dom_state
246 {
247 DOM_NONE, /* Not computed at all. */
248 DOM_NO_FAST_QUERY, /* The data is OK, but the fast query data are not usable. */
249 DOM_OK /* Everything is ok. */
250 };
251
252 /* What sort of profiling information we have. */
253 enum profile_status_d
254 {
255 PROFILE_ABSENT,
256 PROFILE_GUESSED,
257 PROFILE_READ,
258 PROFILE_LAST /* Last value, used by profile streaming. */
259 };
260
261 /* A structure to group all the per-function control flow graph data.
262 The x_* prefixing is necessary because otherwise references to the
263 fields of this struct are interpreted as the defines for backward
264 source compatibility following the definition of this struct. */
265 struct GTY(()) control_flow_graph {
266 /* Block pointers for the exit and entry of a function.
267 These are always the head and tail of the basic block list. */
268 basic_block x_entry_block_ptr;
269 basic_block x_exit_block_ptr;
270
271 /* Index by basic block number, get basic block struct info. */
272 VEC(basic_block,gc) *x_basic_block_info;
273
274 /* Number of basic blocks in this flow graph. */
275 int x_n_basic_blocks;
276
277 /* Number of edges in this flow graph. */
278 int x_n_edges;
279
280 /* The first free basic block number. */
281 int x_last_basic_block;
282
283 /* UIDs for LABEL_DECLs. */
284 int last_label_uid;
285
286 /* Mapping of labels to their associated blocks. At present
287 only used for the gimple CFG. */
288 VEC(basic_block,gc) *x_label_to_block_map;
289
290 enum profile_status_d x_profile_status;
291
292 /* Whether the dominators and the postdominators are available. */
293 enum dom_state x_dom_computed[2];
294
295 /* Number of basic blocks in the dominance tree. */
296 unsigned x_n_bbs_in_dom_tree[2];
297
298 /* Maximal number of entities in the single jumptable. Used to estimate
299 final flowgraph size. */
300 int max_jumptable_ents;
301 };
302
303 /* Defines for accessing the fields of the CFG structure for function FN. */
304 #define ENTRY_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_entry_block_ptr)
305 #define EXIT_BLOCK_PTR_FOR_FUNCTION(FN) ((FN)->cfg->x_exit_block_ptr)
306 #define basic_block_info_for_function(FN) ((FN)->cfg->x_basic_block_info)
307 #define n_basic_blocks_for_function(FN) ((FN)->cfg->x_n_basic_blocks)
308 #define n_edges_for_function(FN) ((FN)->cfg->x_n_edges)
309 #define last_basic_block_for_function(FN) ((FN)->cfg->x_last_basic_block)
310 #define label_to_block_map_for_function(FN) ((FN)->cfg->x_label_to_block_map)
311 #define profile_status_for_function(FN) ((FN)->cfg->x_profile_status)
312
313 #define BASIC_BLOCK_FOR_FUNCTION(FN,N) \
314 (VEC_index (basic_block, basic_block_info_for_function(FN), (N)))
315 #define SET_BASIC_BLOCK_FOR_FUNCTION(FN,N,BB) \
316 (VEC_replace (basic_block, basic_block_info_for_function(FN), (N), (BB)))
317
318 /* Defines for textual backward source compatibility. */
319 #define ENTRY_BLOCK_PTR (cfun->cfg->x_entry_block_ptr)
320 #define EXIT_BLOCK_PTR (cfun->cfg->x_exit_block_ptr)
321 #define basic_block_info (cfun->cfg->x_basic_block_info)
322 #define n_basic_blocks (cfun->cfg->x_n_basic_blocks)
323 #define n_edges (cfun->cfg->x_n_edges)
324 #define last_basic_block (cfun->cfg->x_last_basic_block)
325 #define label_to_block_map (cfun->cfg->x_label_to_block_map)
326 #define profile_status (cfun->cfg->x_profile_status)
327
328 #define BASIC_BLOCK(N) (VEC_index (basic_block, basic_block_info, (N)))
329 #define SET_BASIC_BLOCK(N,BB) (VEC_replace (basic_block, basic_block_info, (N), (BB)))
330
331 /* For iterating over basic blocks. */
332 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
333 for (BB = FROM; BB != TO; BB = BB->DIR)
334
335 #define FOR_EACH_BB_FN(BB, FN) \
336 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
337
338 #define FOR_EACH_BB(BB) FOR_EACH_BB_FN (BB, cfun)
339
340 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
341 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
342
343 #define FOR_EACH_BB_REVERSE(BB) FOR_EACH_BB_REVERSE_FN(BB, cfun)
344
345 /* For iterating over insns in basic block. */
346 #define FOR_BB_INSNS(BB, INSN) \
347 for ((INSN) = BB_HEAD (BB); \
348 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
349 (INSN) = NEXT_INSN (INSN))
350
351 /* For iterating over insns in basic block when we might remove the
352 current insn. */
353 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
354 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
355 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
356 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
357
358 #define FOR_BB_INSNS_REVERSE(BB, INSN) \
359 for ((INSN) = BB_END (BB); \
360 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
361 (INSN) = PREV_INSN (INSN))
362
363 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
364 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
365 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
366 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
367
368 /* Cycles through _all_ basic blocks, even the fake ones (entry and
369 exit block). */
370
371 #define FOR_ALL_BB(BB) \
372 for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
373
374 #define FOR_ALL_BB_FN(BB, FN) \
375 for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
376
377 \f
378 /* Stuff for recording basic block info. */
379
380 #define BB_HEAD(B) (B)->il.x.head_
381 #define BB_END(B) (B)->il.x.rtl->end_
382 #define BB_HEADER(B) (B)->il.x.rtl->header_
383 #define BB_FOOTER(B) (B)->il.x.rtl->footer_
384
385 /* Special block numbers [markers] for entry and exit.
386 Neither of them is supposed to hold actual statements. */
387 #define ENTRY_BLOCK (0)
388 #define EXIT_BLOCK (1)
389
390 /* The two blocks that are always in the cfg. */
391 #define NUM_FIXED_BLOCKS (2)
392
393 #define set_block_for_insn(INSN, BB) (BLOCK_FOR_INSN (INSN) = BB)
394
395 extern void compute_bb_for_insn (void);
396 extern unsigned int free_bb_for_insn (void);
397 extern void update_bb_for_insn (basic_block);
398
399 extern void insert_insn_on_edge (rtx, edge);
400 basic_block split_edge_and_insert (edge, rtx);
401
402 extern void commit_one_edge_insertion (edge e);
403 extern void commit_edge_insertions (void);
404
405 extern edge unchecked_make_edge (basic_block, basic_block, int);
406 extern edge cached_make_edge (sbitmap, basic_block, basic_block, int);
407 extern edge make_edge (basic_block, basic_block, int);
408 extern edge make_single_succ_edge (basic_block, basic_block, int);
409 extern void remove_edge_raw (edge);
410 extern void redirect_edge_succ (edge, basic_block);
411 extern edge redirect_edge_succ_nodup (edge, basic_block);
412 extern void redirect_edge_pred (edge, basic_block);
413 extern basic_block create_basic_block_structure (rtx, rtx, rtx, basic_block);
414 extern void clear_bb_flags (void);
415 extern void dump_bb_info (FILE *, basic_block, int, int, bool, bool);
416 extern void dump_edge_info (FILE *, edge, int, int);
417 extern void brief_dump_cfg (FILE *, int);
418 extern void clear_edges (void);
419 extern void scale_bbs_frequencies_int (basic_block *, int, int, int);
420 extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,
421 gcov_type);
422
423 /* Structure to group all of the information to process IF-THEN and
424 IF-THEN-ELSE blocks for the conditional execution support. This
425 needs to be in a public file in case the IFCVT macros call
426 functions passing the ce_if_block data structure. */
427
428 typedef struct ce_if_block
429 {
430 basic_block test_bb; /* First test block. */
431 basic_block then_bb; /* THEN block. */
432 basic_block else_bb; /* ELSE block or NULL. */
433 basic_block join_bb; /* Join THEN/ELSE blocks. */
434 basic_block last_test_bb; /* Last bb to hold && or || tests. */
435 int num_multiple_test_blocks; /* # of && and || basic blocks. */
436 int num_and_and_blocks; /* # of && blocks. */
437 int num_or_or_blocks; /* # of || blocks. */
438 int num_multiple_test_insns; /* # of insns in && and || blocks. */
439 int and_and_p; /* Complex test is &&. */
440 int num_then_insns; /* # of insns in THEN block. */
441 int num_else_insns; /* # of insns in ELSE block. */
442 int pass; /* Pass number. */
443 } ce_if_block_t;
444
445 /* This structure maintains an edge list vector. */
446 /* FIXME: Make this a VEC(edge). */
447 struct edge_list
448 {
449 int num_edges;
450 edge *index_to_edge;
451 };
452
453 /* The base value for branch probability notes and edge probabilities. */
454 #define REG_BR_PROB_BASE 10000
455
456 /* This is the value which indicates no edge is present. */
457 #define EDGE_INDEX_NO_EDGE -1
458
459 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
460 if there is no edge between the 2 basic blocks. */
461 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
462
463 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
464 block which is either the pred or succ end of the indexed edge. */
465 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
466 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
467
468 /* INDEX_EDGE returns a pointer to the edge. */
469 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
470
471 /* Number of edges in the compressed edge list. */
472 #define NUM_EDGES(el) ((el)->num_edges)
473
474 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
475 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
476 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
477
478 /* BB is assumed to contain conditional jump. Return the branch edge. */
479 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
480 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
481
482 /* Return expected execution frequency of the edge E. */
483 #define EDGE_FREQUENCY(e) (((e)->src->frequency \
484 * (e)->probability \
485 + REG_BR_PROB_BASE / 2) \
486 / REG_BR_PROB_BASE)
487
488 /* Return nonzero if edge is critical. */
489 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
490 && EDGE_COUNT ((e)->dest->preds) >= 2)
491
492 #define EDGE_COUNT(ev) VEC_length (edge, (ev))
493 #define EDGE_I(ev,i) VEC_index (edge, (ev), (i))
494 #define EDGE_PRED(bb,i) VEC_index (edge, (bb)->preds, (i))
495 #define EDGE_SUCC(bb,i) VEC_index (edge, (bb)->succs, (i))
496
497 /* Returns true if BB has precisely one successor. */
498
499 static inline bool
500 single_succ_p (const_basic_block bb)
501 {
502 return EDGE_COUNT (bb->succs) == 1;
503 }
504
505 /* Returns true if BB has precisely one predecessor. */
506
507 static inline bool
508 single_pred_p (const_basic_block bb)
509 {
510 return EDGE_COUNT (bb->preds) == 1;
511 }
512
513 /* Returns the single successor edge of basic block BB. Aborts if
514 BB does not have exactly one successor. */
515
516 static inline edge
517 single_succ_edge (const_basic_block bb)
518 {
519 gcc_checking_assert (single_succ_p (bb));
520 return EDGE_SUCC (bb, 0);
521 }
522
523 /* Returns the single predecessor edge of basic block BB. Aborts
524 if BB does not have exactly one predecessor. */
525
526 static inline edge
527 single_pred_edge (const_basic_block bb)
528 {
529 gcc_checking_assert (single_pred_p (bb));
530 return EDGE_PRED (bb, 0);
531 }
532
533 /* Returns the single successor block of basic block BB. Aborts
534 if BB does not have exactly one successor. */
535
536 static inline basic_block
537 single_succ (const_basic_block bb)
538 {
539 return single_succ_edge (bb)->dest;
540 }
541
542 /* Returns the single predecessor block of basic block BB. Aborts
543 if BB does not have exactly one predecessor.*/
544
545 static inline basic_block
546 single_pred (const_basic_block bb)
547 {
548 return single_pred_edge (bb)->src;
549 }
550
551 /* Iterator object for edges. */
552
553 typedef struct {
554 unsigned index;
555 VEC(edge,gc) **container;
556 } edge_iterator;
557
558 static inline VEC(edge,gc) *
559 ei_container (edge_iterator i)
560 {
561 gcc_checking_assert (i.container);
562 return *i.container;
563 }
564
565 #define ei_start(iter) ei_start_1 (&(iter))
566 #define ei_last(iter) ei_last_1 (&(iter))
567
568 /* Return an iterator pointing to the start of an edge vector. */
569 static inline edge_iterator
570 ei_start_1 (VEC(edge,gc) **ev)
571 {
572 edge_iterator i;
573
574 i.index = 0;
575 i.container = ev;
576
577 return i;
578 }
579
580 /* Return an iterator pointing to the last element of an edge
581 vector. */
582 static inline edge_iterator
583 ei_last_1 (VEC(edge,gc) **ev)
584 {
585 edge_iterator i;
586
587 i.index = EDGE_COUNT (*ev) - 1;
588 i.container = ev;
589
590 return i;
591 }
592
593 /* Is the iterator `i' at the end of the sequence? */
594 static inline bool
595 ei_end_p (edge_iterator i)
596 {
597 return (i.index == EDGE_COUNT (ei_container (i)));
598 }
599
600 /* Is the iterator `i' at one position before the end of the
601 sequence? */
602 static inline bool
603 ei_one_before_end_p (edge_iterator i)
604 {
605 return (i.index + 1 == EDGE_COUNT (ei_container (i)));
606 }
607
608 /* Advance the iterator to the next element. */
609 static inline void
610 ei_next (edge_iterator *i)
611 {
612 gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
613 i->index++;
614 }
615
616 /* Move the iterator to the previous element. */
617 static inline void
618 ei_prev (edge_iterator *i)
619 {
620 gcc_checking_assert (i->index > 0);
621 i->index--;
622 }
623
624 /* Return the edge pointed to by the iterator `i'. */
625 static inline edge
626 ei_edge (edge_iterator i)
627 {
628 return EDGE_I (ei_container (i), i.index);
629 }
630
631 /* Return an edge pointed to by the iterator. Do it safely so that
632 NULL is returned when the iterator is pointing at the end of the
633 sequence. */
634 static inline edge
635 ei_safe_edge (edge_iterator i)
636 {
637 return !ei_end_p (i) ? ei_edge (i) : NULL;
638 }
639
640 /* Return 1 if we should continue to iterate. Return 0 otherwise.
641 *Edge P is set to the next edge if we are to continue to iterate
642 and NULL otherwise. */
643
644 static inline bool
645 ei_cond (edge_iterator ei, edge *p)
646 {
647 if (!ei_end_p (ei))
648 {
649 *p = ei_edge (ei);
650 return 1;
651 }
652 else
653 {
654 *p = NULL;
655 return 0;
656 }
657 }
658
659 /* This macro serves as a convenient way to iterate each edge in a
660 vector of predecessor or successor edges. It must not be used when
661 an element might be removed during the traversal, otherwise
662 elements will be missed. Instead, use a for-loop like that shown
663 in the following pseudo-code:
664
665 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
666 {
667 IF (e != taken_edge)
668 remove_edge (e);
669 ELSE
670 ei_next (&ei);
671 }
672 */
673
674 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
675 for ((ITER) = ei_start ((EDGE_VEC)); \
676 ei_cond ((ITER), &(EDGE)); \
677 ei_next (&(ITER)))
678
679 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
680 except for edge forwarding */
681 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
682 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
683 to care REG_DEAD notes. */
684 #define CLEANUP_THREADING 8 /* Do jump threading. */
685 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
686 insns. */
687 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
688 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
689
690 /* In cfganal.c */
691 extern void sbitmap_intersection_of_succs (sbitmap, sbitmap *, basic_block);
692 extern void sbitmap_intersection_of_preds (sbitmap, sbitmap *, basic_block);
693 extern void sbitmap_union_of_succs (sbitmap, sbitmap *, basic_block);
694 extern void sbitmap_union_of_preds (sbitmap, sbitmap *, basic_block);
695
696 /* In lcm.c */
697 extern struct edge_list *pre_edge_lcm (int, sbitmap *, sbitmap *,
698 sbitmap *, sbitmap *, sbitmap **,
699 sbitmap **);
700 extern struct edge_list *pre_edge_rev_lcm (int, sbitmap *,
701 sbitmap *, sbitmap *,
702 sbitmap *, sbitmap **,
703 sbitmap **);
704 extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
705
706 /* In predict.c */
707 extern bool maybe_hot_bb_p (struct function *, const_basic_block);
708 extern bool maybe_hot_edge_p (edge);
709 extern bool probably_never_executed_bb_p (struct function *, const_basic_block);
710 extern bool optimize_bb_for_size_p (const_basic_block);
711 extern bool optimize_bb_for_speed_p (const_basic_block);
712 extern bool optimize_edge_for_size_p (edge);
713 extern bool optimize_edge_for_speed_p (edge);
714 extern bool optimize_loop_for_size_p (struct loop *);
715 extern bool optimize_loop_for_speed_p (struct loop *);
716 extern bool optimize_loop_nest_for_size_p (struct loop *);
717 extern bool optimize_loop_nest_for_speed_p (struct loop *);
718 extern bool gimple_predicted_by_p (const_basic_block, enum br_predictor);
719 extern bool rtl_predicted_by_p (const_basic_block, enum br_predictor);
720 extern void gimple_predict_edge (edge, enum br_predictor, int);
721 extern void rtl_predict_edge (edge, enum br_predictor, int);
722 extern void predict_edge_def (edge, enum br_predictor, enum prediction);
723 extern void guess_outgoing_edge_probabilities (basic_block);
724 extern void remove_predictions_associated_with_edge (edge);
725 extern bool edge_probability_reliable_p (const_edge);
726 extern bool br_prob_note_reliable_p (const_rtx);
727 extern bool predictable_edge_p (edge);
728
729 /* In cfg.c */
730 extern void init_flow (struct function *);
731 extern void debug_bb (basic_block);
732 extern basic_block debug_bb_n (int);
733 extern void dump_flow_info (FILE *, int);
734 extern void expunge_block (basic_block);
735 extern void link_block (basic_block, basic_block);
736 extern void unlink_block (basic_block);
737 extern void compact_blocks (void);
738 extern basic_block alloc_block (void);
739 extern void alloc_aux_for_blocks (int);
740 extern void clear_aux_for_blocks (void);
741 extern void free_aux_for_blocks (void);
742 extern void alloc_aux_for_edge (edge, int);
743 extern void alloc_aux_for_edges (int);
744 extern void clear_aux_for_edges (void);
745 extern void free_aux_for_edges (void);
746
747 /* In cfganal.c */
748 extern void find_unreachable_blocks (void);
749 extern bool mark_dfs_back_edges (void);
750 struct edge_list * create_edge_list (void);
751 void free_edge_list (struct edge_list *);
752 void print_edge_list (FILE *, struct edge_list *);
753 void verify_edge_list (FILE *, struct edge_list *);
754 int find_edge_index (struct edge_list *, basic_block, basic_block);
755 edge find_edge (basic_block, basic_block);
756 extern void remove_fake_edges (void);
757 extern void remove_fake_exit_edges (void);
758 extern void add_noreturn_fake_exit_edges (void);
759 extern void connect_infinite_loops_to_exit (void);
760 extern int post_order_compute (int *, bool, bool);
761 extern int inverted_post_order_compute (int *);
762 extern int pre_and_rev_post_order_compute (int *, int *, bool);
763 extern int dfs_enumerate_from (basic_block, int,
764 bool (*)(const_basic_block, const void *),
765 basic_block *, int, const void *);
766 extern void compute_dominance_frontiers (struct bitmap_head_def *);
767 extern bitmap compute_idf (bitmap, struct bitmap_head_def *);
768
769 /* In cfgrtl.c */
770 extern rtx block_label (basic_block);
771 extern rtx bb_note (basic_block);
772 extern bool purge_all_dead_edges (void);
773 extern bool purge_dead_edges (basic_block);
774 extern bool fixup_abnormal_edges (void);
775 extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx);
776 extern bool forwarder_block_p (const_basic_block);
777 extern bool can_fallthru (basic_block, basic_block);
778
779 /* In cfgbuild.c. */
780 extern void find_many_sub_basic_blocks (sbitmap);
781 extern void rtl_make_eh_edge (sbitmap, basic_block, rtx);
782
783 enum replace_direction { dir_none, dir_forward, dir_backward, dir_both };
784
785 /* In cfgcleanup.c. */
786 extern bool cleanup_cfg (int);
787 extern int flow_find_cross_jump (basic_block, basic_block, rtx *, rtx *,
788 enum replace_direction*);
789 extern int flow_find_head_matching_sequence (basic_block, basic_block,
790 rtx *, rtx *, int);
791
792 extern bool delete_unreachable_blocks (void);
793
794 extern void update_br_prob_note (basic_block);
795 extern bool inside_basic_block_p (const_rtx);
796 extern bool control_flow_insn_p (const_rtx);
797 extern rtx get_last_bb_insn (basic_block);
798
799 /* In dominance.c */
800
801 enum cdi_direction
802 {
803 CDI_DOMINATORS = 1,
804 CDI_POST_DOMINATORS = 2
805 };
806
807 extern enum dom_state dom_info_state (enum cdi_direction);
808 extern void set_dom_info_availability (enum cdi_direction, enum dom_state);
809 extern bool dom_info_available_p (enum cdi_direction);
810 extern void calculate_dominance_info (enum cdi_direction);
811 extern void free_dominance_info (enum cdi_direction);
812 extern basic_block nearest_common_dominator (enum cdi_direction,
813 basic_block, basic_block);
814 extern basic_block nearest_common_dominator_for_set (enum cdi_direction,
815 bitmap);
816 extern void set_immediate_dominator (enum cdi_direction, basic_block,
817 basic_block);
818 extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
819 extern bool dominated_by_p (enum cdi_direction, const_basic_block, const_basic_block);
820 extern VEC (basic_block, heap) *get_dominated_by (enum cdi_direction, basic_block);
821 extern VEC (basic_block, heap) *get_dominated_by_region (enum cdi_direction,
822 basic_block *,
823 unsigned);
824 extern VEC (basic_block, heap) *get_dominated_to_depth (enum cdi_direction,
825 basic_block, int);
826 extern VEC (basic_block, heap) *get_all_dominated_blocks (enum cdi_direction,
827 basic_block);
828 extern void add_to_dominance_info (enum cdi_direction, basic_block);
829 extern void delete_from_dominance_info (enum cdi_direction, basic_block);
830 basic_block recompute_dominator (enum cdi_direction, basic_block);
831 extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
832 basic_block);
833 extern void iterate_fix_dominators (enum cdi_direction,
834 VEC (basic_block, heap) *, bool);
835 extern void verify_dominators (enum cdi_direction);
836 extern basic_block first_dom_son (enum cdi_direction, basic_block);
837 extern basic_block next_dom_son (enum cdi_direction, basic_block);
838 unsigned bb_dom_dfs_in (enum cdi_direction, basic_block);
839 unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
840
841 extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
842 extern void break_superblocks (void);
843 extern void relink_block_chain (bool);
844 extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
845 extern void init_rtl_bb_info (basic_block);
846
847 extern void initialize_original_copy_tables (void);
848 extern void free_original_copy_tables (void);
849 extern void set_bb_original (basic_block, basic_block);
850 extern basic_block get_bb_original (basic_block);
851 extern void set_bb_copy (basic_block, basic_block);
852 extern basic_block get_bb_copy (basic_block);
853 void set_loop_copy (struct loop *, struct loop *);
854 struct loop *get_loop_copy (struct loop *);
855
856 #include "cfghooks.h"
857
858 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
859 static inline bool
860 bb_has_eh_pred (basic_block bb)
861 {
862 edge e;
863 edge_iterator ei;
864
865 FOR_EACH_EDGE (e, ei, bb->preds)
866 {
867 if (e->flags & EDGE_EH)
868 return true;
869 }
870 return false;
871 }
872
873 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
874 static inline bool
875 bb_has_abnormal_pred (basic_block bb)
876 {
877 edge e;
878 edge_iterator ei;
879
880 FOR_EACH_EDGE (e, ei, bb->preds)
881 {
882 if (e->flags & EDGE_ABNORMAL)
883 return true;
884 }
885 return false;
886 }
887
888 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
889 static inline edge
890 find_fallthru_edge (VEC(edge,gc) *edges)
891 {
892 edge e;
893 edge_iterator ei;
894
895 FOR_EACH_EDGE (e, ei, edges)
896 if (e->flags & EDGE_FALLTHRU)
897 break;
898
899 return e;
900 }
901
902 /* In cfgloopmanip.c. */
903 extern edge mfb_kj_edge;
904 extern bool mfb_keep_just (edge);
905
906 /* In cfgexpand.c. */
907 extern void rtl_profile_for_bb (basic_block);
908 extern void rtl_profile_for_edge (edge);
909 extern void default_rtl_profile (void);
910
911 /* In profile.c. */
912 extern gcov_working_set_t *find_working_set(unsigned pct_times_10);
913
914 #endif /* GCC_BASIC_BLOCK_H */