GCC Middle and Back End API Reference
Go to the documentation of this file.
1/* Control flow graph manipulation code header file.
2 Copyright (C) 2014-2024 Free Software Foundation, Inc.
4This file is part of GCC.
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
20#ifndef GCC_CFG_H
21#define GCC_CFG_H
23#include "dominance.h"
25/* What sort of profiling information we have. */
31 PROFILE_LAST /* Last value, used by profile streaming. */
34/* A structure to group all the per-function control flow graph data.
35 The x_* prefixing is necessary because otherwise references to the
36 fields of this struct are interpreted as the defines for backward
37 source compatibility following the definition of this struct. */
39 /* Block pointers for the exit and entry of a function.
40 These are always the head and tail of the basic block list. */
44 /* Index by basic block number, get basic block struct info. */
47 /* Number of basic blocks in this flow graph. */
50 /* Number of edges in this flow graph. */
53 /* The first free basic block number. */
56 /* UIDs for LABEL_DECLs. */
59 /* Mapping of labels to their associated blocks. At present
60 only used for the gimple CFG. */
65 /* Whether the dominators and the postdominators are available. */
66 enum dom_state x_dom_computed[2];
68 /* Number of basic blocks in the dominance tree. */
69 unsigned x_n_bbs_in_dom_tree[2];
71 /* Maximal number of entities in the single jumptable. Used to estimate
72 final flowgraph size. */
75 /* Maximal count of BB in function. */
78 /* Dynamically allocated edge/bb flags. */
82 /* Set if the profile is computed on every edge and basic block. */
87extern void init_flow (function *);
88extern void free_cfg (function *);
89extern basic_block alloc_block (void);
91extern void unlink_block (basic_block);
92extern void compact_blocks (void);
93extern void expunge_block (basic_block);
98extern void remove_edge_raw (edge);
100extern void redirect_edge_pred (edge, basic_block);
101extern void clear_bb_flags (void);
102extern void dump_edge_info (FILE *, edge, dump_flags_t, int);
103extern void debug (edge_def &ref);
104extern void debug (edge_def *ptr);
105extern void alloc_aux_for_blocks (int);
106extern void clear_aux_for_blocks (void);
107extern void free_aux_for_blocks (void);
108extern void alloc_aux_for_edge (edge, int);
109extern void alloc_aux_for_edges (int);
110extern void clear_aux_for_edges (void);
111extern void free_aux_for_edges (void);
112extern void debug_bb (basic_block);
113extern basic_block debug_bb_n (int);
114extern void debug_bb (basic_block, dump_flags_t);
116extern void dump_bb_info (FILE *, basic_block, int, dump_flags_t, bool, bool);
117extern void brief_dump_cfg (FILE *, dump_flags_t);
123extern void initialize_original_copy_tables (void);
124extern void reset_original_copy_tables (void);
125extern void free_original_copy_tables (void);
126extern bool original_copy_tables_initialized_p (void);
129extern void set_bb_copy (basic_block, basic_block);
131void set_loop_copy (class loop *, class loop *);
132class loop *get_loop_copy (class loop *);
136/* Generic RAII class to allocate a bit from storage of integer type T.
137 The allocated bit is accessible as mask with the single bit set
138 via the conversion operator to T. */
140template <class T>
144 /* static assert T is integer type of max HOST_WIDE_INT precision. */
145 auto_flag (T *sptr)
146 {
147 m_sptr = sptr;
148 int free_bit = ffs_hwi (~*sptr);
149 /* If there are no unset bits... */
150 if (free_bit == 0)
152 m_flag = HOST_WIDE_INT_1U << (free_bit - 1);
153 /* ...or if T is signed and thus the complement is sign-extended,
154 check if we ran out of bits. We could spare us this bit
155 if we could use C++11 std::make_unsigned<T>::type to pass
156 ~*sptr to ffs_hwi. */
157 if (m_flag == 0)
159 gcc_checking_assert ((*sptr & m_flag) == 0);
160 *sptr |= m_flag;
161 }
163 {
165 *m_sptr &= ~m_flag;
166 }
167 operator T () const { return m_flag; }
173/* RAII class to allocate an edge flag for temporary use. You have
174 to clear the flag from all edges when you are finished using it. */
176class auto_edge_flag : public auto_flag<int>
180 : auto_flag<int> (&fun->cfg->edge_flags_allocated) {}
183/* RAII class to allocate a bb flag for temporary use. You have
184 to clear the flag from all edges when you are finished using it. */
185class auto_bb_flag : public auto_flag<int>
189 : auto_flag<int> (&fun->cfg->bb_flags_allocated) {}
192#endif /* GCC_CFG_H */
void alloc_aux_for_blocks(int)
Definition cfg.cc:616
void scale_bbs_frequencies_profile_count(basic_block *, int, profile_count, profile_count)
Definition cfg.cc:1034
edge make_single_succ_edge(basic_block, basic_block, int)
Definition cfg.cc:349
void dump_edge_info(FILE *, edge, dump_flags_t, int)
Definition cfg.cc:503
void set_edge_probability_and_rescale_others(edge, profile_probability)
Definition cfg.cc:909
void unlink_block(basic_block)
Definition cfg.cc:159
void free_original_copy_tables(void)
Definition cfg.cc:1089
void set_bb_copy(basic_block, basic_block)
Definition cfg.cc:1156
void alloc_aux_for_edges(int)
Definition cfg.cc:679
void init_flow(function *)
Definition cfg.cc:66
edge unchecked_make_edge(basic_block, basic_block, int)
Definition cfg.cc:278
void scale_strictly_dominated_blocks(basic_block, profile_count, profile_count)
Definition cfg.cc:1204
Definition cfg.h:27
Definition cfg.h:31
Definition cfg.h:30
Definition cfg.h:29
Definition cfg.h:28
void update_bb_profile_for_threading(basic_block, profile_count, edge)
Definition cfg.cc:974
void alloc_aux_for_edge(edge, int)
Definition cfg.cc:667
basic_block get_bb_copy(basic_block)
Definition cfg.cc:1163
void clear_aux_for_blocks(void)
Definition cfg.cc:642
basic_block debug_bb_n(int)
Definition cfg.cc:746
void expunge_block(basic_block)
Definition cfg.cc:200
void free_aux_for_edges(void)
Definition cfg.cc:730
void dump_bb_info(FILE *, basic_block, int, dump_flags_t, bool, bool)
Definition cfg.cc:779
void redirect_edge_pred(edge, basic_block)
Definition cfg.cc:391
basic_block alloc_block(void)
Definition cfg.cc:139
edge cached_make_edge(sbitmap, basic_block, basic_block, int)
Definition cfg.cc:300
class loop * get_loop_copy(class loop *)
Definition cfg.cc:1189
void free_cfg(function *)
Definition cfg.cc:112
void debug_bb(basic_block)
Definition cfg.cc:740
void redirect_edge_succ(edge, basic_block)
Definition cfg.cc:374
void link_block(basic_block, basic_block)
Definition cfg.cc:149
void scale_bbs_frequencies(basic_block *, int, profile_probability)
Definition cfg.cc:1047
void free_aux_for_blocks(void)
Definition cfg.cc:654
void compact_blocks(void)
Definition cfg.cc:169
void remove_edge_raw(edge)
Definition cfg.cc:360
edge make_edge(basic_block, basic_block, int)
Definition cfg.cc:331
void clear_aux_for_edges(void)
Definition cfg.cc:712
bool original_copy_tables_initialized_p(void)
Definition cfg.cc:1103
void clear_bb_flags(void)
Definition cfg.cc:403
void reset_original_copy_tables(void)
Definition cfg.cc:1079
void brief_dump_cfg(FILE *, dump_flags_t)
Definition cfg.cc:895
basic_block get_bb_original(basic_block)
Definition cfg.cc:1142
void set_loop_copy(class loop *, class loop *)
Definition cfg.cc:1178
void set_bb_original(basic_block, basic_block)
Definition cfg.cc:1135
void initialize_original_copy_tables(void)
Definition cfg.cc:1068
Definition cfg.h:186
auto_bb_flag(function *fun)
Definition cfg.h:188
Definition cfg.h:177
auto_edge_flag(function *fun)
Definition cfg.h:179
Definition cfg.h:142
T * m_sptr
Definition cfg.h:169
Definition cfg.h:162
T m_flag
Definition cfg.h:170
auto_flag(T *sptr)
Definition cfg.h:145
Definition basic-block.h:26
Definition cfgloop.h:120
Definition profile-count.h:147
bool debug
Definition collect-utils.cc:34
class edge_def * edge
Definition coretypes.h:343
#define GTY(x)
Definition coretypes.h:41
Definition dominance.h:32
enum dump_flag dump_flags_t
Definition dumpfile.h:209
static struct token T
Definition gengtype-parse.cc:45
int ffs_hwi(unsigned HOST_WIDE_INT x)
Definition hwint.cc:103
#define HOST_WIDE_INT_1U
Definition hwint.h:70
Definition basic-block.h:117
Definition cfg.h:38
basic_block x_entry_block_ptr
Definition cfg.h:41
int max_jumptable_ents
Definition cfg.h:73
int x_n_basic_blocks
Definition cfg.h:48
enum profile_status_d x_profile_status
Definition cfg.h:63
bool full_profile
Definition cfg.h:83
vec< basic_block, va_gc > * x_basic_block_info
Definition cfg.h:45
int x_last_basic_block
Definition cfg.h:54
unsigned x_n_bbs_in_dom_tree[2]
Definition cfg.h:69
int edge_flags_allocated
Definition cfg.h:79
int last_label_uid
Definition cfg.h:57
basic_block x_exit_block_ptr
Definition cfg.h:42
enum dom_state x_dom_computed[2]
Definition cfg.h:66
vec< basic_block, va_gc > * x_label_to_block_map
Definition cfg.h:61
int bb_flags_allocated
Definition cfg.h:80
profile_count count_max
Definition cfg.h:76
int x_n_edges
Definition cfg.h:51
Definition function.h:249
Definition profile-count.h:750
Definition sbitmap.h:87
Definition vec.h:450
#define gcc_unreachable()
Definition system.h:848
#define gcc_checking_assert(EXPR)
Definition system.h:828