1/* Hooks for cfg representation specific functions. 2 Copyright (C) 2003-2015 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/* Only basic-block.h includes this. */ 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.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. */ 41 int num_mismatched_freq_in[2]; 42 /* Likewise for a basic block's successors. */ 43 int num_mismatched_freq_out[2]; 44 /* The number of basic blocks where sum(count) of the block's predecessors 45 doesn't match reasonably well with the incoming frequency. */ 46 int num_mismatched_count_in[2]; 47 /* Likewise for a basic block's successors. */ 48 int num_mismatched_count_out[2]; 49 /* A weighted cost of the run-time of the function body. */ 50 gcov_type time[2]; 51 /* A weighted cost of the size of the function body. */ 52 int size[2]; 53 /* True iff this pass actually was run. */ 54 bool run; 55}; 56 57 58struct cfg_hooks 59{ 60 /* Name of the corresponding ir. */ 61 const char *name; 62 63 /* Debugging. */ 64 int (*verify_flow_info) (void); 65 void (*dump_bb) (FILE *, basic_block, int, int); 66 void (*dump_bb_for_graph) (pretty_printer *, basic_block); 67 68 /* Basic CFG manipulation. */ 69 70 /* Return new basic block. */ 71 basic_block (*create_basic_block) (void *head, void *end, basic_block after); 72 73 /* Redirect edge E to the given basic block B and update underlying program 74 representation. Returns edge representing redirected branch (that may not 75 be equivalent to E in the case of duplicate edges being removed) or NULL 76 if edge is not easily redirectable for whatever reason. */ 77 edge (*redirect_edge_and_branch) (edge e, basic_block b); 78 79 /* Same as the above but allows redirecting of fallthru edges. In that case 80 newly created forwarder basic block is returned. The edge must 81 not be abnormal. */ 82 basic_block (*redirect_edge_and_branch_force) (edge, basic_block); 83 84 /* Returns true if it is possible to remove the edge by redirecting it 85 to the destination of the other edge going from its source. */ 86 bool (*can_remove_branch_p) (const_edge); 87 88 /* Remove statements corresponding to a given basic block. */ 89 void (*delete_basic_block) (basic_block); 90 91 /* Creates a new basic block just after basic block B by splitting 92 everything after specified instruction I. */ 93 basic_block (*split_block) (basic_block b, void * i); 94 95 /* Move block B immediately after block A. */ 96 bool (*move_block_after) (basic_block b, basic_block a); 97 98 /* Return true when blocks A and B can be merged into single basic block. */ 99 bool (*can_merge_blocks_p) (basic_block a, basic_block b); 100 101 /* Merge blocks A and B. */ 102 void (*merge_blocks) (basic_block a, basic_block b); 103 104 /* Predict edge E using PREDICTOR to given PROBABILITY. */ 105 void (*predict_edge) (edge e, enum br_predictor predictor, int probability); 106 107 /* Return true if the one of outgoing edges is already predicted by 108 PREDICTOR. */ 109 bool (*predicted_by_p) (const_basic_block bb, enum br_predictor predictor); 110 111 /* Return true when block A can be duplicated. */ 112 bool (*can_duplicate_block_p) (const_basic_block a); 113 114 /* Duplicate block A. */ 115 basic_block (*duplicate_block) (basic_block a); 116 117 /* Higher level functions representable by primitive operations above if 118 we didn't have some oddities in RTL and Tree representations. */ 119 basic_block (*split_edge) (edge); 120 void (*make_forwarder_block) (edge); 121 122 /* Try to make the edge fallthru. */ 123 void (*tidy_fallthru_edge) (edge); 124 125 /* Make the edge non-fallthru. */ 126 basic_block (*force_nonfallthru) (edge); 127 128 /* Say whether a block ends with a call, possibly followed by some 129 other code that must stay with the call. */ 130 bool (*block_ends_with_call_p) (basic_block); 131 132 /* Say whether a block ends with a conditional branch. Switches 133 and unconditional branches do not qualify. */ 134 bool (*block_ends_with_condjump_p) (const_basic_block); 135 136 /* Add fake edges to the function exit for any non constant and non noreturn 137 calls, volatile inline assembly in the bitmap of blocks specified by 138 BLOCKS or to the whole CFG if BLOCKS is zero. Return the number of blocks 139 that were split. 140 141 The goal is to expose cases in which entering a basic block does not imply 142 that all subsequent instructions must be executed. */ 143 int (*flow_call_edges_add) (sbitmap); 144 145 /* This function is called immediately after edge E is added to the 146 edge vector E->dest->preds. */ 147 void (*execute_on_growing_pred) (edge); 148 149 /* This function is called immediately before edge E is removed from 150 the edge vector E->dest->preds. */ 151 void (*execute_on_shrinking_pred) (edge); 152 153 /* A hook for duplicating loop in CFG, currently this is used 154 in loop versioning. */ 155 bool (*cfg_hook_duplicate_loop_to_header_edge) (struct loop *, edge, 156 unsigned, sbitmap, 157 edge, vec<edge> *, 158 int); 159 160 /* Add condition to new basic block and update CFG used in loop 161 versioning. */ 162 void (*lv_add_condition_to_bb) (basic_block, basic_block, basic_block, 163 void *); 164 /* Update the PHI nodes in case of loop versioning. */ 165 void (*lv_adjust_loop_header_phi) (basic_block, basic_block, 166 basic_block, edge); 167 168 /* Given a condition BB extract the true/false taken/not taken edges 169 (depending if we are on tree's or RTL). */ 170 void (*extract_cond_bb_edges) (basic_block, edge *, edge *); 171 172 173 /* Add PHI arguments queued in PENDINT_STMT list on edge E to edge 174 E->dest (only in tree-ssa loop versioning. */ 175 void (*flush_pending_stmts) (edge); 176 177 /* True if a block contains no executable instructions. */ 178 bool (*empty_block_p) (basic_block); 179 180 /* Split a basic block if it ends with a conditional branch and if 181 the other part of the block is not empty. */ 182 basic_block (*split_block_before_cond_jump) (basic_block); 183 184 /* Do book-keeping of a basic block for the profile consistency checker. */ 185 void (*account_profile_record) (basic_block, int, struct profile_record *); 186}; 187 188extern void verify_flow_info (void); 189extern void dump_bb (FILE *, basic_block, int, int); 190extern void dump_bb_for_graph (pretty_printer *, basic_block); 191extern void dump_flow_info (FILE *, int); 192 193extern edge redirect_edge_and_branch (edge, basic_block); 194extern basic_block redirect_edge_and_branch_force (edge, basic_block); 195extern edge redirect_edge_succ_nodup (edge, basic_block); 196extern bool can_remove_branch_p (const_edge); 197extern void remove_branch (edge); 198extern void remove_edge (edge); 199extern edge split_block (basic_block, void *); 200extern edge split_block_after_labels (basic_block); 201extern bool move_block_after (basic_block, basic_block); 202extern void delete_basic_block (basic_block); 203extern basic_block split_edge (edge); 204extern basic_block create_basic_block (void *, void *, basic_block); 205extern basic_block create_empty_bb (basic_block); 206extern bool can_merge_blocks_p (basic_block, basic_block); 207extern void merge_blocks (basic_block, basic_block); 208extern edge make_forwarder_block (basic_block, bool (*)(edge), 209 void (*) (basic_block)); 210extern basic_block force_nonfallthru (edge); 211extern void tidy_fallthru_edge (edge); 212extern void tidy_fallthru_edges (void); 213extern void predict_edge (edge e, enum br_predictor predictor, int probability); 214extern bool predicted_by_p (const_basic_block bb, enum br_predictor predictor); 215extern bool can_duplicate_block_p (const_basic_block); 216extern basic_block duplicate_block (basic_block, edge, basic_block); 217extern bool block_ends_with_call_p (basic_block bb); 218extern bool empty_block_p (basic_block); 219extern basic_block split_block_before_cond_jump (basic_block); 220extern bool block_ends_with_condjump_p (const_basic_block bb); 221extern int flow_call_edges_add (sbitmap); 222extern void execute_on_growing_pred (edge); 223extern void execute_on_shrinking_pred (edge); 224extern bool cfg_hook_duplicate_loop_to_header_edge (struct loop *loop, edge, 225 unsigned int ndupl, 226 sbitmap wont_exit, 227 edge orig, 228 vec<edge> *to_remove, 229 int flags); 230 231extern void lv_flush_pending_stmts (edge); 232extern void extract_cond_bb_edges (basic_block, edge *, edge*); 233extern void lv_adjust_loop_header_phi (basic_block, basic_block, basic_block, 234 edge); 235extern void lv_add_condition_to_bb (basic_block, basic_block, basic_block, 236 void *); 237 238extern bool can_copy_bbs_p (basic_block *, unsigned); 239extern void copy_bbs (basic_block *, unsigned, basic_block *, 240 edge *, unsigned, edge *, struct loop *, 241 basic_block, bool); 242 243void account_profile_record (struct profile_record *, int); 244 245/* Hooks containers. */ 246extern struct cfg_hooks gimple_cfg_hooks; 247extern struct cfg_hooks rtl_cfg_hooks; 248extern struct cfg_hooks cfg_layout_rtl_cfg_hooks; 249 250/* Declarations. */ 251extern enum ir_type current_ir_type (void); 252extern void rtl_register_cfg_hooks (void); 253extern void cfg_layout_rtl_register_cfg_hooks (void); 254extern void gimple_register_cfg_hooks (void); 255extern struct cfg_hooks get_cfg_hooks (void); 256extern void set_cfg_hooks (struct cfg_hooks); 257 258#endif /* GCC_CFGHOOKS_H */ 259