llvm.org GIT mirror llvm / 0320b14
SchedGraphCommon header file. Contains class definition for SchedGraphCommon which is used by SchedGraph and ModuloSchedGraph (coming soon). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8149 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 17 years ago
1 changed file(s) with 215 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===-- SchedGraphCommon.h - Scheduling Base Graph ---------------*- C++ -*---=//
1 //
2 // A common graph class that is based on the SSA graph. It includes
3 // extra dependencies that are caused by machine resources.
4 //
5 //===-------------------------------------------------------------------------=//
6
7 #ifndef LLVM_CODEGEN_SCHEDGRAPHCOMMON_H
8 #define LLVM_CODEGEN_SCHEDGRAPHCOMMON_H
9
10 #include
11 #include
12 #include "llvm/Value.h"
13
14
15 class SchedGraphEdge;
16 class SchedGraphNode;
17
18 /******************** Exported Data Types and Constants ********************/
19
20 typedef int ResourceId;
21 const ResourceId InvalidRID = -1;
22 const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
23 const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
24 const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
25
26 //*********************** Public Class Declarations ************************/
27
28 class SchedGraphNodeCommon {
29 protected:
30 unsigned ID;
31 std::vector inEdges;
32 std::vector outEdges;
33 int latency;
34
35 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
36
37 public:
38 typedef std::vector:: iterator iterator;
39 typedef std::vector::const_iterator const_iterator;
40 typedef std::vector:: reverse_iterator reverse_iterator;
41 typedef std::vector::const_reverse_iterator const_reverse_iterator;
42
43 // Accessor methods
44 unsigned getNodeId () const { return ID; }
45 int getLatency () const { return latency; }
46 unsigned getNumInEdges () const { return inEdges.size(); }
47 unsigned getNumOutEdges () const { return outEdges.size(); }
48
49
50 // Iterators
51 iterator beginInEdges () { return inEdges.begin(); }
52 iterator endInEdges () { return inEdges.end(); }
53 iterator beginOutEdges () { return outEdges.begin(); }
54 iterator endOutEdges () { return outEdges.end(); }
55
56 const_iterator beginInEdges () const { return inEdges.begin(); }
57 const_iterator endInEdges () const { return inEdges.end(); }
58 const_iterator beginOutEdges () const { return outEdges.begin(); }
59 const_iterator endOutEdges () const { return outEdges.end(); }
60
61
62 // Debugging support
63 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNodeCommon& node);
64
65 void dump (int indent=0) const;
66
67 protected:
68 friend class SchedGraph;
69 friend class SchedGraphCommon;
70 friend class SchedGraphEdge; // give access for adding edges
71 //friend class ModuloSchedGraph;
72
73 void addInEdge (SchedGraphEdge* edge);
74 void addOutEdge (SchedGraphEdge* edge);
75
76 void removeInEdge (const SchedGraphEdge* edge);
77 void removeOutEdge (const SchedGraphEdge* edge);
78
79 // disable default constructor and provide a ctor for single-block graphs
80 SchedGraphNodeCommon(); // DO NOT IMPLEMENT
81
82 SchedGraphNodeCommon(unsigned Id);
83
84 virtual ~SchedGraphNodeCommon();
85 };
86
87
88 class SchedGraphEdge {
89 public:
90 enum SchedGraphEdgeDepType {
91 CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
92 };
93 enum DataDepOrderType {
94 TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
95 };
96
97 protected:
98 SchedGraphNodeCommon* src;
99 SchedGraphNodeCommon* sink;
100 SchedGraphEdgeDepType depType;
101 unsigned int depOrderType;
102 int minDelay; // cached latency (assumes fixed target arch)
103 int iteDiff;
104
105 union {
106 const Value* val;
107 int machineRegNum;
108 ResourceId resourceId;
109 };
110
111 public:
112 // For all constructors, if minDelay is unspecified, minDelay is
113 // set to _src->getLatency().
114 // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
115 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
116 SchedGraphNodeCommon* _sink,
117 SchedGraphEdgeDepType _depType,
118 unsigned int _depOrderType,
119 int _minDelay = -1);
120
121 // constructor for explicit value dependence (may be true/anti/output)
122 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
123 SchedGraphNodeCommon* _sink,
124 const Value* _val,
125 unsigned int _depOrderType,
126 int _minDelay = -1);
127
128 // constructor for machine register dependence
129 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
130 SchedGraphNodeCommon* _sink,
131 unsigned int _regNum,
132 unsigned int _depOrderType,
133 int _minDelay = -1);
134
135 // constructor for any other machine resource dependences.
136 // DataDepOrderType is always NonDataDep. It it not an argument to
137 // avoid overloading ambiguity with previous constructor.
138 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
139 SchedGraphNodeCommon* _sink,
140 ResourceId _resourceId,
141 int _minDelay = -1);
142
143 /*dtor*/ ~SchedGraphEdge();
144
145 SchedGraphNodeCommon* getSrc () const { return src; }
146 SchedGraphNodeCommon* getSink () const { return sink; }
147 int getMinDelay () const { return minDelay; }
148 SchedGraphEdgeDepType getDepType () const { return depType; }
149
150 const Value* getValue () const {
151 assert(depType == ValueDep); return val;
152 }
153 int getMachineReg () const {
154 assert(depType == MachineRegister); return machineRegNum;
155 }
156 int getResourceId () const {
157 assert(depType == MachineResource); return resourceId;
158 }
159 void setIteDiff (int _iteDiff) {
160 iteDiff = _iteDiff;
161 }
162 int getIteDiff (){
163 return iteDiff;
164 }
165
166 public:
167 //
168 // Debugging support
169 //
170 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
171
172 void dump (int indent=0) const;
173
174 private:
175 // disable default ctor
176 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
177 };
178
179
180 class SchedGraphCommon {
181
182 protected:
183 SchedGraphNodeCommon* graphRoot; // the root and leaf are not inserted
184 SchedGraphNodeCommon* graphLeaf; // in the hash_map (see getNumNodes())
185
186 public:
187 //
188 // Accessor methods
189 //
190 SchedGraphNodeCommon* getRoot() const { return graphRoot; }
191 SchedGraphNodeCommon* getLeaf() const { return graphLeaf; }
192
193 //
194 // Delete nodes or edges from the graph.
195 //
196 void eraseNode (SchedGraphNodeCommon* node);
197
198 void eraseIncomingEdges (SchedGraphNodeCommon* node,
199 bool addDummyEdges = true);
200
201 void eraseOutgoingEdges (SchedGraphNodeCommon* node,
202 bool addDummyEdges = true);
203
204 void eraseIncidentEdges (SchedGraphNodeCommon* node,
205 bool addDummyEdges = true);
206
207 /*ctor*/ SchedGraphCommon ();
208 /*dtor*/ ~SchedGraphCommon ();
209
210 };
211
212
213
214 #endif