46#define DEBUG_TYPE "si-insert-waitcnts"
49 "Force emit s_waitcnt expcnt(0) instrs");
51 "Force emit s_waitcnt lgkmcnt(0) instrs");
53 "Force emit s_waitcnt vmcnt(0) instrs");
57 cl::desc(
"Force all waitcnt instrs to be emitted as "
58 "s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)"),
62 "amdgpu-waitcnt-load-forcezero",
63 cl::desc(
"Force all waitcnt load counters to wait until 0"),
67 "amdgpu-expert-scheduling-mode",
68 cl::desc(
"Enable expert scheduling mode 2 for all functions (GFX12+ only)"),
82 SAMPLE_CNT = NUM_NORMAL_INST_CNTS,
86 NUM_EXTENDED_INST_CNTS,
87 VA_VDST = NUM_EXTENDED_INST_CNTS,
90 NUM_INST_CNTS = NUM_EXPERT_INST_CNTS
104auto inst_counter_types(InstCounterType MaxCounter = NUM_INST_CNTS) {
105 return enum_seq(LOAD_CNT, MaxCounter);
123 TRACKINGID_RANGE_LEN = (1 << 16),
128 REGUNITS_END = REGUNITS_BEGIN + TRACKINGID_RANGE_LEN,
133 NUM_LDSDMA = TRACKINGID_RANGE_LEN,
134 LDSDMA_BEGIN = REGUNITS_END,
135 LDSDMA_END = LDSDMA_BEGIN + NUM_LDSDMA,
139static constexpr VMEMID toVMEMID(MCRegUnit RU) {
140 return static_cast<unsigned>(RU);
143struct HardwareLimits {
147 unsigned StorecntMax;
148 unsigned SamplecntMax;
156#define AMDGPU_DECLARE_WAIT_EVENTS(DECL) \
158 DECL(VMEM_SAMPLER_READ_ACCESS) \
159 DECL(VMEM_BVH_READ_ACCESS) \
160 DECL(GLOBAL_INV_ACCESS) \
161 DECL(VMEM_WRITE_ACCESS) \
162 DECL(SCRATCH_WRITE_ACCESS) \
172 DECL(EXP_POS_ACCESS) \
173 DECL(EXP_PARAM_ACCESS) \
175 DECL(EXP_LDS_ACCESS) \
176 DECL(VGPR_CSMACC_WRITE) \
177 DECL(VGPR_DPMACC_WRITE) \
178 DECL(VGPR_TRANS_WRITE) \
179 DECL(VGPR_XDL_WRITE) \
180 DECL(VGPR_LDS_READ) \
181 DECL(VGPR_FLAT_READ) \
185#define AMDGPU_EVENT_ENUM(Name) Name,
190#undef AMDGPU_EVENT_ENUM
192#define AMDGPU_EVENT_NAME(Name) #Name,
196#undef AMDGPU_EVENT_NAME
217static const unsigned instrsForExtendedCounterTypes[NUM_EXTENDED_INST_CNTS] = {
218 AMDGPU::S_WAIT_LOADCNT, AMDGPU::S_WAIT_DSCNT, AMDGPU::S_WAIT_EXPCNT,
219 AMDGPU::S_WAIT_STORECNT, AMDGPU::S_WAIT_SAMPLECNT, AMDGPU::S_WAIT_BVHCNT,
220 AMDGPU::S_WAIT_KMCNT, AMDGPU::S_WAIT_XCNT};
228static bool isNormalMode(InstCounterType MaxCounter) {
229 return MaxCounter == NUM_NORMAL_INST_CNTS;
234 assert(updateVMCntOnly(Inst));
236 return VMEM_NOSAMPLER;
250 return VMEM_NOSAMPLER;
262 return Wait.StoreCnt;
264 return Wait.SampleCnt;
281 unsigned &WC = getCounterRef(
Wait,
T);
282 WC = std::min(WC,
Count);
286 getCounterRef(
Wait,
T) = ~0
u;
290 return getCounterRef(
Wait,
T);
294InstCounterType eventCounter(
const unsigned *masks, WaitEventType
E) {
295 for (
auto T : inst_counter_types()) {
296 if (masks[
T] & (1 <<
E))
302class WaitcntBrackets;
310class WaitcntGenerator {
312 const GCNSubtarget *ST =
nullptr;
313 const SIInstrInfo *TII =
nullptr;
314 AMDGPU::IsaVersion IV;
315 InstCounterType MaxCounter;
319 WaitcntGenerator() =
default;
320 WaitcntGenerator(
const MachineFunction &MF, InstCounterType MaxCounter)
321 : ST(&MF.getSubtarget<GCNSubtarget>()), TII(ST->getInstrInfo()),
328 bool isOptNone()
const {
return OptNone; }
342 applyPreexistingWaitcnt(WaitcntBrackets &ScoreBrackets,
343 MachineInstr &OldWaitcntInstr, AMDGPU::Waitcnt &
Wait,
347 bool promoteSoftWaitCnt(MachineInstr *Waitcnt)
const;
351 virtual bool createNewWaitcnt(MachineBasicBlock &
Block,
353 AMDGPU::Waitcnt
Wait) = 0;
357 virtual const unsigned *getWaitEventMask()
const = 0;
361 virtual AMDGPU::Waitcnt getAllZeroWaitcnt(
bool IncludeVSCnt)
const = 0;
363 virtual ~WaitcntGenerator() =
default;
366 static constexpr unsigned
367 eventMask(std::initializer_list<WaitEventType> Events) {
369 for (
auto &
E : Events)
376class WaitcntGeneratorPreGFX12 :
public WaitcntGenerator {
378 using WaitcntGenerator::WaitcntGenerator;
381 applyPreexistingWaitcnt(WaitcntBrackets &ScoreBrackets,
382 MachineInstr &OldWaitcntInstr, AMDGPU::Waitcnt &
Wait,
385 bool createNewWaitcnt(MachineBasicBlock &
Block,
387 AMDGPU::Waitcnt
Wait)
override;
389 const unsigned *getWaitEventMask()
const override {
392 static const unsigned WaitEventMaskForInstPreGFX12[NUM_INST_CNTS] = {
394 {VMEM_ACCESS, VMEM_SAMPLER_READ_ACCESS, VMEM_BVH_READ_ACCESS}),
395 eventMask({SMEM_ACCESS, LDS_ACCESS, GDS_ACCESS, SQ_MESSAGE}),
396 eventMask({EXP_GPR_LOCK, GDS_GPR_LOCK, VMW_GPR_LOCK, EXP_PARAM_ACCESS,
397 EXP_POS_ACCESS, EXP_LDS_ACCESS}),
398 eventMask({VMEM_WRITE_ACCESS, SCRATCH_WRITE_ACCESS}),
406 return WaitEventMaskForInstPreGFX12;
409 AMDGPU::Waitcnt getAllZeroWaitcnt(
bool IncludeVSCnt)
const override;
412class WaitcntGeneratorGFX12Plus :
public WaitcntGenerator {
417 WaitcntGeneratorGFX12Plus() =
default;
418 WaitcntGeneratorGFX12Plus(
const MachineFunction &MF,
419 InstCounterType MaxCounter,
bool IsExpertMode)
420 : WaitcntGenerator(MF, MaxCounter), IsExpertMode(IsExpertMode) {}
423 applyPreexistingWaitcnt(WaitcntBrackets &ScoreBrackets,
424 MachineInstr &OldWaitcntInstr, AMDGPU::Waitcnt &
Wait,
427 bool createNewWaitcnt(MachineBasicBlock &
Block,
429 AMDGPU::Waitcnt
Wait)
override;
431 const unsigned *getWaitEventMask()
const override {
434 static const unsigned WaitEventMaskForInstGFX12Plus[NUM_INST_CNTS] = {
435 eventMask({VMEM_ACCESS, GLOBAL_INV_ACCESS}),
436 eventMask({LDS_ACCESS, GDS_ACCESS}),
437 eventMask({EXP_GPR_LOCK, GDS_GPR_LOCK, VMW_GPR_LOCK, EXP_PARAM_ACCESS,
438 EXP_POS_ACCESS, EXP_LDS_ACCESS}),
439 eventMask({VMEM_WRITE_ACCESS, SCRATCH_WRITE_ACCESS}),
440 eventMask({VMEM_SAMPLER_READ_ACCESS}),
441 eventMask({VMEM_BVH_READ_ACCESS}),
442 eventMask({SMEM_ACCESS, SQ_MESSAGE, SCC_WRITE}),
443 eventMask({VMEM_GROUP, SMEM_GROUP}),
444 eventMask({VGPR_CSMACC_WRITE, VGPR_DPMACC_WRITE, VGPR_TRANS_WRITE,
446 eventMask({VGPR_LDS_READ, VGPR_FLAT_READ, VGPR_VMEM_READ})};
448 return WaitEventMaskForInstGFX12Plus;
451 AMDGPU::Waitcnt getAllZeroWaitcnt(
bool IncludeVSCnt)
const override;
454class SIInsertWaitcnts {
456 const GCNSubtarget *ST;
457 const SIInstrInfo *TII =
nullptr;
458 const SIRegisterInfo *TRI =
nullptr;
459 const MachineRegisterInfo *MRI =
nullptr;
460 InstCounterType SmemAccessCounter;
461 InstCounterType MaxCounter;
462 bool IsExpertMode =
false;
463 const unsigned *WaitEventMaskForInst;
466 DenseMap<const Value *, MachineBasicBlock *> SLoadAddresses;
467 DenseMap<MachineBasicBlock *, bool> PreheadersToFlush;
468 MachineLoopInfo *MLI;
469 MachinePostDominatorTree *PDT;
473 std::unique_ptr<WaitcntBrackets> Incoming;
477 MapVector<MachineBasicBlock *, BlockInfo> BlockInfos;
479 bool ForceEmitWaitcnt[NUM_INST_CNTS];
484 WaitcntGeneratorPreGFX12 WCGPreGFX12;
485 WaitcntGeneratorGFX12Plus WCGGFX12Plus;
487 WaitcntGenerator *WCG =
nullptr;
490 DenseSet<MachineInstr *> CallInsts;
491 DenseSet<MachineInstr *> ReturnInsts;
495 DenseSet<MachineInstr *> ReleaseVGPRInsts;
497 HardwareLimits Limits;
500 SIInsertWaitcnts(MachineLoopInfo *MLI, MachinePostDominatorTree *PDT,
502 : MLI(MLI), PDT(PDT), AA(AA) {
503 (void)ForceExpCounter;
504 (void)ForceLgkmCounter;
505 (void)ForceVMCounter;
508 unsigned getWaitCountMax(InstCounterType
T)
const {
511 return Limits.LoadcntMax;
513 return Limits.DscntMax;
515 return Limits.ExpcntMax;
517 return Limits.StorecntMax;
519 return Limits.SamplecntMax;
521 return Limits.BvhcntMax;
523 return Limits.KmcntMax;
525 return Limits.XcntMax;
527 return Limits.VaVdstMax;
529 return Limits.VmVsrcMax;
536 bool shouldFlushVmCnt(MachineLoop *
ML,
const WaitcntBrackets &Brackets);
537 bool isPreheaderToFlush(MachineBasicBlock &
MBB,
538 const WaitcntBrackets &ScoreBrackets);
539 bool isVMEMOrFlatVMEM(
const MachineInstr &
MI)
const;
540 bool run(MachineFunction &MF);
542 void setForceEmitWaitcnt() {
548 ForceEmitWaitcnt[
EXP_CNT] =
true;
550 ForceEmitWaitcnt[
EXP_CNT] =
false;
555 ForceEmitWaitcnt[DS_CNT] =
true;
556 ForceEmitWaitcnt[KM_CNT] =
true;
558 ForceEmitWaitcnt[DS_CNT] =
false;
559 ForceEmitWaitcnt[KM_CNT] =
false;
564 ForceEmitWaitcnt[LOAD_CNT] =
true;
565 ForceEmitWaitcnt[SAMPLE_CNT] =
true;
566 ForceEmitWaitcnt[BVH_CNT] =
true;
568 ForceEmitWaitcnt[LOAD_CNT] =
false;
569 ForceEmitWaitcnt[SAMPLE_CNT] =
false;
570 ForceEmitWaitcnt[BVH_CNT] =
false;
573 ForceEmitWaitcnt[VA_VDST] =
false;
574 ForceEmitWaitcnt[VM_VSRC] =
false;
580 WaitEventType getVmemWaitEventType(
const MachineInstr &Inst)
const {
583 case AMDGPU::GLOBAL_INV:
584 return GLOBAL_INV_ACCESS;
586 case AMDGPU::GLOBAL_WB:
587 case AMDGPU::GLOBAL_WBINV:
588 return VMEM_WRITE_ACCESS;
594 static const WaitEventType VmemReadMapping[NUM_VMEM_TYPES] = {
595 VMEM_ACCESS, VMEM_SAMPLER_READ_ACCESS, VMEM_BVH_READ_ACCESS};
604 if (TII->mayAccessScratch(Inst))
605 return SCRATCH_WRITE_ACCESS;
606 return VMEM_WRITE_ACCESS;
610 return VmemReadMapping[getVmemType(Inst)];
613 std::optional<WaitEventType>
614 getExpertSchedulingEventType(
const MachineInstr &Inst)
const;
616 bool isVmemAccess(
const MachineInstr &
MI)
const;
617 bool generateWaitcntInstBefore(MachineInstr &
MI,
618 WaitcntBrackets &ScoreBrackets,
619 MachineInstr *OldWaitcntInstr,
621 bool generateWaitcnt(AMDGPU::Waitcnt
Wait,
623 MachineBasicBlock &
Block, WaitcntBrackets &ScoreBrackets,
624 MachineInstr *OldWaitcntInstr);
625 void updateEventWaitcntAfter(MachineInstr &Inst,
626 WaitcntBrackets *ScoreBrackets);
628 MachineBasicBlock *
Block)
const;
629 bool insertForcedWaitAfter(MachineInstr &Inst, MachineBasicBlock &
Block,
630 WaitcntBrackets &ScoreBrackets);
631 bool insertWaitcntInBlock(MachineFunction &MF, MachineBasicBlock &
Block,
632 WaitcntBrackets &ScoreBrackets);
634 bool ExpertMode)
const;
645class WaitcntBrackets {
647 WaitcntBrackets(
const SIInsertWaitcnts *Context) : Context(Context) {
648 assert(Context->TRI->getNumRegUnits() < REGUNITS_END);
653 unsigned NumUnusedVmem = 0, NumUnusedSGPRs = 0;
654 for (
auto &[
ID, Val] : VMem) {
658 for (
auto &[
ID, Val] : SGPRs) {
663 if (NumUnusedVmem || NumUnusedSGPRs) {
664 errs() <<
"WaitcntBracket had unused entries at destruction time: "
665 << NumUnusedVmem <<
" VMem and " << NumUnusedSGPRs
666 <<
" SGPR unused entries\n";
672 bool isSmemCounter(InstCounterType
T)
const {
673 return T == Context->SmemAccessCounter ||
T == X_CNT;
676 unsigned getSgprScoresIdx(InstCounterType
T)
const {
677 assert(isSmemCounter(
T) &&
"Invalid SMEM counter");
678 return T == X_CNT ? 1 : 0;
681 unsigned getScoreLB(InstCounterType
T)
const {
686 unsigned getScoreUB(InstCounterType
T)
const {
691 unsigned getScoreRange(InstCounterType
T)
const {
692 return getScoreUB(
T) - getScoreLB(
T);
695 unsigned getSGPRScore(MCRegUnit RU, InstCounterType
T)
const {
696 auto It = SGPRs.find(RU);
697 return It != SGPRs.end() ? It->second.Scores[getSgprScoresIdx(
T)] : 0;
700 unsigned getVMemScore(VMEMID TID, InstCounterType
T)
const {
701 auto It = VMem.find(TID);
702 return It != VMem.end() ? It->second.Scores[
T] : 0;
707 bool counterOutOfOrder(InstCounterType
T)
const;
708 void simplifyWaitcnt(AMDGPU::Waitcnt &
Wait)
const {
711 void simplifyWaitcnt(
const AMDGPU::Waitcnt &CheckWait,
712 AMDGPU::Waitcnt &UpdateWait)
const;
713 void simplifyWaitcnt(InstCounterType
T,
unsigned &
Count)
const;
714 bool hasRedundantXCntWithKmCnt(
const AMDGPU::Waitcnt &
Wait)
const;
715 bool canOptimizeXCntWithLoadCnt(
const AMDGPU::Waitcnt &
Wait)
const;
716 void simplifyXcnt(
const AMDGPU::Waitcnt &CheckWait,
717 AMDGPU::Waitcnt &UpdateWait)
const;
718 void simplifyVmVsrc(
const AMDGPU::Waitcnt &CheckWait,
719 AMDGPU::Waitcnt &UpdateWait)
const;
721 void determineWaitForPhysReg(InstCounterType
T,
MCPhysReg Reg,
722 AMDGPU::Waitcnt &
Wait)
const;
723 void determineWaitForLDSDMA(InstCounterType
T, VMEMID TID,
724 AMDGPU::Waitcnt &
Wait)
const;
725 void tryClearSCCWriteEvent(MachineInstr *Inst);
727 void applyWaitcnt(
const AMDGPU::Waitcnt &
Wait);
728 void applyWaitcnt(InstCounterType
T,
unsigned Count);
729 void updateByEvent(WaitEventType
E, MachineInstr &
MI);
731 unsigned hasPendingEvent()
const {
return PendingEvents; }
732 unsigned hasPendingEvent(WaitEventType
E)
const {
733 return PendingEvents & (1 <<
E);
735 unsigned hasPendingEvent(InstCounterType
T)
const {
736 unsigned HasPending = PendingEvents & Context->WaitEventMaskForInst[
T];
737 assert((HasPending != 0) == (getScoreRange(
T) != 0));
741 bool hasMixedPendingEvents(InstCounterType
T)
const {
742 unsigned Events = hasPendingEvent(
T);
744 return Events & (Events - 1);
747 bool hasPendingFlat()
const {
748 return ((LastFlat[DS_CNT] > ScoreLBs[DS_CNT] &&
749 LastFlat[DS_CNT] <= ScoreUBs[DS_CNT]) ||
750 (LastFlat[LOAD_CNT] > ScoreLBs[LOAD_CNT] &&
751 LastFlat[LOAD_CNT] <= ScoreUBs[LOAD_CNT]));
754 void setPendingFlat() {
755 LastFlat[LOAD_CNT] = ScoreUBs[LOAD_CNT];
756 LastFlat[DS_CNT] = ScoreUBs[DS_CNT];
759 bool hasPendingGDS()
const {
760 return LastGDS > ScoreLBs[DS_CNT] && LastGDS <= ScoreUBs[DS_CNT];
763 unsigned getPendingGDSWait()
const {
764 return std::min(getScoreUB(DS_CNT) - LastGDS,
765 Context->getWaitCountMax(DS_CNT) - 1);
768 void setPendingGDS() { LastGDS = ScoreUBs[DS_CNT]; }
772 bool hasOtherPendingVmemTypes(
MCPhysReg Reg, VmemType V)
const {
773 for (MCRegUnit RU : regunits(
Reg)) {
774 auto It = VMem.find(toVMEMID(RU));
775 if (It != VMem.end() && (It->second.VMEMTypes & ~(1 << V)))
782 for (MCRegUnit RU : regunits(
Reg)) {
783 if (
auto It = VMem.find(toVMEMID(RU)); It != VMem.end()) {
784 It->second.VMEMTypes = 0;
785 if (It->second.empty())
791 void setStateOnFunctionEntryOrReturn() {
792 setScoreUB(STORE_CNT,
793 getScoreUB(STORE_CNT) + Context->getWaitCountMax(STORE_CNT));
794 PendingEvents |= Context->WaitEventMaskForInst[STORE_CNT];
797 ArrayRef<const MachineInstr *> getLDSDMAStores()
const {
801 bool hasPointSampleAccel(
const MachineInstr &
MI)
const;
802 bool hasPointSamplePendingVmemTypes(
const MachineInstr &
MI,
805 void print(raw_ostream &)
const;
810 void purgeEmptyTrackingData();
820 void determineWaitForScore(InstCounterType
T,
unsigned Score,
821 AMDGPU::Waitcnt &
Wait)
const;
823 static bool mergeScore(
const MergeInfo &M,
unsigned &Score,
824 unsigned OtherScore);
827 assert(
Reg != AMDGPU::SCC &&
"Shouldn't be used on SCC");
828 if (!Context->TRI->isInAllocatableClass(
Reg))
830 const TargetRegisterClass *RC = Context->TRI->getPhysRegBaseClass(
Reg);
831 unsigned Size = Context->TRI->getRegSizeInBits(*RC);
832 if (
Size == 16 && Context->ST->hasD16Writes32BitVgpr())
833 Reg = Context->TRI->get32BitRegister(
Reg);
834 return Context->TRI->regunits(
Reg);
837 void setScoreLB(InstCounterType
T,
unsigned Val) {
842 void setScoreUB(InstCounterType
T,
unsigned Val) {
849 if (getScoreRange(EXP_CNT) > Context->getWaitCountMax(EXP_CNT))
850 ScoreLBs[
EXP_CNT] = ScoreUBs[
EXP_CNT] - Context->getWaitCountMax(EXP_CNT);
853 void setRegScore(
MCPhysReg Reg, InstCounterType
T,
unsigned Val) {
854 const SIRegisterInfo *
TRI = Context->TRI;
855 if (
Reg == AMDGPU::SCC) {
857 }
else if (
TRI->isVectorRegister(*Context->MRI,
Reg)) {
858 for (MCRegUnit RU : regunits(
Reg))
859 VMem[toVMEMID(RU)].Scores[
T] = Val;
860 }
else if (
TRI->isSGPRReg(*Context->MRI,
Reg)) {
861 auto STy = getSgprScoresIdx(
T);
862 for (MCRegUnit RU : regunits(
Reg))
863 SGPRs[RU].Scores[STy] = Val;
869 void setVMemScore(VMEMID TID, InstCounterType
T,
unsigned Val) {
870 VMem[TID].Scores[
T] = Val;
873 void setScoreByOperand(
const MachineOperand &
Op, InstCounterType CntTy,
876 const SIInsertWaitcnts *Context;
878 unsigned ScoreLBs[NUM_INST_CNTS] = {0};
879 unsigned ScoreUBs[NUM_INST_CNTS] = {0};
880 unsigned PendingEvents = 0;
882 unsigned LastFlat[NUM_INST_CNTS] = {0};
884 unsigned LastGDS = 0;
901 std::array<unsigned, NUM_INST_CNTS> Scores = {0};
903 unsigned VMEMTypes = 0;
906 return all_of(Scores, [](
unsigned K) {
return K == 0; }) && !VMEMTypes;
915 std::array<unsigned, 2> Scores = {0};
917 bool empty()
const {
return !Scores[0] && !Scores[1]; }
920 DenseMap<VMEMID, VMEMInfo> VMem;
921 DenseMap<MCRegUnit, SGPRInfo> SGPRs;
924 unsigned SCCScore = 0;
926 const MachineInstr *PendingSCCWrite =
nullptr;
930 SmallVector<const MachineInstr *> LDSDMAStores;
936 SIInsertWaitcntsLegacy() : MachineFunctionPass(ID) {}
938 bool runOnMachineFunction(MachineFunction &MF)
override;
940 StringRef getPassName()
const override {
941 return "SI insert wait instructions";
944 void getAnalysisUsage(AnalysisUsage &AU)
const override {
947 AU.
addRequired<MachinePostDominatorTreeWrapperPass>();
957 InstCounterType CntTy,
unsigned Score) {
958 setRegScore(
Op.getReg().asMCReg(), CntTy, Score);
966bool WaitcntBrackets::hasPointSampleAccel(
const MachineInstr &
MI)
const {
971 const AMDGPU::MIMGBaseOpcodeInfo *BaseInfo =
981bool WaitcntBrackets::hasPointSamplePendingVmemTypes(
const MachineInstr &
MI,
983 if (!hasPointSampleAccel(
MI))
986 return hasOtherPendingVmemTypes(
Reg, VMEM_NOSAMPLER);
989void WaitcntBrackets::updateByEvent(WaitEventType
E, MachineInstr &Inst) {
990 InstCounterType
T = eventCounter(
Context->WaitEventMaskForInst,
E);
993 unsigned UB = getScoreUB(
T);
994 unsigned CurrScore = UB + 1;
1000 PendingEvents |= 1 <<
E;
1001 setScoreUB(
T, CurrScore);
1004 const MachineRegisterInfo *
MRI =
Context->MRI;
1013 if (
const auto *AddrOp =
TII->getNamedOperand(Inst, AMDGPU::OpName::addr))
1014 setScoreByOperand(*AddrOp, EXP_CNT, CurrScore);
1017 if (
const auto *Data0 =
1018 TII->getNamedOperand(Inst, AMDGPU::OpName::data0))
1019 setScoreByOperand(*Data0, EXP_CNT, CurrScore);
1020 if (
const auto *Data1 =
1021 TII->getNamedOperand(Inst, AMDGPU::OpName::data1))
1022 setScoreByOperand(*Data1, EXP_CNT, CurrScore);
1024 Inst.
getOpcode() != AMDGPU::DS_APPEND &&
1025 Inst.
getOpcode() != AMDGPU::DS_CONSUME &&
1026 Inst.
getOpcode() != AMDGPU::DS_ORDERED_COUNT) {
1027 for (
const MachineOperand &
Op : Inst.
all_uses()) {
1028 if (
TRI->isVectorRegister(*
MRI,
Op.getReg()))
1029 setScoreByOperand(
Op, EXP_CNT, CurrScore);
1032 }
else if (
TII->isFLAT(Inst)) {
1034 setScoreByOperand(*
TII->getNamedOperand(Inst, AMDGPU::OpName::data),
1035 EXP_CNT, CurrScore);
1037 setScoreByOperand(*
TII->getNamedOperand(Inst, AMDGPU::OpName::data),
1038 EXP_CNT, CurrScore);
1040 }
else if (
TII->isMIMG(Inst)) {
1042 setScoreByOperand(Inst.
getOperand(0), EXP_CNT, CurrScore);
1044 setScoreByOperand(*
TII->getNamedOperand(Inst, AMDGPU::OpName::data),
1045 EXP_CNT, CurrScore);
1047 }
else if (
TII->isMTBUF(Inst)) {
1049 setScoreByOperand(Inst.
getOperand(0), EXP_CNT, CurrScore);
1050 }
else if (
TII->isMUBUF(Inst)) {
1052 setScoreByOperand(Inst.
getOperand(0), EXP_CNT, CurrScore);
1054 setScoreByOperand(*
TII->getNamedOperand(Inst, AMDGPU::OpName::data),
1055 EXP_CNT, CurrScore);
1057 }
else if (
TII->isLDSDIR(Inst)) {
1059 setScoreByOperand(*
TII->getNamedOperand(Inst, AMDGPU::OpName::vdst),
1060 EXP_CNT, CurrScore);
1062 if (
TII->isEXP(Inst)) {
1067 for (MachineOperand &DefMO : Inst.
all_defs()) {
1068 if (
TRI->isVGPR(*
MRI, DefMO.getReg())) {
1069 setScoreByOperand(DefMO, EXP_CNT, CurrScore);
1073 for (
const MachineOperand &
Op : Inst.
all_uses()) {
1074 if (
TRI->isVectorRegister(*
MRI,
Op.getReg()))
1075 setScoreByOperand(
Op, EXP_CNT, CurrScore);
1078 }
else if (
T == X_CNT) {
1079 WaitEventType OtherEvent =
E == SMEM_GROUP ? VMEM_GROUP : SMEM_GROUP;
1080 if (PendingEvents & (1 << OtherEvent)) {
1085 setScoreLB(
T, getScoreUB(
T) - 1);
1086 PendingEvents &= ~(1 << OtherEvent);
1088 for (
const MachineOperand &
Op : Inst.
all_uses())
1089 setScoreByOperand(
Op,
T, CurrScore);
1090 }
else if (
T == VA_VDST ||
T == VM_VSRC) {
1093 for (
const MachineOperand &
Op : Inst.
operands()) {
1094 if (!
Op.isReg() || (
T == VA_VDST &&
Op.isUse()) ||
1095 (
T == VM_VSRC &&
Op.isDef()))
1098 setScoreByOperand(
Op,
T, CurrScore);
1110 for (
const MachineOperand &
Op : Inst.
defs()) {
1111 if (
T == LOAD_CNT ||
T == SAMPLE_CNT ||
T == BVH_CNT) {
1112 if (!
TRI->isVectorRegister(*
MRI,
Op.getReg()))
1114 if (updateVMCntOnly(Inst)) {
1119 VmemType
V = getVmemType(Inst);
1120 unsigned char TypesMask = 1 <<
V;
1123 if (hasPointSampleAccel(Inst))
1124 TypesMask |= 1 << VMEM_NOSAMPLER;
1125 for (MCRegUnit RU : regunits(
Op.getReg().asMCReg()))
1126 VMem[toVMEMID(RU)].VMEMTypes |= TypesMask;
1129 setScoreByOperand(
Op,
T, CurrScore);
1132 (
TII->isDS(Inst) ||
TII->mayWriteLDSThroughDMA(Inst))) {
1141 if (!MemOp->isStore() ||
1146 auto AAI = MemOp->getAAInfo();
1152 if (!AAI || !AAI.Scope)
1154 for (
unsigned I = 0,
E = LDSDMAStores.
size();
I !=
E && !Slot; ++
I) {
1155 for (
const auto *MemOp : LDSDMAStores[
I]->memoperands()) {
1156 if (MemOp->isStore() && AAI == MemOp->getAAInfo()) {
1171 setVMemScore(LDSDMA_BEGIN,
T, CurrScore);
1172 if (Slot && Slot < NUM_LDSDMA)
1173 setVMemScore(LDSDMA_BEGIN + Slot,
T, CurrScore);
1177 setRegScore(AMDGPU::SCC,
T, CurrScore);
1178 PendingSCCWrite = &Inst;
1183void WaitcntBrackets::print(raw_ostream &OS)
const {
1187 for (
auto T : inst_counter_types(
Context->MaxCounter)) {
1188 unsigned SR = getScoreRange(
T);
1192 OS <<
" " << (
ST->hasExtendedWaitCounts() ?
"LOAD" :
"VM") <<
"_CNT("
1196 OS <<
" " << (
ST->hasExtendedWaitCounts() ?
"DS" :
"LGKM") <<
"_CNT("
1200 OS <<
" EXP_CNT(" << SR <<
"):";
1203 OS <<
" " << (
ST->hasExtendedWaitCounts() ?
"STORE" :
"VS") <<
"_CNT("
1207 OS <<
" SAMPLE_CNT(" << SR <<
"):";
1210 OS <<
" BVH_CNT(" << SR <<
"):";
1213 OS <<
" KM_CNT(" << SR <<
"):";
1216 OS <<
" X_CNT(" << SR <<
"):";
1219 OS <<
" VA_VDST(" << SR <<
"): ";
1222 OS <<
" VM_VSRC(" << SR <<
"): ";
1225 OS <<
" UNKNOWN(" << SR <<
"):";
1231 unsigned LB = getScoreLB(
T);
1234 sort(SortedVMEMIDs);
1236 for (
auto ID : SortedVMEMIDs) {
1237 unsigned RegScore = VMem.at(
ID).Scores[
T];
1240 unsigned RelScore = RegScore - LB - 1;
1241 if (
ID < REGUNITS_END) {
1242 OS <<
' ' << RelScore <<
":vRU" <<
ID;
1244 assert(
ID >= LDSDMA_BEGIN &&
ID < LDSDMA_END &&
1245 "Unhandled/unexpected ID value!");
1246 OS <<
' ' << RelScore <<
":LDSDMA" <<
ID;
1251 if (isSmemCounter(
T)) {
1253 sort(SortedSMEMIDs);
1254 for (
auto ID : SortedSMEMIDs) {
1255 unsigned RegScore = SGPRs.at(
ID).Scores[getSgprScoresIdx(
T)];
1258 unsigned RelScore = RegScore - LB - 1;
1259 OS <<
' ' << RelScore <<
":sRU" <<
static_cast<unsigned>(
ID);
1263 if (
T == KM_CNT && SCCScore > 0)
1264 OS <<
' ' << SCCScore <<
":scc";
1269 OS <<
"Pending Events: ";
1270 if (hasPendingEvent()) {
1272 for (
unsigned I = 0;
I != NUM_WAIT_EVENTS; ++
I) {
1273 if (hasPendingEvent((WaitEventType)
I)) {
1274 OS <<
LS << WaitEventTypeName[
I];
1287void WaitcntBrackets::simplifyWaitcnt(
const AMDGPU::Waitcnt &CheckWait,
1288 AMDGPU::Waitcnt &UpdateWait)
const {
1289 simplifyWaitcnt(LOAD_CNT, UpdateWait.
LoadCnt);
1290 simplifyWaitcnt(EXP_CNT, UpdateWait.
ExpCnt);
1291 simplifyWaitcnt(DS_CNT, UpdateWait.
DsCnt);
1292 simplifyWaitcnt(STORE_CNT, UpdateWait.
StoreCnt);
1293 simplifyWaitcnt(SAMPLE_CNT, UpdateWait.
SampleCnt);
1294 simplifyWaitcnt(BVH_CNT, UpdateWait.
BvhCnt);
1295 simplifyWaitcnt(KM_CNT, UpdateWait.
KmCnt);
1296 simplifyXcnt(CheckWait, UpdateWait);
1297 simplifyWaitcnt(VA_VDST, UpdateWait.
VaVdst);
1298 simplifyVmVsrc(CheckWait, UpdateWait);
1301void WaitcntBrackets::simplifyWaitcnt(InstCounterType
T,
1302 unsigned &
Count)
const {
1306 if (
Count >= getScoreRange(
T))
1310void WaitcntBrackets::simplifyVmVsrc(
const AMDGPU::Waitcnt &CheckWait,
1311 AMDGPU::Waitcnt &UpdateWait)
const {
1316 std::min({CheckWait.LoadCnt, CheckWait.StoreCnt, CheckWait.SampleCnt,
1317 CheckWait.BvhCnt, CheckWait.DsCnt}))
1319 simplifyWaitcnt(VM_VSRC, UpdateWait.
VmVsrc);
1322void WaitcntBrackets::purgeEmptyTrackingData() {
1333void WaitcntBrackets::determineWaitForScore(InstCounterType
T,
1334 unsigned ScoreToWait,
1335 AMDGPU::Waitcnt &
Wait)
const {
1336 const unsigned LB = getScoreLB(
T);
1337 const unsigned UB = getScoreUB(
T);
1340 if ((UB >= ScoreToWait) && (ScoreToWait > LB)) {
1341 if ((
T == LOAD_CNT ||
T == DS_CNT) && hasPendingFlat() &&
1342 !
Context->ST->hasFlatLgkmVMemCountInOrder()) {
1346 addWait(
Wait,
T, 0);
1347 }
else if (counterOutOfOrder(
T)) {
1351 addWait(
Wait,
T, 0);
1355 unsigned NeededWait =
1356 std::min(UB - ScoreToWait,
Context->getWaitCountMax(
T) - 1);
1357 addWait(
Wait,
T, NeededWait);
1362void WaitcntBrackets::determineWaitForPhysReg(InstCounterType
T,
MCPhysReg Reg,
1363 AMDGPU::Waitcnt &
Wait)
const {
1364 if (
Reg == AMDGPU::SCC) {
1365 determineWaitForScore(
T, SCCScore,
Wait);
1368 for (MCRegUnit RU : regunits(
Reg))
1369 determineWaitForScore(
1370 T, IsVGPR ? getVMemScore(toVMEMID(RU),
T) : getSGPRScore(RU,
T),
1375void WaitcntBrackets::determineWaitForLDSDMA(InstCounterType
T, VMEMID TID,
1376 AMDGPU::Waitcnt &
Wait)
const {
1377 assert(TID >= LDSDMA_BEGIN && TID < LDSDMA_END);
1378 determineWaitForScore(
T, getVMemScore(TID,
T),
Wait);
1381void WaitcntBrackets::tryClearSCCWriteEvent(MachineInstr *Inst) {
1384 if (PendingSCCWrite &&
1385 PendingSCCWrite->
getOpcode() == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM &&
1387 unsigned SCC_WRITE_PendingEvent = 1 << SCC_WRITE;
1389 if ((PendingEvents &
Context->WaitEventMaskForInst[KM_CNT]) ==
1390 SCC_WRITE_PendingEvent) {
1391 setScoreLB(KM_CNT, getScoreUB(KM_CNT));
1394 PendingEvents &= ~SCC_WRITE_PendingEvent;
1395 PendingSCCWrite =
nullptr;
1399void WaitcntBrackets::applyWaitcnt(
const AMDGPU::Waitcnt &
Wait) {
1400 applyWaitcnt(LOAD_CNT,
Wait.LoadCnt);
1401 applyWaitcnt(EXP_CNT,
Wait.ExpCnt);
1402 applyWaitcnt(DS_CNT,
Wait.DsCnt);
1403 applyWaitcnt(STORE_CNT,
Wait.StoreCnt);
1404 applyWaitcnt(SAMPLE_CNT,
Wait.SampleCnt);
1405 applyWaitcnt(BVH_CNT,
Wait.BvhCnt);
1406 applyWaitcnt(KM_CNT,
Wait.KmCnt);
1407 applyWaitcnt(X_CNT,
Wait.XCnt);
1408 applyWaitcnt(VA_VDST,
Wait.VaVdst);
1409 applyWaitcnt(VM_VSRC,
Wait.VmVsrc);
1412void WaitcntBrackets::applyWaitcnt(InstCounterType
T,
unsigned Count) {
1413 const unsigned UB = getScoreUB(
T);
1417 if (counterOutOfOrder(
T))
1419 setScoreLB(
T, std::max(getScoreLB(
T), UB -
Count));
1422 PendingEvents &= ~Context->WaitEventMaskForInst[
T];
1425 if (
T == KM_CNT &&
Count == 0 && hasPendingEvent(SMEM_GROUP)) {
1426 if (!hasMixedPendingEvents(X_CNT))
1427 applyWaitcnt(X_CNT, 0);
1429 PendingEvents &= ~(1 << SMEM_GROUP);
1431 if (
T == LOAD_CNT && hasPendingEvent(VMEM_GROUP) &&
1432 !hasPendingEvent(STORE_CNT)) {
1433 if (!hasMixedPendingEvents(X_CNT))
1434 applyWaitcnt(X_CNT,
Count);
1435 else if (
Count == 0)
1436 PendingEvents &= ~(1 << VMEM_GROUP);
1440bool WaitcntBrackets::hasRedundantXCntWithKmCnt(
1441 const AMDGPU::Waitcnt &
Wait)
const {
1445 return Wait.KmCnt == 0 && hasPendingEvent(SMEM_GROUP);
1448bool WaitcntBrackets::canOptimizeXCntWithLoadCnt(
1449 const AMDGPU::Waitcnt &
Wait)
const {
1453 return Wait.LoadCnt != ~0
u && hasPendingEvent(VMEM_GROUP) &&
1454 !hasPendingEvent(STORE_CNT);
1457void WaitcntBrackets::simplifyXcnt(
const AMDGPU::Waitcnt &CheckWait,
1458 AMDGPU::Waitcnt &UpdateWait)
const {
1464 if (hasRedundantXCntWithKmCnt(CheckWait))
1465 UpdateWait.
XCnt = ~0
u;
1466 if (canOptimizeXCntWithLoadCnt(CheckWait) &&
1468 UpdateWait.
XCnt = ~0
u;
1469 simplifyWaitcnt(X_CNT, UpdateWait.
XCnt);
1474bool WaitcntBrackets::counterOutOfOrder(InstCounterType
T)
const {
1476 if ((
T ==
Context->SmemAccessCounter && hasPendingEvent(SMEM_ACCESS)) ||
1477 (
T == X_CNT && hasPendingEvent(SMEM_GROUP)))
1483 if (
T == LOAD_CNT) {
1484 unsigned Events = hasPendingEvent(
T);
1487 Events &= ~(1 << GLOBAL_INV_ACCESS);
1490 return Events & (Events - 1);
1493 return hasMixedPendingEvents(
T);
1503char SIInsertWaitcntsLegacy::
ID = 0;
1508 return new SIInsertWaitcntsLegacy();
1513 int OpIdx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(),
OpName);
1518 if (NewEnc == MO.
getImm())
1529 case AMDGPU::S_WAIT_LOADCNT:
1531 case AMDGPU::S_WAIT_EXPCNT:
1533 case AMDGPU::S_WAIT_STORECNT:
1535 case AMDGPU::S_WAIT_SAMPLECNT:
1537 case AMDGPU::S_WAIT_BVHCNT:
1539 case AMDGPU::S_WAIT_DSCNT:
1541 case AMDGPU::S_WAIT_KMCNT:
1543 case AMDGPU::S_WAIT_XCNT:
1550bool WaitcntGenerator::promoteSoftWaitCnt(MachineInstr *Waitcnt)
const {
1564bool WaitcntGeneratorPreGFX12::applyPreexistingWaitcnt(
1565 WaitcntBrackets &ScoreBrackets, MachineInstr &OldWaitcntInstr,
1568 assert(isNormalMode(MaxCounter));
1571 MachineInstr *WaitcntInstr =
nullptr;
1572 MachineInstr *WaitcntVsCntInstr =
nullptr;
1575 dbgs() <<
"PreGFX12::applyPreexistingWaitcnt at: ";
1577 dbgs() <<
"end of block\n";
1585 if (
II.isMetaInstruction()) {
1591 bool TrySimplify = Opcode !=
II.getOpcode() && !OptNone;
1595 if (Opcode == AMDGPU::S_WAITCNT) {
1596 unsigned IEnc =
II.getOperand(0).getImm();
1599 ScoreBrackets.simplifyWaitcnt(OldWait);
1603 if (WaitcntInstr || (!
Wait.hasWaitExceptStoreCnt() && TrySimplify)) {
1604 II.eraseFromParent();
1608 }
else if (Opcode == AMDGPU::S_WAITCNT_lds_direct) {
1611 <<
"Before: " <<
Wait <<
'\n';);
1612 ScoreBrackets.determineWaitForLDSDMA(LOAD_CNT, LDSDMA_BEGIN,
Wait);
1621 II.eraseFromParent();
1623 assert(Opcode == AMDGPU::S_WAITCNT_VSCNT);
1624 assert(
II.getOperand(0).getReg() == AMDGPU::SGPR_NULL);
1627 TII->getNamedOperand(
II, AMDGPU::OpName::simm16)->getImm();
1629 ScoreBrackets.simplifyWaitcnt(InstCounterType::STORE_CNT, OldVSCnt);
1630 Wait.StoreCnt = std::min(
Wait.StoreCnt, OldVSCnt);
1632 if (WaitcntVsCntInstr || (!
Wait.hasWaitStoreCnt() && TrySimplify)) {
1633 II.eraseFromParent();
1636 WaitcntVsCntInstr = &
II;
1643 Modified |= promoteSoftWaitCnt(WaitcntInstr);
1645 ScoreBrackets.applyWaitcnt(LOAD_CNT,
Wait.LoadCnt);
1646 ScoreBrackets.applyWaitcnt(EXP_CNT,
Wait.ExpCnt);
1647 ScoreBrackets.applyWaitcnt(DS_CNT,
Wait.DsCnt);
1654 <<
"applied pre-existing waitcnt\n"
1655 <<
"New Instr at block end: " << *WaitcntInstr <<
'\n'
1656 :
dbgs() <<
"applied pre-existing waitcnt\n"
1657 <<
"Old Instr: " << *It
1658 <<
"New Instr: " << *WaitcntInstr <<
'\n');
1661 if (WaitcntVsCntInstr) {
1663 AMDGPU::OpName::simm16,
Wait.StoreCnt);
1664 Modified |= promoteSoftWaitCnt(WaitcntVsCntInstr);
1666 ScoreBrackets.applyWaitcnt(STORE_CNT,
Wait.StoreCnt);
1667 Wait.StoreCnt = ~0
u;
1670 ?
dbgs() <<
"applied pre-existing waitcnt\n"
1671 <<
"New Instr at block end: " << *WaitcntVsCntInstr
1673 :
dbgs() <<
"applied pre-existing waitcnt\n"
1674 <<
"Old Instr: " << *It
1675 <<
"New Instr: " << *WaitcntVsCntInstr <<
'\n');
1683bool WaitcntGeneratorPreGFX12::createNewWaitcnt(
1685 AMDGPU::Waitcnt
Wait) {
1687 assert(isNormalMode(MaxCounter));
1694 if (
Wait.hasWaitExceptStoreCnt()) {
1696 [[maybe_unused]]
auto SWaitInst =
1701 if (It !=
Block.instr_end())
dbgs() <<
"Old Instr: " << *It;
1702 dbgs() <<
"New Instr: " << *SWaitInst <<
'\n');
1705 if (
Wait.hasWaitStoreCnt()) {
1708 [[maybe_unused]]
auto SWaitInst =
1715 if (It !=
Block.instr_end())
dbgs() <<
"Old Instr: " << *It;
1716 dbgs() <<
"New Instr: " << *SWaitInst <<
'\n');
1723WaitcntGeneratorPreGFX12::getAllZeroWaitcnt(
bool IncludeVSCnt)
const {
1724 return AMDGPU::Waitcnt(0, 0, 0, IncludeVSCnt &&
ST->hasVscnt() ? 0 : ~0u);
1728WaitcntGeneratorGFX12Plus::getAllZeroWaitcnt(
bool IncludeVSCnt)
const {
1729 unsigned ExpertVal = IsExpertMode ? 0 : ~0
u;
1730 return AMDGPU::Waitcnt(0, 0, 0, IncludeVSCnt ? 0 : ~0u, 0, 0, 0,
1731 ~0u , ExpertVal, ExpertVal);
1738bool WaitcntGeneratorGFX12Plus::applyPreexistingWaitcnt(
1739 WaitcntBrackets &ScoreBrackets, MachineInstr &OldWaitcntInstr,
1742 assert(!isNormalMode(MaxCounter));
1745 MachineInstr *CombinedLoadDsCntInstr =
nullptr;
1746 MachineInstr *CombinedStoreDsCntInstr =
nullptr;
1747 MachineInstr *WaitcntDepctrInstr =
nullptr;
1748 MachineInstr *WaitInstrs[NUM_EXTENDED_INST_CNTS] = {};
1751 dbgs() <<
"GFX12Plus::applyPreexistingWaitcnt at: ";
1753 dbgs() <<
"end of block\n";
1759 AMDGPU::Waitcnt RequiredWait;
1764 if (
II.isMetaInstruction()) {
1769 MachineInstr **UpdatableInstr;
1775 bool TrySimplify = Opcode !=
II.getOpcode() && !OptNone;
1779 if (Opcode == AMDGPU::S_WAITCNT)
1782 if (Opcode == AMDGPU::S_WAIT_LOADCNT_DSCNT) {
1784 TII->getNamedOperand(
II, AMDGPU::OpName::simm16)->getImm();
1789 RequiredWait = RequiredWait.combined(OldWait);
1790 UpdatableInstr = &CombinedLoadDsCntInstr;
1791 }
else if (Opcode == AMDGPU::S_WAIT_STORECNT_DSCNT) {
1793 TII->getNamedOperand(
II, AMDGPU::OpName::simm16)->getImm();
1798 RequiredWait = RequiredWait.combined(OldWait);
1799 UpdatableInstr = &CombinedStoreDsCntInstr;
1800 }
else if (Opcode == AMDGPU::S_WAITCNT_DEPCTR) {
1802 TII->getNamedOperand(
II, AMDGPU::OpName::simm16)->getImm();
1803 AMDGPU::Waitcnt OldWait;
1807 ScoreBrackets.simplifyWaitcnt(OldWait);
1809 UpdatableInstr = &WaitcntDepctrInstr;
1810 }
else if (Opcode == AMDGPU::S_WAITCNT_lds_direct) {
1813 II.eraseFromParent();
1819 TII->getNamedOperand(
II, AMDGPU::OpName::simm16)->getImm();
1821 addWait(
Wait, CT.value(), OldCnt);
1823 addWait(RequiredWait, CT.value(), OldCnt);
1824 UpdatableInstr = &WaitInstrs[CT.value()];
1828 if (!*UpdatableInstr) {
1829 *UpdatableInstr = &
II;
1830 }
else if (Opcode == AMDGPU::S_WAITCNT_DEPCTR) {
1837 unsigned Enc =
TII->getNamedOperand(
II, AMDGPU::OpName::simm16)->getImm();
1845 II.eraseFromParent();
1849 II.eraseFromParent();
1854 ScoreBrackets.simplifyWaitcnt(
Wait.combined(RequiredWait),
Wait);
1855 Wait =
Wait.combined(RequiredWait);
1857 if (CombinedLoadDsCntInstr) {
1870 if (
Wait.LoadCnt != ~0u &&
Wait.DsCnt != ~0u) {
1873 AMDGPU::OpName::simm16, NewEnc);
1874 Modified |= promoteSoftWaitCnt(CombinedLoadDsCntInstr);
1875 ScoreBrackets.applyWaitcnt(LOAD_CNT,
Wait.LoadCnt);
1876 ScoreBrackets.applyWaitcnt(DS_CNT,
Wait.DsCnt);
1881 ?
dbgs() <<
"applied pre-existing waitcnt\n"
1882 <<
"New Instr at block end: "
1883 << *CombinedLoadDsCntInstr <<
'\n'
1884 :
dbgs() <<
"applied pre-existing waitcnt\n"
1885 <<
"Old Instr: " << *It <<
"New Instr: "
1886 << *CombinedLoadDsCntInstr <<
'\n');
1893 if (CombinedStoreDsCntInstr) {
1895 if (
Wait.StoreCnt != ~0u &&
Wait.DsCnt != ~0u) {
1898 AMDGPU::OpName::simm16, NewEnc);
1899 Modified |= promoteSoftWaitCnt(CombinedStoreDsCntInstr);
1900 ScoreBrackets.applyWaitcnt(STORE_CNT,
Wait.StoreCnt);
1901 ScoreBrackets.applyWaitcnt(DS_CNT,
Wait.DsCnt);
1902 Wait.StoreCnt = ~0
u;
1906 ?
dbgs() <<
"applied pre-existing waitcnt\n"
1907 <<
"New Instr at block end: "
1908 << *CombinedStoreDsCntInstr <<
'\n'
1909 :
dbgs() <<
"applied pre-existing waitcnt\n"
1910 <<
"Old Instr: " << *It <<
"New Instr: "
1911 << *CombinedStoreDsCntInstr <<
'\n');
1924 if (
Wait.DsCnt != ~0u) {
1933 if (
Wait.LoadCnt != ~0u) {
1934 WaitsToErase.
push_back(&WaitInstrs[LOAD_CNT]);
1935 WaitsToErase.
push_back(&WaitInstrs[DS_CNT]);
1936 }
else if (
Wait.StoreCnt != ~0u) {
1937 WaitsToErase.
push_back(&WaitInstrs[STORE_CNT]);
1938 WaitsToErase.
push_back(&WaitInstrs[DS_CNT]);
1941 for (MachineInstr **WI : WaitsToErase) {
1945 (*WI)->eraseFromParent();
1951 for (
auto CT : inst_counter_types(NUM_EXTENDED_INST_CNTS)) {
1952 if (!WaitInstrs[CT])
1955 unsigned NewCnt = getWait(
Wait, CT);
1956 if (NewCnt != ~0u) {
1958 AMDGPU::OpName::simm16, NewCnt);
1959 Modified |= promoteSoftWaitCnt(WaitInstrs[CT]);
1961 ScoreBrackets.applyWaitcnt(CT, NewCnt);
1962 setNoWait(
Wait, CT);
1965 ?
dbgs() <<
"applied pre-existing waitcnt\n"
1966 <<
"New Instr at block end: " << *WaitInstrs[CT]
1968 :
dbgs() <<
"applied pre-existing waitcnt\n"
1969 <<
"Old Instr: " << *It
1970 <<
"New Instr: " << *WaitInstrs[CT] <<
'\n');
1977 if (WaitcntDepctrInstr) {
1981 TII->getNamedOperand(*WaitcntDepctrInstr, AMDGPU::OpName::simm16)
1986 ScoreBrackets.applyWaitcnt(VA_VDST,
Wait.VaVdst);
1987 ScoreBrackets.applyWaitcnt(VM_VSRC,
Wait.VmVsrc);
1996 AMDGPU::OpName::simm16, Enc);
1998 ?
dbgs() <<
"applyPreexistingWaitcnt\n"
1999 <<
"New Instr at block end: "
2000 << *WaitcntDepctrInstr <<
'\n'
2001 :
dbgs() <<
"applyPreexistingWaitcnt\n"
2002 <<
"Old Instr: " << *It
2003 <<
"New Instr: " << *WaitcntDepctrInstr <<
'\n');
2014bool WaitcntGeneratorGFX12Plus::createNewWaitcnt(
2016 AMDGPU::Waitcnt
Wait) {
2018 assert(!isNormalMode(MaxCounter));
2024 if (
Wait.DsCnt != ~0u) {
2025 MachineInstr *SWaitInst =
nullptr;
2027 if (
Wait.LoadCnt != ~0u) {
2035 }
else if (
Wait.StoreCnt != ~0u) {
2042 Wait.StoreCnt = ~0
u;
2050 if (It !=
Block.instr_end())
dbgs() <<
"Old Instr: " << *It;
2051 dbgs() <<
"New Instr: " << *SWaitInst <<
'\n');
2058 for (
auto CT : inst_counter_types(NUM_EXTENDED_INST_CNTS)) {
2063 [[maybe_unused]]
auto SWaitInst =
2070 if (It !=
Block.instr_end())
dbgs() <<
"Old Instr: " << *It;
2071 dbgs() <<
"New Instr: " << *SWaitInst <<
'\n');
2074 if (
Wait.hasWaitDepctr()) {
2079 [[maybe_unused]]
auto SWaitInst =
2085 if (It !=
Block.instr_end())
dbgs() <<
"Old Instr: " << *It;
2086 dbgs() <<
"New Instr: " << *SWaitInst <<
'\n');
2104bool SIInsertWaitcnts::generateWaitcntInstBefore(MachineInstr &
MI,
2105 WaitcntBrackets &ScoreBrackets,
2106 MachineInstr *OldWaitcntInstr,
2108 setForceEmitWaitcnt();
2112 AMDGPU::Waitcnt
Wait;
2113 const unsigned Opc =
MI.getOpcode();
2119 if (
Opc == AMDGPU::BUFFER_WBINVL1 ||
Opc == AMDGPU::BUFFER_WBINVL1_SC ||
2120 Opc == AMDGPU::BUFFER_WBINVL1_VOL ||
Opc == AMDGPU::BUFFER_GL0_INV ||
2121 Opc == AMDGPU::BUFFER_GL1_INV) {
2128 if (
Opc == AMDGPU::SI_RETURN_TO_EPILOG ||
Opc == AMDGPU::SI_RETURN ||
2129 Opc == AMDGPU::SI_WHOLE_WAVE_FUNC_RETURN ||
2130 Opc == AMDGPU::S_SETPC_B64_return) {
2132 AMDGPU::Waitcnt AllZeroWait =
2133 WCG->getAllZeroWaitcnt(
false);
2138 if (
ST->hasExtendedWaitCounts() &&
2139 !ScoreBrackets.hasPendingEvent(VMEM_ACCESS))
2151 else if (
Opc == AMDGPU::S_ENDPGM ||
Opc == AMDGPU::S_ENDPGM_SAVED) {
2152 if (!WCG->isOptNone() &&
2153 (
MI.getMF()->getInfo<SIMachineFunctionInfo>()->isDynamicVGPREnabled() ||
2154 (
ST->getGeneration() >= AMDGPUSubtarget::GFX11 &&
2155 ScoreBrackets.getScoreRange(STORE_CNT) != 0 &&
2156 !ScoreBrackets.hasPendingEvent(SCRATCH_WRITE_ACCESS))))
2160 else if ((
Opc == AMDGPU::S_SENDMSG ||
Opc == AMDGPU::S_SENDMSGHALT) &&
2161 ST->hasLegacyGeometry() &&
2172 if (
MI.modifiesRegister(AMDGPU::EXEC,
TRI)) {
2175 if (ScoreBrackets.hasPendingEvent(EXP_GPR_LOCK) ||
2176 ScoreBrackets.hasPendingEvent(EXP_PARAM_ACCESS) ||
2177 ScoreBrackets.hasPendingEvent(EXP_POS_ACCESS) ||
2178 ScoreBrackets.hasPendingEvent(GDS_GPR_LOCK)) {
2185 if (
TII->isAlwaysGDS(
Opc) && ScoreBrackets.hasPendingGDS())
2186 addWait(
Wait, DS_CNT, ScoreBrackets.getPendingGDSWait());
2193 Wait = AMDGPU::Waitcnt();
2195 const MachineOperand &CallAddrOp =
TII->getCalleeOperand(
MI);
2196 if (CallAddrOp.
isReg()) {
2197 ScoreBrackets.determineWaitForPhysReg(
2200 if (
const auto *RtnAddrOp =
2201 TII->getNamedOperand(
MI, AMDGPU::OpName::dst)) {
2202 ScoreBrackets.determineWaitForPhysReg(
2203 SmemAccessCounter, RtnAddrOp->getReg().asMCReg(),
Wait);
2206 }
else if (
Opc == AMDGPU::S_BARRIER_WAIT) {
2207 ScoreBrackets.tryClearSCCWriteEvent(&
MI);
2223 for (
const MachineMemOperand *Memop :
MI.memoperands()) {
2224 const Value *Ptr = Memop->getValue();
2225 if (Memop->isStore()) {
2226 if (
auto It = SLoadAddresses.
find(Ptr); It != SLoadAddresses.
end()) {
2227 addWait(
Wait, SmemAccessCounter, 0);
2229 SLoadAddresses.
erase(It);
2232 unsigned AS = Memop->getAddrSpace();
2236 if (
TII->mayWriteLDSThroughDMA(
MI))
2240 unsigned TID = LDSDMA_BEGIN;
2241 if (Ptr && Memop->getAAInfo()) {
2242 const auto &LDSDMAStores = ScoreBrackets.getLDSDMAStores();
2243 for (
unsigned I = 0,
E = LDSDMAStores.size();
I !=
E; ++
I) {
2244 if (
MI.mayAlias(AA, *LDSDMAStores[
I],
true)) {
2245 if ((
I + 1) >= NUM_LDSDMA) {
2248 ScoreBrackets.determineWaitForLDSDMA(LOAD_CNT, TID,
Wait);
2252 ScoreBrackets.determineWaitForLDSDMA(LOAD_CNT, TID +
I + 1,
Wait);
2256 ScoreBrackets.determineWaitForLDSDMA(LOAD_CNT, TID,
Wait);
2258 if (Memop->isStore()) {
2259 ScoreBrackets.determineWaitForLDSDMA(EXP_CNT, TID,
Wait);
2264 for (
const MachineOperand &
Op :
MI.operands()) {
2269 if (
Op.isTied() &&
Op.isUse() &&
TII->doesNotReadTiedSource(
MI))
2274 const bool IsVGPR =
TRI->isVectorRegister(*
MRI,
Op.getReg());
2281 if (
Op.isImplicit() &&
MI.mayLoadOrStore())
2284 ScoreBrackets.determineWaitForPhysReg(VA_VDST,
Reg,
Wait);
2286 ScoreBrackets.determineWaitForPhysReg(VM_VSRC,
Reg,
Wait);
2293 if (
Op.isUse() || !updateVMCntOnly(
MI) ||
2294 ScoreBrackets.hasOtherPendingVmemTypes(
Reg, getVmemType(
MI)) ||
2295 ScoreBrackets.hasPointSamplePendingVmemTypes(
MI,
Reg) ||
2296 !
ST->hasVmemWriteVgprInOrder()) {
2297 ScoreBrackets.determineWaitForPhysReg(LOAD_CNT,
Reg,
Wait);
2298 ScoreBrackets.determineWaitForPhysReg(SAMPLE_CNT,
Reg,
Wait);
2299 ScoreBrackets.determineWaitForPhysReg(BVH_CNT,
Reg,
Wait);
2300 ScoreBrackets.clearVgprVmemTypes(
Reg);
2303 if (
Op.isDef() || ScoreBrackets.hasPendingEvent(EXP_LDS_ACCESS)) {
2304 ScoreBrackets.determineWaitForPhysReg(EXP_CNT,
Reg,
Wait);
2306 ScoreBrackets.determineWaitForPhysReg(DS_CNT,
Reg,
Wait);
2307 }
else if (
Op.getReg() == AMDGPU::SCC) {
2308 ScoreBrackets.determineWaitForPhysReg(KM_CNT,
Reg,
Wait);
2310 ScoreBrackets.determineWaitForPhysReg(SmemAccessCounter,
Reg,
Wait);
2313 if (
ST->hasWaitXCnt() &&
Op.isDef())
2314 ScoreBrackets.determineWaitForPhysReg(X_CNT,
Reg,
Wait);
2331 if (
Opc == AMDGPU::S_BARRIER && !
ST->hasAutoWaitcntBeforeBarrier() &&
2332 !
ST->supportsBackOffBarrier()) {
2333 Wait =
Wait.combined(WCG->getAllZeroWaitcnt(
true));
2340 ScoreBrackets.hasPendingEvent(SMEM_ACCESS)) {
2345 ScoreBrackets.simplifyWaitcnt(
Wait);
2351 if (
TII->isVALU(
MI))
2357 if (
Wait.XCnt != ~0u && isVmemAccess(
MI)) {
2358 ScoreBrackets.applyWaitcnt(X_CNT,
Wait.XCnt);
2365 Wait = WCG->getAllZeroWaitcnt(
false);
2367 if (ForceEmitWaitcnt[LOAD_CNT])
2369 if (ForceEmitWaitcnt[EXP_CNT])
2371 if (ForceEmitWaitcnt[DS_CNT])
2373 if (ForceEmitWaitcnt[SAMPLE_CNT])
2375 if (ForceEmitWaitcnt[BVH_CNT])
2377 if (ForceEmitWaitcnt[KM_CNT])
2379 if (ForceEmitWaitcnt[X_CNT])
2383 if (ForceEmitWaitcnt[VA_VDST])
2385 if (ForceEmitWaitcnt[VM_VSRC])
2390 if (ScoreBrackets.hasPendingEvent(LOAD_CNT))
2392 if (ScoreBrackets.hasPendingEvent(SAMPLE_CNT))
2394 if (ScoreBrackets.hasPendingEvent(BVH_CNT))
2401 return generateWaitcnt(
Wait,
MI.getIterator(), *
MI.getParent(), ScoreBrackets,
2405bool SIInsertWaitcnts::generateWaitcnt(AMDGPU::Waitcnt
Wait,
2407 MachineBasicBlock &
Block,
2408 WaitcntBrackets &ScoreBrackets,
2409 MachineInstr *OldWaitcntInstr) {
2412 if (OldWaitcntInstr)
2416 WCG->applyPreexistingWaitcnt(ScoreBrackets, *OldWaitcntInstr,
Wait, It);
2420 ScoreBrackets.applyWaitcnt(
Wait);
2423 if (
Wait.ExpCnt != ~0u && It !=
Block.instr_end() &&
2425 MachineOperand *WaitExp =
2426 TII->getNamedOperand(*It, AMDGPU::OpName::waitexp);
2434 <<
"Update Instr: " << *It);
2437 if (WCG->createNewWaitcnt(
Block, It,
Wait))
2443std::optional<WaitEventType>
2444SIInsertWaitcnts::getExpertSchedulingEventType(
const MachineInstr &Inst)
const {
2445 if (
TII->isVALU(Inst)) {
2450 if (
TII->isXDL(Inst))
2451 return VGPR_XDL_WRITE;
2453 if (
TII->isTRANS(Inst))
2454 return VGPR_TRANS_WRITE;
2457 return VGPR_DPMACC_WRITE;
2459 return VGPR_CSMACC_WRITE;
2466 if (
TII->isFLAT(Inst))
2467 return VGPR_FLAT_READ;
2469 if (
TII->isDS(Inst))
2470 return VGPR_LDS_READ;
2472 if (
TII->isVMEM(Inst) ||
TII->isVIMAGE(Inst) ||
TII->isVSAMPLE(Inst))
2473 return VGPR_VMEM_READ;
2480bool SIInsertWaitcnts::isVmemAccess(
const MachineInstr &
MI)
const {
2481 return (
TII->isFLAT(
MI) &&
TII->mayAccessVMEMThroughFlat(
MI)) ||
2488 MachineBasicBlock *
Block)
const {
2489 auto BlockEnd =
Block->getParent()->end();
2490 auto BlockIter =
Block->getIterator();
2494 if (++BlockIter != BlockEnd) {
2495 It = BlockIter->instr_begin();
2502 if (!It->isMetaInstruction())
2510 return It->getOpcode() == AMDGPU::S_ENDPGM;
2514bool SIInsertWaitcnts::insertForcedWaitAfter(MachineInstr &Inst,
2515 MachineBasicBlock &
Block,
2516 WaitcntBrackets &ScoreBrackets) {
2517 AMDGPU::Waitcnt
Wait;
2518 bool NeedsEndPGMCheck =
false;
2526 NeedsEndPGMCheck =
true;
2529 ScoreBrackets.simplifyWaitcnt(
Wait);
2532 bool Result = generateWaitcnt(
Wait, SuccessorIt,
Block, ScoreBrackets,
2535 if (Result && NeedsEndPGMCheck && isNextENDPGM(SuccessorIt, &
Block)) {
2543void SIInsertWaitcnts::updateEventWaitcntAfter(MachineInstr &Inst,
2544 WaitcntBrackets *ScoreBrackets) {
2552 bool IsVMEMAccess =
false;
2553 bool IsSMEMAccess =
false;
2556 if (
const auto ET = getExpertSchedulingEventType(Inst))
2557 ScoreBrackets->updateByEvent(*ET, Inst);
2560 if (
TII->isDS(Inst) &&
TII->usesLGKM_CNT(Inst)) {
2562 TII->hasModifiersSet(Inst, AMDGPU::OpName::gds)) {
2563 ScoreBrackets->updateByEvent(GDS_ACCESS, Inst);
2564 ScoreBrackets->updateByEvent(GDS_GPR_LOCK, Inst);
2565 ScoreBrackets->setPendingGDS();
2567 ScoreBrackets->updateByEvent(LDS_ACCESS, Inst);
2569 }
else if (
TII->isFLAT(Inst)) {
2571 ScoreBrackets->updateByEvent(getVmemWaitEventType(Inst), Inst);
2577 int FlatASCount = 0;
2579 if (
TII->mayAccessVMEMThroughFlat(Inst)) {
2581 IsVMEMAccess =
true;
2582 ScoreBrackets->updateByEvent(getVmemWaitEventType(Inst), Inst);
2585 if (
TII->mayAccessLDSThroughFlat(Inst)) {
2587 ScoreBrackets->updateByEvent(LDS_ACCESS, Inst);
2596 ScoreBrackets->setPendingFlat();
2599 IsVMEMAccess =
true;
2600 ScoreBrackets->updateByEvent(getVmemWaitEventType(Inst), Inst);
2602 if (
ST->vmemWriteNeedsExpWaitcnt() &&
2604 ScoreBrackets->updateByEvent(VMW_GPR_LOCK, Inst);
2606 }
else if (
TII->isSMRD(Inst)) {
2607 IsSMEMAccess =
true;
2608 ScoreBrackets->updateByEvent(SMEM_ACCESS, Inst);
2609 }
else if (Inst.
isCall()) {
2611 ScoreBrackets->applyWaitcnt(WCG->getAllZeroWaitcnt(
false));
2612 ScoreBrackets->setStateOnFunctionEntryOrReturn();
2614 ScoreBrackets->updateByEvent(EXP_LDS_ACCESS, Inst);
2615 }
else if (
TII->isVINTERP(Inst)) {
2616 int64_t
Imm =
TII->getNamedOperand(Inst, AMDGPU::OpName::waitexp)->getImm();
2617 ScoreBrackets->applyWaitcnt(EXP_CNT, Imm);
2619 unsigned Imm =
TII->getNamedOperand(Inst, AMDGPU::OpName::tgt)->getImm();
2621 ScoreBrackets->updateByEvent(EXP_PARAM_ACCESS, Inst);
2623 ScoreBrackets->updateByEvent(EXP_POS_ACCESS, Inst);
2625 ScoreBrackets->updateByEvent(EXP_GPR_LOCK, Inst);
2627 ScoreBrackets->updateByEvent(SCC_WRITE, Inst);
2630 case AMDGPU::S_SENDMSG:
2631 case AMDGPU::S_SENDMSG_RTN_B32:
2632 case AMDGPU::S_SENDMSG_RTN_B64:
2633 case AMDGPU::S_SENDMSGHALT:
2634 ScoreBrackets->updateByEvent(SQ_MESSAGE, Inst);
2636 case AMDGPU::S_MEMTIME:
2637 case AMDGPU::S_MEMREALTIME:
2638 case AMDGPU::S_GET_BARRIER_STATE_M0:
2639 case AMDGPU::S_GET_BARRIER_STATE_IMM:
2640 ScoreBrackets->updateByEvent(SMEM_ACCESS, Inst);
2645 if (!
ST->hasWaitXCnt())
2649 ScoreBrackets->updateByEvent(VMEM_GROUP, Inst);
2652 ScoreBrackets->updateByEvent(SMEM_GROUP, Inst);
2655bool WaitcntBrackets::mergeScore(
const MergeInfo &M,
unsigned &Score,
2656 unsigned OtherScore) {
2657 unsigned MyShifted = Score <=
M.OldLB ? 0 : Score +
M.MyShift;
2658 unsigned OtherShifted =
2659 OtherScore <=
M.OtherLB ? 0 : OtherScore +
M.OtherShift;
2660 Score = std::max(MyShifted, OtherShifted);
2661 return OtherShifted > MyShifted;
2669bool WaitcntBrackets::merge(
const WaitcntBrackets &
Other) {
2670 bool StrictDom =
false;
2674 for (
auto K :
Other.VMem.keys())
2675 VMem.try_emplace(K);
2676 for (
auto K :
Other.SGPRs.keys())
2677 SGPRs.try_emplace(K);
2679 for (
auto T : inst_counter_types(
Context->MaxCounter)) {
2681 const unsigned *WaitEventMaskForInst =
Context->WaitEventMaskForInst;
2682 const unsigned OldEvents = PendingEvents & WaitEventMaskForInst[
T];
2683 const unsigned OtherEvents =
Other.PendingEvents & WaitEventMaskForInst[
T];
2684 if (OtherEvents & ~OldEvents)
2686 PendingEvents |= OtherEvents;
2689 const unsigned MyPending = ScoreUBs[
T] - ScoreLBs[
T];
2690 const unsigned OtherPending =
Other.ScoreUBs[
T] -
Other.ScoreLBs[
T];
2691 const unsigned NewUB = ScoreLBs[
T] + std::max(MyPending, OtherPending);
2692 if (NewUB < ScoreLBs[
T])
2696 M.OldLB = ScoreLBs[
T];
2697 M.OtherLB =
Other.ScoreLBs[
T];
2698 M.MyShift = NewUB - ScoreUBs[
T];
2699 M.OtherShift = NewUB -
Other.ScoreUBs[
T];
2701 ScoreUBs[
T] = NewUB;
2703 StrictDom |= mergeScore(M, LastFlat[
T],
Other.LastFlat[
T]);
2706 StrictDom |= mergeScore(M, LastGDS,
Other.LastGDS);
2709 StrictDom |= mergeScore(M, SCCScore,
Other.SCCScore);
2710 if (
Other.hasPendingEvent(SCC_WRITE)) {
2711 unsigned OldEventsHasSCCWrite = OldEvents & (1 << SCC_WRITE);
2712 if (!OldEventsHasSCCWrite) {
2713 PendingSCCWrite =
Other.PendingSCCWrite;
2714 }
else if (PendingSCCWrite !=
Other.PendingSCCWrite) {
2715 PendingSCCWrite =
nullptr;
2720 for (
auto &[RegID,
Info] : VMem)
2721 StrictDom |= mergeScore(M,
Info.Scores[
T],
Other.getVMemScore(RegID,
T));
2723 if (isSmemCounter(
T)) {
2724 unsigned Idx = getSgprScoresIdx(
T);
2725 for (
auto &[RegID,
Info] : SGPRs) {
2726 auto It =
Other.SGPRs.find(RegID);
2727 unsigned OtherScore =
2728 (It !=
Other.SGPRs.end()) ? It->second.Scores[Idx] : 0;
2729 StrictDom |= mergeScore(M,
Info.Scores[Idx], OtherScore);
2734 for (
auto &[TID,
Info] : VMem) {
2735 if (
auto It =
Other.VMem.find(TID); It !=
Other.VMem.end()) {
2736 unsigned char NewVmemTypes =
Info.VMEMTypes | It->second.VMEMTypes;
2737 StrictDom |= NewVmemTypes !=
Info.VMEMTypes;
2738 Info.VMEMTypes = NewVmemTypes;
2742 purgeEmptyTrackingData();
2748 return Opcode == AMDGPU::S_WAITCNT ||
2751 Opcode == AMDGPU::S_WAIT_LOADCNT_DSCNT ||
2752 Opcode == AMDGPU::S_WAIT_STORECNT_DSCNT ||
2753 Opcode == AMDGPU::S_WAITCNT_lds_direct ||
2757void SIInsertWaitcnts::setSchedulingMode(MachineBasicBlock &
MBB,
2759 bool ExpertMode)
const {
2763 .
addImm(ExpertMode ? 2 : 0)
2768bool SIInsertWaitcnts::insertWaitcntInBlock(MachineFunction &MF,
2769 MachineBasicBlock &
Block,
2770 WaitcntBrackets &ScoreBrackets) {
2774 dbgs() <<
"*** Begin Block: ";
2776 ScoreBrackets.dump();
2782 bool VCCZCorrect =
true;
2783 if (
ST->hasReadVCCZBug()) {
2786 VCCZCorrect =
false;
2787 }
else if (!
ST->partialVCCWritesUpdateVCCZ()) {
2790 VCCZCorrect =
false;
2794 MachineInstr *OldWaitcntInstr =
nullptr;
2799 MachineInstr &Inst = *Iter;
2808 (IsExpertMode && Inst.
getOpcode() == AMDGPU::S_WAITCNT_DEPCTR)) {
2809 if (!OldWaitcntInstr)
2810 OldWaitcntInstr = &Inst;
2815 bool FlushVmCnt =
Block.getFirstTerminator() == Inst &&
2816 isPreheaderToFlush(
Block, ScoreBrackets);
2819 Modified |= generateWaitcntInstBefore(Inst, ScoreBrackets, OldWaitcntInstr,
2821 OldWaitcntInstr =
nullptr;
2827 if (
ST->hasReadVCCZBug() || !
ST->partialVCCWritesUpdateVCCZ()) {
2831 if (!
ST->partialVCCWritesUpdateVCCZ())
2832 VCCZCorrect =
false;
2841 if (
ST->hasReadVCCZBug() &&
2842 ScoreBrackets.hasPendingEvent(SMEM_ACCESS)) {
2845 VCCZCorrect =
false;
2853 if (
TII->isSMRD(Inst)) {
2854 for (
const MachineMemOperand *Memop : Inst.
memoperands()) {
2857 if (!Memop->isInvariant()) {
2858 const Value *Ptr = Memop->getValue();
2862 if (
ST->hasReadVCCZBug()) {
2864 VCCZCorrect =
false;
2868 updateEventWaitcntAfter(Inst, &ScoreBrackets);
2870 Modified |= insertForcedWaitAfter(Inst,
Block, ScoreBrackets);
2874 ScoreBrackets.dump();
2884 TII->get(
ST->isWave32() ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64),
2896 AMDGPU::Waitcnt
Wait;
2897 if (
Block.getFirstTerminator() ==
Block.end() &&
2898 isPreheaderToFlush(
Block, ScoreBrackets)) {
2899 if (ScoreBrackets.hasPendingEvent(LOAD_CNT))
2901 if (ScoreBrackets.hasPendingEvent(SAMPLE_CNT))
2903 if (ScoreBrackets.hasPendingEvent(BVH_CNT))
2912 dbgs() <<
"*** End Block: ";
2914 ScoreBrackets.dump();
2922bool SIInsertWaitcnts::isPreheaderToFlush(
2923 MachineBasicBlock &
MBB,
const WaitcntBrackets &ScoreBrackets) {
2924 auto [Iterator, IsInserted] = PreheadersToFlush.
try_emplace(&
MBB,
false);
2926 return Iterator->second;
2937 shouldFlushVmCnt(Loop, ScoreBrackets)) {
2938 Iterator->second =
true;
2945bool SIInsertWaitcnts::isVMEMOrFlatVMEM(
const MachineInstr &
MI)
const {
2947 return TII->mayAccessVMEMThroughFlat(
MI);
2959bool SIInsertWaitcnts::shouldFlushVmCnt(MachineLoop *
ML,
2960 const WaitcntBrackets &Brackets) {
2961 bool HasVMemLoad =
false;
2962 bool HasVMemStore =
false;
2963 bool UsesVgprLoadedOutside =
false;
2964 DenseSet<MCRegUnit> VgprUse;
2965 DenseSet<MCRegUnit> VgprDef;
2967 for (MachineBasicBlock *
MBB :
ML->blocks()) {
2968 for (MachineInstr &
MI : *
MBB) {
2969 if (isVMEMOrFlatVMEM(
MI)) {
2970 HasVMemLoad |=
MI.mayLoad();
2971 HasVMemStore |=
MI.mayStore();
2974 for (
const MachineOperand &
Op :
MI.all_uses()) {
2975 if (
Op.isDebug() || !
TRI->isVectorRegister(*
MRI,
Op.getReg()))
2978 for (MCRegUnit RU :
TRI->regunits(
Op.getReg().asMCReg())) {
2986 VMEMID
ID = toVMEMID(RU);
2987 if (Brackets.getVMemScore(
ID, LOAD_CNT) >
2988 Brackets.getScoreLB(LOAD_CNT) ||
2989 Brackets.getVMemScore(
ID, SAMPLE_CNT) >
2990 Brackets.getScoreLB(SAMPLE_CNT) ||
2991 Brackets.getVMemScore(
ID, BVH_CNT) >
2992 Brackets.getScoreLB(BVH_CNT)) {
2993 UsesVgprLoadedOutside =
true;
3000 if (isVMEMOrFlatVMEM(
MI) &&
MI.mayLoad()) {
3001 for (
const MachineOperand &
Op :
MI.all_defs()) {
3002 for (MCRegUnit RU :
TRI->regunits(
Op.getReg().asMCReg())) {
3013 if (!
ST->hasVscnt() && HasVMemStore && !HasVMemLoad && UsesVgprLoadedOutside)
3015 return HasVMemLoad && UsesVgprLoadedOutside &&
ST->hasVmemWriteVgprInOrder();
3018bool SIInsertWaitcntsLegacy::runOnMachineFunction(MachineFunction &MF) {
3019 auto *MLI = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
3021 &getAnalysis<MachinePostDominatorTreeWrapperPass>().getPostDomTree();
3023 if (
auto *AAR = getAnalysisIfAvailable<AAResultsWrapperPass>())
3024 AA = &AAR->getAAResults();
3026 return SIInsertWaitcnts(MLI, PDT, AA).run(MF);
3038 if (!SIInsertWaitcnts(MLI, PDT,
AA).
run(MF))
3043 .preserve<AAManager>();
3048 TII = ST->getInstrInfo();
3049 TRI = &
TII->getRegisterInfo();
3055 if (ST->hasExtendedWaitCounts()) {
3056 IsExpertMode = ST->hasExpertSchedulingMode() &&
3062 MaxCounter = IsExpertMode ? NUM_EXPERT_INST_CNTS : NUM_EXTENDED_INST_CNTS;
3063 WCGGFX12Plus = WaitcntGeneratorGFX12Plus(MF, MaxCounter, IsExpertMode);
3064 WCG = &WCGGFX12Plus;
3066 MaxCounter = NUM_NORMAL_INST_CNTS;
3067 WCGPreGFX12 = WaitcntGeneratorPreGFX12(MF, MaxCounter);
3071 for (
auto T : inst_counter_types())
3072 ForceEmitWaitcnt[
T] =
false;
3074 WaitEventMaskForInst = WCG->getWaitEventMask();
3076 SmemAccessCounter = eventCounter(WaitEventMaskForInst, SMEM_ACCESS);
3078 if (
ST->hasExtendedWaitCounts()) {
3097 MachineBasicBlock &EntryBB = MF.
front();
3107 while (
I != EntryBB.
end() &&
I->isMetaInstruction())
3110 if (
ST->hasExtendedWaitCounts()) {
3113 for (
auto CT : inst_counter_types(NUM_EXTENDED_INST_CNTS)) {
3114 if (CT == LOAD_CNT || CT == DS_CNT || CT == STORE_CNT || CT == X_CNT)
3117 if (!
ST->hasImageInsts() &&
3118 (CT == EXP_CNT || CT == SAMPLE_CNT || CT == BVH_CNT))
3122 TII->get(instrsForExtendedCounterTypes[CT]))
3135 auto NonKernelInitialState = std::make_unique<WaitcntBrackets>(
this);
3136 NonKernelInitialState->setStateOnFunctionEntryOrReturn();
3137 BlockInfos[&EntryBB].Incoming = std::move(NonKernelInitialState);
3144 for (
auto *
MBB : ReversePostOrderTraversal<MachineFunction *>(&MF))
3147 std::unique_ptr<WaitcntBrackets> Brackets;
3152 for (
auto BII = BlockInfos.
begin(), BIE = BlockInfos.
end(); BII != BIE;
3154 MachineBasicBlock *
MBB = BII->first;
3155 BlockInfo &BI = BII->second;
3161 Brackets = std::make_unique<WaitcntBrackets>(*BI.Incoming);
3163 *Brackets = *BI.Incoming;
3166 Brackets = std::make_unique<WaitcntBrackets>(
this);
3168 *Brackets = WaitcntBrackets(
this);
3171 Modified |= insertWaitcntInBlock(MF, *
MBB, *Brackets);
3174 if (Brackets->hasPendingEvent()) {
3175 BlockInfo *MoveBracketsToSucc =
nullptr;
3177 auto *SuccBII = BlockInfos.
find(Succ);
3178 BlockInfo &SuccBI = SuccBII->second;
3179 if (!SuccBI.Incoming) {
3180 SuccBI.Dirty =
true;
3181 if (SuccBII <= BII) {
3185 if (!MoveBracketsToSucc) {
3186 MoveBracketsToSucc = &SuccBI;
3188 SuccBI.Incoming = std::make_unique<WaitcntBrackets>(*Brackets);
3190 }
else if (SuccBI.Incoming->merge(*Brackets)) {
3191 SuccBI.Dirty =
true;
3192 if (SuccBII <= BII) {
3198 if (MoveBracketsToSucc)
3199 MoveBracketsToSucc->Incoming = std::move(Brackets);
3204 if (
ST->hasScalarStores()) {
3205 SmallVector<MachineBasicBlock *, 4> EndPgmBlocks;
3206 bool HaveScalarStores =
false;
3208 for (MachineBasicBlock &
MBB : MF) {
3209 for (MachineInstr &
MI :
MBB) {
3210 if (!HaveScalarStores &&
TII->isScalarStore(
MI))
3211 HaveScalarStores =
true;
3213 if (
MI.getOpcode() == AMDGPU::S_ENDPGM ||
3214 MI.getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG)
3219 if (HaveScalarStores) {
3228 for (MachineBasicBlock *
MBB : EndPgmBlocks) {
3229 bool SeenDCacheWB =
false;
3233 if (
I->getOpcode() == AMDGPU::S_DCACHE_WB)
3234 SeenDCacheWB =
true;
3235 else if (
TII->isScalarStore(*
I))
3236 SeenDCacheWB =
false;
3239 if ((
I->getOpcode() == AMDGPU::S_ENDPGM ||
3240 I->getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG) &&
3256 while (
I != EntryBB.
end() &&
I->isMetaInstruction())
3258 setSchedulingMode(EntryBB,
I,
true);
3260 for (MachineInstr *
MI : CallInsts) {
3261 MachineBasicBlock &
MBB = *
MI->getParent();
3262 setSchedulingMode(
MBB,
MI,
false);
3263 setSchedulingMode(
MBB, std::next(
MI->getIterator()),
true);
3266 for (MachineInstr *
MI : ReturnInsts)
3267 setSchedulingMode(*
MI->getParent(),
MI,
false);
3278 for (MachineInstr *
MI : ReleaseVGPRInsts) {
3280 TII->get(AMDGPU::S_ALLOC_VGPR))
3285 if (!ReleaseVGPRInsts.empty() &&
3286 (MF.getFrameInfo().hasCalls() ||
3287 ST->getOccupancyWithNumVGPRs(
3288 TRI->getNumUsedPhysRegs(*
MRI, AMDGPU::VGPR_32RegClass),
3291 for (MachineInstr *
MI : ReleaseVGPRInsts) {
3292 if (
ST->requiresNopBeforeDeallocVGPRs()) {
3294 TII->get(AMDGPU::S_NOP))
3298 TII->get(AMDGPU::S_SENDMSG))
3306 ReturnInsts.
clear();
3307 ReleaseVGPRInsts.clear();
3308 PreheadersToFlush.
clear();
3309 SLoadAddresses.
clear();
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
static bool isOptNone(const MachineFunction &MF)
static LoopDeletionResult merge(LoopDeletionResult A, LoopDeletionResult B)
Register const TargetRegisterInfo * TRI
This file implements a map that provides insertion order iteration.
static bool isReg(const MCInst &MI, unsigned OpNo)
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static cl::opt< bool > ForceEmitZeroLoadFlag("amdgpu-waitcnt-load-forcezero", cl::desc("Force all waitcnt load counters to wait until 0"), cl::init(false), cl::Hidden)
#define AMDGPU_EVENT_NAME(Name)
static bool updateOperandIfDifferent(MachineInstr &MI, AMDGPU::OpName OpName, unsigned NewEnc)
static bool isWaitInstr(MachineInstr &Inst)
static std::optional< InstCounterType > counterTypeForInstr(unsigned Opcode)
Determine if MI is a gfx12+ single-counter S_WAIT_*CNT instruction, and if so, which counter it is wa...
static cl::opt< bool > ExpertSchedulingModeFlag("amdgpu-expert-scheduling-mode", cl::desc("Enable expert scheduling mode 2 for all functions (GFX12+ only)"), cl::init(false), cl::Hidden)
static cl::opt< bool > ForceEmitZeroFlag("amdgpu-waitcnt-forcezero", cl::desc("Force all waitcnt instrs to be emitted as " "s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)"), cl::init(false), cl::Hidden)
#define AMDGPU_DECLARE_WAIT_EVENTS(DECL)
#define AMDGPU_EVENT_ENUM(Name)
Provides some synthesis utilities to produce sequences of values.
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static const uint32_t IV[8]
A manager for alias analyses.
bool isEntryFunction() const
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
LLVM_ABI bool getValueAsBool() const
Return the attribute's value as a boolean.
Represents analyses that only rely on functions' control flow.
static bool shouldExecute(CounterInfo &Counter)
static bool isCounterSet(CounterInfo &Info)
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
bool erase(const KeyT &Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
FunctionPass class - This class is used to implement most global optimizations.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
LLVM_ABI const MachineBasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
Instructions::iterator instr_iterator
instr_iterator instr_end()
iterator_range< succ_iterator > successors()
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
mop_range defs()
Returns all explicit operands that are register definitions.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
const MachineBasicBlock * getParent() const
filtered_mop_range all_defs()
Returns an iterator range over all operands that are (explicit or implicit) register defs.
bool isCall(QueryType Type=AnyInBundle) const
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
bool definesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr fully defines the specified register.
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
LLVM_ABI 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.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
filtered_mop_range all_uses()
Returns an iterator range over all operands that are (explicit or implicit) register uses.
const MachineOperand & getOperand(unsigned i) const
bool isMetaInstruction(QueryType Type=IgnoreBundle) const
Return true if this instruction doesn't produce any output in the form of executable instructions.
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineOperand class - Representation of each machine instruction operand.
void setImm(int64_t immVal)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
iterator find(const KeyT &Key)
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
static bool isCBranchVCCZRead(const MachineInstr &MI)
static bool isVMEM(const MachineInstr &MI)
static bool isFLATScratch(const MachineInstr &MI)
static bool isEXP(const MachineInstr &MI)
static bool mayWriteLDSThroughDMA(const MachineInstr &MI)
static bool isLDSDIR(const MachineInstr &MI)
static bool isGWS(const MachineInstr &MI)
static bool isFLATGlobal(const MachineInstr &MI)
static bool isVSAMPLE(const MachineInstr &MI)
static bool isAtomicRet(const MachineInstr &MI)
static bool isImage(const MachineInstr &MI)
static unsigned getNonSoftWaitcntOpcode(unsigned Opcode)
static bool isVINTERP(const MachineInstr &MI)
static bool isGFX12CacheInvOrWBInst(unsigned Opc)
static bool isSBarrierSCCWrite(unsigned Opcode)
static bool isMIMG(const MachineInstr &MI)
static bool isFLAT(const MachineInstr &MI)
static bool isLDSDMA(const MachineInstr &MI)
static bool isAtomicNoRet(const MachineInstr &MI)
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
bool isDynamicVGPREnabled() const
void push_back(const T &Elt)
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
@ LOCAL_ADDRESS
Address space for local memory.
@ FLAT_ADDRESS
Address space for flat memory.
unsigned getVmVsrcBitMask()
unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst)
unsigned getVaVdstBitMask()
unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc)
unsigned decodeFieldVaVdst(unsigned Encoded)
int getDefaultDepCtrEncoding(const MCSubtargetInfo &STI)
unsigned decodeFieldVmVsrc(unsigned Encoded)
unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI)
@ ID_DEALLOC_VGPRS_GFX11Plus
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt)
Decodes Vmcnt, Expcnt and Lgkmcnt from given Waitcnt for given isa Version, and writes decoded values...
bool isDPMACCInstruction(unsigned Opc)
unsigned getStorecntBitMask(const IsaVersion &Version)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
unsigned encodeWaitcnt(const IsaVersion &Version, unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt)
Encodes Vmcnt, Expcnt and Lgkmcnt into Waitcnt for given isa Version.
unsigned getSamplecntBitMask(const IsaVersion &Version)
unsigned getKmcntBitMask(const IsaVersion &Version)
unsigned getVmcntBitMask(const IsaVersion &Version)
unsigned getXcntBitMask(const IsaVersion &Version)
Waitcnt decodeStorecntDscnt(const IsaVersion &Version, unsigned StorecntDscnt)
unsigned getLgkmcntBitMask(const IsaVersion &Version)
unsigned getBvhcntBitMask(const IsaVersion &Version)
unsigned getExpcntBitMask(const IsaVersion &Version)
Waitcnt decodeLoadcntDscnt(const IsaVersion &Version, unsigned LoadcntDscnt)
static unsigned encodeStorecntDscnt(const IsaVersion &Version, unsigned Storecnt, unsigned Dscnt)
bool getMUBUFIsBufferInv(unsigned Opc)
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
unsigned getLoadcntBitMask(const IsaVersion &Version)
static unsigned encodeLoadcntDscnt(const IsaVersion &Version, unsigned Loadcnt, unsigned Dscnt)
unsigned getDscntBitMask(const IsaVersion &Version)
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ Undef
Value of the register doesn't matter.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
FunctionAddr VTableAddr Value
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
char & SIInsertWaitcntsID
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
CodeGenOptLevel
Code generation optimization level.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
FunctionPass * createSIInsertWaitcntsPass()
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
static constexpr ValueType Default
static constexpr uint64_t encode(Fields... Values)
Instruction set architecture version.
Represents the counter values to wait for in an s_waitcnt instruction.
static constexpr bool is_iterable