1 /* DDG - Data Dependence Graph - interface. 2 Copyright (C) 2004-2018 Free Software Foundation, Inc. 3 Contributed by Ayal Zaks and Mustafa Hagog <zaks,mustafa@il.ibm.com> 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify it under 8 the terms of the GNU General Public License as published by the Free 9 Software Foundation; either version 3, or (at your option) any later 10 version. 11 12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13 WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 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 #ifndef GCC_DDG_H 22 #define GCC_DDG_H 23 24 /* For sbitmap. */ 25 26 typedef struct ddg_node *ddg_node_ptr; 27 typedef struct ddg_edge *ddg_edge_ptr; 28 typedef struct ddg *ddg_ptr; 29 typedef struct ddg_scc *ddg_scc_ptr; 30 typedef struct ddg_all_sccs *ddg_all_sccs_ptr; 31 32 enum dep_type {TRUE_DEP, OUTPUT_DEP, ANTI_DEP}; 33 enum dep_data_type {REG_OR_MEM_DEP, REG_DEP, MEM_DEP, REG_AND_MEM_DEP}; 34 35 /* The following two macros enables direct access to the successors and 36 predecessors bitmaps held in each ddg_node. Do not make changes to 37 these bitmaps, unless you want to change the DDG. */ 38 #define NODE_SUCCESSORS(x) ((x)->successors) 39 #define NODE_PREDECESSORS(x) ((x)->predecessors) 40 41 /* A structure that represents a node in the DDG. */ 42 struct ddg_node 43 { 44 /* Each node has a unique CUID index. These indices increase monotonically 45 (according to the order of the corresponding INSN in the BB), starting 46 from 0 with no gaps. */ 47 int cuid; 48 49 /* The insn represented by the node. */ 50 rtx_insn *insn; 51 52 /* A note preceding INSN (or INSN itself), such that all insns linked 53 from FIRST_NOTE until INSN (inclusive of both) are moved together 54 when reordering the insns. This takes care of notes that should 55 continue to precede INSN. */ 56 rtx_insn *first_note; 57 58 /* Incoming and outgoing dependency edges. */ 59 ddg_edge_ptr in; 60 ddg_edge_ptr out; 61 62 /* Each bit corresponds to a ddg_node according to its cuid, and is 63 set iff the node is a successor/predecessor of "this" node. */ 64 sbitmap successors; 65 sbitmap predecessors; 66 67 /* For general use by algorithms manipulating the ddg. */ 68 union { 69 int count; 70 void *info; 71 } aux; 72 }; 73 74 /* A structure that represents an edge in the DDG. */ 75 struct ddg_edge 76 { 77 /* The source and destination nodes of the dependency edge. */ 78 ddg_node_ptr src; 79 ddg_node_ptr dest; 80 81 /* TRUE, OUTPUT or ANTI dependency. */ 82 dep_type type; 83 84 /* REG or MEM dependency. */ 85 dep_data_type data_type; 86 87 /* Latency of the dependency. */ 88 int latency; 89 90 /* The distance: number of loop iterations the dependency crosses. */ 91 int distance; 92 93 /* The following two fields are used to form a linked list of the in/out 94 going edges to/from each node. */ 95 ddg_edge_ptr next_in; 96 ddg_edge_ptr next_out; 97 98 /* For general use by algorithms manipulating the ddg. */ 99 union { 100 int count; 101 void *info; 102 } aux; 103 }; 104 105 /* This structure holds the Data Dependence Graph for a basic block. */ 106 struct ddg 107 { 108 /* The basic block for which this DDG is built. */ 109 basic_block bb; 110 111 /* Number of instructions in the basic block. */ 112 int num_nodes; 113 114 /* Number of load/store instructions in the BB - statistics. */ 115 int num_loads; 116 int num_stores; 117 118 /* Number of debug instructions in the BB. */ 119 int num_debug; 120 121 /* This array holds the nodes in the graph; it is indexed by the node 122 cuid, which follows the order of the instructions in the BB. */ 123 ddg_node_ptr nodes; 124 125 /* The branch closing the loop. */ 126 ddg_node_ptr closing_branch; 127 128 /* Build dependence edges for closing_branch, when set. In certain cases, 129 the closing branch can be dealt with separately from the insns of the 130 loop, and then no such deps are needed. */ 131 int closing_branch_deps; 132 133 /* Array and number of backarcs (edges with distance > 0) in the DDG. */ 134 int num_backarcs; 135 ddg_edge_ptr *backarcs; 136 }; 137 138 139 /* Holds information on an SCC (Strongly Connected Component) of the DDG. */ 140 struct ddg_scc 141 { 142 /* A bitmap that represents the nodes of the DDG that are in the SCC. */ 143 sbitmap nodes; 144 145 /* Array and number of backarcs (edges with distance > 0) in the SCC. */ 146 ddg_edge_ptr *backarcs; 147 int num_backarcs; 148 149 /* The maximum of (total_latency/total_distance) over all cycles in SCC. */ 150 int recurrence_length; 151 }; 152 153 /* This structure holds the SCCs of the DDG. */ 154 struct ddg_all_sccs 155 { 156 /* Array that holds the SCCs in the DDG, and their number. */ 157 ddg_scc_ptr *sccs; 158 int num_sccs; 159 160 ddg_ptr ddg; 161 }; 162 163 164 ddg_ptr create_ddg (basic_block, int closing_branch_deps); 165 void free_ddg (ddg_ptr); 166 167 void print_ddg (FILE *, ddg_ptr); 168 void vcg_print_ddg (FILE *, ddg_ptr); 169 void print_ddg_edge (FILE *, ddg_edge_ptr); 170 void print_sccs (FILE *, ddg_all_sccs_ptr, ddg_ptr); 171 172 ddg_node_ptr get_node_of_insn (ddg_ptr, rtx_insn *); 173 174 void find_successors (sbitmap result, ddg_ptr, sbitmap); 175 void find_predecessors (sbitmap result, ddg_ptr, sbitmap); 176 177 ddg_all_sccs_ptr create_ddg_all_sccs (ddg_ptr); 178 void free_ddg_all_sccs (ddg_all_sccs_ptr); 179 180 int find_nodes_on_paths (sbitmap result, ddg_ptr, sbitmap from, sbitmap to); 181 int longest_simple_path (ddg_ptr, int from, int to, sbitmap via); 182 183 bool autoinc_var_is_used_p (rtx_insn *, rtx_insn *); 184 185 #endif /* GCC_DDG_H */ 186