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