Skip to content

Commit 5ce0538

Browse files
committed
1. Embed and not inherit vector for NodeGroup. 2. Iterate operands and not uses (performance.) 3. Some long pending comment changes. llvm-svn: 24119
1 parent 88fc69f commit 5ce0538

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// The LLVM Compiler Infrastructure
44
//
5-
// This file was developed by Chris Lattner and is distributed under the
5+
// This file was developed by James M. Laskey and is distributed under the
66
// University of Illinois Open Source License. See LICENSE.TXT for details.
77
//
88
//===----------------------------------------------------------------------===//
@@ -192,15 +192,17 @@ class ResourceTally {
192192

193193
// Forward
194194
class NodeInfo;
195-
typedef std::vector<NodeInfo *> NIVector;
196-
typedef std::vector<NodeInfo *>::iterator NIIterator;
195+
typedef NodeInfo *NodeInfoPtr;
196+
typedef std::vector<NodeInfoPtr> NIVector;
197+
typedef std::vector<NodeInfoPtr>::iterator NIIterator;
197198

198199
//===----------------------------------------------------------------------===//
199200
///
200201
/// Node group - This struct is used to manage flagged node groups.
201202
///
202-
class NodeGroup : public NIVector {
203+
class NodeGroup {
203204
private:
205+
NIVector Members; // Group member nodes
204206
int Pending; // Number of visits pending before
205207
// adding to order
206208

@@ -209,10 +211,24 @@ class NodeGroup : public NIVector {
209211
NodeGroup() : Pending(0) {}
210212

211213
// Accessors
212-
inline NodeInfo *getLeader() { return empty() ? NULL : front(); }
214+
inline NodeInfo *getLeader() {
215+
return Members.empty() ? NULL : Members.front();
216+
}
213217
inline int getPending() const { return Pending; }
214218
inline void setPending(int P) { Pending = P; }
215219
inline int addPending(int I) { return Pending += I; }
220+
221+
// Pass thru
222+
inline bool group_empty() { return Members.empty(); }
223+
inline NIIterator group_begin() { return Members.begin(); }
224+
inline NIIterator group_end() { return Members.end(); }
225+
inline void group_push_back(const NodeInfoPtr &NI) { Members.push_back(NI); }
226+
inline NIIterator group_insert(NIIterator Pos, const NodeInfoPtr &NI) {
227+
return Members.insert(Pos, NI);
228+
}
229+
inline void group_insert(NIIterator Pos, NIIterator First, NIIterator Last) {
230+
Members.insert(Pos, First, Last);
231+
}
216232

217233
static void Add(NodeInfo *D, NodeInfo *U);
218234
static unsigned CountInternalUses(NodeInfo *D, NodeInfo *U);
@@ -257,7 +273,7 @@ class NodeInfo {
257273

258274
// Accessors
259275
inline bool isInGroup() const {
260-
assert(!Group || !Group->empty() && "Group with no members");
276+
assert(!Group || !Group->group_empty() && "Group with no members");
261277
return Group != NULL;
262278
}
263279
inline bool isGroupLeader() const {
@@ -298,8 +314,8 @@ class NodeGroupIterator {
298314
if (N->isInGroup()) {
299315
// get Group
300316
NodeGroup *Group = NI->Group;
301-
NGI = Group->begin();
302-
NGE = Group->end();
317+
NGI = Group->group_begin();
318+
NGE = Group->group_end();
303319
// Prevent this node from being used (will be in members list
304320
NI = NULL;
305321
}
@@ -491,7 +507,8 @@ void NodeGroup::Add(NodeInfo *D, NodeInfo *U) {
491507
}
492508
}
493509
// Merge the two lists
494-
DGroup->insert(DGroup->end(), UGroup->begin(), UGroup->end());
510+
DGroup->group_insert(DGroup->group_end(),
511+
UGroup->group_begin(), UGroup->group_end());
495512
} else if (DGroup) {
496513
// Make user member of definers group
497514
U->Group = DGroup;
@@ -503,7 +520,7 @@ void NodeGroup::Add(NodeInfo *D, NodeInfo *U) {
503520
// Remove internal edges
504521
DGroup->addPending(-CountInternalUses(DNI, U));
505522
}
506-
DGroup->push_back(U);
523+
DGroup->group_push_back(U);
507524
} else if (UGroup) {
508525
// Make definer member of users group
509526
D->Group = UGroup;
@@ -515,24 +532,25 @@ void NodeGroup::Add(NodeInfo *D, NodeInfo *U) {
515532
// Remove internal edges
516533
UGroup->addPending(-CountInternalUses(D, UNI));
517534
}
518-
UGroup->insert(UGroup->begin(), D);
535+
UGroup->group_insert(UGroup->group_begin(), D);
519536
} else {
520537
D->Group = U->Group = DGroup = new NodeGroup();
521538
DGroup->addPending(D->Node->use_size() + U->Node->use_size() -
522539
CountInternalUses(D, U));
523-
DGroup->push_back(D);
524-
DGroup->push_back(U);
540+
DGroup->group_push_back(D);
541+
DGroup->group_push_back(U);
525542
}
526543
}
527544

528545
/// CountInternalUses - Returns the number of edges between the two nodes.
529546
///
530547
unsigned NodeGroup::CountInternalUses(NodeInfo *D, NodeInfo *U) {
531548
unsigned N = 0;
532-
for (SDNode:: use_iterator UI = D->Node->use_begin(),
533-
E = D->Node->use_end(); UI != E; UI++) {
534-
if (*UI == U->Node) N++;
549+
for (unsigned M = U->Node->getNumOperands(); 0 < M--;) {
550+
SDOperand Op = U->Node->getOperand(M);
551+
if (Op.Val == D->Node) N++;
535552
}
553+
536554
return N;
537555
}
538556
//===----------------------------------------------------------------------===//
@@ -743,7 +761,7 @@ void SimpleSched::GatherSchedulingInfo() {
743761
unsigned ResourceSet = 0;
744762
bool IsCall = false;
745763

746-
for (NIIterator NGI = Group->begin(), NGE = Group->end();
764+
for (NIIterator NGI = Group->group_begin(), NGE = Group->group_end();
747765
NGI != NGE; NGI++) {
748766
NodeInfo* NGNI = *NGI;
749767
Latency += NGNI->Latency;
@@ -798,7 +816,8 @@ bool SimpleSched::isStrongDependency(NodeInfo *A, NodeInfo *B) {
798816
}
799817

800818
/// isWeakDependency Return true if node A produces a result that will
801-
/// conflict with operands of B.
819+
/// conflict with operands of B. It is assumed that we have called
820+
/// isStrongDependency prior.
802821
bool SimpleSched::isWeakDependency(NodeInfo *A, NodeInfo *B) {
803822
// TODO check for conflicting real registers and aliases
804823
#if 0 // FIXME - Since we are in SSA form and not checking register aliasing
@@ -1225,7 +1244,7 @@ void SimpleSched::printChanges(unsigned Index) {
12251244
std::cerr << "\n";
12261245
if (NI->isGroupLeader()) {
12271246
NodeGroup *Group = NI->Group;
1228-
for (NIIterator NII = Group->begin(), E = Group->end();
1247+
for (NIIterator NII = Group->group_begin(), E = Group->group_end();
12291248
NII != E; NII++) {
12301249
std::cerr << " ";
12311250
printSI(std::cerr, *NII);
@@ -1269,7 +1288,7 @@ void SimpleSched::print(std::ostream &O) const {
12691288
O << "\n";
12701289
if (NI->isGroupLeader()) {
12711290
NodeGroup *Group = NI->Group;
1272-
for (NIIterator NII = Group->begin(), E = Group->end();
1291+
for (NIIterator NII = Group->group_begin(), E = Group->group_end();
12731292
NII != E; NII++) {
12741293
O << " ";
12751294
printSI(O, *NII);

0 commit comments

Comments
 (0)