41 CurrCycleInstr(nullptr),
44 TII(*
ST.getInstrInfo()),
45 TRI(
TII.getRegisterInfo()),
46 ClauseUses(
TRI.getNumRegUnits()),
47 ClauseDefs(
TRI.getNumRegUnits()) {
60 return Opcode == AMDGPU::V_DIV_FMAS_F32 || Opcode == AMDGPU::V_DIV_FMAS_F64;
64 return Opcode == AMDGPU::S_GETREG_B32;
68 return Opcode == AMDGPU::S_SETREG_B32 || Opcode == AMDGPU::S_SETREG_IMM32_B32;
72 return Opcode == AMDGPU::V_READLANE_B32 || Opcode == AMDGPU::V_WRITELANE_B32;
75 static bool isRFE(
unsigned Opcode) {
76 return Opcode == AMDGPU::S_RFE_B64;
81 case AMDGPU::S_MOVRELS_B32:
82 case AMDGPU::S_MOVRELS_B64:
83 case AMDGPU::S_MOVRELD_B32:
84 case AMDGPU::S_MOVRELD_B64:
93 case AMDGPU::S_SENDMSG:
94 case AMDGPU::S_SENDMSGHALT:
95 case AMDGPU::S_TTRACEDATA:
105 AMDGPU::OpName::simm16);
119 && checkVMEMHazards(MI) > 0)
145 checkReadM0Hazards(MI) > 0)
149 checkReadM0Hazards(MI) > 0)
152 if (MI->
isInlineAsm() && checkInlineAsmHazards(MI) > 0)
155 if (checkAnyInstHazards(MI) > 0)
166 int WaitStates =
std::max(0, checkAnyInstHazards(MI));
169 return std::max(WaitStates, checkSMRDHazards(MI));
172 WaitStates =
std::max(WaitStates, checkVALUHazards(MI));
175 WaitStates =
std::max(WaitStates, checkVMEMHazards(MI));
178 WaitStates =
std::max(WaitStates, checkDPPHazards(MI));
181 WaitStates =
std::max(WaitStates, checkDivFMasHazards(MI));
184 WaitStates =
std::max(WaitStates, checkRWLaneHazards(MI));
187 return std::max(WaitStates, checkInlineAsmHazards(MI));
190 return std::max(WaitStates, checkGetRegHazards(MI));
193 return std::max(WaitStates, checkSetRegHazards(MI));
196 return std::max(WaitStates, checkRFEHazards(MI));
200 return std::max(WaitStates, checkReadM0Hazards(MI));
203 return std::max(WaitStates, checkReadM0Hazards(MI));
209 EmittedInstrs.push_front(
nullptr);
221 EmittedInstrs.push_front(CurrCycleInstr);
228 EmittedInstrs.push_front(
nullptr);
236 CurrCycleInstr =
nullptr;
240 llvm_unreachable(
"hazard recognizer does not support bottom-up scheduling.");
247 int GCNHazardRecognizer::getWaitStatesSince(
255 unsigned Opcode =
MI->getOpcode();
256 if (Opcode == AMDGPU::DBG_VALUE || Opcode == AMDGPU::IMPLICIT_DEF ||
265 int GCNHazardRecognizer::getWaitStatesSinceDef(
270 return IsHazardDef(
MI) &&
MI->modifiesRegister(Reg, TRI);
273 return getWaitStatesSince(IsHazardFn);
276 int GCNHazardRecognizer::getWaitStatesSinceSetReg(
282 return getWaitStatesSince(IsHazardFn);
310 int GCNHazardRecognizer::checkSoftClauseHazards(
MachineInstr *MEM) {
316 bool IsSMRD = TII.
isSMRD(*MEM);
342 if (ClauseDefs.
none())
355 return ClauseDefs.
anyCommon(ClauseUses) ? 1 : 0;
360 int WaitStatesNeeded = 0;
362 WaitStatesNeeded = checkSoftClauseHazards(SMRD);
366 return WaitStatesNeeded;
370 int SmrdSgprWaitStates = 4;
379 int WaitStatesNeededForUse =
380 SmrdSgprWaitStates - getWaitStatesSinceDef(
Use.getReg(), IsHazardDefFn);
381 WaitStatesNeeded =
std::max(WaitStatesNeeded, WaitStatesNeededForUse);
391 int WaitStatesNeededForUse =
392 SmrdSgprWaitStates - getWaitStatesSinceDef(
Use.getReg(),
393 IsBufferHazardDefFn);
394 WaitStatesNeeded =
std::max(WaitStatesNeeded, WaitStatesNeededForUse);
398 return WaitStatesNeeded;
401 int GCNHazardRecognizer::checkVMEMHazards(
MachineInstr* VMEM) {
405 int WaitStatesNeeded = checkSoftClauseHazards(VMEM);
409 const int VmemSgprWaitStates = 5;
416 int WaitStatesNeededForUse =
417 VmemSgprWaitStates - getWaitStatesSinceDef(
Use.getReg(), IsHazardDefFn);
418 WaitStatesNeeded =
std::max(WaitStatesNeeded, WaitStatesNeededForUse);
420 return WaitStatesNeeded;
428 int DppVgprWaitStates = 2;
429 int DppExecWaitStates = 5;
430 int WaitStatesNeeded = 0;
436 int WaitStatesNeededForUse =
437 DppVgprWaitStates - getWaitStatesSinceDef(
Use.getReg());
438 WaitStatesNeeded =
std::max(WaitStatesNeeded, WaitStatesNeededForUse);
443 DppExecWaitStates - getWaitStatesSinceDef(AMDGPU::EXEC, IsHazardDefFn));
445 return WaitStatesNeeded;
448 int GCNHazardRecognizer::checkDivFMasHazards(
MachineInstr *DivFMas) {
453 const int DivFMasWaitStates = 4;
455 int WaitStatesNeeded = getWaitStatesSinceDef(AMDGPU::VCC, IsHazardDefFn);
457 return DivFMasWaitStates - WaitStatesNeeded;
460 int GCNHazardRecognizer::checkGetRegHazards(
MachineInstr *GetRegInstr) {
462 unsigned GetRegHWReg =
getHWReg(TII, *GetRegInstr);
464 const int GetRegWaitStates = 2;
466 return GetRegHWReg ==
getHWReg(TII, *MI);
468 int WaitStatesNeeded = getWaitStatesSinceSetReg(IsHazardFn);
470 return GetRegWaitStates - WaitStatesNeeded;
473 int GCNHazardRecognizer::checkSetRegHazards(
MachineInstr *SetRegInstr) {
475 unsigned HWReg =
getHWReg(TII, *SetRegInstr);
477 const int SetRegWaitStates =
482 int WaitStatesNeeded = getWaitStatesSinceSetReg(IsHazardFn);
483 return SetRegWaitStates - WaitStatesNeeded;
486 int GCNHazardRecognizer::createsVALUHazard(
const MachineInstr &MI) {
511 (!SOffset || !SOffset->
isReg()))
541 const int VALUWaitStates = 1;
542 int WaitStatesNeeded = 0;
545 return WaitStatesNeeded;
546 unsigned Reg = Def.
getReg();
548 int DataIdx = createsVALUHazard(*MI);
549 return DataIdx >= 0 &&
552 int WaitStatesNeededForDef =
553 VALUWaitStates - getWaitStatesSince(IsHazardFn);
554 WaitStatesNeeded =
std::max(WaitStatesNeeded, WaitStatesNeededForDef);
556 return WaitStatesNeeded;
566 int WaitStatesNeeded = 0;
569 WaitStatesNeeded =
std::max(WaitStatesNeeded, checkVALUHazardsHelper(Def, MRI));
572 return WaitStatesNeeded;
575 int GCNHazardRecognizer::checkInlineAsmHazards(
MachineInstr *IA) {
588 int WaitStatesNeeded = 0;
594 WaitStatesNeeded =
std::max(WaitStatesNeeded, checkVALUHazardsHelper(Op, MRI));
598 return WaitStatesNeeded;
601 int GCNHazardRecognizer::checkRWLaneHazards(
MachineInstr *RWLane) {
612 unsigned LaneSelectReg = LaneSelectOp->
getReg();
617 const int RWLaneWaitStates = 4;
618 int WaitStatesSince = getWaitStatesSinceDef(LaneSelectReg, IsHazardFn);
619 return RWLaneWaitStates - WaitStatesSince;
622 int GCNHazardRecognizer::checkRFEHazards(
MachineInstr *RFE) {
628 const int RFEWaitStates = 1;
633 int WaitStatesNeeded = getWaitStatesSinceSetReg(IsHazardFn);
634 return RFEWaitStates - WaitStatesNeeded;
637 int GCNHazardRecognizer::checkAnyInstHazards(
MachineInstr *MI) {
647 int MovFedWaitStates = 1;
648 int WaitStatesNeeded = 0;
654 return MI->
getOpcode() == AMDGPU::S_MOV_FED_B32;
656 int WaitStatesNeededForUse =
657 MovFedWaitStates - getWaitStatesSinceDef(
Use.getReg(), IsHazardFn);
658 WaitStatesNeeded =
std::max(WaitStatesNeeded, WaitStatesNeededForUse);
661 return WaitStatesNeeded;
664 int GCNHazardRecognizer::checkReadM0Hazards(
MachineInstr *MI) {
666 const int SMovRelWaitStates = 1;
670 return SMovRelWaitStates - getWaitStatesSinceDef(AMDGPU::M0, IsHazardFn);
static bool isSMovRel(unsigned Opcode)
Interface definition for SIRegisterInfo.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
AMDGPU specific subclass of TargetSubtarget.
Compute iterated dominance frontiers using a linear time algorithm.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
bool hasReadM0MovRelInterpHazard() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
static bool isVINTRP(const MachineInstr &MI)
static bool isSendMsgTraceDataOrGDS(const MachineInstr &MI)
unsigned getRegBitWidth(unsigned RCID)
Get the size in bits of a register from the register class RC.
An efficient, type-erasing, non-owning reference to a callable.
static bool isRFE(unsigned Opcode)
const SIInstrInfo * getInstrInfo() const override
static void addRegUnits(const SIRegisterInfo &TRI, BitVector &BV, unsigned Reg)
unsigned const TargetRegisterInfo * TRI
static bool isSMRD(const MachineInstr &MI)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
void EmitNoop() override
EmitNoop - This callback is invoked when a noop was added to the instruction stream.
static bool isFLAT(const MachineInstr &MI)
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)
A Use represents the edge between a Value definition and its users.
bool hasSMovFedHazard() const
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static bool isVALU(const MachineInstr &MI)
INLINEASM - Represents an inline asm block.
bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
static bool isMUBUF(const MachineInstr &MI)
static bool isSSetReg(unsigned Opcode)
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
unsigned PreEmitNoops(SUnit *SU) override
PreEmitNoops - This callback is invoked prior to emitting an instruction.
void RecedeCycle() override
RecedeCycle - This callback is invoked whenever the next bottom-up instruction to be scheduled cannot...
void EmitInstruction(SUnit *SU) override
EmitInstruction - This callback is invoked when an instruction is emitted, to advance the hazard stat...
unsigned MaxLookAhead
MaxLookAhead - Indicate the number of cycles in the scoreboard state.
static bool isDPP(const MachineInstr &MI)
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
static void addRegsToSet(const SIRegisterInfo &TRI, iterator_range< MachineInstr::const_mop_iterator > Ops, BitVector &Set)
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
unsigned const MachineRegisterInfo * MRI
unsigned getMaxLookAhead() const
bool anyCommon(const BitVector &RHS) const
Test if any common bits are set.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
Generation getGeneration() const
bool isDebugInstr() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumWaitStates(const MachineInstr &MI) const
Return the number of wait states that result from executing this instruction.
static bool isSALU(const MachineInstr &MI)
HazardType getHazardType(SUnit *SU, int Stalls) override
getHazardType - Return the hazard type of emitting this node.
MachineOperand class - Representation of each machine instruction operand.
GCNHazardRecognizer(const MachineFunction &MF)
A range adaptor for a pair of iterators.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
void AdvanceCycle() override
AdvanceCycle - This callback is invoked whenever the next top-down instruction to be scheduled cannot...
static bool isRWLane(unsigned Opcode)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool none() const
none - Returns true if none of the bits are set.
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
Interface definition for SIInstrInfo.
static bool isMTBUF(const MachineInstr &MI)
bool has12DWordStoreHazard() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
bool isXNACKEnabled() const
static bool isVMEM(const MachineInstr &MI)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isSGetReg(unsigned Opcode)
const MCOperandInfo * OpInfo
static unsigned getHWReg(const SIInstrInfo *TII, const MachineInstr &RegInstr)
const MachineOperand & getOperand(unsigned i) const
bool hasReadM0SendMsgHazard() const
bool isBufferSMRD(const MachineInstr &MI) const
Scheduling unit. This is a node in the scheduling DAG.
const SIRegisterInfo * getRegisterInfo() const override
static bool isDivFMas(unsigned Opcode)