Skip to content

Commit c72c865

Browse files
committed
Comments
1 parent 4b41adf commit c72c865

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.
@@ -594,12 +595,30 @@ class SIInsertWaitcnts {
594595
class WaitcntBrackets {
595596
public:
596597
WaitcntBrackets(const SIInsertWaitcnts *Context) : Context(Context) {
597-
static_assert(REGUNITS_BEGIN == 0,
598-
"REGUNITS_BEGIN must be zero; tracking depends on being able "
599-
"to convert a register unit ID to a VMEMID directly!");
600598
assert(Context->TRI->getNumRegUnits() < REGUNITS_END);
601599
}
602600

601+
#ifndef NDEBUG
602+
~WaitcntBrackets() {
603+
unsigned NumUnusedVmem = 0, NumUnusedSGPRs = 0;
604+
for (auto &[ID, Val] : VMem) {
605+
if (Val.empty())
606+
++NumUnusedVmem;
607+
}
608+
for (auto &[ID, Val] : SGPRs) {
609+
if (Val.empty())
610+
++NumUnusedSGPRs;
611+
}
612+
613+
if (NumUnusedVmem || NumUnusedSGPRs) {
614+
errs() << "WaitcntBracket had unused entries at destruction time: "
615+
<< NumUnusedVmem << " VMem and " << NumUnusedSGPRs
616+
<< " SGPR unused entries\n";
617+
std::abort();
618+
}
619+
}
620+
#endif
621+
603622
bool isSmemCounter(InstCounterType T) const {
604623
return T == Context->SmemAccessCounter || T == X_CNT;
605624
}
@@ -1073,7 +1092,7 @@ void WaitcntBrackets::updateByEvent(WaitEventType E, MachineInstr &Inst) {
10731092
}
10741093
}
10751094
}
1076-
if (Slot)
1095+
if (Slot || LDSDMAStores.size() == NUM_LDSDMA - 1)
10771096
break;
10781097
// The slot may not be valid because it can be >= NUM_LDSDMA which
10791098
// means the scoreboard cannot track it. We still want to preserve the

0 commit comments

Comments
 (0)