22
22
#include " llvm/CodeGen/MachineBasicBlock.h"
23
23
#include " llvm/Support/CFG.h"
24
24
#include " Support/PostOrderIterator.h"
25
- using std::cerr;
26
25
27
26
std::ostream &operator <<(std::ostream &os, const NodeDelayPair* nd) {
28
27
return os << " Delay for node " << nd->node ->getNodeId ()
@@ -43,41 +42,35 @@ SchedPriorities::SchedPriorities(const Function *, const SchedGraph *G,
43
42
44
43
45
44
void
46
- SchedPriorities::initialize ()
47
- {
45
+ SchedPriorities::initialize () {
48
46
initializeReadyHeap (graph);
49
47
}
50
48
51
49
52
50
void
53
- SchedPriorities::computeDelays (const SchedGraph* graph)
54
- {
51
+ SchedPriorities::computeDelays (const SchedGraph* graph) {
55
52
po_iterator<const SchedGraph*> poIter = po_begin (graph), poEnd =po_end (graph);
56
- for ( ; poIter != poEnd; ++poIter)
57
- {
58
- const SchedGraphNode* node = *poIter;
59
- cycles_t nodeDelay;
60
- if (node->beginOutEdges () == node->endOutEdges ())
61
- nodeDelay = node->getLatency ();
62
- else
63
- {
64
- // Iterate over the out-edges of the node to compute delay
65
- nodeDelay = 0 ;
66
- for (SchedGraphNode::const_iterator E=node->beginOutEdges ();
67
- E != node->endOutEdges (); ++E)
68
- {
69
- cycles_t sinkDelay = getNodeDelay ((SchedGraphNode*)(*E)->getSink ());
70
- nodeDelay = std::max (nodeDelay, sinkDelay + (*E)->getMinDelay ());
71
- }
72
- }
73
- getNodeDelayRef (node) = nodeDelay;
53
+ for ( ; poIter != poEnd; ++poIter) {
54
+ const SchedGraphNode* node = *poIter;
55
+ cycles_t nodeDelay;
56
+ if (node->beginOutEdges () == node->endOutEdges ())
57
+ nodeDelay = node->getLatency ();
58
+ else {
59
+ // Iterate over the out-edges of the node to compute delay
60
+ nodeDelay = 0 ;
61
+ for (SchedGraphNode::const_iterator E=node->beginOutEdges ();
62
+ E != node->endOutEdges (); ++E) {
63
+ cycles_t sinkDelay = getNodeDelay ((SchedGraphNode*)(*E)->getSink ());
64
+ nodeDelay = std::max (nodeDelay, sinkDelay + (*E)->getMinDelay ());
65
+ }
74
66
}
67
+ getNodeDelayRef (node) = nodeDelay;
68
+ }
75
69
}
76
70
77
71
78
72
void
79
- SchedPriorities::initializeReadyHeap (const SchedGraph* graph)
80
- {
73
+ SchedPriorities::initializeReadyHeap (const SchedGraph* graph) {
81
74
const SchedGraphNode* graphRoot = (const SchedGraphNode*)graph->getRoot ();
82
75
assert (graphRoot->getMachineInstr () == NULL && " Expect dummy root" );
83
76
@@ -88,65 +81,64 @@ SchedPriorities::initializeReadyHeap(const SchedGraph* graph)
88
81
89
82
#undef TEST_HEAP_CONVERSION
90
83
#ifdef TEST_HEAP_CONVERSION
91
- cerr << " Before heap conversion:\n " ;
84
+ std:: cerr << " Before heap conversion:\n " ;
92
85
copy (candsAsHeap.begin (), candsAsHeap.end (),
93
- ostream_iterator<NodeDelayPair*>(cerr," \n " ));
86
+ ostream_iterator<NodeDelayPair*>(std:: cerr," \n " ));
94
87
#endif
95
88
96
89
candsAsHeap.makeHeap ();
97
90
98
91
nextToTry = candsAsHeap.begin ();
99
92
100
93
#ifdef TEST_HEAP_CONVERSION
101
- cerr << " After heap conversion:\n " ;
94
+ std:: cerr << " After heap conversion:\n " ;
102
95
copy (candsAsHeap.begin (), candsAsHeap.end (),
103
- ostream_iterator<NodeDelayPair*>(cerr," \n " ));
96
+ ostream_iterator<NodeDelayPair*>(std:: cerr," \n " ));
104
97
#endif
105
98
}
106
99
107
100
void
108
- SchedPriorities::insertReady (const SchedGraphNode* node)
109
- {
101
+ SchedPriorities::insertReady (const SchedGraphNode* node) {
110
102
candsAsHeap.insert (node, nodeDelayVec[node->getNodeId ()]);
111
103
candsAsSet.insert (node);
112
104
mcands.clear (); // ensure reset choices is called before any more choices
113
105
earliestReadyTime = std::min (earliestReadyTime,
114
106
getEarliestReadyTimeForNode (node));
115
107
116
- if (SchedDebugLevel >= Sched_PrintSchedTrace)
117
- {
118
- cerr << " Node " << node->getNodeId () << " will be ready in Cycle "
119
- << getEarliestReadyTimeForNode (node) << " ; "
120
- << " Delay = " <<(long )getNodeDelay (node) << " ; Instruction: \n " ;
121
- cerr << " " << *node->getMachineInstr () << " \n " ;
122
- }
108
+ if (SchedDebugLevel >= Sched_PrintSchedTrace) {
109
+ std::cerr << " Node " << node->getNodeId () << " will be ready in Cycle "
110
+ << getEarliestReadyTimeForNode (node) << " ; "
111
+ << " Delay = " <<(long )getNodeDelay (node) << " ; Instruction: \n "
112
+ << " " << *node->getMachineInstr () << " \n " ;
113
+ }
123
114
}
124
115
125
116
void
126
117
SchedPriorities::issuedReadyNodeAt (cycles_t curTime,
127
- const SchedGraphNode* node)
128
- {
118
+ const SchedGraphNode* node) {
129
119
candsAsHeap.removeNode (node);
130
120
candsAsSet.erase (node);
131
121
mcands.clear (); // ensure reset choices is called before any more choices
132
122
133
- if (earliestReadyTime == getEarliestReadyTimeForNode (node))
134
- {// earliestReadyTime may have been due to this node, so recompute it
135
- earliestReadyTime = HUGE_LATENCY;
136
- for (NodeHeap::const_iterator I=candsAsHeap.begin ();
137
- I != candsAsHeap.end (); ++I)
138
- if (candsAsHeap.getNode (I))
139
- earliestReadyTime = std::min (earliestReadyTime,
140
- getEarliestReadyTimeForNode (candsAsHeap.getNode (I)));
141
- }
123
+ if (earliestReadyTime == getEarliestReadyTimeForNode (node)) {
124
+ // earliestReadyTime may have been due to this node, so recompute it
125
+ earliestReadyTime = HUGE_LATENCY;
126
+ for (NodeHeap::const_iterator I=candsAsHeap.begin ();
127
+ I != candsAsHeap.end (); ++I)
128
+ if (candsAsHeap.getNode (I)) {
129
+ earliestReadyTime =
130
+ std::min (earliestReadyTime,
131
+ getEarliestReadyTimeForNode (candsAsHeap.getNode (I)));
132
+ }
133
+ }
142
134
143
135
// Now update ready times for successors
144
136
for (SchedGraphNode::const_iterator E=node->beginOutEdges ();
145
- E != node->endOutEdges (); ++E)
146
- {
147
- cycles_t & etime = getEarliestReadyTimeForNodeRef ((SchedGraphNode*)(*E)->getSink ());
148
- etime = std::max (etime, curTime + (*E)->getMinDelay ());
149
- }
137
+ E != node->endOutEdges (); ++E) {
138
+ cycles_t & etime =
139
+ getEarliestReadyTimeForNodeRef ((SchedGraphNode*)(*E)->getSink ());
140
+ etime = std::max (etime, curTime + (*E)->getMinDelay ());
141
+ }
150
142
}
151
143
152
144
@@ -160,15 +152,13 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime,
160
152
// ----------------------------------------------------------------------
161
153
162
154
inline int
163
- SchedPriorities::chooseByRule1 (std::vector<candIndex>& mcands)
164
- {
155
+ SchedPriorities::chooseByRule1 (std::vector<candIndex>& mcands) {
165
156
return (mcands.size () == 1 )? 0 // only one choice exists so take it
166
157
: -1 ; // -1 indicates multiple choices
167
158
}
168
159
169
160
inline int
170
- SchedPriorities::chooseByRule2 (std::vector<candIndex>& mcands)
171
- {
161
+ SchedPriorities::chooseByRule2 (std::vector<candIndex>& mcands) {
172
162
assert (mcands.size () >= 1 && " Should have at least one candidate here." );
173
163
for (unsigned i=0 , N = mcands.size (); i < N; i++)
174
164
if (instructionHasLastUse (methodLiveVarInfo,
@@ -178,67 +168,60 @@ SchedPriorities::chooseByRule2(std::vector<candIndex>& mcands)
178
168
}
179
169
180
170
inline int
181
- SchedPriorities::chooseByRule3 (std::vector<candIndex>& mcands)
182
- {
171
+ SchedPriorities::chooseByRule3 (std::vector<candIndex>& mcands) {
183
172
assert (mcands.size () >= 1 && " Should have at least one candidate here." );
184
173
int maxUses = candsAsHeap.getNode (mcands[0 ])->getNumOutEdges ();
185
174
int indexWithMaxUses = 0 ;
186
- for (unsigned i=1 , N = mcands.size (); i < N; i++)
187
- {
188
- int numUses = candsAsHeap.getNode (mcands[i])->getNumOutEdges ();
189
- if (numUses > maxUses)
190
- {
191
- maxUses = numUses;
192
- indexWithMaxUses = i;
193
- }
175
+ for (unsigned i=1 , N = mcands.size (); i < N; i++) {
176
+ int numUses = candsAsHeap.getNode (mcands[i])->getNumOutEdges ();
177
+ if (numUses > maxUses) {
178
+ maxUses = numUses;
179
+ indexWithMaxUses = i;
194
180
}
181
+ }
195
182
return indexWithMaxUses;
196
183
}
197
184
198
185
const SchedGraphNode*
199
186
SchedPriorities::getNextHighest (const SchedulingManager& S,
200
- cycles_t curTime)
201
- {
187
+ cycles_t curTime) {
202
188
int nextIdx = -1 ;
203
189
const SchedGraphNode* nextChoice = NULL ;
204
190
205
191
if (mcands.size () == 0 )
206
192
findSetWithMaxDelay (mcands, S);
207
193
208
- while (nextIdx < 0 && mcands.size () > 0 )
209
- {
210
- nextIdx = chooseByRule1 (mcands); // rule 1
194
+ while (nextIdx < 0 && mcands.size () > 0 ) {
195
+ nextIdx = chooseByRule1 (mcands); // rule 1
211
196
212
- if (nextIdx == -1 )
213
- nextIdx = chooseByRule2 (mcands); // rule 2
197
+ if (nextIdx == -1 )
198
+ nextIdx = chooseByRule2 (mcands); // rule 2
214
199
215
- if (nextIdx == -1 )
216
- nextIdx = chooseByRule3 (mcands); // rule 3
200
+ if (nextIdx == -1 )
201
+ nextIdx = chooseByRule3 (mcands); // rule 3
217
202
218
- if (nextIdx == -1 )
219
- nextIdx = 0 ; // default to first choice by delays
203
+ if (nextIdx == -1 )
204
+ nextIdx = 0 ; // default to first choice by delays
220
205
221
- // We have found the next best candidate. Check if it ready in
222
- // the current cycle, and if it is feasible.
223
- // If not, remove it from mcands and continue. Refill mcands if
224
- // it becomes empty.
225
- nextChoice = candsAsHeap.getNode (mcands[nextIdx]);
226
- if (getEarliestReadyTimeForNode (nextChoice) > curTime
227
- || ! instrIsFeasible (S, nextChoice->getMachineInstr ()->getOpCode ()))
228
- {
229
- mcands.erase (mcands.begin () + nextIdx);
230
- nextIdx = -1 ;
231
- if (mcands.size () == 0 )
232
- findSetWithMaxDelay (mcands, S);
233
- }
234
- }
235
-
236
- if (nextIdx >= 0 )
206
+ // We have found the next best candidate. Check if it ready in
207
+ // the current cycle, and if it is feasible.
208
+ // If not, remove it from mcands and continue. Refill mcands if
209
+ // it becomes empty.
210
+ nextChoice = candsAsHeap.getNode (mcands[nextIdx]);
211
+ if (getEarliestReadyTimeForNode (nextChoice) > curTime
212
+ || ! instrIsFeasible (S, nextChoice->getMachineInstr ()->getOpCode ()))
237
213
{
238
214
mcands.erase (mcands.begin () + nextIdx);
239
- return nextChoice;
215
+ nextIdx = -1 ;
216
+ if (mcands.size () == 0 )
217
+ findSetWithMaxDelay (mcands, S);
240
218
}
241
- else
219
+ }
220
+
221
+ if (nextIdx >= 0 ) {
222
+ mcands.erase (mcands.begin () + nextIdx);
223
+ return nextChoice;
224
+ } else
242
225
return NULL ;
243
226
}
244
227
@@ -258,15 +241,14 @@ SchedPriorities::findSetWithMaxDelay(std::vector<candIndex>& mcands,
258
241
259
242
nextToTry = next;
260
243
261
- if (SchedDebugLevel >= Sched_PrintSchedTrace)
262
- {
263
- cerr << " Cycle " << (long )getTime () << " : "
264
- << " Next highest delay = " << (long )maxDelay << " : "
265
- << mcands.size () << " Nodes with this delay: " ;
266
- for (unsigned i=0 ; i < mcands.size (); i++)
267
- cerr << candsAsHeap.getNode (mcands[i])->getNodeId () << " , " ;
268
- cerr << " \n " ;
269
- }
244
+ if (SchedDebugLevel >= Sched_PrintSchedTrace) {
245
+ std::cerr << " Cycle " << (long )getTime () << " : "
246
+ << " Next highest delay = " << (long )maxDelay << " : "
247
+ << mcands.size () << " Nodes with this delay: " ;
248
+ for (unsigned i=0 ; i < mcands.size (); i++)
249
+ std::cerr << candsAsHeap.getNode (mcands[i])->getNodeId () << " , " ;
250
+ std::cerr << " \n " ;
251
+ }
270
252
}
271
253
}
272
254
0 commit comments