Skip to content

Commit fb99055

Browse files
committedMar 27, 2017
[AMDGPU] SISched: Detect dependency types between blocks
Patch by Axel Davy (axel.davy@normalesup.org) Differential revision: https://reviews.llvm.org/D30153 llvm-svn: 298872
1 parent 1856cee commit fb99055

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed
 

‎llvm/lib/Target/AMDGPU/SIMachineScheduler.cpp

+29-23
Original file line numberDiff line numberDiff line change
@@ -539,21 +539,30 @@ void SIScheduleBlock::addPred(SIScheduleBlock *Pred) {
539539
Preds.push_back(Pred);
540540

541541
assert(none_of(Succs,
542-
[=](SIScheduleBlock *S) { return PredID == S->getID(); }) &&
542+
[=](std::pair<SIScheduleBlock*,
543+
SIScheduleBlockLinkKind> S) {
544+
return PredID == S.first->getID();
545+
}) &&
543546
"Loop in the Block Graph!");
544547
}
545548

546-
void SIScheduleBlock::addSucc(SIScheduleBlock *Succ) {
549+
void SIScheduleBlock::addSucc(SIScheduleBlock *Succ,
550+
SIScheduleBlockLinkKind Kind) {
547551
unsigned SuccID = Succ->getID();
548552

549553
// Check if not already predecessor.
550-
for (SIScheduleBlock* S : Succs) {
551-
if (SuccID == S->getID())
554+
for (std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind> &S : Succs) {
555+
if (SuccID == S.first->getID()) {
556+
if (S.second == SIScheduleBlockLinkKind::NoData &&
557+
Kind == SIScheduleBlockLinkKind::Data)
558+
S.second = Kind;
552559
return;
560+
}
553561
}
554562
if (Succ->isHighLatencyBlock())
555563
++NumHighLatencySuccessors;
556-
Succs.push_back(Succ);
564+
Succs.push_back(std::make_pair(Succ, Kind));
565+
557566
assert(none_of(Preds,
558567
[=](SIScheduleBlock *P) { return SuccID == P->getID(); }) &&
559568
"Loop in the Block Graph!");
@@ -573,8 +582,10 @@ void SIScheduleBlock::printDebug(bool full) {
573582
}
574583

575584
dbgs() << "\nSuccessors:\n";
576-
for (SIScheduleBlock* S : Succs) {
577-
S->printDebug(false);
585+
for (std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind> S : Succs) {
586+
if (S.second == SIScheduleBlockLinkKind::Data)
587+
dbgs() << "(Data Dep) ";
588+
S.first->printDebug(false);
578589
}
579590

580591
if (Scheduled) {
@@ -1096,7 +1107,8 @@ void SIScheduleBlockCreator::createBlocksForVariant(SISchedulerBlockCreatorVaria
10961107
if (SuccDep.isWeak() || Succ->NodeNum >= DAGSize)
10971108
continue;
10981109
if (Node2CurrentBlock[Succ->NodeNum] != SUID)
1099-
CurrentBlocks[SUID]->addSucc(CurrentBlocks[Node2CurrentBlock[Succ->NodeNum]]);
1110+
CurrentBlocks[SUID]->addSucc(CurrentBlocks[Node2CurrentBlock[Succ->NodeNum]],
1111+
SuccDep.isCtrl() ? NoData : Data);
11001112
}
11011113
for (SDep& PredDep : SU->Preds) {
11021114
SUnit *Pred = PredDep.getSUnit();
@@ -1290,10 +1302,8 @@ void SIScheduleBlockCreator::fillStats() {
12901302
Block->Height = 0;
12911303
else {
12921304
unsigned Height = 0;
1293-
for (SIScheduleBlock *Succ : Block->getSuccs()) {
1294-
if (Height < Succ->Height + 1)
1295-
Height = Succ->Height + 1;
1296-
}
1305+
for (const auto &Succ : Block->getSuccs())
1306+
Height = std::min(Height, Succ.first->Height + 1);
12971307
Block->Height = Height;
12981308
}
12991309
}
@@ -1574,17 +1584,13 @@ void SIScheduleBlockScheduler::decreaseLiveRegs(SIScheduleBlock *Block,
15741584
}
15751585

15761586
void SIScheduleBlockScheduler::releaseBlockSuccs(SIScheduleBlock *Parent) {
1577-
for (SIScheduleBlock* Block : Parent->getSuccs()) {
1578-
--BlockNumPredsLeft[Block->getID()];
1579-
if (BlockNumPredsLeft[Block->getID()] == 0) {
1580-
ReadyBlocks.push_back(Block);
1581-
}
1582-
// TODO: Improve check. When the dependency between the high latency
1583-
// instructions and the instructions of the other blocks are WAR or WAW
1584-
// there will be no wait triggered. We would like these cases to not
1585-
// update LastPosHighLatencyParentScheduled.
1586-
if (Parent->isHighLatencyBlock())
1587-
LastPosHighLatencyParentScheduled[Block->getID()] = NumBlockScheduled;
1587+
for (const auto &Block : Parent->getSuccs()) {
1588+
if (--BlockNumPredsLeft[Block.first->getID()] == 0)
1589+
ReadyBlocks.push_back(Block.first);
1590+
1591+
if (Parent->isHighLatencyBlock() &&
1592+
Block.second == SIScheduleBlockLinkKind::Data)
1593+
LastPosHighLatencyParentScheduled[Block.first->getID()] = NumBlockScheduled;
15881594
}
15891595
}
15901596

‎llvm/lib/Target/AMDGPU/SIMachineScheduler.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ struct SISchedulerCandidate {
5454
class SIScheduleDAGMI;
5555
class SIScheduleBlockCreator;
5656

57+
enum SIScheduleBlockLinkKind {
58+
NoData,
59+
Data
60+
};
61+
5762
class SIScheduleBlock {
5863
SIScheduleDAGMI *DAG;
5964
SIScheduleBlockCreator *BC;
@@ -92,7 +97,8 @@ class SIScheduleBlock {
9297
unsigned ID;
9398

9499
std::vector<SIScheduleBlock*> Preds; // All blocks predecessors.
95-
std::vector<SIScheduleBlock*> Succs; // All blocks successors.
100+
// All blocks successors, and the kind of link
101+
std::vector<std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind>> Succs;
96102
unsigned NumHighLatencySuccessors = 0;
97103

98104
public:
@@ -112,10 +118,11 @@ class SIScheduleBlock {
112118

113119
// Add block pred, which has instruction predecessor of SU.
114120
void addPred(SIScheduleBlock *Pred);
115-
void addSucc(SIScheduleBlock *Succ);
121+
void addSucc(SIScheduleBlock *Succ, SIScheduleBlockLinkKind Kind);
116122

117123
const std::vector<SIScheduleBlock*>& getPreds() const { return Preds; }
118-
const std::vector<SIScheduleBlock*>& getSuccs() const { return Succs; }
124+
ArrayRef<std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind>>
125+
getSuccs() const { return Succs; }
119126

120127
unsigned Height; // Maximum topdown path length to block without outputs
121128
unsigned Depth; // Maximum bottomup path length to block without inputs

0 commit comments

Comments
 (0)
Please sign in to comment.