2013-05-27 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / ddg.h
blobe16c8c9d7731ca82adeb1f6d24553bd1dff6200f
1 /* DDG - Data Dependence Graph - interface.
2 Copyright (C) 2004-2013 Free Software Foundation, Inc.
3 Contributed by Ayal Zaks and Mustafa Hagog <zaks,mustafa@il.ibm.com>
5 This file is part of GCC.
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.
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.
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/>. */
21 #ifndef GCC_DDG_H
22 #define GCC_DDG_H
24 /* For sbitmap. */
25 #include "sbitmap.h"
26 /* For basic_block. */
27 #include "basic-block.h"
28 #include "df.h"
30 typedef struct ddg_node *ddg_node_ptr;
31 typedef struct ddg_edge *ddg_edge_ptr;
32 typedef struct ddg *ddg_ptr;
33 typedef struct ddg_scc *ddg_scc_ptr;
34 typedef struct ddg_all_sccs *ddg_all_sccs_ptr;
36 typedef enum {TRUE_DEP, OUTPUT_DEP, ANTI_DEP} dep_type;
37 typedef enum {REG_OR_MEM_DEP, REG_DEP, MEM_DEP, REG_AND_MEM_DEP}
38 dep_data_type;
40 /* The following two macros enables direct access to the successors and
41 predecessors bitmaps held in each ddg_node. Do not make changes to
42 these bitmaps, unless you want to change the DDG. */
43 #define NODE_SUCCESSORS(x) ((x)->successors)
44 #define NODE_PREDECESSORS(x) ((x)->predecessors)
46 /* A structure that represents a node in the DDG. */
47 struct ddg_node
49 /* Each node has a unique CUID index. These indices increase monotonically
50 (according to the order of the corresponding INSN in the BB), starting
51 from 0 with no gaps. */
52 int cuid;
54 /* The insn represented by the node. */
55 rtx insn;
57 /* A note preceding INSN (or INSN itself), such that all insns linked
58 from FIRST_NOTE until INSN (inclusive of both) are moved together
59 when reordering the insns. This takes care of notes that should
60 continue to precede INSN. */
61 rtx first_note;
63 /* Incoming and outgoing dependency edges. */
64 ddg_edge_ptr in;
65 ddg_edge_ptr out;
67 /* Each bit corresponds to a ddg_node according to its cuid, and is
68 set iff the node is a successor/predecessor of "this" node. */
69 sbitmap successors;
70 sbitmap predecessors;
72 /* For general use by algorithms manipulating the ddg. */
73 union {
74 int count;
75 void *info;
76 } aux;
79 /* A structure that represents an edge in the DDG. */
80 struct ddg_edge
82 /* The source and destination nodes of the dependency edge. */
83 ddg_node_ptr src;
84 ddg_node_ptr dest;
86 /* TRUE, OUTPUT or ANTI dependency. */
87 dep_type type;
89 /* REG or MEM dependency. */
90 dep_data_type data_type;
92 /* Latency of the dependency. */
93 int latency;
95 /* The distance: number of loop iterations the dependency crosses. */
96 int distance;
98 /* The following two fields are used to form a linked list of the in/out
99 going edges to/from each node. */
100 ddg_edge_ptr next_in;
101 ddg_edge_ptr next_out;
103 /* For general use by algorithms manipulating the ddg. */
104 union {
105 int count;
106 void *info;
107 } aux;
110 /* This structure holds the Data Dependence Graph for a basic block. */
111 struct ddg
113 /* The basic block for which this DDG is built. */
114 basic_block bb;
116 /* Number of instructions in the basic block. */
117 int num_nodes;
119 /* Number of load/store instructions in the BB - statistics. */
120 int num_loads;
121 int num_stores;
123 /* Number of debug instructions in the BB. */
124 int num_debug;
126 /* This array holds the nodes in the graph; it is indexed by the node
127 cuid, which follows the order of the instructions in the BB. */
128 ddg_node_ptr nodes;
130 /* The branch closing the loop. */
131 ddg_node_ptr closing_branch;
133 /* Build dependence edges for closing_branch, when set. In certain cases,
134 the closing branch can be dealt with separately from the insns of the
135 loop, and then no such deps are needed. */
136 int closing_branch_deps;
138 /* Array and number of backarcs (edges with distance > 0) in the DDG. */
139 int num_backarcs;
140 ddg_edge_ptr *backarcs;
144 /* Holds information on an SCC (Strongly Connected Component) of the DDG. */
145 struct ddg_scc
147 /* A bitmap that represents the nodes of the DDG that are in the SCC. */
148 sbitmap nodes;
150 /* Array and number of backarcs (edges with distance > 0) in the SCC. */
151 ddg_edge_ptr *backarcs;
152 int num_backarcs;
154 /* The maximum of (total_latency/total_distance) over all cycles in SCC. */
155 int recurrence_length;
158 /* This structure holds the SCCs of the DDG. */
159 struct ddg_all_sccs
161 /* Array that holds the SCCs in the DDG, and their number. */
162 ddg_scc_ptr *sccs;
163 int num_sccs;
165 ddg_ptr ddg;
169 ddg_ptr create_ddg (basic_block, int closing_branch_deps);
170 void free_ddg (ddg_ptr);
172 void print_ddg (FILE *, ddg_ptr);
173 void vcg_print_ddg (FILE *, ddg_ptr);
174 void print_ddg_edge (FILE *, ddg_edge_ptr);
175 void print_sccs (FILE *, ddg_all_sccs_ptr, ddg_ptr);
177 ddg_node_ptr get_node_of_insn (ddg_ptr, rtx);
179 void find_successors (sbitmap result, ddg_ptr, sbitmap);
180 void find_predecessors (sbitmap result, ddg_ptr, sbitmap);
182 ddg_all_sccs_ptr create_ddg_all_sccs (ddg_ptr);
183 void free_ddg_all_sccs (ddg_all_sccs_ptr);
185 int find_nodes_on_paths (sbitmap result, ddg_ptr, sbitmap from, sbitmap to);
186 int longest_simple_path (ddg_ptr, int from, int to, sbitmap via);
188 bool autoinc_var_is_used_p (rtx, rtx);
190 #endif /* GCC_DDG_H */