Skip to content

Commit 2049624

Browse files
committed
Comments
1 parent 1a77571 commit 2049624

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,17 @@ using VMEMID = uint32_t;
114114
enum : VMEMID {
115115
TRACKINGID_RANGE_LEN = (1 << 16),
116116

117+
// Important: MCRegUnits must always be tracked starting from 0, as we
118+
// need to be able to convert between a MCRegUnit and a VMEMID freely.
117119
REGUNITS_BEGIN = 0,
118120
REGUNITS_END = REGUNITS_BEGIN + TRACKINGID_RANGE_LEN,
119121

120122
// Note for LDSDMA: LDSDMA_BEGIN corresponds to the "common"
121123
// entry, which is updated for all LDS DMA operations encountered.
122124
// Specific LDS DMA IDs start at LDSDMA_BEGIN + 1.
125+
NUM_LDSDMA = TRACKINGID_RANGE_LEN,
123126
LDSDMA_BEGIN = REGUNITS_END,
124-
LDSDMA_END = LDSDMA_BEGIN + TRACKINGID_RANGE_LEN,
125-
126-
NUM_LDSDMA = TRACKINGID_RANGE_LEN
127+
LDSDMA_END = LDSDMA_BEGIN + NUM_LDSDMA,
127128
};
128129

129130
/// Convert a MCRegUnit to a VMEMID.
@@ -601,12 +602,30 @@ class SIInsertWaitcnts {
601602
class WaitcntBrackets {
602603
public:
603604
WaitcntBrackets(const SIInsertWaitcnts *Context) : Context(Context) {
604-
static_assert(REGUNITS_BEGIN == 0,
605-
"REGUNITS_BEGIN must be zero; tracking depends on being able "
606-
"to convert a register unit ID to a VMEMID directly!");
607605
assert(Context->TRI->getNumRegUnits() < REGUNITS_END);
608606
}
609607

608+
#ifndef NDEBUG
609+
~WaitcntBrackets() {
610+
unsigned NumUnusedVmem = 0, NumUnusedSGPRs = 0;
611+
for (auto &[ID, Val] : VMem) {
612+
if (Val.empty())
613+
++NumUnusedVmem;
614+
}
615+
for (auto &[ID, Val] : SGPRs) {
616+
if (Val.empty())
617+
++NumUnusedSGPRs;
618+
}
619+
620+
if (NumUnusedVmem || NumUnusedSGPRs) {
621+
errs() << "WaitcntBracket had unused entries at destruction time: "
622+
<< NumUnusedVmem << " VMem and " << NumUnusedSGPRs
623+
<< " SGPR unused entries\n";
624+
std::abort();
625+
}
626+
}
627+
#endif
628+
610629
bool isSmemCounter(InstCounterType T) const {
611630
return T == Context->SmemAccessCounter || T == X_CNT;
612631
}
@@ -1079,7 +1098,7 @@ void WaitcntBrackets::updateByEvent(WaitEventType E, MachineInstr &Inst) {
10791098
}
10801099
}
10811100
}
1082-
if (Slot)
1101+
if (Slot || LDSDMAStores.size() == NUM_LDSDMA - 1)
10831102
break;
10841103
Slot = LDSDMAStores.size() + 1;
10851104
LDSDMAStores.push_back(&Inst);

0 commit comments

Comments
 (0)