56 #define DEBUG_TYPE "si-insert-waitcnts" 59 "Force emit s_waitcnt expcnt(0) instrs");
61 "Force emit s_waitcnt lgkmcnt(0) instrs");
63 "Force emit s_waitcnt vmcnt(0) instrs");
66 "amdgpu-waitcnt-forcezero",
67 cl::desc(
"Force all waitcnt instrs to be emitted as s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)"),
76 #define CNT_MASK(t) (1u << (t)) 80 using RegInterval = std::pair<signed, signed>;
118 SQ_MAX_PGM_VGPRS = 256,
119 SQ_MAX_PGM_SGPRS = 256,
122 NUM_ALL_VGPRS = SQ_MAX_PGM_VGPRS + NUM_EXTRA_VGPRS,
125 #define ForAllWaitEventType(w) \ 126 for (enum WaitEventType w = (enum WaitEventType)0; \ 127 (w) < (enum WaitEventType)NUM_WAIT_EVENTS; \ 128 (w) = (enum WaitEventType)((w) + 1)) 137 class BlockWaitcntBrackets {
142 memset(VgprScores[
T], 0,
sizeof(VgprScores[T]));
146 ~BlockWaitcntBrackets() =
default;
151 return HardwareLimits.VmcntMax;
153 return HardwareLimits.LgkmcntMax;
155 return HardwareLimits.ExpcntMax;
163 assert(T < NUM_INST_CNTS);
164 if (T >= NUM_INST_CNTS)
170 assert(T < NUM_INST_CNTS);
171 if (T >= NUM_INST_CNTS)
175 int32_t UB = (int)(ScoreUBs[T] - getWaitCountMax(
EXP_CNT));
176 if (ScoreLBs[T] < UB)
182 assert(T < NUM_INST_CNTS);
183 if (T >= NUM_INST_CNTS)
189 assert(T < NUM_INST_CNTS);
190 if (T >= NUM_INST_CNTS)
209 case EXP_PARAM_ACCESS:
214 return NUM_INST_CNTS;
218 if (GprNo < NUM_ALL_VGPRS) {
219 if (GprNo > VgprUB) {
222 VgprScores[
T][GprNo] = Val;
225 if (GprNo - NUM_ALL_VGPRS > SgprUB) {
226 SgprUB = GprNo - NUM_ALL_VGPRS;
228 SgprScores[GprNo - NUM_ALL_VGPRS] = Val;
233 if (GprNo < NUM_ALL_VGPRS) {
234 return VgprScores[
T][GprNo];
236 return SgprScores[GprNo - NUM_ALL_VGPRS];
240 memset(ScoreLBs, 0,
sizeof(ScoreLBs));
241 memset(ScoreUBs, 0,
sizeof(ScoreUBs));
242 memset(EventUBs, 0,
sizeof(EventUBs));
245 memset(VgprScores[T], 0,
sizeof(VgprScores[T]));
247 memset(SgprScores, 0,
sizeof(SgprScores));
257 unsigned OpNo, int32_t Val);
259 void setWaitAtBeginning() { WaitAtBeginning =
true; }
260 void clearWaitAtBeginning() { WaitAtBeginning =
false; }
261 bool getWaitAtBeginning()
const {
return WaitAtBeginning; }
262 void setEventUB(
enum WaitEventType W, int32_t Val) { EventUBs[
W] = Val; }
263 int32_t getMaxVGPR()
const {
return VgprUB; }
264 int32_t getMaxSGPR()
const {
return SgprUB; }
267 assert(W < NUM_WAIT_EVENTS);
277 bool hasPendingSMEM()
const {
278 return (EventUBs[SMEM_ACCESS] > ScoreLBs[
LGKM_CNT] &&
279 EventUBs[SMEM_ACCESS] <= ScoreUBs[
LGKM_CNT]);
282 bool hasPendingFlat()
const {
289 void setPendingFlat() {
298 bool getRevisitLoop()
const {
return RevisitLoop; }
299 void setRevisitLoop(
bool RevisitLoopIn) { RevisitLoop = RevisitLoopIn; }
301 void setPostOrder(int32_t PostOrderIn) { PostOrder = PostOrderIn; }
302 int32_t getPostOrder()
const {
return PostOrder; }
304 void setWaitcnt(
MachineInstr *WaitcntIn) { Waitcnt = WaitcntIn; }
305 void clearWaitcnt() { Waitcnt =
nullptr; }
308 bool mixedExpTypes()
const {
return MixedExpTypes; }
309 void setMixedExpTypes(
bool MixedExpTypesIn) {
310 MixedExpTypes = MixedExpTypesIn;
318 bool WaitAtBeginning =
false;
319 bool RevisitLoop =
false;
320 bool MixedExpTypes =
false;
321 int32_t PostOrder = 0;
323 int32_t ScoreLBs[NUM_INST_CNTS] = {0};
324 int32_t ScoreUBs[NUM_INST_CNTS] = {0};
325 int32_t EventUBs[NUM_WAIT_EVENTS] = {0};
327 int32_t LastFlat[NUM_INST_CNTS] = {0};
332 int32_t VgprScores[NUM_INST_CNTS][NUM_ALL_VGPRS];
334 int32_t SgprScores[SQ_MAX_PGM_SGPRS] = {0};
342 class LoopWaitcntData {
344 LoopWaitcntData() =
default;
345 ~LoopWaitcntData() =
default;
347 void incIterCnt() { IterCnt++; }
348 void resetIterCnt() { IterCnt = 0; }
349 unsigned getIterCnt() {
return IterCnt; }
351 void setWaitcnt(
MachineInstr *WaitcntIn) { LfWaitcnt = WaitcntIn; }
380 BlockWaitcntBracketsMap;
382 std::vector<MachineBasicBlock *> BlockWaitcntProcessedSet;
386 std::vector<std::unique_ptr<BlockWaitcntBrackets>> KillWaitBrackets;
390 bool ForceEmitZeroWaitcnts;
391 bool ForceEmitWaitcnt[NUM_INST_CNTS];
397 (void)ForceExpCounter;
398 (void)ForceLgkmCounter;
399 (void)ForceVMCounter;
405 return "SI insert wait instructions";
414 void addKillWaitBracket(BlockWaitcntBrackets *Bracket) {
417 KillWaitBrackets.push_back(
418 llvm::make_unique<BlockWaitcntBrackets>(*Bracket));
421 bool isForceEmitWaitcnt()
const {
424 if (ForceEmitWaitcnt[
T])
429 void setForceEmitWaitcnt() {
435 ForceEmitWaitcnt[
EXP_CNT] =
true;
437 ForceEmitWaitcnt[
EXP_CNT] =
false;
449 ForceEmitWaitcnt[
VM_CNT] =
true;
451 ForceEmitWaitcnt[
VM_CNT] =
false;
458 BlockWaitcntBrackets *ScoreBrackets);
460 BlockWaitcntBrackets *ScoreBrackets);
463 unsigned countNumBottomBlocks(
const MachineLoop *Loop);
466 bool isWaitcntStronger(
unsigned LHS,
unsigned RHS);
467 unsigned combineWaitcnt(
unsigned LHS,
unsigned RHS);
472 RegInterval BlockWaitcntBrackets::getRegInterval(
const MachineInstr *
MI,
479 if (!Op.
isReg() || !TRI->isInAllocatableClass(Op.
getReg()) ||
480 (Def && !Op.
isDef()))
490 unsigned Reg = TRI->getEncodingValue(Op.
getReg());
493 assert(Reg >= RegisterEncoding.VGPR0 && Reg <= RegisterEncoding.VGPRL);
494 Result.first = Reg - RegisterEncoding.VGPR0;
495 assert(Result.first >= 0 && Result.first < SQ_MAX_PGM_VGPRS);
497 assert(Reg >= RegisterEncoding.SGPR0 && Reg < SQ_MAX_PGM_SGPRS);
498 Result.first = Reg - RegisterEncoding.SGPR0 + NUM_ALL_VGPRS;
499 assert(Result.first >= NUM_ALL_VGPRS &&
500 Result.first < SQ_MAX_PGM_SGPRS + NUM_ALL_VGPRS);
509 unsigned Size = TRI->getRegSizeInBits(*RC);
510 Result.second = Result.first + (Size / 32);
515 void BlockWaitcntBrackets::setExpScore(
const MachineInstr *MI,
519 unsigned OpNo, int32_t Val) {
520 RegInterval
Interval = getRegInterval(MI, TII, MRI, TRI, OpNo,
false);
525 for (
signed RegNo = Interval.first; RegNo < Interval.second; ++RegNo) {
526 setRegScore(RegNo,
EXP_CNT, Val);
530 void BlockWaitcntBrackets::updateByEvent(
const SIInstrInfo *TII,
536 int32_t CurrScore = getScoreUB(T) + 1;
540 EventUBs[
E] = CurrScore;
541 setScoreUB(T, CurrScore);
546 if (!MixedExpTypes) {
547 MixedExpTypes = counterOutOfOrder(
EXP_CNT);
555 if (Inst.
getOpcode() != AMDGPU::DS_APPEND &&
556 Inst.
getOpcode() != AMDGPU::DS_CONSUME) {
558 &Inst, TII, TRI, MRI,
564 &Inst, TII, TRI, MRI,
568 AMDGPU::OpName::data1) != -1) {
569 setExpScore(&Inst, TII, TRI, MRI,
571 AMDGPU::OpName::data1),
575 Inst.
getOpcode() != AMDGPU::DS_GWS_INIT &&
576 Inst.
getOpcode() != AMDGPU::DS_GWS_SEMA_V &&
577 Inst.
getOpcode() != AMDGPU::DS_GWS_SEMA_BR &&
578 Inst.
getOpcode() != AMDGPU::DS_GWS_SEMA_P &&
579 Inst.
getOpcode() != AMDGPU::DS_GWS_BARRIER &&
581 Inst.
getOpcode() != AMDGPU::DS_CONSUME &&
582 Inst.
getOpcode() != AMDGPU::DS_ORDERED_COUNT) {
586 setExpScore(&Inst, TII, TRI, MRI,
I, CurrScore);
590 }
else if (TII->
isFLAT(Inst)) {
593 &Inst, TII, TRI, MRI,
598 &Inst, TII, TRI, MRI,
602 }
else if (TII->
isMIMG(Inst)) {
604 setExpScore(&Inst, TII, TRI, MRI, 0, CurrScore);
607 &Inst, TII, TRI, MRI,
611 }
else if (TII->
isMTBUF(Inst)) {
613 setExpScore(&Inst, TII, TRI, MRI, 0, CurrScore);
615 }
else if (TII->
isMUBUF(Inst)) {
617 setExpScore(&Inst, TII, TRI, MRI, 0, CurrScore);
620 &Inst, TII, TRI, MRI,
625 if (TII->
isEXP(Inst)) {
642 setExpScore(&Inst, TII, TRI, MRI,
I, CurrScore);
646 #if 0 // TODO: check if this is handled by MUBUF code above. 647 }
else if (Inst.
getOpcode() == AMDGPU::BUFFER_STORE_DWORD ||
648 Inst.
getOpcode() == AMDGPU::BUFFER_STORE_DWORDX2 ||
649 Inst.
getOpcode() == AMDGPU::BUFFER_STORE_DWORDX4) {
652 RegInterval
Interval = getRegInterval(&Inst, TII, MRI, TRI, OpNo,
false);
653 for (
signed RegNo = Interval.first; RegNo < Interval.second;
655 setRegScore(RegNo + NUM_ALL_VGPRS, t, CurrScore);
661 RegInterval
Interval = getRegInterval(&Inst, TII, MRI, TRI,
I,
true);
662 if (T ==
VM_CNT && Interval.first >= NUM_ALL_VGPRS)
664 for (
signed RegNo = Interval.first; RegNo < Interval.second; ++RegNo) {
665 setRegScore(RegNo, T, CurrScore);
669 setRegScore(SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS, T, CurrScore);
678 int LB = getScoreLB(
T);
679 int UB = getScoreUB(
T);
683 OS <<
" VM_CNT(" << UB - LB <<
"): ";
686 OS <<
" LGKM_CNT(" << UB - LB <<
"): ";
689 OS <<
" EXP_CNT(" << UB - LB <<
"): ";
692 OS <<
" UNKNOWN(" << UB - LB <<
"): ";
698 for (
int J = 0; J <= getMaxVGPR(); J++) {
699 int RegScore = getRegScore(J,
T);
702 int RelScore = RegScore - LB - 1;
703 if (J < SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS) {
704 OS << RelScore <<
":v" << J <<
" ";
706 OS << RelScore <<
":ds ";
711 for (
int J = 0; J <= getMaxSGPR(); J++) {
712 int RegScore = getRegScore(J + NUM_ALL_VGPRS,
LGKM_CNT);
715 int RelScore = RegScore - LB - 1;
716 OS << RelScore <<
":s" << J <<
" ";
727 unsigned int NeedWait = 0;
728 if (ScoreToWait == -1) {
734 setScoreLB(T, getScoreUB(T));
740 const int32_t LB = getScoreLB(T);
741 const int32_t UB = getScoreUB(T);
742 if ((UB >= ScoreToWait) && (ScoreToWait > LB)) {
745 !
ST->hasFlatLgkmVMemCountInOrder()) {
750 setScoreLB(T, getScoreUB(T));
751 }
else if (counterOutOfOrder(T)) {
756 setScoreLB(T, getScoreUB(T));
759 setScoreLB(T, ScoreToWait);
773 if (EventUBs[SMEM_ACCESS] > ScoreLBs[
LGKM_CNT] &&
774 EventUBs[SMEM_ACCESS] <= ScoreUBs[
LGKM_CNT]) {
778 int NumEventTypes = 0;
779 if (EventUBs[LDS_ACCESS] > ScoreLBs[LGKM_CNT] &&
780 EventUBs[LDS_ACCESS] <= ScoreUBs[LGKM_CNT]) {
783 if (EventUBs[GDS_ACCESS] > ScoreLBs[LGKM_CNT] &&
784 EventUBs[GDS_ACCESS] <= ScoreUBs[LGKM_CNT]) {
787 if (EventUBs[SQ_MESSAGE] > ScoreLBs[LGKM_CNT] &&
788 EventUBs[SQ_MESSAGE] <= ScoreUBs[LGKM_CNT]) {
791 if (NumEventTypes <= 1) {
801 int NumEventTypes = 0;
802 if (EventUBs[EXP_GPR_LOCK] > ScoreLBs[
EXP_CNT] &&
803 EventUBs[EXP_GPR_LOCK] <= ScoreUBs[
EXP_CNT]) {
806 if (EventUBs[GDS_GPR_LOCK] > ScoreLBs[EXP_CNT] &&
807 EventUBs[GDS_GPR_LOCK] <= ScoreUBs[EXP_CNT]) {
810 if (EventUBs[VMW_GPR_LOCK] > ScoreLBs[EXP_CNT] &&
811 EventUBs[VMW_GPR_LOCK] <= ScoreUBs[EXP_CNT]) {
814 if (EventUBs[EXP_PARAM_ACCESS] > ScoreLBs[EXP_CNT] &&
815 EventUBs[EXP_PARAM_ACCESS] <= ScoreUBs[EXP_CNT]) {
819 if (EventUBs[EXP_POS_ACCESS] > ScoreLBs[EXP_CNT] &&
820 EventUBs[EXP_POS_ACCESS] <= ScoreUBs[EXP_CNT]) {
824 if (NumEventTypes <= 1) {
840 char SIInsertWaitcnts::
ID = 0;
845 return new SIInsertWaitcnts();
850 return (Opc == AMDGPU::S_CBRANCH_VCCNZ || Opc == AMDGPU::S_CBRANCH_VCCZ) &&
855 bool SIInsertWaitcnts::isWaitcntStronger(
unsigned LHS,
unsigned RHS) {
867 unsigned SIInsertWaitcnts::combineWaitcnt(
unsigned LHS,
unsigned RHS) {
887 void SIInsertWaitcnts::generateWaitcntInstBefore(
891 unsigned int EmitWaitcnt = 0;
898 bool NeedLineMapping =
false;
901 bool ForceEmitZeroWaitcnt =
false;
903 setForceEmitWaitcnt();
904 bool IsForceEmitWaitcnt = isForceEmitWaitcnt();
914 if (ScoreBrackets->getWaitAtBeginning()) {
917 ScoreBrackets->clearWaitAtBeginning();
921 ScoreBrackets->setScoreLB(
T, ScoreBrackets->getScoreUB(
T));
927 else if (MI.
getOpcode() == AMDGPU::BUFFER_WBINVL1 ||
928 MI.
getOpcode() == AMDGPU::BUFFER_WBINVL1_SC ||
929 MI.
getOpcode() == AMDGPU::BUFFER_WBINVL1_VOL) {
931 ScoreBrackets->updateByWait(
VM_CNT, ScoreBrackets->getScoreUB(
VM_CNT));
937 if (MI.
getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG ||
938 MI.
getOpcode() == AMDGPU::S_SETPC_B64_return) {
941 if (ScoreBrackets->getScoreUB(
T) > ScoreBrackets->getScoreLB(
T)) {
942 ScoreBrackets->setScoreLB(
T, ScoreBrackets->getScoreUB(
T));
948 else if ((MI.
getOpcode() == AMDGPU::S_SENDMSG ||
949 MI.
getOpcode() == AMDGPU::S_SENDMSGHALT) &&
952 if (ScoreBrackets->getScoreUB(
VM_CNT) > ScoreBrackets->getScoreLB(
VM_CNT)) {
953 ScoreBrackets->setScoreLB(
VM_CNT, ScoreBrackets->getScoreUB(
VM_CNT));
957 #if 0 // TODO: the following blocks of logic when we have fence. 959 const unsigned int group_size =
960 context->shader_info->GetMaxThreadGroupSize();
962 const bool group_is_multi_wave =
963 (group_size == 0 || group_size > target_info->GetWaveFrontSize());
964 const bool fence_is_global = !((SCInstInternalMisc*)Inst)->IsGroupFence();
966 for (
unsigned int i = 0; i < Inst->NumSrcOperands(); i++) {
967 SCRegType src_type = Inst->GetSrcType(i);
970 if (group_is_multi_wave ||
971 context->OptFlagIsOn(OPT_R1100_LDSMEM_FENCE_CHICKEN_BIT)) {
972 EmitWaitcnt |= ScoreBrackets->updateByWait(
LGKM_CNT,
973 ScoreBrackets->getScoreUB(
LGKM_CNT));
975 if (target_info->HasBufferLoadToLDS()) {
976 EmitWaitcnt |= ScoreBrackets->updateByWait(
VM_CNT,
977 ScoreBrackets->getScoreUB(
VM_CNT));
983 if (group_is_multi_wave || fence_is_global) {
984 EmitWaitcnt |= ScoreBrackets->updateByWait(
EXP_CNT,
985 ScoreBrackets->getScoreUB(
EXP_CNT));
986 EmitWaitcnt |= ScoreBrackets->updateByWait(
LGKM_CNT,
987 ScoreBrackets->getScoreUB(
LGKM_CNT));
995 if (group_is_multi_wave || fence_is_global) {
996 EmitWaitcnt |= ScoreBrackets->updateByWait(
EXP_CNT,
997 ScoreBrackets->getScoreUB(
EXP_CNT));
998 EmitWaitcnt |= ScoreBrackets->updateByWait(
VM_CNT,
999 ScoreBrackets->getScoreUB(
VM_CNT));
1019 EmitWaitcnt |= ScoreBrackets->updateByWait(
1020 EXP_CNT, ScoreBrackets->getEventUB(EXP_GPR_LOCK));
1021 EmitWaitcnt |= ScoreBrackets->updateByWait(
1022 EXP_CNT, ScoreBrackets->getEventUB(EXP_PARAM_ACCESS));
1023 EmitWaitcnt |= ScoreBrackets->updateByWait(
1024 EXP_CNT, ScoreBrackets->getEventUB(EXP_POS_ACCESS));
1025 EmitWaitcnt |= ScoreBrackets->updateByWait(
1026 EXP_CNT, ScoreBrackets->getEventUB(GDS_GPR_LOCK));
1029 #if 0 // TODO: the following code to handle CALL. 1037 if (ScoreBrackets->getScoreUB(
EXP_CNT) >
1038 ScoreBrackets->getScoreLB(
EXP_CNT)) {
1039 ScoreBrackets->setScoreLB(
EXP_CNT, ScoreBrackets->getScoreUB(
EXP_CNT));
1053 unsigned AS = Memop->getAddrSpace();
1054 if (AS != AMDGPUASI.LOCAL_ADDRESS)
1056 unsigned RegNo = SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS;
1058 EmitWaitcnt |= ScoreBrackets->updateByWait(
1066 ScoreBrackets->getRegInterval(&MI,
TII,
MRI,
TRI,
I,
false);
1067 for (
signed RegNo = Interval.first; RegNo < Interval.second; ++RegNo) {
1070 EmitWaitcnt |= ScoreBrackets->updateByWait(
1073 EmitWaitcnt |= ScoreBrackets->updateByWait(
1088 unsigned AS = Memop->getAddrSpace();
1089 if (AS != AMDGPUASI.LOCAL_ADDRESS)
1091 unsigned RegNo = SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS;
1092 EmitWaitcnt |= ScoreBrackets->updateByWait(
1094 EmitWaitcnt |= ScoreBrackets->updateByWait(
1102 ScoreBrackets->getRegInterval(&MI,
TII,
MRI,
TRI,
I,
true);
1103 for (
signed RegNo = Interval.first; RegNo < Interval.second; ++RegNo) {
1105 EmitWaitcnt |= ScoreBrackets->updateByWait(
1107 EmitWaitcnt |= ScoreBrackets->updateByWait(
1110 EmitWaitcnt |= ScoreBrackets->updateByWait(
1120 if (MI.
getOpcode() == AMDGPU::S_BARRIER &&
1121 !
ST->hasAutoWaitcntBeforeBarrier()) {
1123 ScoreBrackets->updateByWait(
VM_CNT, ScoreBrackets->getScoreUB(
VM_CNT));
1124 EmitWaitcnt |= ScoreBrackets->updateByWait(
1126 EmitWaitcnt |= ScoreBrackets->updateByWait(
1134 if (ScoreBrackets->getScoreLB(
LGKM_CNT) <
1135 ScoreBrackets->getScoreUB(
LGKM_CNT) &&
1136 ScoreBrackets->hasPendingSMEM()) {
1145 ForceEmitZeroWaitcnt =
true;
1151 if (EmitWaitcnt || IsForceEmitWaitcnt) {
1152 int CntVal[NUM_INST_CNTS];
1154 bool UseDefaultWaitcntStrategy =
true;
1155 if (ForceEmitZeroWaitcnt || ForceEmitZeroWaitcnts) {
1159 ScoreBrackets->setScoreLB(
T, ScoreBrackets->getScoreUB(
T));
1164 UseDefaultWaitcntStrategy =
false;
1167 if (UseDefaultWaitcntStrategy) {
1172 ScoreBrackets->getScoreUB(
T) - ScoreBrackets->getScoreLB(
T);
1173 int MaxDelta = ScoreBrackets->getWaitCountMax(
T);
1174 if (Delta >= MaxDelta) {
1177 ScoreBrackets->setScoreLB(
1178 T, ScoreBrackets->getScoreUB(
T) - MaxDelta);
1192 if (EmitWaitcnt != 0 || IsForceEmitWaitcnt) {
1193 MachineInstr *OldWaitcnt = ScoreBrackets->getWaitcnt();
1203 if (ContainingLoop) {
1205 BlockWaitcntBrackets *ScoreBracket =
1206 BlockWaitcntBracketsMap[TBB].get();
1207 if (!ScoreBracket) {
1208 assert(!BlockVisitedSet.count(TBB));
1209 BlockWaitcntBracketsMap[TBB] =
1210 llvm::make_unique<BlockWaitcntBrackets>(
ST);
1211 ScoreBracket = BlockWaitcntBracketsMap[TBB].get();
1213 ScoreBracket->setRevisitLoop(
true);
1215 <<
"set-revisit2: Block" 1228 bool insertSWaitInst =
true;
1231 insertSWaitInst &&
I !=
B; --
I) {
1235 switch (
I->getOpcode()) {
1236 case AMDGPU::S_WAITCNT:
1237 if (isWaitcntStronger(
I->getOperand(0).getImm(), Enc))
1238 insertSWaitInst =
false;
1239 else if (!OldWaitcnt) {
1241 Enc = combineWaitcnt(
I->getOperand(0).getImm(), Enc);
1248 if (insertSWaitInst) {
1249 if (OldWaitcnt && OldWaitcnt->
getOpcode() == AMDGPU::S_WAITCNT) {
1250 if (ForceEmitZeroWaitcnts)
1253 <<
"Force emit s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)\n");
1254 if (IsForceEmitWaitcnt)
1256 <<
"Force emit a s_waitcnt due to debug counter\n");
1263 <<
"Old Instr: " << MI <<
'\n' 1264 <<
"New Instr: " << *OldWaitcnt <<
'\n');
1269 TrackedWaitcntSet.insert(SWaitInst);
1272 <<
"Old Instr: " << MI <<
'\n' 1273 <<
"New Instr: " << *SWaitInst <<
'\n');
1277 if (CntVal[EXP_CNT] == 0) {
1278 ScoreBrackets->setMixedExpTypes(
false);
1302 bool SIInsertWaitcnts::mayAccessLDSThroughFlat(
const MachineInstr &MI)
const {
1307 unsigned AS = Memop->getAddrSpace();
1308 if (AS == AMDGPUASI.LOCAL_ADDRESS || AS == AMDGPUASI.FLAT_ADDRESS)
1315 void SIInsertWaitcnts::updateEventWaitcntAfter(
1316 MachineInstr &Inst, BlockWaitcntBrackets *ScoreBrackets) {
1321 if (
TII->isDS(Inst) &&
TII->usesLGKM_CNT(Inst)) {
1322 if (
TII->hasModifiersSet(Inst, AMDGPU::OpName::gds)) {
1323 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, GDS_ACCESS, Inst);
1324 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, GDS_GPR_LOCK, Inst);
1326 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, LDS_ACCESS, Inst);
1328 }
else if (
TII->isFLAT(Inst)) {
1331 if (
TII->usesVM_CNT(Inst))
1332 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, VMEM_ACCESS, Inst);
1334 if (
TII->usesLGKM_CNT(Inst)) {
1335 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, LDS_ACCESS, Inst);
1340 if (mayAccessLDSThroughFlat(Inst))
1341 ScoreBrackets->setPendingFlat();
1345 Inst.
getOpcode() != AMDGPU::BUFFER_WBINVL1 &&
1346 Inst.
getOpcode() != AMDGPU::BUFFER_WBINVL1_SC &&
1347 Inst.
getOpcode() != AMDGPU::BUFFER_WBINVL1_VOL) {
1348 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, VMEM_ACCESS, Inst);
1349 if (
ST->vmemWriteNeedsExpWaitcnt() &&
1351 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, VMW_GPR_LOCK, Inst);
1353 }
else if (
TII->isSMRD(Inst)) {
1354 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, SMEM_ACCESS, Inst);
1357 case AMDGPU::S_SENDMSG:
1358 case AMDGPU::S_SENDMSGHALT:
1359 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, SQ_MESSAGE, Inst);
1362 case AMDGPU::EXP_DONE: {
1363 int Imm =
TII->getNamedOperand(Inst, AMDGPU::OpName::tgt)->getImm();
1364 if (Imm >= 32 && Imm <= 63)
1365 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, EXP_PARAM_ACCESS, Inst);
1366 else if (Imm >= 12 && Imm <= 15)
1367 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, EXP_POS_ACCESS, Inst);
1369 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, EXP_GPR_LOCK, Inst);
1372 case AMDGPU::S_MEMTIME:
1373 case AMDGPU::S_MEMREALTIME:
1374 ScoreBrackets->updateByEvent(
TII,
TRI,
MRI, SMEM_ACCESS, Inst);
1385 BlockWaitcntBrackets *ScoreBrackets = BlockWaitcntBracketsMap[&Block].get();
1386 int32_t MaxPending[NUM_INST_CNTS] = {0};
1387 int32_t MaxFlat[NUM_INST_CNTS] = {0};
1388 bool MixedExpTypes =
false;
1396 std::unique_ptr<BlockWaitcntBrackets> S;
1401 S = llvm::make_unique<BlockWaitcntBrackets>(*ScoreBrackets);
1402 ScoreBrackets = S.get();
1405 ScoreBrackets->clear();
1410 BlockWaitcntBrackets *PredScoreBrackets =
1411 BlockWaitcntBracketsMap[Pred].get();
1412 bool Visited = BlockVisitedSet.count(Pred);
1413 if (!Visited || PredScoreBrackets->getWaitAtBeginning()) {
1419 PredScoreBrackets->getScoreUB(
T) - PredScoreBrackets->getScoreLB(
T);
1420 MaxPending[
T] =
std::max(MaxPending[
T], span);
1422 PredScoreBrackets->pendingFlat(T) - PredScoreBrackets->getScoreLB(T);
1423 MaxFlat[
T] =
std::max(MaxFlat[T], span);
1426 MixedExpTypes |= PredScoreBrackets->mixedExpTypes();
1431 if (Block.
succ_empty() && !KillWaitBrackets.empty()) {
1432 for (
unsigned int I = 0;
I < KillWaitBrackets.size();
I++) {
1435 int Span = KillWaitBrackets[
I]->getScoreUB(
T) -
1436 KillWaitBrackets[
I]->getScoreLB(
T);
1437 MaxPending[
T] =
std::max(MaxPending[
T], Span);
1438 Span = KillWaitBrackets[
I]->pendingFlat(T) -
1439 KillWaitBrackets[
I]->getScoreLB(T);
1440 MaxFlat[
T] =
std::max(MaxFlat[T], Span);
1443 MixedExpTypes |= KillWaitBrackets[
I]->mixedExpTypes();
1449 BlockWaitcntBrackets *PredScoreBrackets =
1450 BlockWaitcntBracketsMap[Pred].get();
1451 bool Visited = BlockVisitedSet.count(Pred);
1452 if (!Visited || PredScoreBrackets->getWaitAtBeginning()) {
1456 int GDSSpan = PredScoreBrackets->getEventUB(GDS_GPR_LOCK) -
1457 PredScoreBrackets->getScoreLB(
EXP_CNT);
1459 int EXPSpan = PredScoreBrackets->getEventUB(EXP_GPR_LOCK) -
1460 PredScoreBrackets->getScoreLB(EXP_CNT);
1465 if (Block.
succ_empty() && !KillWaitBrackets.empty()) {
1466 for (
unsigned int I = 0;
I < KillWaitBrackets.size();
I++) {
1467 int GDSSpan = KillWaitBrackets[
I]->getEventUB(GDS_GPR_LOCK) -
1468 KillWaitBrackets[
I]->getScoreLB(
EXP_CNT);
1470 int EXPSpan = KillWaitBrackets[
I]->getEventUB(EXP_GPR_LOCK) -
1471 KillWaitBrackets[
I]->getScoreLB(EXP_CNT);
1482 ScoreBrackets->setWaitAtBeginning();
1490 ScoreBrackets->setScoreUB(
T, MaxPending[
T]);
1491 ScoreBrackets->setScoreLB(T, 0);
1492 ScoreBrackets->setLastFlat(T, MaxFlat[T]);
1495 ScoreBrackets->setMixedExpTypes(MixedExpTypes);
1499 if (!BlockVisitedSet.count(Pred)) {
1503 BlockWaitcntBrackets *PredScoreBrackets =
1504 BlockWaitcntBracketsMap[Pred].get();
1509 int PredLB = PredScoreBrackets->getScoreLB(
T);
1510 int PredUB = PredScoreBrackets->getScoreUB(
T);
1511 if (PredLB < PredUB) {
1512 int PredScale = MaxPending[
T] - PredUB;
1514 for (
int J = 0; J <= PredScoreBrackets->getMaxVGPR(); J++) {
1515 int PredRegScore = PredScoreBrackets->getRegScore(J,
T);
1516 if (PredRegScore <= PredLB)
1518 int NewRegScore = PredScale + PredRegScore;
1519 ScoreBrackets->setRegScore(
1520 J,
T,
std::max(ScoreBrackets->getRegScore(J,
T), NewRegScore));
1524 for (
int J = 0; J <= PredScoreBrackets->getMaxSGPR(); J++) {
1526 PredScoreBrackets->getRegScore(J + NUM_ALL_VGPRS,
LGKM_CNT);
1527 if (PredRegScore <= PredLB)
1529 int NewRegScore = PredScale + PredRegScore;
1530 ScoreBrackets->setRegScore(
1533 ScoreBrackets->getRegScore(J + NUM_ALL_VGPRS,
LGKM_CNT),
1543 int PredEventUB = PredScoreBrackets->getEventUB(
W);
1544 if (PredEventUB > PredScoreBrackets->getScoreLB(T)) {
1546 MaxPending[
T] + PredEventUB - PredScoreBrackets->getScoreUB(T);
1547 if (NewEventUB > 0) {
1548 ScoreBrackets->setEventUB(
1549 W,
std::max(ScoreBrackets->getEventUB(
W), NewEventUB));
1557 if (Block.
succ_empty() && !KillWaitBrackets.empty()) {
1558 for (
unsigned int I = 0;
I < KillWaitBrackets.size();
I++) {
1562 int PredLB = KillWaitBrackets[
I]->getScoreLB(
T);
1563 int PredUB = KillWaitBrackets[
I]->getScoreUB(
T);
1564 if (PredLB < PredUB) {
1565 int PredScale = MaxPending[
T] - PredUB;
1567 for (
int J = 0; J <= KillWaitBrackets[
I]->getMaxVGPR(); J++) {
1568 int PredRegScore = KillWaitBrackets[
I]->getRegScore(J,
T);
1569 if (PredRegScore <= PredLB)
1571 int NewRegScore = PredScale + PredRegScore;
1572 ScoreBrackets->setRegScore(
1573 J,
T,
std::max(ScoreBrackets->getRegScore(J,
T), NewRegScore));
1577 for (
int J = 0; J <= KillWaitBrackets[
I]->getMaxSGPR(); J++) {
1579 KillWaitBrackets[
I]->getRegScore(J + NUM_ALL_VGPRS,
LGKM_CNT);
1580 if (PredRegScore <= PredLB)
1582 int NewRegScore = PredScale + PredRegScore;
1583 ScoreBrackets->setRegScore(
1586 ScoreBrackets->getRegScore(J + NUM_ALL_VGPRS,
LGKM_CNT),
1596 int PredEventUB = KillWaitBrackets[
I]->getEventUB(
W);
1597 if (PredEventUB > KillWaitBrackets[
I]->getScoreLB(T)) {
1599 MaxPending[
T] + PredEventUB - KillWaitBrackets[
I]->getScoreUB(T);
1600 if (NewEventUB > 0) {
1601 ScoreBrackets->setEventUB(
1602 W,
std::max(ScoreBrackets->getEventUB(
W), NewEventUB));
1613 if (!BlockVisitedSet.count(Pred)) {
1617 BlockWaitcntBrackets *PredScoreBrackets =
1618 BlockWaitcntBracketsMap[Pred].get();
1620 int pred_gds_ub = PredScoreBrackets->getEventUB(GDS_GPR_LOCK);
1621 if (pred_gds_ub > PredScoreBrackets->getScoreLB(
EXP_CNT)) {
1622 int new_gds_ub = MaxPending[
EXP_CNT] + pred_gds_ub -
1623 PredScoreBrackets->getScoreUB(
EXP_CNT);
1624 if (new_gds_ub > 0) {
1625 ScoreBrackets->setEventUB(
1627 std::max(ScoreBrackets->getEventUB(GDS_GPR_LOCK), new_gds_ub));
1630 int pred_exp_ub = PredScoreBrackets->getEventUB(EXP_GPR_LOCK);
1631 if (pred_exp_ub > PredScoreBrackets->getScoreLB(
EXP_CNT)) {
1632 int new_exp_ub = MaxPending[
EXP_CNT] + pred_exp_ub -
1633 PredScoreBrackets->getScoreUB(
EXP_CNT);
1634 if (new_exp_ub > 0) {
1635 ScoreBrackets->setEventUB(
1637 std::max(ScoreBrackets->getEventUB(EXP_GPR_LOCK), new_exp_ub));
1645 BlockWaitcntBracketsMap[&Block] = llvm::make_unique<BlockWaitcntBrackets>(*ScoreBrackets);
1663 unsigned SIInsertWaitcnts::countNumBottomBlocks(
const MachineLoop *Loop) {
1677 mergeInputScoreBrackets(Block);
1679 BlockWaitcntBrackets *ScoreBrackets = BlockWaitcntBracketsMap[&Block].get();
1683 ScoreBrackets->dump();
1691 if (Inst.
getOpcode() == AMDGPU::S_WAITCNT) {
1695 if (!TrackedWaitcntSet.count(&Inst))
1701 ScoreBrackets->setWaitcnt(&Inst);
1709 addKillWaitBracket(ScoreBrackets);
1712 bool VCCZBugWorkAround =
false;
1714 (!VCCZBugHandledSet.count(&Inst))) {
1715 if (ScoreBrackets->getScoreLB(
LGKM_CNT) <
1716 ScoreBrackets->getScoreUB(
LGKM_CNT) &&
1717 ScoreBrackets->hasPendingSMEM()) {
1719 VCCZBugWorkAround =
true;
1725 generateWaitcntInstBefore(Inst, ScoreBrackets);
1727 updateEventWaitcntAfter(Inst, ScoreBrackets);
1729 #if 0 // TODO: implement resource type check controlled by options with ub = LB. 1733 if (RequireCheckResourceType(Inst, context)) {
1735 ScoreBrackets->setScoreLB(
VM_CNT,
1736 ScoreBrackets->getScoreUB(
VM_CNT));
1740 ScoreBrackets->clearWaitcnt();
1744 ScoreBrackets->dump();
1750 if (Inst.
getOpcode() == AMDGPU::DS_GWS_INIT ||
1751 Inst.
getOpcode() == AMDGPU::DS_GWS_SEMA_V ||
1752 Inst.
getOpcode() == AMDGPU::DS_GWS_SEMA_BR ||
1753 Inst.
getOpcode() == AMDGPU::DS_GWS_SEMA_P ||
1754 Inst.
getOpcode() == AMDGPU::DS_GWS_BARRIER) {
1756 ScoreBrackets->updateByWait(
VM_CNT, ScoreBrackets->getScoreUB(
VM_CNT));
1757 ScoreBrackets->updateByWait(
EXP_CNT, ScoreBrackets->getScoreUB(
EXP_CNT));
1758 ScoreBrackets->updateByWait(
LGKM_CNT,
1759 ScoreBrackets->getScoreUB(
LGKM_CNT));
1764 if (VCCZBugWorkAround) {
1770 .addReg(AMDGPU::VCC);
1771 VCCZBugHandledSet.insert(&Inst);
1778 MachineLoop *ContainingLoop = MLI->getLoopFor(&Block);
1779 if (ContainingLoop && isLoopBottom(ContainingLoop, &Block)) {
1780 LoopWaitcntData *WaitcntData = LoopWaitcntDataMap[ContainingLoop].get();
1781 WaitcntData->print();
1790 if (WaitcntData->getIterCnt() > (countNumBottomBlocks(ContainingLoop) + 1)) {
1795 bool HasPending =
false;
1799 if (ScoreBrackets->getScoreUB(
T) > ScoreBrackets->getScoreLB(
T)) {
1800 ScoreBrackets->setScoreLB(
T, ScoreBrackets->getScoreUB(
T));
1811 TrackedWaitcntSet.insert(SWaitInst);
1812 #if 0 // TODO: Format the debug output 1813 OutputTransformBanner(
"insertWaitcntInBlock",0,
"Create:",context);
1814 OutputTransformAdd(SWaitInst, context);
1818 _DEV( REPORTED_STATS->force_waitcnt_converge = 1; )
1825 dbgs() <<
"\nAdjusted score board:";
1826 ScoreBrackets->dump();
1832 insertWaitcntBeforeCF(Block, SWaitInst);
1833 WaitcntData->setWaitcnt(SWaitInst);
1841 TII =
ST->getInstrInfo();
1844 MLI = &getAnalysis<MachineLoopInfo>();
1847 AMDGPUASI =
ST->getAMDGPUAS();
1852 ForceEmitWaitcnt[
T] =
false;
1858 HardwareLimits.NumVGPRsMax =
ST->getAddressableNumVGPRs();
1859 HardwareLimits.NumSGPRsMax =
ST->getAddressableNumSGPRs();
1860 assert(HardwareLimits.NumVGPRsMax <= SQ_MAX_PGM_VGPRS);
1861 assert(HardwareLimits.NumSGPRsMax <= SQ_MAX_PGM_SGPRS);
1863 RegisterEncoding.VGPR0 =
TRI->getEncodingValue(AMDGPU::VGPR0);
1864 RegisterEncoding.VGPRL =
1865 RegisterEncoding.VGPR0 + HardwareLimits.NumVGPRsMax - 1;
1866 RegisterEncoding.SGPR0 =
TRI->getEncodingValue(AMDGPU::SGPR0);
1867 RegisterEncoding.SGPRL =
1868 RegisterEncoding.SGPR0 + HardwareLimits.NumSGPRsMax - 1;
1870 TrackedWaitcntSet.clear();
1871 BlockVisitedSet.clear();
1872 VCCZBugHandledSet.clear();
1873 LoopWaitcntDataMap.clear();
1874 BlockWaitcntProcessedSet.clear();
1886 BlockVisitedSet.insert(&MBB);
1888 BlockWaitcntBrackets *ScoreBrackets = BlockWaitcntBracketsMap[&MBB].get();
1889 if (!ScoreBrackets) {
1890 BlockWaitcntBracketsMap[&MBB] = llvm::make_unique<BlockWaitcntBrackets>(
ST);
1891 ScoreBrackets = BlockWaitcntBracketsMap[&MBB].get();
1893 ScoreBrackets->setPostOrder(MBB.
getNumber());
1894 MachineLoop *ContainingLoop = MLI->getLoopFor(&MBB);
1895 if (ContainingLoop && LoopWaitcntDataMap[ContainingLoop] ==
nullptr)
1896 LoopWaitcntDataMap[ContainingLoop] = llvm::make_unique<LoopWaitcntData>();
1901 if (ContainingLoop && ContainingLoop->
getHeader() == &MBB) {
1902 unsigned Count = countNumBottomBlocks(ContainingLoop);
1906 if ((
std::count(BlockWaitcntProcessedSet.begin(),
1907 BlockWaitcntProcessedSet.end(), &MBB) < (
int)Count)) {
1908 BlockWaitcntBracketsMap[&MBB]->setRevisitLoop(
true);
1915 insertWaitcntInBlock(MF, MBB);
1918 BlockWaitcntProcessedSet.push_back(&MBB);
1922 if (ContainingLoop && isLoopBottom(ContainingLoop, &MBB) &&
1924 BlockWaitcntProcessedSet.end(), &MBB) == 1) {
1926 BlockWaitcntBrackets *EntrySB = BlockWaitcntBracketsMap[EntryBB].get();
1927 if (EntrySB && EntrySB->getRevisitLoop()) {
1928 EntrySB->setRevisitLoop(
false);
1930 int32_t PostOrder = EntrySB->getPostOrder();
1942 LoopWaitcntData *WaitcntData = LoopWaitcntDataMap[ContainingLoop].get();
1943 WaitcntData->incIterCnt();
1947 LoopWaitcntData *WaitcntData = LoopWaitcntDataMap[ContainingLoop].get();
1951 WaitcntData->resetIterCnt();
1961 bool HaveScalarStores =
false;
1969 if (!HaveScalarStores && TII->isScalarStore(*
I))
1970 HaveScalarStores =
true;
1972 if (
I->getOpcode() == AMDGPU::S_ENDPGM ||
1973 I->getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG)
1978 if (HaveScalarStores) {
1987 bool SeenDCacheWB =
false;
1991 if (
I->getOpcode() == AMDGPU::S_DCACHE_WB)
1992 SeenDCacheWB =
true;
1993 else if (TII->isScalarStore(*
I))
1994 SeenDCacheWB =
false;
1997 if ((
I->getOpcode() == AMDGPU::S_ENDPGM ||
1998 I->getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG) &&
2001 BuildMI(*MBB,
I,
I->getDebugLoc(), TII->
get(AMDGPU::S_DCACHE_WB));
2007 if (!MFI->isEntryFunction()) {
void push_back(const T &Elt)
static cl::opt< unsigned > ForceEmitZeroFlag("amdgpu-waitcnt-forcezero", cl::desc("Force all waitcnt instrs to be emitted as s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)"), cl::init(0), cl::Hidden)
Interface definition for SIRegisterInfo.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool modifiesRegister(unsigned Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
AMDGPU specific subclass of TargetSubtarget.
Compute iterated dominance frontiers using a linear time algorithm.
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
Implements a dense probed hash-table based set.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const TargetRegisterClass * getOpRegClass(const MachineInstr &MI, unsigned OpNo) const
Return the correct register class for OpNo.
unsigned getReg() const
getReg - Returns the register number.
unsigned getSubReg() const
unsigned const TargetRegisterInfo * TRI
iterator_range< mmo_iterator > memoperands()
LLVM_READONLY int getAtomicNoRetOp(uint16_t Opcode)
FunctionPass * createSIInsertWaitcntsPass()
DEBUG_COUNTER(ForceExpCounter, DEBUG_TYPE"-forceexp", "Force emit s_waitcnt expcnt(0) instrs")
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static bool isDS(const MachineInstr &MI)
static const AMDGPUSubtarget & get(const MachineFunction &MF)
AnalysisUsage & addRequired()
A description of a memory reference used in the backend.
static bool isFLAT(const MachineInstr &MI)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
OpenCL uses address spaces to differentiate between various memory regions on the hardware...
const HexagonInstrInfo * TII
bool isSGPRReg(const MachineRegisterInfo &MRI, unsigned Reg) const
unsigned getNumOperands() const
Access to explicit operands of the instruction.
static bool isMIMG(const MachineInstr &MI)
static bool readsVCCZ(const MachineInstr &MI)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
This file provides an implementation of debug counters.
BlockT * getHeader() const
bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const
static bool isMUBUF(const MachineInstr &MI)
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
static bool isCounterSet(unsigned ID)
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
Instruction set architecture version.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void setImm(int64_t immVal)
FunctionPass class - This class is used to implement most global optimizations.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
self_iterator getIterator()
static bool shouldExecute(unsigned CounterName)
iterator_range< pred_iterator > predecessors()
void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
const MachineBasicBlock & front() const
pred_iterator pred_begin()
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
bool isDebugInstr() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isEXP(const MachineInstr &MI)
unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
char & SIInsertWaitcntsID
unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version)
Iterator for intrusive lists based on ilist_node.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned getExpcntBitMask(const IsaInfo::IsaVersion &Version)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static void clear(coro::Shape &Shape)
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
INITIALIZE_PASS_BEGIN(SIInsertWaitcnts, DEBUG_TYPE, "SI Insert Waitcnts", false, false) INITIALIZE_PASS_END(SIInsertWaitcnts
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
static bool isMTBUF(const MachineInstr &MI)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
Represents a single loop in the control flow graph.
unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt)
Encodes Vmcnt, Expcnt and Lgkmcnt into Waitcnt for given isa Version.
void push_back(MachineInstr *MI)
static bool isVMEM(const MachineInstr &MI)
typename std::vector< NodeRef >::reverse_iterator rpo_iterator
unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version)
#define ForAllWaitEventType(w)
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it. ...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
bool memoperands_empty() const
Return true if we don't have any memory operands which described the memory access done by this instr...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
const MachineOperand & getOperand(unsigned i) const
iterator_range< block_iterator > blocks() const
IsaVersion getIsaVersion(const FeatureBitset &Features)
const SIRegisterInfo * getRegisterInfo() const override