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-2024 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
26/* Structure to gather statistic about profile consistency, per pass.
27 An array of this structure, indexed by pass static number, is allocated
28 in passes.cc. The structure is defined here so that different CFG modes
29 can do their book-keeping via CFG hooks.
30
31 For every field[2], field[0] is the count before the pass runs, and
32 field[1] is the post-pass count. This allows us to monitor the effect
33 of each individual pass on the profile consistency.
34
35 This structure is not supposed to be used by anything other than passes.cc
36 and one CFG hook per CFG mode. */
38{
39 /* A weighted cost of the run-time of the function body. */
40 double time;
41 /* Frequency of execution of basic blocks where sum(prob) of the block's
42 predecessors doesn't match reasonably probability 1. */
44 /* Frequency of execution basic blocks where sum(count) of the block's
45 predecessors doesn't match reasonably well with the incoming frequency. */
47 /* The number of basic blocks where sum(prob) of the block's predecessors
48 doesn't match reasonably probability 1. */
50 /* The number of basic blocks where sum(count) of the block's predecessors
51 doesn't match reasonably well with the incoming frequency. */
53 /* A weighted cost of the size of the function body. */
54 int size;
55 /* True iff this pass actually was run. */
56 bool run;
57 bool fdo;
58};
59
60typedef int_hash <unsigned short, 0> dependence_hash;
61
62/* Optional data for duplicate_block. */
63
65{
66public:
69
70 /* A map from the copied BBs dependence info cliques to
71 equivalents in the BBs duplicated to. */
73};
74
76{
77 /* Name of the corresponding ir. */
78 const char *name;
79
80 /* Debugging. */
82 void (*dump_bb) (FILE *, basic_block, int, dump_flags_t);
84
85 /* Basic CFG manipulation. */
86
87 /* Return new basic block. */
89
90 /* Redirect edge E to the given basic block B and update underlying program
91 representation. Returns edge representing redirected branch (that may not
92 be equivalent to E in the case of duplicate edges being removed) or NULL
93 if edge is not easily redirectable for whatever reason. */
95
96 /* Same as the above but allows redirecting of fallthru edges. In that case
97 newly created forwarder basic block is returned. The edge must
98 not be abnormal. */
100
101 /* Returns true if it is possible to remove the edge by redirecting it
102 to the destination of the other edge going from its source. */
104
105 /* Remove statements corresponding to a given basic block. */
107
108 /* Creates a new basic block just after basic block B by splitting
109 everything after specified instruction I. */
111
112 /* Move block B immediately after block A. */
114
115 /* Return true when blocks A and B can be merged into single basic block. */
117
118 /* Merge blocks A and B. */
120
121 /* Predict edge E using PREDICTOR to given PROBABILITY. */
122 void (*predict_edge) (edge e, enum br_predictor predictor, int probability);
123
124 /* Return true if the one of outgoing edges is already predicted by
125 PREDICTOR. */
127
128 /* Return true when block A can be duplicated. */
130
131 /* Duplicate block A. */
133
134 /* Higher level functions representable by primitive operations above if
135 we didn't have some oddities in RTL and Tree representations. */
138
139 /* Try to make the edge fallthru. */
141
142 /* Make the edge non-fallthru. */
144
145 /* Say whether a block ends with a call, possibly followed by some
146 other code that must stay with the call. */
148
149 /* Say whether a block ends with a conditional branch. Switches
150 and unconditional branches do not qualify. */
152
153 /* Add fake edges to the function exit for any non constant and non noreturn
154 calls, volatile inline assembly in the bitmap of blocks specified by
155 BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks
156 that were split.
157
158 The goal is to expose cases in which entering a basic block does not imply
159 that all subsequent instructions must be executed. */
161
162 /* This function is called immediately after edge E is added to the
163 edge vector E->dest->preds. */
165
166 /* This function is called immediately before edge E is removed from
167 the edge vector E->dest->preds. */
169
170 /* A hook for duplicating loop in CFG, currently this is used
171 in loop versioning. */
173 unsigned, sbitmap, edge,
174 vec<edge> *, int);
175
176 /* Add condition to new basic block and update CFG used in loop
177 versioning. */
179 void *);
180 /* Update the PHI nodes in case of loop versioning. */
183
184 /* Given a condition BB extract the true/false taken/not taken edges
185 (depending if we are on tree's or RTL). */
187
188
189 /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge
190 E->dest (only in tree-ssa loop versioning. */
192
193 /* True if a block contains no executable instructions. */
195
196 /* Split a basic block if it ends with a conditional branch and if
197 the other part of the block is not empty. */
199
200 /* Do book-keeping of a basic block for the profile consistency checker. */
202};
203
204extern void verify_flow_info (void);
205
206/* Check control flow invariants, if internal consistency checks are
207 enabled. */
208
209inline void
211{
212 /* TODO: Add a separate option for -fchecking=cfg. */
213 if (flag_checking)
215}
216
217extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
219extern void dump_flow_info (FILE *, dump_flags_t);
220
224extern bool can_remove_branch_p (const_edge);
225extern void remove_branch (edge);
226extern void remove_edge (edge);
231extern void delete_basic_block (basic_block);
238extern edge make_forwarder_block (basic_block, bool (*)(edge),
239 void (*) (basic_block));
241extern void tidy_fallthru_edge (edge);
242extern void tidy_fallthru_edges (void);
243extern void predict_edge (edge e, enum br_predictor predictor, int probability);
244extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor);
247 copy_bb_data * = NULL);
248extern bool block_ends_with_call_p (basic_block bb);
249extern bool empty_block_p (basic_block);
252extern int flow_call_edges_add (sbitmap);
253extern void execute_on_growing_pred (edge);
254extern void execute_on_shrinking_pred (edge);
255extern bool
257 unsigned int ndupl,
258 sbitmap wont_exit, edge orig,
259 vec<edge> *to_remove, int flags);
260
261extern void lv_flush_pending_stmts (edge);
262extern void extract_cond_bb_edges (basic_block, edge *, edge*);
264 edge);
266 void *);
267
268extern bool can_copy_bbs_p (basic_block *, unsigned);
269extern void copy_bbs (basic_block *, unsigned, basic_block *,
270 edge *, unsigned, edge *, class loop *,
271 basic_block, bool);
272
275
276/* Hooks containers. */
277extern struct cfg_hooks gimple_cfg_hooks;
278extern struct cfg_hooks rtl_cfg_hooks;
280
281/* Declarations. */
282extern enum ir_type current_ir_type (void);
283extern void rtl_register_cfg_hooks (void);
284extern void cfg_layout_rtl_register_cfg_hooks (void);
285extern void gimple_register_cfg_hooks (void);
286extern struct cfg_hooks get_cfg_hooks (void);
287extern void set_cfg_hooks (struct cfg_hooks);
288
289#endif /* GCC_CFGHOOKS_H */
bool empty_block_p(basic_block)
Definition cfghooks.cc:1452
void delete_basic_block(basic_block)
Definition cfghooks.cc:615
void verify_flow_info(void)
Definition cfghooks.cc:102
bool can_merge_blocks_p(basic_block, basic_block)
Definition cfghooks.cc:779
basic_block create_basic_block(rtx, rtx, basic_block)
Definition cfghooks.cc:762
edge redirect_edge_and_branch(edge, basic_block)
Definition cfghooks.cc:383
void dump_bb_for_graph(pretty_printer *, basic_block)
Definition cfghooks.cc:342
basic_block create_empty_bb(basic_block)
Definition cfghooks.cc:771
void set_cfg_hooks(struct cfg_hooks)
Definition cfghooks.cc:76
bool block_ends_with_call_p(basic_block bb)
Definition cfghooks.cc:1183
struct cfg_hooks cfg_layout_rtl_cfg_hooks
Definition cfgrtl.cc:5427
int_hash< unsigned short, 0 > dependence_hash
Definition cfghooks.h:60
void merge_blocks(basic_block, basic_block)
Definition cfghooks.cc:812
edge make_forwarder_block(basic_block, bool(*)(edge), void(*)(basic_block))
Definition cfghooks.cc:890
basic_block redirect_edge_and_branch_force(edge, basic_block)
Definition cfghooks.cc:497
basic_block split_edge(edge)
Definition cfghooks.cc:654
void lv_add_condition_to_bb(basic_block, basic_block, basic_block, void *)
Definition cfghooks.cc:1296
void tidy_fallthru_edge(edge)
Definition cfghooks.cc:984
void predict_edge(edge e, enum br_predictor predictor, int probability)
Definition cfghooks.cc:792
basic_block split_block_before_cond_jump(basic_block)
Definition cfghooks.cc:1461
int flow_call_edges_add(sbitmap)
Definition cfghooks.cc:1212
void lv_adjust_loop_header_phi(basic_block, basic_block, basic_block, edge)
Definition cfghooks.cc:1285
struct cfg_hooks rtl_cfg_hooks
Definition cfgrtl.cc:5385
void execute_on_shrinking_pred(edge)
Definition cfghooks.cc:1236
void remove_branch(edge)
Definition cfghooks.cc:422
void remove_edge(edge)
Definition cfghooks.cc:443
bool predicted_by_p(const_basic_block bb, enum br_predictor predictor)
Definition cfghooks.cc:801
void checking_verify_flow_info(void)
Definition cfghooks.h:210
bool cfg_hook_duplicate_loop_body_to_header_edge(class loop *loop, edge, unsigned int ndupl, sbitmap wont_exit, edge orig, vec< edge > *to_remove, int flags)
Definition cfghooks.cc:1261
void gimple_register_cfg_hooks(void)
Definition cfghooks.cc:64
bool can_remove_branch_p(const_edge)
Definition cfghooks.cc:405
void dump_flow_info(FILE *, dump_flags_t)
Definition cfghooks.cc:357
enum ir_type current_ir_type(void)
Definition cfghooks.cc:84
bool can_copy_bbs_p(basic_block *, unsigned)
Definition cfghooks.cc:1305
basic_block duplicate_block(basic_block, edge, basic_block, copy_bb_data *=NULL)
Definition cfghooks.cc:1103
bool can_duplicate_block_p(const_basic_block)
Definition cfghooks.cc:1079
void execute_on_growing_pred(edge)
Definition cfghooks.cc:1225
edge split_block(basic_block, rtx)
Definition cfghooks.cc:583
bool move_block_after(basic_block, basic_block)
Definition cfghooks.cc:600
void lv_flush_pending_stmts(edge)
Definition cfghooks.cc:1247
struct cfg_hooks get_cfg_hooks(void)
Definition cfghooks.cc:70
edge split_block_after_labels(basic_block)
Definition cfghooks.cc:591
void tidy_fallthru_edges(void)
Definition cfghooks.cc:998
void dump_bb(FILE *, basic_block, int, dump_flags_t)
Definition cfghooks.cc:299
edge redirect_edge_succ_nodup(edge, basic_block)
Definition cfghooks.cc:472
void profile_record_account_profile(profile_record *)
Definition cfghooks.cc:1556
bool block_ends_with_condjump_p(const_basic_block bb)
Definition cfghooks.cc:1194
void rtl_register_cfg_hooks(void)
Definition cfghooks.cc:49
void cfg_layout_rtl_register_cfg_hooks(void)
Definition cfghooks.cc:56
struct cfg_hooks gimple_cfg_hooks
Definition tree-cfg.cc:9401
void copy_bbs(basic_block *, unsigned, basic_block *, edge *, unsigned, edge *, class loop *, basic_block, bool)
Definition cfghooks.cc:1364
void profile_record_check_consistency(profile_record *)
Definition cfghooks.cc:1472
basic_block force_nonfallthru(edge)
Definition cfghooks.cc:1043
void extract_cond_bb_edges(basic_block, edge *, edge *)
Definition cfghooks.cc:1276
Definition cfghooks.h:65
copy_bb_data()
Definition cfghooks.h:67
~copy_bb_data()
Definition cfghooks.h:68
hash_map< dependence_hash, unsigned short > * dependence_map
Definition cfghooks.h:72
Definition hash-map.h:40
Definition cfgloop.h:120
Definition pretty-print.h:241
struct basic_block_def * basic_block
Definition coretypes.h:355
class edge_def * edge
Definition coretypes.h:352
ir_type
Definition coretypes.h:191
struct simple_bitmap_def * sbitmap
Definition coretypes.h:54
const class edge_def * const_edge
Definition coretypes.h:353
const struct basic_block_def * const_basic_block
Definition coretypes.h:356
enum dump_flag dump_flags_t
Definition dumpfile.h:209
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 basic-block.h:117
Definition cfghooks.h:76
void(* merge_blocks)(basic_block a, basic_block b)
Definition cfghooks.h:119
bool(* cfg_hook_duplicate_loop_body_to_header_edge)(class loop *, edge, unsigned, sbitmap, edge, vec< edge > *, int)
Definition cfghooks.h:172
bool(* empty_block_p)(basic_block)
Definition cfghooks.h:194
void(* execute_on_growing_pred)(edge)
Definition cfghooks.h:164
void(* extract_cond_bb_edges)(basic_block, edge *, edge *)
Definition cfghooks.h:186
void(* lv_adjust_loop_header_phi)(basic_block, basic_block, basic_block, edge)
Definition cfghooks.h:181
void(* make_forwarder_block)(edge)
Definition cfghooks.h:137
bool(* can_merge_blocks_p)(basic_block a, basic_block b)
Definition cfghooks.h:116
bool(* can_duplicate_block_p)(const_basic_block a)
Definition cfghooks.h:129
bool(* predicted_by_p)(const_basic_block bb, enum br_predictor predictor)
Definition cfghooks.h:126
const char * name
Definition cfghooks.h:78
basic_block(* split_edge)(edge)
Definition cfghooks.h:136
bool(* can_remove_branch_p)(const_edge)
Definition cfghooks.h:103
basic_block(* create_basic_block)(void *head, void *end, basic_block after)
Definition cfghooks.h:88
void(* dump_bb)(FILE *, basic_block, int, dump_flags_t)
Definition cfghooks.h:82
bool(* verify_flow_info)(void)
Definition cfghooks.h:81
bool(* block_ends_with_condjump_p)(const_basic_block)
Definition cfghooks.h:151
void(* account_profile_record)(basic_block, struct profile_record *)
Definition cfghooks.h:201
void(* execute_on_shrinking_pred)(edge)
Definition cfghooks.h:168
basic_block(* split_block_before_cond_jump)(basic_block)
Definition cfghooks.h:198
basic_block(* duplicate_block)(basic_block a, copy_bb_data *)
Definition cfghooks.h:132
void(* dump_bb_for_graph)(pretty_printer *, basic_block)
Definition cfghooks.h:83
int(* flow_call_edges_add)(sbitmap)
Definition cfghooks.h:160
void(* flush_pending_stmts)(edge)
Definition cfghooks.h:191
edge(* redirect_edge_and_branch)(edge e, basic_block b)
Definition cfghooks.h:94
void(* lv_add_condition_to_bb)(basic_block, basic_block, basic_block, void *)
Definition cfghooks.h:178
basic_block(* redirect_edge_and_branch_force)(edge, basic_block)
Definition cfghooks.h:99
void(* delete_basic_block)(basic_block)
Definition cfghooks.h:106
basic_block(* split_block)(basic_block b, void *i)
Definition cfghooks.h:110
bool(* block_ends_with_call_p)(basic_block)
Definition cfghooks.h:147
void(* tidy_fallthru_edge)(edge)
Definition cfghooks.h:140
basic_block(* force_nonfallthru)(edge)
Definition cfghooks.h:143
bool(* move_block_after)(basic_block b, basic_block a)
Definition cfghooks.h:113
void(* predict_edge)(edge e, enum br_predictor predictor, int probability)
Definition cfghooks.h:122
Definition gimple.h:221
Definition collect2.cc:175
Definition cfghooks.h:38
int size
Definition cfghooks.h:54
bool fdo
Definition cfghooks.h:57
double dyn_mismatched_count_in
Definition cfghooks.h:46
double dyn_mismatched_prob_out
Definition cfghooks.h:43
bool run
Definition cfghooks.h:56
int num_mismatched_count_in
Definition cfghooks.h:52
double time
Definition cfghooks.h:40
int num_mismatched_prob_out
Definition cfghooks.h:49
Definition rtl.h:311
Definition sbitmap.h:87
Definition vec.h:450
#define NULL
Definition system.h:50
#define bool
Definition system.h:886
T * end(vec< T, A, L > *v)
Definition vec.h:457