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