]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cfghooks.h
[testsuite] Add missing dg-require-effective-target label_values
[thirdparty/gcc.git] / gcc / cfghooks.h
CommitLineData
1026363d 1/* Hooks for cfg representation specific functions.
fbd26352 2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
1026363d 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
8c4c00c1 9the Free Software Foundation; either version 3, or (at your option)
1026363d 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
8c4c00c1 18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
1026363d 20
ce6bb0f3 21#ifndef GCC_CFGHOOKS_H
22#define GCC_CFGHOOKS_H
23
d040a5b0 24#include "predict.h"
1026363d 25
e5a23585 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.c. 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.c
36 and one CFG hook per CFG mode. */
37struct profile_record
38{
39 /* The number of basic blocks where sum(freq) of the block's predecessors
40 doesn't match reasonably well with the incoming frequency. */
ae1e77fa 41 int num_mismatched_freq_in;
e5a23585 42 /* Likewise for a basic block's successors. */
ae1e77fa 43 int num_mismatched_freq_out;
e5a23585 44 /* The number of basic blocks where sum(count) of the block's predecessors
45 doesn't match reasonably well with the incoming frequency. */
ae1e77fa 46 int num_mismatched_count_in;
e5a23585 47 /* Likewise for a basic block's successors. */
ae1e77fa 48 int num_mismatched_count_out;
e5a23585 49 /* A weighted cost of the run-time of the function body. */
ae1e77fa 50 gcov_type_unsigned time;
e5a23585 51 /* A weighted cost of the size of the function body. */
ae1e77fa 52 int size;
e5a23585 53 /* True iff this pass actually was run. */
54 bool run;
55};
56
3350055c 57typedef int_hash <unsigned short, 0> dependence_hash;
58
59/* Optional data for duplicate_block. */
60
61struct copy_bb_data
62{
63 copy_bb_data() : dependence_map (NULL) {}
64 ~copy_bb_data () { delete dependence_map; }
65
66 /* A map from the copied BBs dependence info cliques to
67 equivalents in the BBs duplicated to. */
68 hash_map<dependence_hash, unsigned short> *dependence_map;
69};
e5a23585 70
1026363d 71struct cfg_hooks
72{
5f5d4cd1 73 /* Name of the corresponding ir. */
74 const char *name;
75
76 /* Debugging. */
77 int (*verify_flow_info) (void);
3f6e5ced 78 void (*dump_bb) (FILE *, basic_block, int, dump_flags_t);
e079344a 79 void (*dump_bb_for_graph) (pretty_printer *, basic_block);
1026363d 80
81 /* Basic CFG manipulation. */
82
8b332087 83 /* Return new basic block. */
5a2784f8 84 basic_block (*create_basic_block) (void *head, void *end, basic_block after);
c60fa3a7 85
1026363d 86 /* Redirect edge E to the given basic block B and update underlying program
4ee9c684 87 representation. Returns edge representing redirected branch (that may not
88 be equivalent to E in the case of duplicate edges being removed) or NULL
89 if edge is not easily redirectable for whatever reason. */
90 edge (*redirect_edge_and_branch) (edge e, basic_block b);
1026363d 91
92 /* Same as the above but allows redirecting of fallthru edges. In that case
1fa3a8f6 93 newly created forwarder basic block is returned. The edge must
94 not be abnormal. */
4c9e08a4 95 basic_block (*redirect_edge_and_branch_force) (edge, basic_block);
1026363d 96
611d2ac1 97 /* Returns true if it is possible to remove the edge by redirecting it
98 to the destination of the other edge going from its source. */
5493cb9a 99 bool (*can_remove_branch_p) (const_edge);
611d2ac1 100
5f5d4cd1 101 /* Remove statements corresponding to a given basic block. */
102 void (*delete_basic_block) (basic_block);
103
104 /* Creates a new basic block just after basic block B by splitting
105 everything after specified instruction I. */
106 basic_block (*split_block) (basic_block b, void * i);
48e1416a 107
5f5d4cd1 108 /* Move block B immediately after block A. */
109 bool (*move_block_after) (basic_block b, basic_block a);
1026363d 110
c60fa3a7 111 /* Return true when blocks A and B can be merged into single basic block. */
47aaf6e6 112 bool (*can_merge_blocks_p) (basic_block a, basic_block b);
c60fa3a7 113
114 /* Merge blocks A and B. */
5a2784f8 115 void (*merge_blocks) (basic_block a, basic_block b);
c60fa3a7 116
4ee9c684 117 /* Predict edge E using PREDICTOR to given PROBABILITY. */
118 void (*predict_edge) (edge e, enum br_predictor predictor, int probability);
119
120 /* Return true if the one of outgoing edges is already predicted by
121 PREDICTOR. */
5493cb9a 122 bool (*predicted_by_p) (const_basic_block bb, enum br_predictor predictor);
4ee9c684 123
124 /* Return true when block A can be duplicated. */
5493cb9a 125 bool (*can_duplicate_block_p) (const_basic_block a);
4ee9c684 126
127 /* Duplicate block A. */
3350055c 128 basic_block (*duplicate_block) (basic_block a, copy_bb_data *);
4ee9c684 129
1026363d 130 /* Higher level functions representable by primitive operations above if
131 we didn't have some oddities in RTL and Tree representations. */
5f5d4cd1 132 basic_block (*split_edge) (edge);
133 void (*make_forwarder_block) (edge);
134
202bbc06 135 /* Try to make the edge fallthru. */
5f5d4cd1 136 void (*tidy_fallthru_edge) (edge);
4ee9c684 137
202bbc06 138 /* Make the edge non-fallthru. */
139 basic_block (*force_nonfallthru) (edge);
140
4ee9c684 141 /* Say whether a block ends with a call, possibly followed by some
142 other code that must stay with the call. */
47aaf6e6 143 bool (*block_ends_with_call_p) (basic_block);
4ee9c684 144
145 /* Say whether a block ends with a conditional branch. Switches
146 and unconditional branches do not qualify. */
5493cb9a 147 bool (*block_ends_with_condjump_p) (const_basic_block);
4ee9c684 148
149 /* Add fake edges to the function exit for any non constant and non noreturn
150 calls, volatile inline assembly in the bitmap of blocks specified by
151 BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks
152 that were split.
153
154 The goal is to expose cases in which entering a basic block does not imply
155 that all subsequent instructions must be executed. */
156 int (*flow_call_edges_add) (sbitmap);
26b12c91 157
158 /* This function is called immediately after edge E is added to the
159 edge vector E->dest->preds. */
160 void (*execute_on_growing_pred) (edge);
161
162 /* This function is called immediately before edge E is removed from
163 the edge vector E->dest->preds. */
164 void (*execute_on_shrinking_pred) (edge);
c50ae675 165
166 /* A hook for duplicating loop in CFG, currently this is used
167 in loop versioning. */
f3c40e6d 168 bool (*cfg_hook_duplicate_loop_to_header_edge) (struct loop *, edge,
169 unsigned, sbitmap,
f1f41a6c 170 edge, vec<edge> *,
f3c40e6d 171 int);
c50ae675 172
442e3cb9 173 /* Add condition to new basic block and update CFG used in loop
c50ae675 174 versioning. */
175 void (*lv_add_condition_to_bb) (basic_block, basic_block, basic_block,
a0c938f0 176 void *);
c50ae675 177 /* Update the PHI nodes in case of loop versioning. */
178 void (*lv_adjust_loop_header_phi) (basic_block, basic_block,
179 basic_block, edge);
a0c938f0 180
c50ae675 181 /* Given a condition BB extract the true/false taken/not taken edges
182 (depending if we are on tree's or RTL). */
183 void (*extract_cond_bb_edges) (basic_block, edge *, edge *);
184
a0c938f0 185
c50ae675 186 /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge
187 E->dest (only in tree-ssa loop versioning. */
188 void (*flush_pending_stmts) (edge);
9631926a 189
190 /* True if a block contains no executable instructions. */
191 bool (*empty_block_p) (basic_block);
192
193 /* Split a basic block if it ends with a conditional branch and if
194 the other part of the block is not empty. */
195 basic_block (*split_block_before_cond_jump) (basic_block);
98193482 196
197 /* Do book-keeping of a basic block for the profile consistency checker. */
ae1e77fa 198 void (*account_profile_record) (basic_block, struct profile_record *);
1026363d 199};
200
5f5d4cd1 201extern void verify_flow_info (void);
382ecba7 202
203/* Check control flow invariants, if internal consistency checks are
204 enabled. */
205
206static inline void
207checking_verify_flow_info (void)
208{
209 /* TODO: Add a separate option for -fchecking=cfg. */
210 if (flag_checking)
211 verify_flow_info ();
212}
213
3f6e5ced 214extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
e079344a 215extern void dump_bb_for_graph (pretty_printer *, basic_block);
3f6e5ced 216extern void dump_flow_info (FILE *, dump_flags_t);
e079344a 217
4ee9c684 218extern edge redirect_edge_and_branch (edge, basic_block);
5f5d4cd1 219extern basic_block redirect_edge_and_branch_force (edge, basic_block);
e5a23585 220extern edge redirect_edge_succ_nodup (edge, basic_block);
5493cb9a 221extern bool can_remove_branch_p (const_edge);
611d2ac1 222extern void remove_branch (edge);
c8e41bd9 223extern void remove_edge (edge);
4302d619 224extern edge split_block (basic_block, rtx);
42acab1c 225extern edge split_block (basic_block, gimple *);
5f5d4cd1 226extern edge split_block_after_labels (basic_block);
227extern bool move_block_after (basic_block, basic_block);
228extern void delete_basic_block (basic_block);
229extern basic_block split_edge (edge);
4302d619 230extern basic_block create_basic_block (rtx, rtx, basic_block);
231extern basic_block create_basic_block (gimple_seq, basic_block);
5f5d4cd1 232extern basic_block create_empty_bb (basic_block);
47aaf6e6 233extern bool can_merge_blocks_p (basic_block, basic_block);
5f5d4cd1 234extern void merge_blocks (basic_block, basic_block);
235extern edge make_forwarder_block (basic_block, bool (*)(edge),
236 void (*) (basic_block));
202bbc06 237extern basic_block force_nonfallthru (edge);
5f5d4cd1 238extern void tidy_fallthru_edge (edge);
239extern void tidy_fallthru_edges (void);
4ee9c684 240extern void predict_edge (edge e, enum br_predictor predictor, int probability);
5493cb9a 241extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor);
242extern bool can_duplicate_block_p (const_basic_block);
3350055c 243extern basic_block duplicate_block (basic_block, edge, basic_block,
244 copy_bb_data * = NULL);
47aaf6e6 245extern bool block_ends_with_call_p (basic_block bb);
9631926a 246extern bool empty_block_p (basic_block);
247extern basic_block split_block_before_cond_jump (basic_block);
5493cb9a 248extern bool block_ends_with_condjump_p (const_basic_block bb);
4ee9c684 249extern int flow_call_edges_add (sbitmap);
26b12c91 250extern void execute_on_growing_pred (edge);
251extern void execute_on_shrinking_pred (edge);
c50ae675 252extern bool cfg_hook_duplicate_loop_to_header_edge (struct loop *loop, edge,
c50ae675 253 unsigned int ndupl,
254 sbitmap wont_exit,
f3c40e6d 255 edge orig,
f1f41a6c 256 vec<edge> *to_remove,
c50ae675 257 int flags);
258
259extern void lv_flush_pending_stmts (edge);
260extern void extract_cond_bb_edges (basic_block, edge *, edge*);
261extern void lv_adjust_loop_header_phi (basic_block, basic_block, basic_block,
262 edge);
263extern void lv_add_condition_to_bb (basic_block, basic_block, basic_block,
264 void *);
1026363d 265
23a070f3 266extern bool can_copy_bbs_p (basic_block *, unsigned);
267extern void copy_bbs (basic_block *, unsigned, basic_block *,
268 edge *, unsigned, edge *, struct loop *,
d99f53b2 269 basic_block, bool);
23a070f3 270
ae1e77fa 271void profile_record_check_consistency (profile_record *);
272void profile_record_account_profile (profile_record *);
98193482 273
1026363d 274/* Hooks containers. */
75a70cf9 275extern struct cfg_hooks gimple_cfg_hooks;
1026363d 276extern struct cfg_hooks rtl_cfg_hooks;
5f5d4cd1 277extern struct cfg_hooks cfg_layout_rtl_cfg_hooks;
1026363d 278
279/* Declarations. */
15b8fe07 280extern enum ir_type current_ir_type (void);
4c9e08a4 281extern void rtl_register_cfg_hooks (void);
282extern void cfg_layout_rtl_register_cfg_hooks (void);
75a70cf9 283extern void gimple_register_cfg_hooks (void);
e1ab7874 284extern struct cfg_hooks get_cfg_hooks (void);
285extern void set_cfg_hooks (struct cfg_hooks);
1026363d 286
ce6bb0f3 287#endif /* GCC_CFGHOOKS_H */