47 #define DEBUG_TYPE "si-insert-waits"
70 typedef std::pair<unsigned, unsigned> RegInterval;
100 RegCounters DefinedRegs;
103 unsigned ExpInstrTypesSeen = 0;
108 bool LastInstWritesM0;
111 bool IsFlatOutstanding;
117 bool VCCZCorrupt =
false;
153 bool hasOutstandingLGKM()
const;
163 return "SI insert wait instructions";
175 "SI Insert Waits",
false,
false)
179 char SIInsertWaits::
ID = 0;
184 return new SIInsertWaits();
187 const Counters SIInsertWaits::ZeroCounts = { { 0, 0, 0 } };
191 return (Opc == AMDGPU::S_CBRANCH_VCCNZ || Opc == AMDGPU::S_CBRANCH_VCCZ) &&
195 bool SIInsertWaits::hasOutstandingLGKM()
const {
196 return WaitedOn.Named.LGKM != LastIssued.Named.LGKM;
211 if (
TII->isSMRD(MI)) {
215 "First LGKM operand must be a register!");
219 unsigned Size = TRI->getRegSizeInBits(*RC);
220 Result.Named.LGKM = Size > 32 ? 2 : 1;
225 Result.Named.LGKM = 1;
229 Result.Named.LGKM = 1;
233 Result.Named.LGKM = 0;
241 if (!Op.
isReg() || !TRI->isInAllocatableClass(Op.
getReg()))
272 if (
TII->isFLAT(MI)) {
283 if (
I->isReg() &&
I->isUse())
292 unsigned Size = TRI->getRegSizeInBits(*RC);
296 Result.first = TRI->getEncodingValue(Reg.
getReg());
297 Result.second = Result.first + Size / 32;
309 if (
TII->mayAccessFlatAddressSpace(*I))
310 IsFlatOutstanding =
true;
312 for (
unsigned i = 0; i < 3; ++i) {
313 LastIssued.Array[i] += Increment.Array[i];
314 if (Increment.Array[i])
315 Limit.Array[i] = LastIssued.Array[i];
316 Sum += Increment.Array[i];
321 LastOpcodeType = OTHER;
335 if (LastOpcodeType == VMEM && Increment.Named.VM) {
339 LastInstWritesM0 =
false;
343 LastOpcodeType = SMEM;
344 else if (Increment.Named.VM)
345 LastOpcodeType = VMEM;
349 if (Increment.Named.EXP) {
350 ExpInstrTypesSeen |=
TII->isEXP(*I) ? 1 : 2;
353 for (
unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
355 if (!isOpRelevant(Op))
359 RegInterval
Interval = getRegInterval(RC, Op);
360 for (
unsigned j = Interval.first; j < Interval.second; ++j) {
364 DefinedRegs[j] = Limit;
379 if (I != MBB.
end() && I->getOpcode() == AMDGPU::S_ENDPGM && ReturnsVoid)
387 Ordered[0] = !IsFlatOutstanding;
390 Ordered[1] = ExpInstrTypesSeen == 3;
399 bool NeedWait =
false;
401 for (
unsigned i = 0; i < 3; ++i) {
402 if (Required.Array[i] <= WaitedOn.Array[i])
408 unsigned Value = LastIssued.Array[i] - Required.Array[i];
411 Counts.Array[i] =
std::min(Value, HardwareLimits.Array[i]);
417 WaitedOn.Array[i] = LastIssued.Array[i] - Counts.Array[i];
424 if (Counts.Named.EXP == 0)
425 ExpInstrTypesSeen = 0;
434 LastOpcodeType = OTHER;
435 LastInstWritesM0 =
false;
436 IsFlatOutstanding =
false;
442 for (
unsigned i = 0; i < 3; ++i)
443 Dst.Array[i] =
std::max(Dst.Array[i], Src.Array[i]);
448 for (
unsigned i = 0; i < 3; ++i)
449 if (Counter.Array[i])
455 assert(I->getOpcode() == AMDGPU::S_WAITCNT);
457 unsigned Imm = I->getOperand(0).getImm();
464 for (
unsigned i = 0; i < 3; ++i) {
465 if (Counts.Array[i] <= LastIssued.Array[i])
466 WaitOn.Array[i] = LastIssued.Array[i] - Counts.Array[i];
484 if (!Op.
isReg() || !TRI->isInAllocatableClass(Op.
getReg()))
488 RegInterval Interval = getRegInterval(RC, Op);
489 for (
unsigned j = Interval.first; j < Interval.second; ++j) {
509 if (LastInstWritesM0 && (I->getOpcode() == AMDGPU::S_SENDMSG || I->getOpcode() == AMDGPU::S_SENDMSGHALT)) {
511 LastInstWritesM0 =
false;
516 LastInstWritesM0 =
false;
518 unsigned NumOperands = I->getNumOperands();
519 for (
unsigned i = 0; i < NumOperands; i++) {
523 LastInstWritesM0 =
true;
540 bool Changes =
false;
543 TII =
ST->getInstrInfo();
553 WaitedOn = ZeroCounts;
554 DelayedWaitOn = ZeroCounts;
555 LastIssued = ZeroCounts;
556 LastOpcodeType = OTHER;
557 LastInstWritesM0 =
false;
558 IsFlatOutstanding =
false;
559 ReturnsVoid = MFI->returnsVoid();
561 memset(&UsedRegs, 0,
sizeof(UsedRegs));
562 memset(&DefinedRegs, 0,
sizeof(DefinedRegs));
567 bool HaveScalarStores =
false;
577 if (!HaveScalarStores && TII->isScalarStore(*I))
578 HaveScalarStores =
true;
589 if (TII->isSMRD(I->getOpcode())) {
591 }
else if (!hasOutstandingLGKM() && I->modifiesRegister(AMDGPU::VCC, TRI)) {
600 DEBUG(
dbgs() <<
"Inserting vccz bug work-around before: " << *I <<
'\n');
607 insertWait(MBB, I, LastIssued);
612 BuildMI(MBB, I, I->getDebugLoc(), TII->get(AMDGPU::S_MOV_B64),
614 .addReg(AMDGPU::VCC);
619 if (I->getOpcode() == AMDGPU::S_WAITCNT) {
620 handleExistingWait(*I);
632 if ((I->getOpcode() == AMDGPU::S_BARRIER &&
633 !
ST->hasAutoWaitcntBeforeBarrier()) ||
634 I->getOpcode() == AMDGPU::S_SENDMSG ||
635 I->getOpcode() == AMDGPU::S_SENDMSGHALT)
636 Required = LastIssued;
638 Required = handleOperands(*I);
640 Counters Increment = getHwCounts(*I);
645 Changes |= insertWait(MBB, I, Required);
647 pushInstruction(MBB, I, Increment);
648 handleSendMsg(MBB, I);
650 if (I->getOpcode() == AMDGPU::S_ENDPGM ||
651 I->getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG)
661 if (HaveScalarStores) {
670 bool SeenDCacheWB =
false;
675 if (I->getOpcode() == AMDGPU::S_DCACHE_WB)
677 else if (TII->isScalarStore(*I))
678 SeenDCacheWB =
false;
681 if ((I->getOpcode() == AMDGPU::S_ENDPGM ||
682 I->getOpcode() == AMDGPU::SI_RETURN_TO_EPILOG) && !SeenDCacheWB) {
684 BuildMI(*MBB, I, I->getDebugLoc(), TII->get(AMDGPU::S_DCACHE_WB));
691 I->eraseFromParent();
693 if (!MFI->isEntryFunction()) {
unsigned succ_size() const
void push_back(const T &Elt)
mop_iterator operands_end()
Interface definition for SIRegisterInfo.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
AMDGPU specific subclass of TargetSubtarget.
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool mayStore() const
Return true if this instruction could possibly modify memory.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Reg
All possible values of the reg field in the ModR/M byte.
unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
unsigned getNumOperands() const
Access to explicit operands of the instruction.
const MachineBasicBlock & front() const
static void increaseCounters(Counters &Dst, const Counters &Src)
helper function for handleOperands
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
static bool hasTrivialSuccessor(const MachineBasicBlock &MBB)
Return true if MBB has one successor immediately following, and is its only predecessor.
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static bool countersNonZero(const Counters &Counter)
check whether any of the counters is non-zero
Instruction set architecture version.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
succ_iterator succ_begin()
static bool readsVCCZ(const MachineInstr &MI)
unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version)
Iterator for intrusive lists based on ilist_node.
const SIRegisterInfo * getRegisterInfo() const override
MachineOperand class - Representation of each machine instruction operand.
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.
INITIALIZE_PASS_BEGIN(SIInsertWaits, DEBUG_TYPE,"SI Insert Waits", false, false) INITIALIZE_PASS_END(SIInsertWaits
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static uint8_t Counters[N]
Representation of each machine instruction.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt)
unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt)
Encodes Vmcnt, Expcnt and Lgkmcnt into Waitcnt for given isa Version.
unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version)
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
FunctionPass * createSIInsertWaitsPass()
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
mop_iterator operands_begin()
StringRef - Represent a constant reference to a string, i.e.
bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
unsigned pred_size() const
IsaVersion getIsaVersion(const FeatureBitset &Features)