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-2013 Free Software Foundation, Inc.
3  Contributed by Sebastian Pop <s.pop@laposte.net>
4 
5 This file is part of GCC.
6 
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11 
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20 
21 /* Only basic-block.h includes this. */
22 
23 struct cfg_hooks
24 {
25  /* Name of the corresponding ir. */
26  const char *name;
27 
28  /* Debugging. */
29  int (*verify_flow_info) (void);
30  void (*dump_bb) (FILE *, basic_block, int, int);
32 
33  /* Basic CFG manipulation. */
34 
35  /* Return new basic block. */
36  basic_block (*create_basic_block) (void *head, void *end, basic_block after);
37 
38  /* Redirect edge E to the given basic block B and update underlying program
39  representation. Returns edge representing redirected branch (that may not
40  be equivalent to E in the case of duplicate edges being removed) or NULL
41  if edge is not easily redirectable for whatever reason. */
43 
44  /* Same as the above but allows redirecting of fallthru edges. In that case
45  newly created forwarder basic block is returned. The edge must
46  not be abnormal. */
48 
49  /* Returns true if it is possible to remove the edge by redirecting it
50  to the destination of the other edge going from its source. */
52 
53  /* Remove statements corresponding to a given basic block. */
55 
56  /* Creates a new basic block just after basic block B by splitting
57  everything after specified instruction I. */
58  basic_block (*split_block) (basic_block b, void * i);
59 
60  /* Move block B immediately after block A. */
62 
63  /* Return true when blocks A and B can be merged into single basic block. */
65 
66  /* Merge blocks A and B. */
67  void (*merge_blocks) (basic_block a, basic_block b);
68 
69  /* Predict edge E using PREDICTOR to given PROBABILITY. */
70  void (*predict_edge) (edge e, enum br_predictor predictor, int probability);
71 
72  /* Return true if the one of outgoing edges is already predicted by
73  PREDICTOR. */
74  bool (*predicted_by_p) (const_basic_block bb, enum br_predictor predictor);
75 
76  /* Return true when block A can be duplicated. */
78 
79  /* Duplicate block A. */
81 
82  /* Higher level functions representable by primitive operations above if
83  we didn't have some oddities in RTL and Tree representations. */
86 
87  /* Try to make the edge fallthru. */
88  void (*tidy_fallthru_edge) (edge);
89 
90  /* Make the edge non-fallthru. */
92 
93  /* Say whether a block ends with a call, possibly followed by some
94  other code that must stay with the call. */
96 
97  /* Say whether a block ends with a conditional branch. Switches
98  and unconditional branches do not qualify. */
100 
101  /* Add fake edges to the function exit for any non constant and non noreturn
102  calls, volatile inline assembly in the bitmap of blocks specified by
103  BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks
104  that were split.
105 
106  The goal is to expose cases in which entering a basic block does not imply
107  that all subsequent instructions must be executed. */
109 
110  /* This function is called immediately after edge E is added to the
111  edge vector E->dest->preds. */
113 
114  /* This function is called immediately before edge E is removed from
115  the edge vector E->dest->preds. */
118  /* A hook for duplicating loop in CFG, currently this is used
119  in loop versioning. */
121  unsigned, sbitmap,
123  int);
124 
125  /* Add condition to new basic block and update CFG used in loop
126  versioning. */
128  void *);
129  /* Update the PHI nodes in case of loop versioning. */
131  basic_block, edge);
133  /* Given a condition BB extract the true/false taken/not taken edges
134  (depending if we are on tree's or RTL). */
135  void (*extract_cond_bb_edges) (basic_block, edge *, edge *);
136 
138  /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge
139  E->dest (only in tree-ssa loop versioning. */
140  void (*flush_pending_stmts) (edge);
141 
142  /* True if a block contains no executable instructions. */
143  bool (*empty_block_p) (basic_block);
144 
145  /* Split a basic block if it ends with a conditional branch and if
146  the other part of the block is not empty. */
148 
149  /* Do book-keeping of a basic block for the profile consistency checker. */
150  void (*account_profile_record) (basic_block, int, struct profile_record *);
151 };
152 
153 extern void verify_flow_info (void);
154 extern void dump_bb (FILE *, basic_block, int, int);
156 
160 extern void remove_branch (edge);
161 extern void remove_edge (edge);
162 extern edge split_block (basic_block, void *);
166 extern basic_block split_edge (edge);
167 extern basic_block create_basic_block (void *, void *, basic_block);
170 extern void merge_blocks (basic_block, basic_block);
172  void (*) (basic_block));
174 extern void tidy_fallthru_edge (edge);
175 extern void tidy_fallthru_edges (void);
176 extern void predict_edge (edge e, enum br_predictor predictor, int probability);
177 extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor);
181 extern bool empty_block_p (basic_block);
185 extern void execute_on_growing_pred (edge);
186 extern void execute_on_shrinking_pred (edge);
188  unsigned int ndupl,
189  sbitmap wont_exit,
190  edge orig,
191  vec<edge> *to_remove,
192  int flags);
193 
194 extern void lv_flush_pending_stmts (edge);
195 extern void extract_cond_bb_edges (basic_block, edge *, edge*);
197  edge);
199  void *);
200 
201 extern bool can_copy_bbs_p (basic_block *, unsigned);
202 extern void copy_bbs (basic_block *, unsigned, basic_block *,
203  edge *, unsigned, edge *, struct loop *,
204  basic_block, bool);
205 
206 void account_profile_record (struct profile_record *, int);
207 
208 extern void cfg_layout_initialize (unsigned int);
209 extern void cfg_layout_finalize (void);
210 
211 /* Hooks containers. */
212 extern struct cfg_hooks gimple_cfg_hooks;
213 extern struct cfg_hooks rtl_cfg_hooks;
214 extern struct cfg_hooks cfg_layout_rtl_cfg_hooks;
215 
216 /* Declarations. */
217 extern enum ir_type current_ir_type (void);
218 extern void rtl_register_cfg_hooks (void);
219 extern void cfg_layout_rtl_register_cfg_hooks (void);
220 extern void gimple_register_cfg_hooks (void);
221 extern struct cfg_hooks get_cfg_hooks (void);
222 extern void set_cfg_hooks (struct cfg_hooks);
223