mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
AMDGPU/SI: Use common topological sort algorithm in SIScheduleDAGMI
Reviewers: arsenm, axeldavy Subscribers: MatzeB, arsenm, llvm-commits Differential Revision: http://reviews.llvm.org/D19823 llvm-svn: 272346
This commit is contained in:
parent
b7b3917848
commit
8ca66729b9
@ -1670,70 +1670,10 @@ ScheduleDAGInstrs *llvm::createSIMachineScheduler(MachineSchedContext *C) {
|
||||
// Does a topological sort over the SUs.
|
||||
// Both TopDown and BottomUp
|
||||
void SIScheduleDAGMI::topologicalSort() {
|
||||
std::vector<int> TopDownSU2Index;
|
||||
unsigned DAGSize = SUnits.size();
|
||||
std::vector<SUnit*> WorkList;
|
||||
Topo.InitDAGTopologicalSorting();
|
||||
|
||||
DEBUG(dbgs() << "Topological Sort\n");
|
||||
WorkList.reserve(DAGSize);
|
||||
|
||||
TopDownIndex2SU.resize(DAGSize);
|
||||
TopDownSU2Index.resize(DAGSize);
|
||||
BottomUpIndex2SU.resize(DAGSize);
|
||||
|
||||
WorkList.push_back(&getExitSU());
|
||||
for (unsigned i = 0, e = DAGSize; i != e; ++i) {
|
||||
SUnit *SU = &SUnits[i];
|
||||
int NodeNum = SU->NodeNum;
|
||||
unsigned Degree = SU->Succs.size();
|
||||
TopDownSU2Index[NodeNum] = Degree;
|
||||
if (Degree == 0) {
|
||||
assert(SU->Succs.empty() && "SUnit should have no successors");
|
||||
WorkList.push_back(SU);
|
||||
}
|
||||
}
|
||||
|
||||
int Id = DAGSize;
|
||||
while (!WorkList.empty()) {
|
||||
SUnit *SU = WorkList.back();
|
||||
WorkList.pop_back();
|
||||
if (SU->NodeNum < DAGSize) {
|
||||
TopDownSU2Index[SU->NodeNum] = --Id;
|
||||
TopDownIndex2SU[Id] = SU->NodeNum;
|
||||
}
|
||||
for (SDep& Pred : SU->Preds) {
|
||||
SUnit *SU = Pred.getSUnit();
|
||||
if (SU->NodeNum < DAGSize && !--TopDownSU2Index[SU->NodeNum])
|
||||
WorkList.push_back(SU);
|
||||
}
|
||||
}
|
||||
|
||||
BottomUpIndex2SU = std::vector<int>(TopDownIndex2SU.rbegin(),
|
||||
TopDownIndex2SU.rend());
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Check correctness of the ordering
|
||||
for (unsigned i = 0, e = DAGSize; i != e; ++i) {
|
||||
SUnit *SU = &SUnits[i];
|
||||
for (SDep& Pred : SU->Preds) {
|
||||
if (Pred.getSUnit()->NodeNum >= DAGSize)
|
||||
continue;
|
||||
assert(TopDownSU2Index[SU->NodeNum] >
|
||||
TopDownSU2Index[Pred.getSUnit()->NodeNum] &&
|
||||
"Wrong Top Down topological sorting");
|
||||
}
|
||||
}
|
||||
for (unsigned i = 0, e = DAGSize; i != e; ++i) {
|
||||
SUnit *SU = &SUnits[i];
|
||||
for (SDep& Succ : SU->Succs) {
|
||||
if (Succ.getSUnit()->NodeNum >= DAGSize)
|
||||
continue;
|
||||
assert(TopDownSU2Index[SU->NodeNum] <
|
||||
TopDownSU2Index[Succ.getSUnit()->NodeNum] &&
|
||||
"Wrong Bottom Up topological sorting");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
TopDownIndex2SU = std::vector<int>(Topo.begin(), Topo.end());
|
||||
BottomUpIndex2SU = std::vector<int>(Topo.rbegin(), Topo.rend());
|
||||
}
|
||||
|
||||
// Move low latencies further from their user without
|
||||
@ -1850,7 +1790,6 @@ void SIScheduleDAGMI::schedule()
|
||||
SU.dumpAll(this)
|
||||
);
|
||||
|
||||
Topo.InitDAGTopologicalSorting();
|
||||
topologicalSort();
|
||||
findRootsAndBiasEdges(TopRoots, BotRoots);
|
||||
// We reuse several ScheduleDAGMI and ScheduleDAGMILive
|
||||
|
Loading…
Reference in New Issue
Block a user