/* Define control flow data structures for the CFG.
Copyright (C) 1987-2025 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
. */
#ifndef GCC_BASIC_BLOCK_H
#define GCC_BASIC_BLOCK_H
#include
/* Control flow edge information. */
class GTY((user)) edge_def {
public:
/* The two blocks at the ends of the edge. */
basic_block src;
basic_block dest;
/* Instructions queued on the edge. */
union edge_def_insns {
gimple_seq g;
rtx_insn *r;
} insns;
/* Auxiliary info specific to a pass. */
void *aux;
/* Location of any goto implicit in the edge. */
location_t goto_locus;
/* The index number corresponding to this edge in the edge vector
dest->preds. */
unsigned int dest_idx;
int flags; /* see cfg-flags.def */
profile_probability probability;
/* Return count of edge E. */
inline profile_count count () const;
};
/* Masks for edge.flags. */
#define DEF_EDGE_FLAG(NAME,IDX) EDGE_##NAME = 1 << IDX ,
enum cfg_edge_flags {
#include "cfg-flags.def"
LAST_CFG_EDGE_FLAG /* this is only used for EDGE_ALL_FLAGS */
};
#undef DEF_EDGE_FLAG
/* Bit mask for all edge flags. */
#define EDGE_ALL_FLAGS ((LAST_CFG_EDGE_FLAG - 1) * 2 - 1)
/* The following four flags all indicate something special about an edge.
Test the edge flags on EDGE_COMPLEX to detect all forms of "strange"
control flow transfers. */
#define EDGE_COMPLEX \
(EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH | EDGE_PRESERVE)
struct GTY(()) rtl_bb_info {
/* The first insn of the block is embedded into bb->il.x. */
/* The last insn of the block. */
rtx_insn *end_;
/* In CFGlayout mode points to insn notes/jumptables to be placed just before
and after the block. */
rtx_insn *header_;
rtx_insn *footer_;
};
struct GTY(()) gimple_bb_info {
/* Sequence of statements in this block. */
gimple_seq seq;
/* PHI nodes for this block. */
gimple_seq phi_nodes;
};
/* A basic block is a sequence of instructions with only one entry and
only one exit. If any one of the instructions are executed, they
will all be executed, and in sequence from first to last.
There may be COND_EXEC instructions in the basic block. The
COND_EXEC *instructions* will be executed -- but if the condition
is false the conditionally executed *expressions* will of course
not be executed. We don't consider the conditionally executed
expression (which might have side-effects) to be in a separate
basic block because the program counter will always be at the same
location after the COND_EXEC instruction, regardless of whether the
condition is true or not.
Basic blocks need not start with a label nor end with a jump insn.
For example, a previous basic block may just "conditionally fall"
into the succeeding basic block, and the last basic block need not
end with a jump insn. Block 0 is a descendant of the entry block.
A basic block beginning with two labels cannot have notes between
the labels.
Data for jump tables are stored in jump_insns that occur in no
basic block even though these insns can follow or precede insns in
basic blocks. */
/* Basic block information indexed by block number. */
struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_def {
/* The edges into and out of the block. */
vec *preds;
vec *succs;
/* Auxiliary info specific to a pass. */
void *GTY ((skip (""))) aux;
/* Innermost loop containing the block. */
class loop *loop_father;
/* The dominance and postdominance information node. */
struct et_node * GTY ((skip (""))) dom[2];
/* Previous and next blocks in the chain. */
basic_block prev_bb;
basic_block next_bb;
union basic_block_il_dependent {
struct gimple_bb_info GTY ((tag ("0"))) gimple;
struct {
rtx_insn *head_;
struct rtl_bb_info * rtl;
} GTY ((tag ("1"))) x;
} GTY ((desc ("((%1.flags & BB_RTL) != 0)"))) il;
/* Various flags. See cfg-flags.def. */
int flags;
/* The index of this block. */
int index;
/* Expected number of executions: calculated in profile.cc. */
profile_count count;
};
/* This ensures that struct gimple_bb_info is smaller than
struct rtl_bb_info, so that inlining the former into basic_block_def
is the better choice. */
STATIC_ASSERT (sizeof (rtl_bb_info) >= sizeof (gimple_bb_info));
#define BB_FREQ_MAX 10000
/* Masks for basic_block.flags. */
#define DEF_BASIC_BLOCK_FLAG(NAME,IDX) BB_##NAME = 1 << IDX ,
enum cfg_bb_flags
{
#include "cfg-flags.def"
LAST_CFG_BB_FLAG /* this is only used for BB_ALL_FLAGS */
};
#undef DEF_BASIC_BLOCK_FLAG
/* Bit mask for all basic block flags. */
#define BB_ALL_FLAGS ((LAST_CFG_BB_FLAG - 1) * 2 - 1)
/* Bit mask for all basic block flags that must be preserved. These are
the bit masks that are *not* cleared by clear_bb_flags. */
#define BB_FLAGS_TO_PRESERVE \
(BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET \
| BB_HOT_PARTITION | BB_COLD_PARTITION)
/* Dummy bitmask for convenience in the hot/cold partitioning code. */
#define BB_UNPARTITIONED 0
/* Partitions, to be used when partitioning hot and cold basic blocks into
separate sections. */
#define BB_PARTITION(bb) ((bb)->flags & (BB_HOT_PARTITION|BB_COLD_PARTITION))
#define BB_SET_PARTITION(bb, part) do { \
basic_block bb_ = (bb); \
bb_->flags = ((bb_->flags & ~(BB_HOT_PARTITION|BB_COLD_PARTITION)) \
| (part)); \
} while (0)
#define BB_COPY_PARTITION(dstbb, srcbb) \
BB_SET_PARTITION (dstbb, BB_PARTITION (srcbb))
/* Defines for accessing the fields of the CFG structure for function FN. */
#define ENTRY_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_entry_block_ptr)
#define EXIT_BLOCK_PTR_FOR_FN(FN) ((FN)->cfg->x_exit_block_ptr)
#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
#define BASIC_BLOCK_FOR_FN(FN,N) \
((*basic_block_info_for_fn (FN))[(N)])
#define SET_BASIC_BLOCK_FOR_FN(FN,N,BB) \
((*basic_block_info_for_fn (FN))[(N)] = (BB))
/* For iterating over basic blocks. */
#define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
for (BB = FROM; BB != TO; BB = BB->DIR)
#define FOR_EACH_BB_FN(BB, FN) \
FOR_BB_BETWEEN (BB, (FN)->cfg->x_entry_block_ptr->next_bb, (FN)->cfg->x_exit_block_ptr, next_bb)
#define FOR_EACH_BB_REVERSE_FN(BB, FN) \
FOR_BB_BETWEEN (BB, (FN)->cfg->x_exit_block_ptr->prev_bb, (FN)->cfg->x_entry_block_ptr, prev_bb)
/* For iterating over insns in basic block. */
#define FOR_BB_INSNS(BB, INSN) \
for ((INSN) = BB_HEAD (BB); \
(INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
(INSN) = NEXT_INSN (INSN))
/* For iterating over insns in basic block when we might remove the
current insn. */
#define FOR_BB_INSNS_SAFE(BB, INSN, CURR) \
for ((INSN) = BB_HEAD (BB), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL; \
(INSN) && (INSN) != NEXT_INSN (BB_END (BB)); \
(INSN) = (CURR), (CURR) = (INSN) ? NEXT_INSN ((INSN)) : NULL)
#define FOR_BB_INSNS_REVERSE(BB, INSN) \
for ((INSN) = BB_END (BB); \
(INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
(INSN) = PREV_INSN (INSN))
#define FOR_BB_INSNS_REVERSE_SAFE(BB, INSN, CURR) \
for ((INSN) = BB_END (BB),(CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL; \
(INSN) && (INSN) != PREV_INSN (BB_HEAD (BB)); \
(INSN) = (CURR), (CURR) = (INSN) ? PREV_INSN ((INSN)) : NULL)
/* Cycles through _all_ basic blocks, even the fake ones (entry and
exit block). */
#define FOR_ALL_BB_FN(BB, FN) \
for (BB = ENTRY_BLOCK_PTR_FOR_FN (FN); BB; BB = BB->next_bb)