@@ -114,16 +114,17 @@ using VMEMID = uint32_t;
114114enum : 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 {
601602class WaitcntBrackets {
602603public:
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