llvm.org GIT mirror llvm / 1796cb7
Cleaned up the code (spacing, not needed headers) and changed ostream function. Also made some functions inline. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8154 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 17 years ago
1 changed file(s) with 96 addition(s) and 101 deletion(s). Raw diff Collapse all Expand all
77 #ifndef LLVM_CODEGEN_SCHEDGRAPHCOMMON_H
88 #define LLVM_CODEGEN_SCHEDGRAPHCOMMON_H
99
10 #include
11 #include
1210 #include "llvm/Value.h"
13
1411
1512 class SchedGraphEdge;
1613 class SchedGraphNode;
2320 const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
2421 const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
2522
23
2624 //*********************** Public Class Declarations ************************/
27
2825 class SchedGraphNodeCommon {
2926 protected:
3027 unsigned ID;
3229 std::vector outEdges;
3330 int latency;
3431
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;
32 public:
33 typedef std::vector::iterator iterator;
34 typedef std::vector::const_iterator const_iterator;
35 typedef std::vector::reverse_iterator reverse_iterator;
4136 typedef std::vector::const_reverse_iterator const_reverse_iterator;
4237
4338 // 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(); }
39 unsigned getNodeId() const { return ID; }
40 int getLatency() const { return latency; }
41 unsigned getNumInEdges() const { return inEdges.size(); }
42 unsigned getNumOutEdges() const { return outEdges.size(); }
4843
4944
5045 // 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
46 iterator beginInEdges() { return inEdges.begin(); }
47 iterator endInEdges() { return inEdges.end(); }
48 iterator beginOutEdges() { return outEdges.begin(); }
49 iterator endOutEdges() { return outEdges.end(); }
50
51 const_iterator beginInEdges() const { return inEdges.begin(); }
52 const_iterator endInEdges() const { return inEdges.end(); }
53 const_iterator beginOutEdges() const { return outEdges.begin(); }
54 const_iterator endOutEdges() const { return outEdges.end(); }
55
56 void dump(int indent=0) const;
6157
6258 // Debugging support
63 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNodeCommon& node);
64
65 void dump (int indent=0) const;
66
59 virtual void print(std::ostream &os) const = 0;
60
6761 protected:
6862 friend class SchedGraph;
6963 friend class SchedGraphCommon;
7064 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
65
66
7967 // disable default constructor and provide a ctor for single-block graphs
8068 SchedGraphNodeCommon(); // DO NOT IMPLEMENT
8169
82 SchedGraphNodeCommon(unsigned Id);
83
70 inline SchedGraphNodeCommon(unsigned Id) : ID(Id), latency(0) {}
8471 virtual ~SchedGraphNodeCommon();
72
73 //Functions to add and remove edges
74 inline void addInEdge(SchedGraphEdge* edge) { inEdges.push_back(edge); }
75 inline void addOutEdge(SchedGraphEdge* edge) { outEdges.push_back(edge); }
76 void removeInEdge(const SchedGraphEdge* edge);
77 void removeOutEdge(const SchedGraphEdge* edge);
8578 };
8679
87
80 // ostream << operator for SchedGraphNode class
81 inline std::ostream &operator<<(std::ostream &os,
82 const SchedGraphNodeCommon &node) {
83 node.print(os);
84 return os;
85 }
86
87
88
89
90 //
91 // SchedGraphEdge - Edge class to represent dependencies
92 //
8893 class SchedGraphEdge {
8994 public:
9095 enum SchedGraphEdgeDepType {
98103 SchedGraphNodeCommon* src;
99104 SchedGraphNodeCommon* sink;
100105 SchedGraphEdgeDepType depType;
101 unsigned int depOrderType;
102 int minDelay; // cached latency (assumes fixed target arch)
103 int iteDiff;
106 unsigned int depOrderType;
107 int minDelay; // cached latency (assumes fixed target arch)
108 int iteDiff;
104109
105110 union {
106111 const Value* val;
107112 int machineRegNum;
108113 ResourceId resourceId;
109114 };
110
115
111116 public:
112117 // For all constructors, if minDelay is unspecified, minDelay is
113118 // set to _src->getLatency().
119
114120 // 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);
121 SchedGraphEdge(SchedGraphNodeCommon* _src, SchedGraphNodeCommon* _sink,
122 SchedGraphEdgeDepType _depType, unsigned int _depOrderType,
123 int _minDelay = -1);
120124
121125 // 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);
126 SchedGraphEdge(SchedGraphNodeCommon* _src, SchedGraphNodeCommon* _sink,
127 const Value* _val, unsigned int _depOrderType,
128 int _minDelay = -1);
127129
128130 // 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);
131 SchedGraphEdge(SchedGraphNodeCommon* _src,SchedGraphNodeCommon* _sink,
132 unsigned int _regNum, unsigned int _depOrderType,
133 int _minDelay = -1);
134134
135135 // constructor for any other machine resource dependences.
136136 // DataDepOrderType is always NonDataDep. It it not an argument to
137137 // 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 {
138 SchedGraphEdge(SchedGraphNodeCommon* _src, SchedGraphNodeCommon* _sink,
139 ResourceId _resourceId, int _minDelay = -1);
140
141 ~SchedGraphEdge();
142
143 SchedGraphNodeCommon* getSrc() const { return src; }
144 SchedGraphNodeCommon* getSink() const { return sink; }
145 int getMinDelay() const { return minDelay; }
146 SchedGraphEdgeDepType getDepType() const { return depType; }
147
148 const Value* getValue() const {
151149 assert(depType == ValueDep); return val;
152150 }
153 int getMachineReg () const {
151
152 int getMachineReg() const {
154153 assert(depType == MachineRegister); return machineRegNum;
155154 }
156 int getResourceId () const {
155
156 int getResourceId() const {
157157 assert(depType == MachineResource); return resourceId;
158158 }
159 void setIteDiff (int _iteDiff) {
159
160 void setIteDiff(int _iteDiff) {
160161 iteDiff = _iteDiff;
161162 }
162 int getIteDiff (){
163
164 int getIteDiff() {
163165 return iteDiff;
164166 }
165167
166168 public:
167 //
168169 // Debugging support
169 //
170 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
171
172 void dump (int indent=0) const;
170 void print(std::ostream &os) const;
171 void dump(int indent=0) const;
173172
174173 private:
175174 // disable default ctor
176 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
175 SchedGraphEdge(); // DO NOT IMPLEMENT
177176 };
178177
178 // ostream << operator for SchedGraphNode class
179 inline std::ostream &operator<<(std::ostream &os, const SchedGraphEdge &edge) {
180 edge.print(os);
181 return os;
182 }
179183
180184 class SchedGraphCommon {
181185
182186 protected:
183 SchedGraphNodeCommon* graphRoot; // the root and leaf are not inserted
184 SchedGraphNodeCommon* graphLeaf; // in the hash_map (see getNumNodes())
187 SchedGraphNodeCommon* graphRoot; // the root and leaf are not inserted
188 SchedGraphNodeCommon* graphLeaf; // in the hash_map (see getNumNodes())
185189
186190 public:
187191 //
188192 // Accessor methods
189193 //
190 SchedGraphNodeCommon* getRoot() const { return graphRoot; }
191 SchedGraphNodeCommon* getLeaf() const { return graphLeaf; }
194 SchedGraphNodeCommon* getRoot() const { return graphRoot; }
195 SchedGraphNodeCommon* getLeaf() const { return graphLeaf; }
192196
193197 //
194198 // Delete nodes or edges from the graph.
195199 //
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
200 void eraseNode(SchedGraphNodeCommon* node);
201 void eraseIncomingEdges(SchedGraphNodeCommon* node, bool addDummyEdges = true);
202 void eraseOutgoingEdges(SchedGraphNodeCommon* node, bool addDummyEdges = true);
203 void eraseIncidentEdges(SchedGraphNodeCommon* node, bool addDummyEdges = true);
204
205 SchedGraphCommon();
206 ~SchedGraphCommon();
210207 };
211208
212
213
214209 #endif