Emit a no longer supported warning for gcoff* options.
[official-gcc.git] / gcc / basic-block.h
blob1505cce81bf589483c93495263830080f4590cd7
1 /* Define control flow data structures for the CFG.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_BASIC_BLOCK_H
21 #define GCC_BASIC_BLOCK_H
23 #include <profile-count.h>
25 /* Control flow edge information. */
26 struct GTY((user)) edge_def {
27 /* The two blocks at the ends of the edge. */
28 basic_block src;
29 basic_block dest;
31 /* Instructions queued on the edge. */
32 union edge_def_insns {
33 gimple_seq g;
34 rtx_insn *r;
35 } insns;
37 /* Auxiliary info specific to a pass. */
38 PTR aux;
40 /* Location of any goto implicit in the edge. */
41 location_t goto_locus;
43 /* The index number corresponding to this edge in the edge vector
44 dest->preds. */
45 unsigned int dest_idx;
47 int flags; /* see cfg-flags.def */
48 profile_probability probability;
50 /* Return count of edge E. */
51 inline profile_count count () const;
54 /* Masks for edge.flags. */
55 #define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
56 enum cfg_edge_flags {
57 #include "cfg-flags.def"
58 LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */
60 #undef DEF_EDGE_FLAG
62 /* Bit mask for all edge flags. */
63 #define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
65 /* The following four flags all indicate something special about an edge.
66 Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
67 control flow transfers. */
68 #define EDGE_COMPLEX \
69 (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
71 struct GTY(()) rtl_bb_info {
72 /* The first insn of the block is embedded into bb->il.x. */
73 /* The last insn of the block. */
74 rtx_insn *end_;
76 /* In CFGlayout mode points to insn notes/jumptables to be placed just before
77 and after the block. */
78 rtx_insn *header_;
79 rtx_insn *footer_;
82 struct GTY(()) gimple_bb_info {
83 /* Sequence of statements in this block. */
84 gimple_seq seq;
86 /* PHI nodes for this block. */
87 gimple_seq phi_nodes;
90 /* A basic block is a sequence of instructions with only one entry and
91 only one exit. If any one of the instructions are executed, they
92 will all be executed, and in sequence from first to last.
94 There may be COND_EXEC instructions in the basic block. The
95 COND_EXEC *instructions* will be executed -- but if the condition
96 is false the conditionally executed *expressions* will of course
97 not be executed. We don't consider the conditionally executed
98 expression (which might have side-effects) to be in a separate
99 basic block because the program counter will always be at the same
100 location after the COND_EXEC instruction, regardless of whether the
101 condition is true or not.
103 Basic blocks need not start with a label nor end with a jump insn.
104 For example, a previous basic block may just "conditionally fall"
105 into the succeeding basic block, and the last basic block need not
106 end with a jump insn. Block 0 is a descendant of the entry block.
108 A basic block beginning with two labels cannot have notes between
109 the labels.
111 Data for jump tables are stored in jump_insns that occur in no
112 basic block even though these insns can follow or precede insns in
113 basic blocks. */
115 /* Basic block information indexed by block number. */
116 struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
117 /* The edges into and out of the block. */
118 vec<edge, va_gc> *preds;
119 vec<edge, va_gc> *succs;
121 /* Auxiliary info specific to a pass. */
122 PTR GTY ((skip (""))) aux;
124 /* Innermost loop containing the block. */
125 struct loop *loop_father;
127 /* The dominance and postdominance information node. */
128 struct et_node * GTY ((skip (""))) dom[2];
130 /* Previous and next blocks in the chain. */
131 basic_block prev_bb;
132 basic_block next_bb;
134 union basic_block_il_dependent {
135 struct gimple_bb_info GTY ((tag ("0"))) gimple;
136 struct {
137 rtx_insn *head_;
138 struct rtl_bb_info * rtl;
139 } GTY ((tag ("1"))) x;
140 } GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
142 /* Various flags. See cfg-flags.def. */
143 int flags;
145 /* The index of this block. */
146 int index;
148 /* Expected number of executions: calculated in profile.c. */
149 profile_count count;
151 /* Expected frequency. Normalized to be in range 0 to BB_FREQ_MAX. */
152 int frequency;
154 /* The discriminator for this block. The discriminator distinguishes
155 among several basic blocks that share a common locus, allowing for
156 more accurate sample-based profiling. */
157 int discriminator;
160 /* This ensures that struct gimple_bb_info is smaller than
161 struct rtl_bb_info, so that inlining the former into basic_block_def
162 is the better choice. */
163 typedef int __assert_gimple_bb_smaller_rtl_bb
164 [(int) sizeof (struct rtl_bb_info)
165 - (int) sizeof (struct gimple_bb_info)];
168 #define BB_FREQ_MAX 10000
170 /* Masks for basic_block.flags. */
171 #define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
172 enum cfg_bb_flags
174 #include "cfg-flags.def"
175 LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
177 #undef DEF_BASIC_BLOCK_FLAG
179 /* Bit mask for all basic block flags. */
180 #define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
182 /* Bit mask for all basic block flags that must be preserved. These are
183 the bit masks that are *not* cleared by clear_bb_flags. */
184 #define BB_FLAGS_TO_PRESERVE \
185 (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
186 | BB_HOT_PARTITION | BB_COLD_PARTITION)
188 /* Dummy bitmask for convenience in the hot/cold partitioning code. */
189 #define BB_UNPARTITIONED 0
191 /* Partitions, to be used when partitioning hot and cold basic blocks into
192 separate sections. */
193 #define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
194 #define BB_SET_PARTITION(bb, part) do { \
195 basic_block bb_ = (bb); \
196 bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
197 | (part)); \
198 } while (0)
200 #define BB_COPY_PARTITION(dstbb, srcbb) \
201 BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
203 /* Defines for accessing the fields of the CFG structure for function FN. */
204 #define ENTRY_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_entry_block_ptr)
205 #define EXIT_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_exit_block_ptr)
206 #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
207 #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
208 #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
209 #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
210 #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
211 #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
213 #define BASIC_BLOCK_FOR_FN(FN,N) \
214 ((*basic_block_info_for_fn (FN))[(N)])
215 #define SET_BASIC_BLOCK_FOR_FN(FN,N,BB) \
216 ((*basic_block_info_for_fn (FN))[(N)] = (BB))
218 /* For iterating over basic blocks. */
219 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
220 for (BB = FROM; BB != TO; BB = BB->DIR)
222 #define FOR_EACH_BB_FN(BB, FN) \
223 FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
225 #define FOR_EACH_BB_REVERSE_FN(BB, FN) \
226 FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
228 /* For iterating over insns in basic block. */
229 #define FOR_BB_INSNS(BB, INSN) \
230 for ((INSN) = BB_HEAD (BB); \
231 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
232 (INSN) = NEXT_INSN (INSN))
234 /* For iterating over insns in basic block when we might remove the
235 current insn. */
236 #define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
237 for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)): NULL; \
238 (INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
239 (INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
241 #define FOR_BB_INSNS_REVERSE(BB, INSN) \
242 for ((INSN) = BB_END (BB); \
243 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
244 (INSN) = PREV_INSN (INSN))
246 #define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
247 for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
248 (INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
249 (INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
251 /* Cycles through _all_ basic blocks, even the fake ones (entry and
252 exit block). */
254 #define FOR_ALL_BB_FN(BB, FN) \
255 for (BB = ENTRY_BLOCK_PTR_FOR_FN (FN); BB; BB = BB->next_bb)
258 /* Stuff for recording basic block info. */
260 /* For now, these will be functions (so that they can include checked casts
261 to rtx_insn. Once the underlying fields are converted from rtx
262 to rtx_insn, these can be converted back to macros. */
264 #define BB_HEAD(B) (B)->il.x.head_
265 #define BB_END(B) (B)->il.x.rtl->end_
266 #define BB_HEADER(B) (B)->il.x.rtl->header_
267 #define BB_FOOTER(B) (B)->il.x.rtl->footer_
269 /* Special block numbers [markers] for entry and exit.
270 Neither of them is supposed to hold actual statements. */
271 #define ENTRY_BLOCK (0)
272 #define EXIT_BLOCK (1)
274 /* The two blocks that are always in the cfg. */
275 #define NUM_FIXED_BLOCKS (2)
277 /* This is the value which indicates no edge is present. */
278 #define EDGE_INDEX_NO_EDGE -1
280 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
281 if there is no edge between the 2 basic blocks. */
282 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
284 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
285 block which is either the pred or succ end of the indexed edge. */
286 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
287 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
289 /* INDEX_EDGE returns a pointer to the edge. */
290 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
292 /* Number of edges in the compressed edge list. */
293 #define NUM_EDGES(el) ((el)->num_edges)
295 /* BB is assumed to contain conditional jump. Return the fallthru edge. */
296 #define FALLTHRU_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
297 ? EDGE_SUCC ((bb), 0) : EDGE_SUCC ((bb), 1))
299 /* BB is assumed to contain conditional jump. Return the branch edge. */
300 #define BRANCH_EDGE(bb) (EDGE_SUCC ((bb), 0)->flags & EDGE_FALLTHRU \
301 ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))
303 /* Return expected execution frequency of the edge E. */
304 #define EDGE_FREQUENCY(e) e->probability.apply (e->src->frequency)
306 /* Compute a scale factor (or probability) suitable for scaling of
307 gcov_type values via apply_probability() and apply_scale(). */
308 #define GCOV_COMPUTE_SCALE(num,den) \
309 ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
311 /* Return nonzero if edge is critical. */
312 #define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
313 && EDGE_COUNT ((e)->dest->preds) >= 2)
315 #define EDGE_COUNT(ev) vec_safe_length (ev)
316 #define EDGE_I(ev,i) (*ev)[(i)]
317 #define EDGE_PRED(bb,i) (*(bb)->preds)[(i)]
318 #define EDGE_SUCC(bb,i) (*(bb)->succs)[(i)]
320 /* Returns true if BB has precisely one successor. */
322 static inline bool
323 single_succ_p (const_basic_block bb)
325 return EDGE_COUNT (bb->succs) == 1;
328 /* Returns true if BB has precisely one predecessor. */
330 static inline bool
331 single_pred_p (const_basic_block bb)
333 return EDGE_COUNT (bb->preds) == 1;
336 /* Returns the single successor edge of basic block BB. Aborts if
337 BB does not have exactly one successor. */
339 static inline edge
340 single_succ_edge (const_basic_block bb)
342 gcc_checking_assert (single_succ_p (bb));
343 return EDGE_SUCC (bb, 0);
346 /* Returns the single predecessor edge of basic block BB. Aborts
347 if BB does not have exactly one predecessor. */
349 static inline edge
350 single_pred_edge (const_basic_block bb)
352 gcc_checking_assert (single_pred_p (bb));
353 return EDGE_PRED (bb, 0);
356 /* Returns the single successor block of basic block BB. Aborts
357 if BB does not have exactly one successor. */
359 static inline basic_block
360 single_succ (const_basic_block bb)
362 return single_succ_edge (bb)->dest;
365 /* Returns the single predecessor block of basic block BB. Aborts
366 if BB does not have exactly one predecessor.*/
368 static inline basic_block
369 single_pred (const_basic_block bb)
371 return single_pred_edge (bb)->src;
374 /* Iterator object for edges. */
376 struct edge_iterator {
377 unsigned index;
378 vec<edge, va_gc> **container;
381 static inline vec<edge, va_gc> *
382 ei_container (edge_iterator i)
384 gcc_checking_assert (i.container);
385 return *i.container;
388 #define ei_start(iter) ei_start_1 (&(iter))
389 #define ei_last(iter) ei_last_1 (&(iter))
391 /* Return an iterator pointing to the start of an edge vector. */
392 static inline edge_iterator
393 ei_start_1 (vec<edge, va_gc> **ev)
395 edge_iterator i;
397 i.index = 0;
398 i.container = ev;
400 return i;
403 /* Return an iterator pointing to the last element of an edge
404 vector. */
405 static inline edge_iterator
406 ei_last_1 (vec<edge, va_gc> **ev)
408 edge_iterator i;
410 i.index = EDGE_COUNT (*ev) - 1;
411 i.container = ev;
413 return i;
416 /* Is the iterator `i' at the end of the sequence? */
417 static inline bool
418 ei_end_p (edge_iterator i)
420 return (i.index == EDGE_COUNT (ei_container (i)));
423 /* Is the iterator `i' at one position before the end of the
424 sequence? */
425 static inline bool
426 ei_one_before_end_p (edge_iterator i)
428 return (i.index + 1 == EDGE_COUNT (ei_container (i)));
431 /* Advance the iterator to the next element. */
432 static inline void
433 ei_next (edge_iterator *i)
435 gcc_checking_assert (i->index < EDGE_COUNT (ei_container (*i)));
436 i->index++;
439 /* Move the iterator to the previous element. */
440 static inline void
441 ei_prev (edge_iterator *i)
443 gcc_checking_assert (i->index > 0);
444 i->index--;
447 /* Return the edge pointed to by the iterator `i'. */
448 static inline edge
449 ei_edge (edge_iterator i)
451 return EDGE_I (ei_container (i), i.index);
454 /* Return an edge pointed to by the iterator. Do it safely so that
455 NULL is returned when the iterator is pointing at the end of the
456 sequence. */
457 static inline edge
458 ei_safe_edge (edge_iterator i)
460 return !ei_end_p (i) ? ei_edge (i) : NULL;
463 /* Return 1 if we should continue to iterate. Return 0 otherwise.
464 *Edge P is set to the next edge if we are to continue to iterate
465 and NULL otherwise. */
467 static inline bool
468 ei_cond (edge_iterator ei, edge *p)
470 if (!ei_end_p (ei))
472 *p = ei_edge (ei);
473 return 1;
475 else
477 *p = NULL;
478 return 0;
482 /* This macro serves as a convenient way to iterate each edge in a
483 vector of predecessor or successor edges. It must not be used when
484 an element might be removed during the traversal, otherwise
485 elements will be missed. Instead, use a for-loop like that shown
486 in the following pseudo-code:
488 FOR (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
490 IF (e != taken_edge)
491 remove_edge (e);
492 ELSE
493 ei_next (&ei);
497 #define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
498 for ((ITER) = ei_start ((EDGE_VEC)); \
499 ei_cond ((ITER), &(EDGE)); \
500 ei_next (&(ITER)))
502 #define CLEANUP_EXPENSIVE 1 /* Do relatively expensive optimizations
503 except for edge forwarding */
504 #define CLEANUP_CROSSJUMP 2 /* Do crossjumping. */
505 #define CLEANUP_POST_REGSTACK 4 /* We run after reg-stack and need
506 to care REG_DEAD notes. */
507 #define CLEANUP_THREADING 8 /* Do jump threading. */
508 #define CLEANUP_NO_INSN_DEL 16 /* Do not try to delete trivially dead
509 insns. */
510 #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */
511 #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */
513 /* Return true if BB is in a transaction. */
515 static inline bool
516 bb_in_transaction (basic_block bb)
518 return bb->flags & BB_IN_TRANSACTION;
521 /* Return true when one of the predecessor edges of BB is marked with EDGE_EH. */
522 static inline bool
523 bb_has_eh_pred (basic_block bb)
525 edge e;
526 edge_iterator ei;
528 FOR_EACH_EDGE (e, ei, bb->preds)
530 if (e->flags & EDGE_EH)
531 return true;
533 return false;
536 /* Return true when one of the predecessor edges of BB is marked with EDGE_ABNORMAL. */
537 static inline bool
538 bb_has_abnormal_pred (basic_block bb)
540 edge e;
541 edge_iterator ei;
543 FOR_EACH_EDGE (e, ei, bb->preds)
545 if (e->flags & EDGE_ABNORMAL)
546 return true;
548 return false;
551 /* Return the fallthru edge in EDGES if it exists, NULL otherwise. */
552 static inline edge
553 find_fallthru_edge (vec<edge, va_gc> *edges)
555 edge e;
556 edge_iterator ei;
558 FOR_EACH_EDGE (e, ei, edges)
559 if (e->flags & EDGE_FALLTHRU)
560 break;
562 return e;
565 /* Check tha probability is sane. */
567 static inline void
568 check_probability (int prob)
570 gcc_checking_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
573 /* Given PROB1 and PROB2, return PROB1*PROB2/REG_BR_PROB_BASE.
574 Used to combine BB probabilities. */
576 static inline int
577 combine_probabilities (int prob1, int prob2)
579 check_probability (prob1);
580 check_probability (prob2);
581 return RDIV (prob1 * prob2, REG_BR_PROB_BASE);
584 /* Apply scale factor SCALE on frequency or count FREQ. Use this
585 interface when potentially scaling up, so that SCALE is not
586 constrained to be < REG_BR_PROB_BASE. */
588 static inline gcov_type
589 apply_scale (gcov_type freq, gcov_type scale)
591 return RDIV (freq * scale, REG_BR_PROB_BASE);
594 /* Apply probability PROB on frequency or count FREQ. */
596 static inline gcov_type
597 apply_probability (gcov_type freq, int prob)
599 check_probability (prob);
600 return apply_scale (freq, prob);
603 /* Return inverse probability for PROB. */
605 static inline int
606 inverse_probability (int prob1)
608 check_probability (prob1);
609 return REG_BR_PROB_BASE - prob1;
612 /* Return true if BB has at least one abnormal outgoing edge. */
614 static inline bool
615 has_abnormal_or_eh_outgoing_edge_p (basic_block bb)
617 edge e;
618 edge_iterator ei;
620 FOR_EACH_EDGE (e, ei, bb->succs)
621 if (e->flags & (EDGE_ABNORMAL | EDGE_EH))
622 return true;
624 return false;
627 /* Return true when one of the predecessor edges of BB is marked with
628 EDGE_ABNORMAL_CALL or EDGE_EH. */
630 static inline bool
631 has_abnormal_call_or_eh_pred_edge_p (basic_block bb)
633 edge e;
634 edge_iterator ei;
636 FOR_EACH_EDGE (e, ei, bb->preds)
637 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
638 return true;
640 return false;
643 /* Return count of edge E. */
644 inline profile_count edge_def::count () const
646 return src->count.apply_probability (probability);
649 #endif /* GCC_BASIC_BLOCK_H */