GCC Middle and Back End API Reference
cfghooks.h
Go to the documentation of this file.
1/* Hooks for cfg representation specific functions.
2 Copyright (C) 2003-2026 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <s.pop@laposte.net>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_CFGHOOKS_H
22#define GCC_CFGHOOKS_H
23
24#include "predict.h"
25
26namespace diagnostics { class sarif_builder; }
27namespace json { class object; }
28
29/* Structure to gather statistic about profile consistency, per pass.
30 An array of this structure, indexed by pass static number, is allocated
31 in passes.cc. The structure is defined here so that different CFG modes
32 can do their book-keeping via CFG hooks.
33
34 For every field[2], field[0] is the count before the pass runs, and
35 field[1] is the post-pass count. This allows us to monitor the effect
36 of each individual pass on the profile consistency.
37
38 This structure is not supposed to be used by anything other than passes.cc
39 and one CFG hook per CFG mode. */
41{
42 /* A weighted cost of the run-time of the function body. */
43 double time;
44 /* Frequency of execution of basic blocks where sum(prob) of the block's
45 predecessors doesn't match reasonably probability 1. */
47 /* Frequency of execution basic blocks where sum(count) of the block's
48 predecessors doesn't match reasonably well with the incoming frequency. */
50 /* The number of basic blocks where sum(prob) of the block's predecessors
51 doesn't match reasonably probability 1. */
53 /* The number of basic blocks where sum(count) of the block's predecessors
54 doesn't match reasonably well with the incoming frequency. */
56 /* A weighted cost of the size of the function body. */
57 int size;
58 /* True iff this pass actually was run. */
59 bool run;
60 bool fdo;
61};
62
63typedef int_hash <unsigned short, 0> dependence_hash;
64
65/* Optional data for duplicate_block. */
66
68{
69public:
72
73 /* A map from the copied BBs dependence info cliques to
74 equivalents in the BBs duplicated to. */
76
77 /* If true copy_bbs assigns one copyid for the region. */
79};
80
82{
83 /* The ir that hooks corresponds with. */
84 enum ir_type ir;
85
86 /* Debugging. */
88 void (*dump_bb) (FILE *, basic_block, int, dump_flags_t);
90 void
94
95 /* Basic CFG manipulation. */
96
97 /* Return new basic block. */
99
100 /* Redirect edge E to the given basic block B and update underlying program
101 representation. Returns edge representing redirected branch (that may not
102 be equivalent to E in the case of duplicate edges being removed) or NULL
103 if edge is not easily redirectable for whatever reason. */
105
106 /* Same as the above but allows redirecting of fallthru edges. In that case
107 newly created forwarder basic block is returned. The edge must
108 not be abnormal. */
110
111 /* Returns true if it is possible to remove the edge by redirecting it
112 to the destination of the other edge going from its source. */
114
115 /* Remove statements corresponding to a given basic block. */
117
118 /* Creates a new basic block just after basic block B by splitting
119 everything after specified instruction I. */
121
122 /* Move block B immediately after block A. */
124
125 /* Return true when blocks A and B can be merged into single basic block. */
127
128 /* Merge blocks A and B. */
130
131 /* Predict edge E using PREDICTOR to given PROBABILITY. */
132 void (*predict_edge) (edge e, enum br_predictor predictor, int probability);
133
134 /* Return true if the one of outgoing edges is already predicted by
135 PREDICTOR. */
137
138 /* Return true when block A can be duplicated. */
140
141 /* Duplicate block A. */
143
144 /* Higher level functions representable by primitive operations above if
145 we didn't have some oddities in RTL and Tree representations. */
148
149 /* Try to make the edge fallthru. */
151
152 /* Make the edge non-fallthru. */
154
155 /* Say whether a block ends with a call, possibly followed by some
156 other code that must stay with the call. */
158
159 /* Say whether a block ends with a conditional branch. Switches
160 and unconditional branches do not qualify. */
162
163 /* Add fake edges to the function exit for any non constant and non noreturn
164 calls, volatile inline assembly in the bitmap of blocks specified by
165 BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks
166 that were split.
167
168 The goal is to expose cases in which entering a basic block does not imply
169 that all subsequent instructions must be executed. */
171
172 /* This function is called immediately after edge E is added to the
173 edge vector E->dest->preds. */
175
176 /* This function is called immediately before edge E is removed from
177 the edge vector E->dest->preds. */
179
180 /* A hook for duplicating loop in CFG, currently this is used
181 in loop versioning. */
183 unsigned, sbitmap, edge,
184 vec<edge> *, int);
185
186 /* Add condition to new basic block and update CFG used in loop
187 versioning. */
189 void *);
190 /* Update the PHI nodes in case of loop versioning. */
193
194 /* Given a condition BB extract the true/false taken/not taken edges
195 (depending if we are on tree's or RTL). */
197
198
199 /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge
200 E->dest (only in tree-ssa loop versioning. */
202
203 /* True if a block contains no executable instructions. */
205
206 /* Split a basic block if it ends with a conditional branch and if
207 the other part of the block is not empty. */
209
210 /* Do book-keeping of a basic block for the profile consistency checker. */
212};
213
214extern void verify_flow_info (void);
215
216/* Check control flow invariants, if internal consistency checks are
217 enabled. */
218
219inline void
221{
222 /* TODO: Add a separate option for -fchecking=cfg. */
223 if (flag_checking)
225}
226
227extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
230 json::object &,
232extern void dump_flow_info (FILE *, dump_flags_t);
233
237extern bool can_remove_branch_p (const_edge);
238extern void remove_branch (edge);
239extern void remove_edge (edge);
244extern void delete_basic_block (basic_block);
251extern edge make_forwarder_block (basic_block, bool (*)(edge, void*), void*);
253extern void tidy_fallthru_edge (edge);
254extern void tidy_fallthru_edges (void);
255extern void predict_edge (edge e, enum br_predictor predictor, int probability);
256extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor);
260 copy_bb_data * = NULL);
261extern bool block_ends_with_call_p (basic_block bb);
262extern bool empty_block_p (basic_block);
265extern int flow_call_edges_add (sbitmap);
266extern void execute_on_growing_pred (edge);
267extern void execute_on_shrinking_pred (edge);
268extern bool
270 unsigned int ndupl,
271 sbitmap wont_exit, edge orig,
272 vec<edge> *to_remove, int flags);
273
274extern void lv_flush_pending_stmts (edge);
275extern void extract_cond_bb_edges (basic_block, edge *, edge*);
277 edge);
279 void *);
280
281extern bool can_copy_bbs_p (basic_block *, unsigned, edge = NULL);
282extern void copy_bbs (basic_block *, unsigned, basic_block *,
283 edge *, unsigned, edge *, class loop *,
284 basic_block, bool, edge = NULL);
285
288
289/* Hooks containers. */
290extern const struct cfg_hooks gimple_cfg_hooks;
291extern const struct cfg_hooks rtl_cfg_hooks;
292extern const struct cfg_hooks cfg_layout_rtl_cfg_hooks;
293
294/* Declarations. */
295extern enum ir_type current_ir_type (void);
296extern void rtl_register_cfg_hooks (void);
297extern void cfg_layout_rtl_register_cfg_hooks (void);
298extern void gimple_register_cfg_hooks (void);
299extern const struct cfg_hooks *get_cfg_hooks (void);
300extern void set_cfg_hooks (const struct cfg_hooks *);
301
302#endif /* GCC_CFGHOOKS_H */
edge split_block_after_labels(basic_block bb)
Definition cfghooks.cc:655
edge redirect_edge_succ_nodup(edge e, basic_block new_succ)
Definition cfghooks.cc:536
void dump_bb(FILE *outf, basic_block bb, int indent, dump_flags_t flags)
Definition cfghooks.cc:336
edge redirect_edge_and_branch(edge e, basic_block dest)
Definition cfghooks.cc:447
bool can_copy_bbs_p(basic_block *bbs, unsigned n, edge prevailing_exit)
Definition cfghooks.cc:1419
basic_block create_empty_bb(basic_block after)
Definition cfghooks.cc:838
void execute_on_growing_pred(edge e)
Definition cfghooks.cc:1335
basic_block create_basic_block(gimple_seq seq, basic_block after)
Definition cfghooks.cc:823
void copy_bbs(basic_block *bbs, unsigned n, basic_block *new_bbs, edge *edges, unsigned num_edges, edge *new_edges, class loop *base, basic_block after, bool update_dominance, edge prevailing_exit)
Definition cfghooks.cc:1497
void merge_blocks(basic_block a, basic_block b)
Definition cfghooks.cc:882
const struct cfg_hooks * get_cfg_hooks(void)
Definition cfghooks.cc:97
void profile_record_check_consistency(profile_record *record)
Definition cfghooks.cc:1635
basic_block force_nonfallthru(edge e)
Definition cfghooks.cc:1120
bool can_duplicate_block_p(const_basic_block bb)
Definition cfghooks.cc:1156
bool block_ends_with_call_p(basic_block bb)
Definition cfghooks.cc:1292
void lv_add_condition_to_bb(basic_block first, basic_block second, basic_block new_block, void *cond)
Definition cfghooks.cc:1406
DEBUG_FUNCTION void verify_flow_info(void)
Definition cfghooks.cc:139
void dump_flow_info(FILE *file, dump_flags_t flags)
Definition cfghooks.cc:421
void delete_basic_block(basic_block bb)
Definition cfghooks.cc:680
void set_cfg_hooks(const struct cfg_hooks *new_cfg_hooks)
Definition cfghooks.cc:103
void remove_edge(edge e)
Definition cfghooks.cc:507
void profile_record_account_profile(profile_record *record)
Definition cfghooks.cc:1719
void predict_edge(edge e, enum br_predictor predictor, int probability)
Definition cfghooks.cc:860
basic_block split_block_before_cond_jump(basic_block bb)
Definition cfghooks.cc:1624
bool can_remove_branch_p(const_edge e)
Definition cfghooks.cc:469
void execute_on_shrinking_pred(edge e)
Definition cfghooks.cc:1346
bool predicted_by_p(const_basic_block bb, enum br_predictor predictor)
Definition cfghooks.cc:870
void remove_branch(edge e)
Definition cfghooks.cc:486
edge split_block(basic_block bb, gimple *i)
Definition cfghooks.cc:641
void gimple_register_cfg_hooks(void)
Definition cfghooks.cc:91
edge make_forwarder_block(basic_block bb, bool(*redirect_edge_p)(edge, void *), void *data)
Definition cfghooks.cc:971
enum ir_type current_ir_type(void)
Definition cfghooks.cc:111
basic_block split_edge(edge e)
Definition cfghooks.cc:720
bool can_duplicate_block_on_edge_p(edge e)
Definition cfghooks.cc:1172
int flow_call_edges_add(sbitmap blocks)
Definition cfghooks.cc:1322
void lv_adjust_loop_header_phi(basic_block first, basic_block second, basic_block new_block, edge e)
Definition cfghooks.cc:1395
void extract_cond_bb_edges(basic_block b, edge *e1, edge *e2)
Definition cfghooks.cc:1386
bool can_merge_blocks_p(basic_block bb1, basic_block bb2)
Definition cfghooks.cc:846
void dump_bb_as_sarif_properties(diagnostics::sarif_builder *builder, json::object &output_bag, basic_block bb)
Definition cfghooks.cc:393
void dump_bb_for_graph(pretty_printer *pp, basic_block bb)
Definition cfghooks.cc:379
void tidy_fallthru_edges(void)
Definition cfghooks.cc:1075
basic_block duplicate_block(basic_block bb, edge e, basic_block after, copy_bb_data *id)
Definition cfghooks.cc:1203
bool block_ends_with_condjump_p(const_basic_block bb)
Definition cfghooks.cc:1304
basic_block redirect_edge_and_branch_force(edge e, basic_block dest)
Definition cfghooks.cc:561
void rtl_register_cfg_hooks(void)
Definition cfghooks.cc:76
void cfg_layout_rtl_register_cfg_hooks(void)
Definition cfghooks.cc:83
bool move_block_after(basic_block bb, basic_block after)
Definition cfghooks.cc:664
bool empty_block_p(basic_block bb)
Definition cfghooks.cc:1615
void lv_flush_pending_stmts(edge e)
Definition cfghooks.cc:1357
bool cfg_hook_duplicate_loop_body_to_header_edge(class loop *loop, edge e, unsigned int ndupl, sbitmap wont_exit, edge orig, vec< edge > *to_remove, int flags)
Definition cfghooks.cc:1371
void tidy_fallthru_edge(edge e)
Definition cfghooks.cc:1061
const struct cfg_hooks rtl_cfg_hooks
Definition cfgrtl.cc:5400
int_hash< unsigned short, 0 > dependence_hash
Definition cfghooks.h:63
const struct cfg_hooks gimple_cfg_hooks
Definition tree-cfg.cc:9407
void checking_verify_flow_info(void)
Definition cfghooks.h:220
const struct cfg_hooks cfg_layout_rtl_cfg_hooks
Definition cfgrtl.cc:5443
Definition cfghooks.h:68
bool skip_copyid
Definition cfghooks.h:78
copy_bb_data()
Definition cfghooks.h:70
~copy_bb_data()
Definition cfghooks.h:71
hash_map< dependence_hash, unsigned short > * dependence_map
Definition cfghooks.h:75
Definition sarif-sink.cc:784
Definition hash-map.h:40
Definition json.h:191
Definition cfgloop.h:120
Definition pretty-print.h:241
struct basic_block_def * basic_block
Definition coretypes.h:359
struct rtx_def * rtx
Definition coretypes.h:57
class edge_def * edge
Definition coretypes.h:356
gimple * gimple_seq
Definition coretypes.h:100
ir_type
Definition coretypes.h:198
struct simple_bitmap_def * sbitmap
Definition coretypes.h:54
const class edge_def * const_edge
Definition coretypes.h:357
const struct basic_block_def * const_basic_block
Definition coretypes.h:360
enum dump_flag dump_flags_t
Definition dumpfile.h:209
Definition cfghooks.h:26
Definition cfghooks.h:27
i
Definition poly-int.h:776
Ca const poly_int< N, Cb > & b
Definition poly-int.h:771
Ca & a
Definition poly-int.h:770
br_predictor
Definition predict.h:38
Definition cfghooks.h:82
basic_block(*) split_block(basic_block b, void *i)
Definition cfghooks.h:120
bool(*) move_block_after(basic_block b, basic_block a)
Definition cfghooks.h:123
bool(*) can_duplicate_block_p(const_basic_block a)
Definition cfghooks.h:139
edge(*) redirect_edge_and_branch(edge e, basic_block b)
Definition cfghooks.h:104
void(*) lv_adjust_loop_header_phi(basic_block, basic_block, basic_block, edge)
Definition cfghooks.h:191
bool(*) verify_flow_info(void)
Definition cfghooks.h:87
bool(*) can_merge_blocks_p(basic_block a, basic_block b)
Definition cfghooks.h:126
void(*) make_forwarder_block(edge)
Definition cfghooks.h:147
int(*) flow_call_edges_add(sbitmap)
Definition cfghooks.h:170
basic_block(*) split_block_before_cond_jump(basic_block)
Definition cfghooks.h:208
enum ir_type ir
Definition cfghooks.h:84
bool(*) block_ends_with_condjump_p(const_basic_block)
Definition cfghooks.h:161
void(*) dump_bb_for_graph(pretty_printer *, basic_block)
Definition cfghooks.h:89
basic_block(*) split_edge(edge)
Definition cfghooks.h:146
bool(*) cfg_hook_duplicate_loop_body_to_header_edge(class loop *, edge, unsigned, sbitmap, edge, vec< edge > *, int)
Definition cfghooks.h:182
void(*) execute_on_shrinking_pred(edge)
Definition cfghooks.h:178
void(*) delete_basic_block(basic_block)
Definition cfghooks.h:116
basic_block(*) duplicate_block(basic_block a, copy_bb_data *)
Definition cfghooks.h:142
bool(*) block_ends_with_call_p(basic_block)
Definition cfghooks.h:157
bool(*) empty_block_p(basic_block)
Definition cfghooks.h:204
void(*) lv_add_condition_to_bb(basic_block, basic_block, basic_block, void *)
Definition cfghooks.h:188
bool(*) predicted_by_p(const_basic_block bb, enum br_predictor predictor)
Definition cfghooks.h:136
void(*) dump_bb_as_sarif_properties(diagnostics::sarif_builder *, json::object &, basic_block)
Definition cfghooks.h:91
basic_block(*) force_nonfallthru(edge)
Definition cfghooks.h:153
void(*) extract_cond_bb_edges(basic_block, edge *, edge *)
Definition cfghooks.h:196
bool(*) can_remove_branch_p(const_edge)
Definition cfghooks.h:113
void(*) merge_blocks(basic_block a, basic_block b)
Definition cfghooks.h:129
void(*) tidy_fallthru_edge(edge)
Definition cfghooks.h:150
basic_block(*) create_basic_block(void *head, void *end, basic_block after)
Definition cfghooks.h:98
basic_block(*) redirect_edge_and_branch_force(edge, basic_block)
Definition cfghooks.h:109
void(*) dump_bb(FILE *, basic_block, int, dump_flags_t)
Definition cfghooks.h:88
void(*) predict_edge(edge e, enum br_predictor predictor, int probability)
Definition cfghooks.h:132
void(*) account_profile_record(basic_block, struct profile_record *)
Definition cfghooks.h:211
void(*) execute_on_growing_pred(edge)
Definition cfghooks.h:174
void(*) flush_pending_stmts(edge)
Definition cfghooks.h:201
Definition gimple.h:224
Definition collect2.cc:175
Definition cfghooks.h:41
int size
Definition cfghooks.h:57
bool fdo
Definition cfghooks.h:60
double dyn_mismatched_count_in
Definition cfghooks.h:49
double dyn_mismatched_prob_out
Definition cfghooks.h:46
bool run
Definition cfghooks.h:59
int num_mismatched_count_in
Definition cfghooks.h:55
double time
Definition cfghooks.h:43
int num_mismatched_prob_out
Definition cfghooks.h:52
Definition vec.h:450
#define NULL
Definition system.h:55
#define false
Definition system.h:846
#define bool
Definition system.h:844
T * end(vec< T, A, L > *v)
Definition vec.h:457