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