GCC Middle and Back End API Reference
Main Page
Namespaces
Data Structures
Files
File List
Globals
basic-block.h
Go to the documentation of this file.
1
/* Define control flow data structures for the CFG.
2
Copyright (C) 1987-2013 Free Software Foundation, Inc.
3
4
This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
20
#ifndef GCC_BASIC_BLOCK_H
21
#define GCC_BASIC_BLOCK_H
22
23
#include "
predict.h
"
24
#include "
vec.h
"
25
#include "
function.h
"
26
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
;
34
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
;
40
41
/* Instructions queued on the edge. */
42
union
edge_def_insns
{
43
gimple_seq
g
;
44
rtx
r
;
45
} insns;
46
47
/* Auxiliary info specific to a pass. */
48
PTR
aux
;
49
50
/* Location of any goto implicit in the edge. */
51
location_t
goto_locus
;
52
53
/* The index number corresponding to this edge in the edge vector
54
dest->preds. */
55
unsigned
int
dest_idx
;
56
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 */
61
};
62
63
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
*);
68
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 */
74
};
75
#undef DEF_EDGE_FLAG
76
77
/* Bit mask for all edge flags. */
78
#define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
79
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)
85
86
/* Counter summary from the last set of coverage counts read by
87
profile.c. */
88
extern
const
struct
gcov_ctr_summary
*
profile_info
;
89
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.
94
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.
98
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
102
{
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
;
119
};
120
121
/* Declared in cfgloop.h. */
122
struct
loop
;
123
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_
;
128
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_
;
133
};
134
135
struct
GTY
(())
gimple_bb_info
{
136
/* Sequence of statements in this block. */
137
gimple_seq
seq
;
138
139
/* PHI nodes for this block. */
140
gimple_seq
phi_nodes
;
141
};
142
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.
146
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.
155
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.
160
161
A basic block beginning with two labels cannot have notes between
162
the labels.
163
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. */
167
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;
173
174
/* Auxiliary info specific to a pass. */
175
PTR GTY ((skip ("
"))) aux;
176
177
/* Innermost loop containing the block. */
178
struct loop *loop_father;
179
180
/* The dominance and postdominance information node. */
181
struct et_node * GTY ((skip ("
"))) dom[2];
182
183
/* Previous and next blocks in the chain. */
184
basic_block prev_bb;
185
basic_block next_bb;
186
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;
194
195
/* Various flags. See cfg-flags.def. */
196
int flags;
197
198
/* The index of this block. */
199
int index;
200
201
/* Expected number of executions: calculated in profile.c. */
202
gcov_type count;
203
204
/* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
205
int frequency;
206
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;
211
};
212
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)];
219
220
221
#define BB_FREQ_MAX 10000
222
223
/* Masks for basic_block.flags. */
224
#define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
225
enum cfg_bb_flags
226
{
227
#include "
cfg-flags.def
"
228
LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
229
};
230
#undef DEF_BASIC_BLOCK_FLAG
231
232
/* Bit mask for all basic block flags. */
233
#define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
234
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)
240
241
/* Dummy bitmask for convenience in the hot/cold partitioning code. */
242
#define BB_UNPARTITIONED 0
243
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)
252
253
#define BB_COPY_PARTITION(dstbb, srcbb) \
254
BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
255
256
/* State of dominance information. */
257
258
enum dom_state
259
{
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. */
263
};
264
265
/* What sort of profiling information we have. */
266
enum profile_status_d
267
{
268
PROFILE_ABSENT,
269
PROFILE_GUESSED,
270
PROFILE_READ,
271
PROFILE_LAST /* Last value, used by profile streaming. */
272
};
273
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;
283
284
/* Index by basic block number, get basic block struct info. */
285
vec<basic_block, va_gc> *x_basic_block_info;
286
287
/* Number of basic blocks in this flow graph. */
288
int x_n_basic_blocks;
289
290
/* Number of edges in this flow graph. */
291
int x_n_edges;
292
293
/* The first free basic block number. */
294
int x_last_basic_block;
295
296
/* UIDs for LABEL_DECLs. */
297
int last_label_uid;
298
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;
302
303
enum profile_status_d x_profile_status;
304
305
/* Whether the dominators and the postdominators are available. */
306
enum dom_state x_dom_computed[2];
307
308
/* Number of basic blocks in the dominance tree. */
309
unsigned x_n_bbs_in_dom_tree[2];
310
311
/* Maximal number of entities in the single jumptable. Used to estimate
312
final flowgraph size. */
313
int max_jumptable_ents;
314
};
315
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)
325
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))
330
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)
340
341
#define BASIC_BLOCK(N) ((*basic_block_info)[(N)])
342
#define SET_BASIC_BLOCK(N,BB) ((*basic_block_info)[(N)] = (BB))
343
344
/* For iterating over basic blocks. */
345
#define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
346
for (BB = FROM; BB != TO; BB = BB->DIR)
347
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)
350
351
#define FOR_EACH_BB(BB) FOR_EACH_BB_FN (BB, cfun)
352
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)
355
356
#define FOR_EACH_BB_REVERSE(BB) FOR_EACH_BB_REVERSE_FN(BB, cfun)
357
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))
363
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)
370
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))
375
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)
380
381
/* Cycles through _all_ basic blocks, even the fake ones (entry and
382
exit block). */
383
384
#define FOR_ALL_BB(BB) \
385
for (BB = ENTRY_BLOCK_PTR; BB; BB = BB->next_bb)
386
387
#define FOR_ALL_BB_FN(BB, FN) \
388
for (BB = ENTRY_BLOCK_PTR_FOR_FUNCTION (FN); BB; BB = BB->next_bb)
389
390
391
/* Stuff for recording basic block info. */
392
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_
397
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)
402
403
/* The two blocks that are always in the cfg. */
404
#define NUM_FIXED_BLOCKS (2)
405
406
#define set_block_for_insn(INSN, BB) (BLOCK_FOR_INSN (INSN) = BB)
407
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);
411
412
extern void insert_insn_on_edge (rtx, edge);
413
basic_block split_edge_and_insert (edge, rtx);
414
415
extern void commit_one_edge_insertion (edge e);
416
extern void commit_edge_insertions (void);
417
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);
437
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. */
442
443
typedef struct ce_if_block
444
{
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;
459
460
/* This structure maintains an edge list vector. */
461
/* FIXME: Make this a vec<edge>. */
462
struct edge_list
463
{
464
int num_edges;
465
edge *index_to_edge;
466
};
467
468
/* The base value for branch probability notes and edge probabilities. */
469
#define REG_BR_PROB_BASE 10000
470
471
/* This is the value which indicates no edge is present. */
472
#define EDGE_INDEX_NO_EDGE -1
473
474
/* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
475
if there is no edge between the 2 basic blocks. */
476
#define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
477
478
/* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
479
block which is either the pred or succ end of the indexed edge. */
480
#define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
481
#define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
482
483
/* INDEX_EDGE returns a pointer to the edge. */
484
#define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
485
486
/* Number of edges in the compressed edge list. */
487
#define NUM_EDGES(el) ((el)->num_edges)
488
489
/* BB is assumed to contain conditional jump. Return the fallthru edge. */
490
#define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
491
? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
492
493
/* BB is assumed to contain conditional jump. Return the branch edge. */
494
#define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
495
? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
496
497
#define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
498
/* Return expected execution frequency of the edge E. */
499
#define EDGE_FREQUENCY(e) RDIV ((e)->src->frequency * (e)->probability, \
500
REG_BR_PROB_BASE)
501
502
/* Compute a scale factor (or probability) suitable for scaling of
503
gcov_type values via apply_probability() and apply_scale(). */
504
#define GCOV_COMPUTE_SCALE(num,den) \
505
((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
506
507
/* Return nonzero if edge is critical. */
508
#define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
509
&& EDGE_COUNT ((e)->dest->preds) >= 2)
510
511
#define EDGE_COUNT(ev) vec_safe_length (ev)
512
#define EDGE_I(ev,i) (*ev)[(i)]
513
#define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
514
#define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
515
516
/* Returns true if BB has precisely one successor. */
517
518
static inline bool
519
single_succ_p (const_basic_block bb)
520
{
521
return EDGE_COUNT (bb->succs) == 1;
522
}
523
524
/* Returns true if BB has precisely one predecessor. */
525
526
static inline bool
527
single_pred_p (const_basic_block bb)
528
{
529
return EDGE_COUNT (bb->preds) == 1;
530
}
531
532
/* Returns the single successor edge of basic block BB. Aborts if
533
BB does not have exactly one successor. */
534
535
static inline edge
536
single_succ_edge (const_basic_block bb)
537
{
538
gcc_checking_assert (single_succ_p (bb));
539
return EDGE_SUCC (bb, 0);
540
}
541
542
/* Returns the single predecessor edge of basic block BB. Aborts
543
if BB does not have exactly one predecessor. */
544
545
static inline edge
546
single_pred_edge (const_basic_block bb)
547
{
548
gcc_checking_assert (single_pred_p (bb));
549
return EDGE_PRED (bb, 0);
550
}
551
552
/* Returns the single successor block of basic block BB. Aborts
553
if BB does not have exactly one successor. */
554
555
static inline basic_block
556
single_succ (const_basic_block bb)
557
{
558
return single_succ_edge (bb)->dest;
559
}
560
561
/* Returns the single predecessor block of basic block BB. Aborts
562
if BB does not have exactly one predecessor.*/
563
564
static inline basic_block
565
single_pred (const_basic_block bb)
566
{
567
return single_pred_edge (bb)->src;
568
}
569
570
/* Iterator object for edges. */
571
572
typedef struct {
573
unsigned index;
574
vec<edge, va_gc> **container;
575
} edge_iterator;
576
577
static inline vec<edge, va_gc> *
578
ei_container (edge_iterator i)
579
{
580
gcc_checking_assert (i.container);
581
return *i.container;
582
}
583
584
#define ei_start(iter) ei_start_1 (&(iter))
585
#define ei_last(iter) ei_last_1 (&(iter))
586
587
/* Return an iterator pointing to the start of an edge vector. */
588
static inline edge_iterator
589
ei_start_1 (vec<edge, va_gc> **ev)
590
{
591
edge_iterator i;
592
593
i.index = 0;
594
i.container = ev;
595
596
return i;
597
}
598
599
/* Return an iterator pointing to the last element of an edge
600
vector. */
601
static inline edge_iterator
602
ei_last_1 (vec<edge, va_gc> **ev)
603
{
604
edge_iterator i;
605
606
i.index = EDGE_COUNT (*ev) - 1;
607
i.container = ev;
608
609
return i;
610
}
611
612
/* Is the iterator `i' at the end of the sequence? */
613
static inline bool
614
ei_end_p (edge_iterator i)
615
{
616
return (i.index == EDGE_COUNT (ei_container (i)));
617
}
618
619
/* Is the iterator `i' at one position before the end of the
620
sequence? */
621
static inline bool
622
ei_one_before_end_p (edge_iterator i)
623
{
624
return (i.index + 1 == EDGE_COUNT (ei_container (i)));
625
}
626
627
/* Advance the iterator to the next element. */
628
static inline void
629
ei_next (edge_iterator *i)
630
{
631
gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
632
i->index++;
633
}
634
635
/* Move the iterator to the previous element. */
636
static inline void
637
ei_prev (edge_iterator *i)
638
{
639
gcc_checking_assert (i->index > 0);
640
i->index--;
641
}
642
643
/* Return the edge pointed to by the iterator `i'. */
644
static inline edge
645
ei_edge (edge_iterator i)
646
{
647
return EDGE_I (ei_container (i), i.index);
648
}
649
650
/* Return an edge pointed to by the iterator. Do it safely so that
651
NULL is returned when the iterator is pointing at the end of the
652
sequence. */
653
static inline edge
654
ei_safe_edge (edge_iterator i)
655
{
656
return !ei_end_p (i) ? ei_edge (i) : NULL;
657
}
658
659
/* Return 1 if we should continue to iterate. Return 0 otherwise.
660
*Edge P is set to the next edge if we are to continue to iterate
661
and NULL otherwise. */
662
663
static inline bool
664
ei_cond (edge_iterator ei, edge *p)
665
{
666
if (!ei_end_p (ei))
667
{
668
*p = ei_edge (ei);
669
return 1;
670
}
671
else
672
{
673
*p = NULL;
674
return 0;
675
}
676
}
677
678
/* This macro serves as a convenient way to iterate each edge in a
679
vector of predecessor or successor edges. It must not be used when
680
an element might be removed during the traversal, otherwise
681
elements will be missed. Instead, use a for-loop like that shown
682
in the following pseudo-code:
683
684
FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
685
{
686
IF (e != taken_edge)
687
remove_edge (e);
688
ELSE
689
ei_next (&ei);
690
}
691
*/
692
693
#define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
694
for ((ITER) = ei_start ((EDGE_VEC)); \
695
ei_cond ((ITER), &(EDGE)); \
696
ei_next (&(ITER)))
697
698
#define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
699
except for edge forwarding */
700
#define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
701
#define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
702
to care REG_DEAD notes. */
703
#define CLEANUP_THREADING 8 /* Do jump threading. */
704
#define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
705
insns. */
706
#define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
707
#define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
708
709
/* In cfganal.c */
710
extern void bitmap_intersection_of_succs (sbitmap, sbitmap *, basic_block);
711
extern void bitmap_intersection_of_preds (sbitmap, sbitmap *, basic_block);
712
extern void bitmap_union_of_succs (sbitmap, sbitmap *, basic_block);
713
extern void bitmap_union_of_preds (sbitmap, sbitmap *, basic_block);
714
715
/* In lcm.c */
716
extern struct edge_list *pre_edge_lcm (int, sbitmap *, sbitmap *,
717
sbitmap *, sbitmap *, sbitmap **,
718
sbitmap **);
719
extern struct edge_list *pre_edge_rev_lcm (int, sbitmap *,
720
sbitmap *, sbitmap *,
721
sbitmap *, sbitmap **,
722
sbitmap **);
723
extern void compute_available (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
724
725
/* In predict.c */
726
extern bool maybe_hot_bb_p (struct function *, const_basic_block);
727
extern bool maybe_hot_edge_p (edge);
728
extern bool probably_never_executed_bb_p (struct function *, const_basic_block);
729
extern bool optimize_bb_for_size_p (const_basic_block);
730
extern bool optimize_bb_for_speed_p (const_basic_block);
731
extern bool optimize_edge_for_size_p (edge);
732
extern bool optimize_edge_for_speed_p (edge);
733
extern bool optimize_loop_for_size_p (struct loop *);
734
extern bool optimize_loop_for_speed_p (struct loop *);
735
extern bool optimize_loop_nest_for_size_p (struct loop *);
736
extern bool optimize_loop_nest_for_speed_p (struct loop *);
737
extern bool gimple_predicted_by_p (const_basic_block, enum br_predictor);
738
extern bool rtl_predicted_by_p (const_basic_block, enum br_predictor);
739
extern void gimple_predict_edge (edge, enum br_predictor, int);
740
extern void rtl_predict_edge (edge, enum br_predictor, int);
741
extern void predict_edge_def (edge, enum br_predictor, enum prediction);
742
extern void guess_outgoing_edge_probabilities (basic_block);
743
extern void remove_predictions_associated_with_edge (edge);
744
extern bool edge_probability_reliable_p (const_edge);
745
extern bool br_prob_note_reliable_p (const_rtx);
746
extern bool predictable_edge_p (edge);
747
748
/* In cfg.c */
749
extern void init_flow (struct function *);
750
extern void debug_bb (basic_block);
751
extern basic_block debug_bb_n (int);
752
extern void dump_flow_info (FILE *, int);
753
extern void expunge_block (basic_block);
754
extern void link_block (basic_block, basic_block);
755
extern void unlink_block (basic_block);
756
extern void compact_blocks (void);
757
extern basic_block alloc_block (void);
758
extern void alloc_aux_for_blocks (int);
759
extern void clear_aux_for_blocks (void);
760
extern void free_aux_for_blocks (void);
761
extern void alloc_aux_for_edge (edge, int);
762
extern void alloc_aux_for_edges (int);
763
extern void clear_aux_for_edges (void);
764
extern void free_aux_for_edges (void);
765
766
/* In cfganal.c */
767
extern void find_unreachable_blocks (void);
768
extern bool mark_dfs_back_edges (void);
769
struct edge_list * create_edge_list (void);
770
void free_edge_list (struct edge_list *);
771
void print_edge_list (FILE *, struct edge_list *);
772
void verify_edge_list (FILE *, struct edge_list *);
773
int find_edge_index (struct edge_list *, basic_block, basic_block);
774
edge find_edge (basic_block, basic_block);
775
extern void remove_fake_edges (void);
776
extern void remove_fake_exit_edges (void);
777
extern void add_noreturn_fake_exit_edges (void);
778
extern void connect_infinite_loops_to_exit (void);
779
extern int post_order_compute (int *, bool, bool);
780
extern basic_block dfs_find_deadend (basic_block);
781
extern int inverted_post_order_compute (int *);
782
extern int pre_and_rev_post_order_compute (int *, int *, bool);
783
extern int dfs_enumerate_from (basic_block, int,
784
bool (*)(const_basic_block, const void *),
785
basic_block *, int, const void *);
786
extern void compute_dominance_frontiers (struct bitmap_head_def *);
787
extern bitmap compute_idf (bitmap, struct bitmap_head_def *);
788
789
/* In cfgrtl.c */
790
extern rtx block_label (basic_block);
791
extern rtx bb_note (basic_block);
792
extern bool purge_all_dead_edges (void);
793
extern bool purge_dead_edges (basic_block);
794
extern bool fixup_abnormal_edges (void);
795
extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx);
796
extern bool contains_no_active_insn_p (const_basic_block);
797
extern bool forwarder_block_p (const_basic_block);
798
extern bool can_fallthru (basic_block, basic_block);
799
extern void emit_barrier_after_bb (basic_block bb);
800
801
/* In cfgbuild.c. */
802
extern void find_many_sub_basic_blocks (sbitmap);
803
extern void rtl_make_eh_edge (sbitmap, basic_block, rtx);
804
805
enum replace_direction { dir_none, dir_forward, dir_backward, dir_both };
806
807
/* In cfgcleanup.c. */
808
extern bool cleanup_cfg (int);
809
extern int flow_find_cross_jump (basic_block, basic_block, rtx *, rtx *,
810
enum replace_direction*);
811
extern int flow_find_head_matching_sequence (basic_block, basic_block,
812
rtx *, rtx *, int);
813
814
extern bool delete_unreachable_blocks (void);
815
816
extern void update_br_prob_note (basic_block);
817
extern bool inside_basic_block_p (const_rtx);
818
extern bool control_flow_insn_p (const_rtx);
819
extern rtx get_last_bb_insn (basic_block);
820
821
/* In dominance.c */
822
823
enum cdi_direction
824
{
825
CDI_DOMINATORS = 1,
826
CDI_POST_DOMINATORS = 2
827
};
828
829
extern enum dom_state dom_info_state (enum cdi_direction);
830
extern void set_dom_info_availability (enum cdi_direction, enum dom_state);
831
extern bool dom_info_available_p (enum cdi_direction);
832
extern void calculate_dominance_info (enum cdi_direction);
833
extern void free_dominance_info (enum cdi_direction);
834
extern basic_block nearest_common_dominator (enum cdi_direction,
835
basic_block, basic_block);
836
extern basic_block nearest_common_dominator_for_set (enum cdi_direction,
837
bitmap);
838
extern void set_immediate_dominator (enum cdi_direction, basic_block,
839
basic_block);
840
extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
841
extern bool dominated_by_p (enum cdi_direction, const_basic_block, const_basic_block);
842
extern vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);
843
extern vec<basic_block> get_dominated_by_region (enum cdi_direction,
844
basic_block *,
845
unsigned);
846
extern vec<basic_block> get_dominated_to_depth (enum cdi_direction,
847
basic_block, int);
848
extern vec<basic_block> get_all_dominated_blocks (enum cdi_direction,
849
basic_block);
850
extern void add_to_dominance_info (enum cdi_direction, basic_block);
851
extern void delete_from_dominance_info (enum cdi_direction, basic_block);
852
basic_block recompute_dominator (enum cdi_direction, basic_block);
853
extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
854
basic_block);
855
extern void iterate_fix_dominators (enum cdi_direction,
856
vec<basic_block> , bool);
857
extern void verify_dominators (enum cdi_direction);
858
extern basic_block first_dom_son (enum cdi_direction, basic_block);
859
extern basic_block next_dom_son (enum cdi_direction, basic_block);
860
unsigned bb_dom_dfs_in (enum cdi_direction, basic_block);
861
unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
862
863
extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
864
extern void break_superblocks (void);
865
extern void relink_block_chain (bool);
866
extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
867
extern void init_rtl_bb_info (basic_block);
868
869
extern void initialize_original_copy_tables (void);
870
extern void free_original_copy_tables (void);
871
extern void set_bb_original (basic_block, basic_block);
872
extern basic_block get_bb_original (basic_block);
873
extern void set_bb_copy (basic_block, basic_block);
874
extern basic_block get_bb_copy (basic_block);
875
void set_loop_copy (struct loop *, struct loop *);
876
struct loop *get_loop_copy (struct loop *);
877
878
#include "
cfghooks.h
"
879
880
/* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
881
static inline bool
882
bb_has_eh_pred (basic_block bb)
883
{
884
edge e;
885
edge_iterator ei;
886
887
FOR_EACH_EDGE (e, ei, bb->preds)
888
{
889
if (e->flags & EDGE_EH)
890
return true;
891
}
892
return false;
893
}
894
895
/* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
896
static inline bool
897
bb_has_abnormal_pred (basic_block bb)
898
{
899
edge e;
900
edge_iterator ei;
901
902
FOR_EACH_EDGE (e, ei, bb->preds)
903
{
904
if (e->flags & EDGE_ABNORMAL)
905
return true;
906
}
907
return false;
908
}
909
910
/* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
911
static inline edge
912
find_fallthru_edge (vec<edge, va_gc> *edges)
913
{
914
edge e;
915
edge_iterator ei;
916
917
FOR_EACH_EDGE (e, ei, edges)
918
if (e->flags & EDGE_FALLTHRU)
919
break;
920
921
return e;
922
}
923
924
/* In cfgloopmanip.c. */
925
extern edge mfb_kj_edge;
926
extern bool mfb_keep_just (edge);
927
928
/* In cfgexpand.c. */
929
extern void rtl_profile_for_bb (basic_block);
930
extern void rtl_profile_for_edge (edge);
931
extern void default_rtl_profile (void);
932
933
/* In profile.c. */
934
typedef struct gcov_working_set_info gcov_working_set_t;
935
extern gcov_working_set_t *find_working_set(unsigned pct_times_10);
936
937
/* Check tha probability is sane. */
938
939
static inline void
940
check_probability (int prob)
941
{
942
gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
943
}
944
945
/* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
946
Used to combine BB probabilities. */
947
948
static inline int
949
combine_probabilities (int prob1, int prob2)
950
{
951
check_probability (prob1);
952
check_probability (prob2);
953
return RDIV (prob1 * prob2, REG_BR_PROB_BASE);
954
}
955
956
/* Apply scale factor SCALE on frequency or count FREQ. Use this
957
interface when potentially scaling up, so that SCALE is not
958
constrained to be < REG_BR_PROB_BASE. */
959
960
static inline gcov_type
961
apply_scale (gcov_type freq, int scale)
962
{
963
return RDIV (freq * scale, REG_BR_PROB_BASE);
964
}
965
966
/* Apply probability PROB on frequency or count FREQ. */
967
968
static inline gcov_type
969
apply_probability (gcov_type freq, int prob)
970
{
971
check_probability (prob);
972
return apply_scale (freq, prob);
973
}
974
975
/* Return inverse probability for PROB. */
976
977
static inline int
978
inverse_probability (int prob1)
979
{
980
check_probability (prob1);
981
return REG_BR_PROB_BASE - prob1;
982
}
983
#endif /* GCC_BASIC_BLOCK_H */
gcc
basic-block.h
Generated by
1.8.1.1