]>
Commit | Line | Data |
---|---|---|
d397e8c6 | 1 | /* DDG - Data Dependence Graph - interface. |
99dee823 | 2 | Copyright (C) 2004-2021 Free Software Foundation, Inc. |
d397e8c6 MH |
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 | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
d397e8c6 MH |
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 | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
d397e8c6 MH |
20 | |
21 | #ifndef GCC_DDG_H | |
22 | #define GCC_DDG_H | |
23 | ||
59587b18 | 24 | /* For sbitmap. */ |
b8698a0f | 25 | |
d397e8c6 MH |
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 | ||
84562394 OE |
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}; | |
d397e8c6 MH |
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. */ | |
9774f20d | 50 | rtx_insn *insn; |
d397e8c6 | 51 | |
1ea7e6ad | 52 | /* A note preceding INSN (or INSN itself), such that all insns linked |
d397e8c6 MH |
53 | from FIRST_NOTE until INSN (inclusive of both) are moved together |
54 | when reordering the insns. This takes care of notes that should | |
1ea7e6ad | 55 | continue to precede INSN. */ |
9774f20d | 56 | rtx_insn *first_note; |
d397e8c6 MH |
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 | ||
728c2e5e RZ |
67 | /* Temporary array used for Floyd-Warshall algorithm to find |
68 | scc recurrence length. */ | |
69 | int *max_dist; | |
70 | ||
d397e8c6 MH |
71 | /* For general use by algorithms manipulating the ddg. */ |
72 | union { | |
73 | int count; | |
74 | void *info; | |
75 | } aux; | |
76 | }; | |
77 | ||
78 | /* A structure that represents an edge in the DDG. */ | |
79 | struct ddg_edge | |
80 | { | |
81 | /* The source and destination nodes of the dependency edge. */ | |
82 | ddg_node_ptr src; | |
83 | ddg_node_ptr dest; | |
84 | ||
85 | /* TRUE, OUTPUT or ANTI dependency. */ | |
86 | dep_type type; | |
87 | ||
88 | /* REG or MEM dependency. */ | |
89 | dep_data_type data_type; | |
90 | ||
61ada8ae | 91 | /* Latency of the dependency. */ |
d397e8c6 MH |
92 | int latency; |
93 | ||
94 | /* The distance: number of loop iterations the dependency crosses. */ | |
95 | int distance; | |
96 | ||
97 | /* The following two fields are used to form a linked list of the in/out | |
98 | going edges to/from each node. */ | |
99 | ddg_edge_ptr next_in; | |
100 | ddg_edge_ptr next_out; | |
101 | ||
728c2e5e RZ |
102 | /* Is true when edge is already in scc. */ |
103 | bool in_scc; | |
d397e8c6 MH |
104 | }; |
105 | ||
106 | /* This structure holds the Data Dependence Graph for a basic block. */ | |
107 | struct ddg | |
108 | { | |
109 | /* The basic block for which this DDG is built. */ | |
110 | basic_block bb; | |
111 | ||
112 | /* Number of instructions in the basic block. */ | |
113 | int num_nodes; | |
114 | ||
115 | /* Number of load/store instructions in the BB - statistics. */ | |
116 | int num_loads; | |
117 | int num_stores; | |
118 | ||
119 | /* This array holds the nodes in the graph; it is indexed by the node | |
120 | cuid, which follows the order of the instructions in the BB. */ | |
121 | ddg_node_ptr nodes; | |
122 | ||
123 | /* The branch closing the loop. */ | |
124 | ddg_node_ptr closing_branch; | |
125 | ||
126 | /* Build dependence edges for closing_branch, when set. In certain cases, | |
127 | the closing branch can be dealt with separately from the insns of the | |
128 | loop, and then no such deps are needed. */ | |
129 | int closing_branch_deps; | |
130 | ||
131 | /* Array and number of backarcs (edges with distance > 0) in the DDG. */ | |
d397e8c6 | 132 | int num_backarcs; |
b5b8b0ac | 133 | ddg_edge_ptr *backarcs; |
d397e8c6 MH |
134 | }; |
135 | ||
136 | \f | |
137 | /* Holds information on an SCC (Strongly Connected Component) of the DDG. */ | |
138 | struct ddg_scc | |
139 | { | |
140 | /* A bitmap that represents the nodes of the DDG that are in the SCC. */ | |
141 | sbitmap nodes; | |
142 | ||
143 | /* Array and number of backarcs (edges with distance > 0) in the SCC. */ | |
144 | ddg_edge_ptr *backarcs; | |
145 | int num_backarcs; | |
146 | ||
147 | /* The maximum of (total_latency/total_distance) over all cycles in SCC. */ | |
148 | int recurrence_length; | |
149 | }; | |
150 | ||
151 | /* This structure holds the SCCs of the DDG. */ | |
152 | struct ddg_all_sccs | |
153 | { | |
154 | /* Array that holds the SCCs in the DDG, and their number. */ | |
155 | ddg_scc_ptr *sccs; | |
156 | int num_sccs; | |
157 | ||
158 | ddg_ptr ddg; | |
159 | }; | |
160 | ||
161 | \f | |
6fb5fa3c | 162 | ddg_ptr create_ddg (basic_block, int closing_branch_deps); |
d397e8c6 MH |
163 | void free_ddg (ddg_ptr); |
164 | ||
165 | void print_ddg (FILE *, ddg_ptr); | |
166 | void vcg_print_ddg (FILE *, ddg_ptr); | |
167 | void print_ddg_edge (FILE *, ddg_edge_ptr); | |
8cec1624 | 168 | void print_sccs (FILE *, ddg_all_sccs_ptr, ddg_ptr); |
d397e8c6 | 169 | |
9774f20d | 170 | ddg_node_ptr get_node_of_insn (ddg_ptr, rtx_insn *); |
d397e8c6 MH |
171 | |
172 | void find_successors (sbitmap result, ddg_ptr, sbitmap); | |
173 | void find_predecessors (sbitmap result, ddg_ptr, sbitmap); | |
174 | ||
175 | ddg_all_sccs_ptr create_ddg_all_sccs (ddg_ptr); | |
176 | void free_ddg_all_sccs (ddg_all_sccs_ptr); | |
177 | ||
178 | int find_nodes_on_paths (sbitmap result, ddg_ptr, sbitmap from, sbitmap to); | |
d397e8c6 | 179 | |
9774f20d | 180 | bool autoinc_var_is_used_p (rtx_insn *, rtx_insn *); |
d8edf83d | 181 | |
d397e8c6 | 182 | #endif /* GCC_DDG_H */ |