Skip to content

Commit 7d56d2c

Browse files
committed
* Eliminate `using' directive
* Make code layout more consistent llvm-svn: 9427
1 parent c7b1bce commit 7d56d2c

File tree

1 file changed

+88
-106
lines changed

1 file changed

+88
-106
lines changed

llvm/lib/CodeGen/InstrSched/SchedPriorities.cpp

Lines changed: 88 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/CodeGen/MachineBasicBlock.h"
2323
#include "llvm/Support/CFG.h"
2424
#include "Support/PostOrderIterator.h"
25-
using std::cerr;
2625

2726
std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd) {
2827
return os << "Delay for node " << nd->node->getNodeId()
@@ -43,41 +42,35 @@ SchedPriorities::SchedPriorities(const Function *, const SchedGraph *G,
4342

4443

4544
void
46-
SchedPriorities::initialize()
47-
{
45+
SchedPriorities::initialize() {
4846
initializeReadyHeap(graph);
4947
}
5048

5149

5250
void
53-
SchedPriorities::computeDelays(const SchedGraph* graph)
54-
{
51+
SchedPriorities::computeDelays(const SchedGraph* graph) {
5552
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+
}
7466
}
67+
getNodeDelayRef(node) = nodeDelay;
68+
}
7569
}
7670

7771

7872
void
79-
SchedPriorities::initializeReadyHeap(const SchedGraph* graph)
80-
{
73+
SchedPriorities::initializeReadyHeap(const SchedGraph* graph) {
8174
const SchedGraphNode* graphRoot = (const SchedGraphNode*)graph->getRoot();
8275
assert(graphRoot->getMachineInstr() == NULL && "Expect dummy root");
8376

@@ -88,65 +81,64 @@ SchedPriorities::initializeReadyHeap(const SchedGraph* graph)
8881

8982
#undef TEST_HEAP_CONVERSION
9083
#ifdef TEST_HEAP_CONVERSION
91-
cerr << "Before heap conversion:\n";
84+
std::cerr << "Before heap conversion:\n";
9285
copy(candsAsHeap.begin(), candsAsHeap.end(),
93-
ostream_iterator<NodeDelayPair*>(cerr,"\n"));
86+
ostream_iterator<NodeDelayPair*>(std::cerr,"\n"));
9487
#endif
9588

9689
candsAsHeap.makeHeap();
9790

9891
nextToTry = candsAsHeap.begin();
9992

10093
#ifdef TEST_HEAP_CONVERSION
101-
cerr << "After heap conversion:\n";
94+
std::cerr << "After heap conversion:\n";
10295
copy(candsAsHeap.begin(), candsAsHeap.end(),
103-
ostream_iterator<NodeDelayPair*>(cerr,"\n"));
96+
ostream_iterator<NodeDelayPair*>(std::cerr,"\n"));
10497
#endif
10598
}
10699

107100
void
108-
SchedPriorities::insertReady(const SchedGraphNode* node)
109-
{
101+
SchedPriorities::insertReady(const SchedGraphNode* node) {
110102
candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]);
111103
candsAsSet.insert(node);
112104
mcands.clear(); // ensure reset choices is called before any more choices
113105
earliestReadyTime = std::min(earliestReadyTime,
114106
getEarliestReadyTimeForNode(node));
115107

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+
}
123114
}
124115

125116
void
126117
SchedPriorities::issuedReadyNodeAt(cycles_t curTime,
127-
const SchedGraphNode* node)
128-
{
118+
const SchedGraphNode* node) {
129119
candsAsHeap.removeNode(node);
130120
candsAsSet.erase(node);
131121
mcands.clear(); // ensure reset choices is called before any more choices
132122

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+
}
142134

143135
// Now update ready times for successors
144136
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+
}
150142
}
151143

152144

@@ -160,15 +152,13 @@ SchedPriorities::issuedReadyNodeAt(cycles_t curTime,
160152
//----------------------------------------------------------------------
161153

162154
inline int
163-
SchedPriorities::chooseByRule1(std::vector<candIndex>& mcands)
164-
{
155+
SchedPriorities::chooseByRule1(std::vector<candIndex>& mcands) {
165156
return (mcands.size() == 1)? 0 // only one choice exists so take it
166157
: -1; // -1 indicates multiple choices
167158
}
168159

169160
inline int
170-
SchedPriorities::chooseByRule2(std::vector<candIndex>& mcands)
171-
{
161+
SchedPriorities::chooseByRule2(std::vector<candIndex>& mcands) {
172162
assert(mcands.size() >= 1 && "Should have at least one candidate here.");
173163
for (unsigned i=0, N = mcands.size(); i < N; i++)
174164
if (instructionHasLastUse(methodLiveVarInfo,
@@ -178,67 +168,60 @@ SchedPriorities::chooseByRule2(std::vector<candIndex>& mcands)
178168
}
179169

180170
inline int
181-
SchedPriorities::chooseByRule3(std::vector<candIndex>& mcands)
182-
{
171+
SchedPriorities::chooseByRule3(std::vector<candIndex>& mcands) {
183172
assert(mcands.size() >= 1 && "Should have at least one candidate here.");
184173
int maxUses = candsAsHeap.getNode(mcands[0])->getNumOutEdges();
185174
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;
194180
}
181+
}
195182
return indexWithMaxUses;
196183
}
197184

198185
const SchedGraphNode*
199186
SchedPriorities::getNextHighest(const SchedulingManager& S,
200-
cycles_t curTime)
201-
{
187+
cycles_t curTime) {
202188
int nextIdx = -1;
203189
const SchedGraphNode* nextChoice = NULL;
204190

205191
if (mcands.size() == 0)
206192
findSetWithMaxDelay(mcands, S);
207193

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
211196

212-
if (nextIdx == -1)
213-
nextIdx = chooseByRule2(mcands); // rule 2
197+
if (nextIdx == -1)
198+
nextIdx = chooseByRule2(mcands); // rule 2
214199

215-
if (nextIdx == -1)
216-
nextIdx = chooseByRule3(mcands); // rule 3
200+
if (nextIdx == -1)
201+
nextIdx = chooseByRule3(mcands); // rule 3
217202

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
220205

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()))
237213
{
238214
mcands.erase(mcands.begin() + nextIdx);
239-
return nextChoice;
215+
nextIdx = -1;
216+
if (mcands.size() == 0)
217+
findSetWithMaxDelay(mcands, S);
240218
}
241-
else
219+
}
220+
221+
if (nextIdx >= 0) {
222+
mcands.erase(mcands.begin() + nextIdx);
223+
return nextChoice;
224+
} else
242225
return NULL;
243226
}
244227

@@ -258,15 +241,14 @@ SchedPriorities::findSetWithMaxDelay(std::vector<candIndex>& mcands,
258241

259242
nextToTry = next;
260243

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+
}
270252
}
271253
}
272254

0 commit comments

Comments
 (0)