]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cfghooks.h
Fortran: fix issues with class(*) assignment [PR114827]
[thirdparty/gcc.git] / gcc / cfghooks.h
CommitLineData
9ee634e3 1/* Hooks for cfg representation specific functions.
a945c346 2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
9ee634e3
JH
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
9dcd6f09 9the Free Software Foundation; either version 3, or (at your option)
9ee634e3
JH
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
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
9ee634e3 20
f1717f8d
KC
21#ifndef GCC_CFGHOOKS_H
22#define GCC_CFGHOOKS_H
23
9fdcd34e 24#include "predict.h"
9ee634e3 25
893479de
AM
26/* Structure to gather statistic about profile consistency, per pass.
27 An array of this structure, indexed by pass static number, is allocated
e53b6e56 28 in passes.cc. The structure is defined here so that different CFG modes
893479de
AM
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
e53b6e56 35 This structure is not supposed to be used by anything other than passes.cc
893479de
AM
36 and one CFG hook per CFG mode. */
37struct profile_record
38{
d1471457
JH
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. */
43 double dyn_mismatched_prob_out;
44 /* Frequency of execution basic blocks where sum(count) of the block's
45 predecessors doesn't match reasonably well with the incoming frequency. */
46 double dyn_mismatched_count_in;
47 /* The number of basic blocks where sum(prob) of the block's predecessors
48 doesn't match reasonably probability 1. */
49 int num_mismatched_prob_out;
893479de
AM
50 /* The number of basic blocks where sum(count) of the block's predecessors
51 doesn't match reasonably well with the incoming frequency. */
160576e1 52 int num_mismatched_count_in;
893479de 53 /* A weighted cost of the size of the function body. */
160576e1 54 int size;
893479de
AM
55 /* True iff this pass actually was run. */
56 bool run;
d1471457 57 bool fdo;
893479de
AM
58};
59
229d576c
RB
60typedef int_hash <unsigned short, 0> dependence_hash;
61
62/* Optional data for duplicate_block. */
63
6c1dae73 64class copy_bb_data
229d576c 65{
6c1dae73 66public:
229d576c
RB
67 copy_bb_data() : dependence_map (NULL) {}
68 ~copy_bb_data () { delete dependence_map; }
69
70 /* A map from the copied BBs dependence info cliques to
71 equivalents in the BBs duplicated to. */
72 hash_map<dependence_hash, unsigned short> *dependence_map;
73};
893479de 74
9ee634e3
JH
75struct cfg_hooks
76{
f470c378
ZD
77 /* Name of the corresponding ir. */
78 const char *name;
79
80 /* Debugging. */
47bd5598 81 bool (*verify_flow_info) (void);
1a817418 82 void (*dump_bb) (FILE *, basic_block, int, dump_flags_t);
2c895bd1 83 void (*dump_bb_for_graph) (pretty_printer *, basic_block);
9ee634e3
JH
84
85 /* Basic CFG manipulation. */
86
6614fd40 87 /* Return new basic block. */
f55ade6e 88 basic_block (*create_basic_block) (void *head, void *end, basic_block after);
bc35512f 89
9ee634e3 90 /* Redirect edge E to the given basic block B and update underlying program
6de9cd9a
DN
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. */
94 edge (*redirect_edge_and_branch) (edge e, basic_block b);
9ee634e3
JH
95
96 /* Same as the above but allows redirecting of fallthru edges. In that case
0e61db61
NS
97 newly created forwarder basic block is returned. The edge must
98 not be abnormal. */
d329e058 99 basic_block (*redirect_edge_and_branch_force) (edge, basic_block);
9ee634e3 100
14fa2cc0
ZD
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. */
9678086d 103 bool (*can_remove_branch_p) (const_edge);
14fa2cc0 104
f470c378
ZD
105 /* Remove statements corresponding to a given basic block. */
106 void (*delete_basic_block) (basic_block);
107
108 /* Creates a new basic block just after basic block B by splitting
109 everything after specified instruction I. */
110 basic_block (*split_block) (basic_block b, void * i);
b8698a0f 111
f470c378
ZD
112 /* Move block B immediately after block A. */
113 bool (*move_block_after) (basic_block b, basic_block a);
9ee634e3 114
bc35512f 115 /* Return true when blocks A and B can be merged into single basic block. */
b48d0358 116 bool (*can_merge_blocks_p) (basic_block a, basic_block b);
bc35512f
JH
117
118 /* Merge blocks A and B. */
f55ade6e 119 void (*merge_blocks) (basic_block a, basic_block b);
bc35512f 120
6de9cd9a
DN
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. */
9678086d 126 bool (*predicted_by_p) (const_basic_block bb, enum br_predictor predictor);
6de9cd9a
DN
127
128 /* Return true when block A can be duplicated. */
9678086d 129 bool (*can_duplicate_block_p) (const_basic_block a);
6de9cd9a
DN
130
131 /* Duplicate block A. */
229d576c 132 basic_block (*duplicate_block) (basic_block a, copy_bb_data *);
6de9cd9a 133
9ee634e3
JH
134 /* Higher level functions representable by primitive operations above if
135 we didn't have some oddities in RTL and Tree representations. */
f470c378
ZD
136 basic_block (*split_edge) (edge);
137 void (*make_forwarder_block) (edge);
138
cf103ca4 139 /* Try to make the edge fallthru. */
f470c378 140 void (*tidy_fallthru_edge) (edge);
6de9cd9a 141
cf103ca4
EB
142 /* Make the edge non-fallthru. */
143 basic_block (*force_nonfallthru) (edge);
144
6de9cd9a
DN
145 /* Say whether a block ends with a call, possibly followed by some
146 other code that must stay with the call. */
b48d0358 147 bool (*block_ends_with_call_p) (basic_block);
6de9cd9a
DN
148
149 /* Say whether a block ends with a conditional branch. Switches
150 and unconditional branches do not qualify. */
9678086d 151 bool (*block_ends_with_condjump_p) (const_basic_block);
6de9cd9a
DN
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. */
160 int (*flow_call_edges_add) (sbitmap);
d9d4706f
KH
161
162 /* This function is called immediately after edge E is added to the
163 edge vector E->dest->preds. */
164 void (*execute_on_growing_pred) (edge);
165
166 /* This function is called immediately before edge E is removed from
167 the edge vector E->dest->preds. */
168 void (*execute_on_shrinking_pred) (edge);
1cb7dfc3
MH
169
170 /* A hook for duplicating loop in CFG, currently this is used
171 in loop versioning. */
4851c80c
XL
172 bool (*cfg_hook_duplicate_loop_body_to_header_edge) (class loop *, edge,
173 unsigned, sbitmap, edge,
174 vec<edge> *, int);
1cb7dfc3 175
0fa2e4df 176 /* Add condition to new basic block and update CFG used in loop
1cb7dfc3
MH
177 versioning. */
178 void (*lv_add_condition_to_bb) (basic_block, basic_block, basic_block,
c22cacf3 179 void *);
1cb7dfc3
MH
180 /* Update the PHI nodes in case of loop versioning. */
181 void (*lv_adjust_loop_header_phi) (basic_block, basic_block,
182 basic_block, edge);
c22cacf3 183
1cb7dfc3
MH
184 /* Given a condition BB extract the true/false taken/not taken edges
185 (depending if we are on tree's or RTL). */
186 void (*extract_cond_bb_edges) (basic_block, edge *, edge *);
187
c22cacf3 188
1cb7dfc3
MH
189 /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge
190 E->dest (only in tree-ssa loop versioning. */
191 void (*flush_pending_stmts) (edge);
df92c640
SB
192
193 /* True if a block contains no executable instructions. */
194 bool (*empty_block_p) (basic_block);
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. */
198 basic_block (*split_block_before_cond_jump) (basic_block);
aa4723d7
SB
199
200 /* Do book-keeping of a basic block for the profile consistency checker. */
160576e1 201 void (*account_profile_record) (basic_block, struct profile_record *);
9ee634e3
JH
202};
203
f470c378 204extern void verify_flow_info (void);
b2b29377
MM
205
206/* Check control flow invariants, if internal consistency checks are
207 enabled. */
208
cb3e0eac 209inline void
b2b29377
MM
210checking_verify_flow_info (void)
211{
212 /* TODO: Add a separate option for -fchecking=cfg. */
213 if (flag_checking)
214 verify_flow_info ();
215}
216
1a817418 217extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
2c895bd1 218extern void dump_bb_for_graph (pretty_printer *, basic_block);
1a817418 219extern void dump_flow_info (FILE *, dump_flags_t);
2c895bd1 220
6de9cd9a 221extern edge redirect_edge_and_branch (edge, basic_block);
f470c378 222extern basic_block redirect_edge_and_branch_force (edge, basic_block);
893479de 223extern edge redirect_edge_succ_nodup (edge, basic_block);
9678086d 224extern bool can_remove_branch_p (const_edge);
14fa2cc0 225extern void remove_branch (edge);
452ba14d 226extern void remove_edge (edge);
c4d281b2 227extern edge split_block (basic_block, rtx);
355fe088 228extern edge split_block (basic_block, gimple *);
f470c378
ZD
229extern edge split_block_after_labels (basic_block);
230extern bool move_block_after (basic_block, basic_block);
231extern void delete_basic_block (basic_block);
232extern basic_block split_edge (edge);
c4d281b2
RB
233extern basic_block create_basic_block (rtx, rtx, basic_block);
234extern basic_block create_basic_block (gimple_seq, basic_block);
f470c378 235extern basic_block create_empty_bb (basic_block);
b48d0358 236extern bool can_merge_blocks_p (basic_block, basic_block);
f470c378
ZD
237extern void merge_blocks (basic_block, basic_block);
238extern edge make_forwarder_block (basic_block, bool (*)(edge),
239 void (*) (basic_block));
cf103ca4 240extern basic_block force_nonfallthru (edge);
f470c378
ZD
241extern void tidy_fallthru_edge (edge);
242extern void tidy_fallthru_edges (void);
6de9cd9a 243extern void predict_edge (edge e, enum br_predictor predictor, int probability);
9678086d
KG
244extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor);
245extern bool can_duplicate_block_p (const_basic_block);
229d576c
RB
246extern basic_block duplicate_block (basic_block, edge, basic_block,
247 copy_bb_data * = NULL);
b48d0358 248extern bool block_ends_with_call_p (basic_block bb);
df92c640
SB
249extern bool empty_block_p (basic_block);
250extern basic_block split_block_before_cond_jump (basic_block);
9678086d 251extern bool block_ends_with_condjump_p (const_basic_block bb);
6de9cd9a 252extern int flow_call_edges_add (sbitmap);
d9d4706f
KH
253extern void execute_on_growing_pred (edge);
254extern void execute_on_shrinking_pred (edge);
4851c80c
XL
255extern bool
256cfg_hook_duplicate_loop_body_to_header_edge (class loop *loop, edge,
257 unsigned int ndupl,
258 sbitmap wont_exit, edge orig,
259 vec<edge> *to_remove, int flags);
1cb7dfc3
MH
260
261extern void lv_flush_pending_stmts (edge);
262extern void extract_cond_bb_edges (basic_block, edge *, edge*);
263extern void lv_adjust_loop_header_phi (basic_block, basic_block, basic_block,
264 edge);
265extern void lv_add_condition_to_bb (basic_block, basic_block, basic_block,
266 void *);
9ee634e3 267
78bde837
SB
268extern bool can_copy_bbs_p (basic_block *, unsigned);
269extern void copy_bbs (basic_block *, unsigned, basic_block *,
99b1c316 270 edge *, unsigned, edge *, class loop *,
f14540b6 271 basic_block, bool);
78bde837 272
160576e1
ML
273void profile_record_check_consistency (profile_record *);
274void profile_record_account_profile (profile_record *);
aa4723d7 275
9ee634e3 276/* Hooks containers. */
726a989a 277extern struct cfg_hooks gimple_cfg_hooks;
9ee634e3 278extern struct cfg_hooks rtl_cfg_hooks;
f470c378 279extern struct cfg_hooks cfg_layout_rtl_cfg_hooks;
9ee634e3
JH
280
281/* Declarations. */
52bca999 282extern enum ir_type current_ir_type (void);
d329e058
AJ
283extern void rtl_register_cfg_hooks (void);
284extern void cfg_layout_rtl_register_cfg_hooks (void);
726a989a 285extern void gimple_register_cfg_hooks (void);
e855c69d
AB
286extern struct cfg_hooks get_cfg_hooks (void);
287extern void set_cfg_hooks (struct cfg_hooks);
9ee634e3 288
f1717f8d 289#endif /* GCC_CFGHOOKS_H */