[llvm-commits] [llvm] r55421 - /llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
Dan Gohman
gohman at apple.com
Wed Aug 27 09:29:48 PDT 2008
Author: djg
Date: Wed Aug 27 11:29:48 2008
New Revision: 55421
URL: http://llvm.org/viewvc/llvm-project?rev=55421&view=rev
Log:
Optimize ScheduleDAGRRList's topological sort to use one pass instead
of two, and to not need a scratch std::vector. Also, compute the ordering
immediately in the result array, instead of in another scratch std::vector
that is copied to the result array.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp?rev=55421&r1=55420&r2=55421&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp Wed Aug 27 11:29:48 2008
@@ -448,18 +448,19 @@
/// immediately after X in Index2Node.
void ScheduleDAGRRList::InitDAGTopologicalSorting() {
unsigned DAGSize = SUnits.size();
- std::vector<unsigned> InDegree(DAGSize);
std::vector<SUnit*> WorkList;
WorkList.reserve(DAGSize);
- std::vector<SUnit*> TopOrder;
- TopOrder.reserve(DAGSize);
+
+ Index2Node.resize(DAGSize);
+ Node2Index.resize(DAGSize);
// Initialize the data structures.
for (unsigned i = 0, e = DAGSize; i != e; ++i) {
SUnit *SU = &SUnits[i];
int NodeNum = SU->NodeNum;
unsigned Degree = SU->Succs.size();
- InDegree[NodeNum] = Degree;
+ // Temporarily use the Node2Index array as scratch space for degree counts.
+ Node2Index[NodeNum] = Degree;
// Is it a node without dependencies?
if (Degree == 0) {
@@ -469,35 +470,23 @@
}
}
+ int Id = DAGSize;
while (!WorkList.empty()) {
SUnit *SU = WorkList.back();
WorkList.pop_back();
- TopOrder.push_back(SU);
+ Allocate(SU->NodeNum, --Id);
for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
I != E; ++I) {
SUnit *SU = I->Dep;
- if (!--InDegree[SU->NodeNum])
+ if (!--Node2Index[SU->NodeNum])
// If all dependencies of the node are processed already,
// then the node can be computed now.
WorkList.push_back(SU);
}
}
- // Second pass, assign the actual topological order as node ids.
- int Id = 0;
-
- Index2Node.clear();
- Node2Index.clear();
- Index2Node.resize(DAGSize);
- Node2Index.resize(DAGSize);
Visited.resize(DAGSize);
- for (std::vector<SUnit*>::reverse_iterator TI = TopOrder.rbegin(),
- TE = TopOrder.rend();TI != TE; ++TI) {
- Allocate((*TI)->NodeNum, Id);
- Id++;
- }
-
#ifndef NDEBUG
// Check correctness of the ordering
for (unsigned i = 0, e = DAGSize; i != e; ++i) {
More information about the llvm-commits
mailing list