LLVM 24.0.0git
GCNHazardRecognizer.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "gcn-hazard-recognizer"
#define DEBUG_TYPE_VERBOSE   "gcn-hazard-recognizer-verbose"

Enumerations

enum  HazardFnResult { HazardFound , HazardExpired , NoHazardFound }

Functions

 STATISTIC (NumWMMANopsHoisted, "Number of WMMA hazard V_NOPs hoisted from loops")
 STATISTIC (NumWMMAHoistingBailed, "Number of WMMA hazards where V_NOP hoisting was not possible")
static bool shouldRunLdsBranchVmemWARHazardFixup (const MachineFunction &MF, const GCNSubtarget &ST)
static bool isDivFMas (unsigned Opcode)
static bool isSGetReg (unsigned Opcode)
static bool isSSetReg (unsigned Opcode)
static bool isRWLane (unsigned Opcode)
static bool isRFE (unsigned Opcode)
static bool isSMovRel (unsigned Opcode)
static bool isSendMsgTraceDataOrGDS (const SIInstrInfo &TII, const MachineInstr &MI)
static bool isPermlane (const MachineInstr &MI)
static bool isLdsDma (const MachineInstr &MI)
static unsigned getHWReg (const SIInstrInfo *TII, const MachineInstr &RegInstr)
static void insertNoopsInBundle (MachineInstr *MI, const SIInstrInfo &TII, unsigned Quantity)
template<typename StateT>
static bool hasHazard (StateT InitialState, function_ref< HazardFnResult(StateT &, const MachineInstr &)> IsHazard, function_ref< void(StateT &, const MachineInstr &)> UpdateState, const MachineBasicBlock *InitialMBB, MachineBasicBlock::const_reverse_instr_iterator InitialI)
static int getWaitStatesSince (GCNHazardRecognizer::IsHazardFn IsHazard, const MachineBasicBlock *MBB, MachineBasicBlock::const_reverse_instr_iterator I, int WaitStates, GCNHazardRecognizer::IsExpiredFn IsExpired, DenseSet< const MachineBasicBlock * > &Visited, GCNHazardRecognizer::GetNumWaitStatesFn GetNumWaitStates=SIInstrInfo::getNumWaitStates)
static int getWaitStatesSince (GCNHazardRecognizer::IsHazardFn IsHazard, const MachineInstr *MI, GCNHazardRecognizer::IsExpiredFn IsExpired, GCNHazardRecognizer::GetNumWaitStatesFn GetNumWaitStates=SIInstrInfo::getNumWaitStates)
static void addRegUnits (const SIRegisterInfo &TRI, BitVector &BV, MCRegister Reg)
static void addRegsToSet (const SIRegisterInfo &TRI, iterator_range< MachineInstr::const_mop_iterator > Ops, BitVector &DefSet, BitVector &UseSet)
static bool breaksSMEMSoftClause (MachineInstr *MI)
static bool breaksVMEMSoftClause (MachineInstr *MI)
static const MachineOperand * getDstSelForwardingOperand (const MachineInstr &MI, const GCNSubtarget &ST)
 Dest sel forwarding issue occurs if additional logic is needed to swizzle / pack the computed value into correct bit position of the dest register.
static bool consumesDstSelForwardingOperand (const MachineInstr *VALU, const MachineOperand *Dst, const SIRegisterInfo *TRI)
 Checks whether the provided MI "consumes" the operand with a Dest sel fowarding issue Dst .
static bool isVCmpXWritesExec (const SIInstrInfo &TII, const SIRegisterInfo &TRI, const MachineInstr &MI)
static bool isStoreCountWaitZero (const MachineInstr &I)
static bool isCoexecutableVALUInst (const MachineInstr &MI)
static unsigned getWMMAHazardInstInCategory (const MachineInstr &MI, const SIInstrInfo *TII, const TargetSchedModel &SchedModel, const GCNSubtarget &ST)
static unsigned getMFMANonMacAGPRFormOp (unsigned Opc)
 One MFMA can be written with up to four opcodes that differ only in how vdst and src2 are encoded: both are either AGPRs or VGPRs, and the mac form ties vdst to src2 instead of taking them as separate operands.
static bool isSameMFMA (unsigned Opc0, unsigned Opc1)
static int GFX940_XDL_N_PassWritesVGPROverlappedXDLOrSMFMASrcCWaitStates (int NumPasses, bool IsGFX950)
static int GFX940_XDL_N_PassWritesVGPROverlappedSGEMMDGEMMSrcCWaitStates (int NumPasses, bool IsGFX950)
static int GFX940_SMFMA_N_PassWritesVGPROverlappedSMFMASrcCWaitStates (int NumPasses)
static int GFX940_SMFMA_N_PassWritesVGPROverlappedSrcABWaitStates (int NumPasses)
static int GFX940_XDL_N_PassWritesVGPROverlappedSrcABWaitStates (int NumPasses, bool IsGFX950)
static int GFX940_SMFMA_N_PassWriteVgprVALUWawWaitStates (int NumPasses)
static int GFX940_XDL_N_PassWriteVgprVALUWawWaitStates (int NumPasses, bool IsGFX950)
static int GFX940_XDL_N_PassWriteVgprVALUMemExpReadWaitStates (int NumPasses, bool IsGFX950)
static int GFX940_SMFMA_N_PassWriteVgprVALUMemExpReadWaitStates (int NumPasses)
static void updateGetPCBundle (MachineInstr *NewMI)
static bool ensureEntrySetPrio (MachineFunction *MF, int Priority, const SIInstrInfo &TII)
static MachineBasicBlock::iterator skipMetaInstructionsForward (MachineBasicBlock::iterator I, MachineBasicBlock::iterator End)

Variables

static cl::opt< unsigned, false, MFMAPaddingRatioParser > MFMAPaddingRatio ("amdgpu-mfma-padding-ratio", cl::init(0), cl::Hidden, cl::desc("Fill a percentage of the latency between " "neighboring MFMA with s_nops."))
static cl::opt< unsigned > NopPadding ("amdgpu-snop-padding", cl::init(0), cl::Hidden, cl::desc("Insert a s_nop x before every instruction"))
static cl::opt< bool > EnableWMMAVnopHoisting ("amdgpu-wmma-vnop-hoisting", cl::init(true), cl::Hidden, cl::desc("Hoist WMMA hazard V_NOPs from loops to preheaders"))

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "gcn-hazard-recognizer"

Definition at line 28 of file GCNHazardRecognizer.cpp.

◆ DEBUG_TYPE_VERBOSE

#define DEBUG_TYPE_VERBOSE   "gcn-hazard-recognizer-verbose"

Definition at line 31 of file GCNHazardRecognizer.cpp.

Enumeration Type Documentation

◆ HazardFnResult

Enumerator
HazardFound 
HazardExpired 
NoHazardFound 

Definition at line 873 of file GCNHazardRecognizer.cpp.

Function Documentation

◆ addRegsToSet()

void addRegsToSet ( const SIRegisterInfo & TRI,
iterator_range< MachineInstr::const_mop_iterator > Ops,
BitVector & DefSet,
BitVector & UseSet )
static

◆ addRegUnits()

void addRegUnits ( const SIRegisterInfo & TRI,
BitVector & BV,
MCRegister Reg )
static

Definition at line 1100 of file GCNHazardRecognizer.cpp.

References Reg, llvm::BitVector::set(), and TRI.

Referenced by addRegsToSet().

◆ breaksSMEMSoftClause()

bool breaksSMEMSoftClause ( MachineInstr * MI)
static

Definition at line 1119 of file GCNHazardRecognizer.cpp.

References llvm::SIInstrInfo::isSMRD(), and MI.

◆ breaksVMEMSoftClause()

bool breaksVMEMSoftClause ( MachineInstr * MI)
static

Definition at line 1123 of file GCNHazardRecognizer.cpp.

References llvm::SIInstrInfo::isVMEM(), and MI.

◆ consumesDstSelForwardingOperand()

bool consumesDstSelForwardingOperand ( const MachineInstr * VALU,
const MachineOperand * Dst,
const SIRegisterInfo * TRI )
static

Checks whether the provided MI "consumes" the operand with a Dest sel fowarding issue Dst .

We may "consume" the Dst via a standard explicit RAW, or through irregular ways (e.g implicit RAW, certain types of WAW)

Definition at line 1495 of file GCNHazardRecognizer.cpp.

References TRI.

◆ ensureEntrySetPrio()

◆ getDstSelForwardingOperand()

const MachineOperand * getDstSelForwardingOperand ( const MachineInstr & MI,
const GCNSubtarget & ST )
static

Dest sel forwarding issue occurs if additional logic is needed to swizzle / pack the computed value into correct bit position of the dest register.

This occurs if we have SDWA with dst_sel != DWORD or if we have op_sel with dst_sel that is not aligned to the register. This function analayzes the MI and

Returns
an operand with dst forwarding issue, or nullptr if none exists.

Definition at line 1449 of file GCNHazardRecognizer.cpp.

References llvm::SISrcMods::DST_OP_SEL, llvm::AMDGPU::SDWA::DWORD, llvm::AMDGPU::FP4, llvm::AMDGPU::FP8, llvm::AMDGPU::getFPDstSelType(), llvm::AMDGPU::hasNamedOperand(), llvm::SIInstrInfo::isSDWA(), llvm::SIInstrInfo::isVALU(), MI, llvm::SISrcMods::OP_SEL_0, and TII.

◆ getHWReg()

◆ getMFMANonMacAGPRFormOp()

unsigned getMFMANonMacAGPRFormOp ( unsigned Opc)
static

One MFMA can be written with up to four opcodes that differ only in how vdst and src2 are encoded: both are either AGPRs or VGPRs, and the mac form ties vdst to src2 instead of taking them as separate operands.

Returns
the AGPR, non-mac opcode, so that every form of the same MFMA maps to one value.

Definition at line 3167 of file GCNHazardRecognizer.cpp.

References llvm::AMDGPU::getAGPRFormOp(), llvm::AMDGPU::getMFMAEarlyClobberOp(), and Opc.

Referenced by isSameMFMA().

◆ getWaitStatesSince() [1/2]

◆ getWaitStatesSince() [2/2]

int getWaitStatesSince ( GCNHazardRecognizer::IsHazardFn IsHazard,
const MachineInstr * MI,
GCNHazardRecognizer::IsExpiredFn IsExpired,
GCNHazardRecognizer::GetNumWaitStatesFn GetNumWaitStates = SIInstrInfo::getNumWaitStates )
static

◆ getWMMAHazardInstInCategory()

unsigned getWMMAHazardInstInCategory ( const MachineInstr & MI,
const SIInstrInfo * TII,
const TargetSchedModel & SchedModel,
const GCNSubtarget & ST )
static

◆ GFX940_SMFMA_N_PassWritesVGPROverlappedSMFMASrcCWaitStates()

int GFX940_SMFMA_N_PassWritesVGPROverlappedSMFMASrcCWaitStates ( int NumPasses)
static

Definition at line 3204 of file GCNHazardRecognizer.cpp.

◆ GFX940_SMFMA_N_PassWritesVGPROverlappedSrcABWaitStates()

int GFX940_SMFMA_N_PassWritesVGPROverlappedSrcABWaitStates ( int NumPasses)
static

Definition at line 3213 of file GCNHazardRecognizer.cpp.

◆ GFX940_SMFMA_N_PassWriteVgprVALUMemExpReadWaitStates()

int GFX940_SMFMA_N_PassWriteVgprVALUMemExpReadWaitStates ( int NumPasses)
static

Definition at line 3560 of file GCNHazardRecognizer.cpp.

◆ GFX940_SMFMA_N_PassWriteVgprVALUWawWaitStates()

int GFX940_SMFMA_N_PassWriteVgprVALUWawWaitStates ( int NumPasses)
static

Definition at line 3532 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWritesVGPROverlappedSGEMMDGEMMSrcCWaitStates()

int GFX940_XDL_N_PassWritesVGPROverlappedSGEMMDGEMMSrcCWaitStates ( int NumPasses,
bool IsGFX950 )
static

Definition at line 3193 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWritesVGPROverlappedSrcABWaitStates()

int GFX940_XDL_N_PassWritesVGPROverlappedSrcABWaitStates ( int NumPasses,
bool IsGFX950 )
static

Definition at line 3221 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWritesVGPROverlappedXDLOrSMFMASrcCWaitStates()

int GFX940_XDL_N_PassWritesVGPROverlappedXDLOrSMFMASrcCWaitStates ( int NumPasses,
bool IsGFX950 )
static

Definition at line 3182 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWriteVgprVALUMemExpReadWaitStates()

int GFX940_XDL_N_PassWriteVgprVALUMemExpReadWaitStates ( int NumPasses,
bool IsGFX950 )
static

Definition at line 3550 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWriteVgprVALUWawWaitStates()

int GFX940_XDL_N_PassWriteVgprVALUWawWaitStates ( int NumPasses,
bool IsGFX950 )
static

Definition at line 3540 of file GCNHazardRecognizer.cpp.

◆ hasHazard()

◆ insertNoopsInBundle()

void insertNoopsInBundle ( MachineInstr * MI,
const SIInstrInfo & TII,
unsigned Quantity )
static

Definition at line 641 of file GCNHazardRecognizer.cpp.

References llvm::MachineInstrBuilder::addImm(), llvm::BuildMI(), MI, and TII.

◆ isCoexecutableVALUInst()

bool isCoexecutableVALUInst ( const MachineInstr & MI)
static

◆ isDivFMas()

◆ isLdsDma()

◆ isPermlane()

bool isPermlane ( const MachineInstr & MI)
static

Definition at line 513 of file GCNHazardRecognizer.cpp.

References MI.

Referenced by llvm::GCNHazardRecognizer::PreEmitNoopsCommon().

◆ isRFE()

◆ isRWLane()

◆ isSameMFMA()

bool isSameMFMA ( unsigned Opc0,
unsigned Opc1 )
static
Returns
true if Opc0 and Opc1 are the same MFMA, ignoring the mac form and whether vdst/src2 are AGPRs or VGPRs.

Definition at line 3177 of file GCNHazardRecognizer.cpp.

References getMFMANonMacAGPRFormOp().

◆ isSendMsgTraceDataOrGDS()

bool isSendMsgTraceDataOrGDS ( const SIInstrInfo & TII,
const MachineInstr & MI )
static

◆ isSGetReg()

◆ isSMovRel()

◆ isSSetReg()

◆ isStoreCountWaitZero()

bool isStoreCountWaitZero ( const MachineInstr & I)
static

Definition at line 2032 of file GCNHazardRecognizer.cpp.

References I.

◆ isVCmpXWritesExec()

bool isVCmpXWritesExec ( const SIInstrInfo & TII,
const SIRegisterInfo & TRI,
const MachineInstr & MI )
static

Definition at line 1791 of file GCNHazardRecognizer.cpp.

References MI, TII, and TRI.

◆ shouldRunLdsBranchVmemWARHazardFixup()

bool shouldRunLdsBranchVmemWARHazardFixup ( const MachineFunction & MF,
const GCNSubtarget & ST )
static

◆ skipMetaInstructionsForward()

Definition at line 4222 of file GCNHazardRecognizer.cpp.

References I.

◆ STATISTIC() [1/2]

STATISTIC ( NumWMMAHoistingBailed ,
"Number of WMMA hazards where V_NOP hoisting was not possible"  )

◆ STATISTIC() [2/2]

STATISTIC ( NumWMMANopsHoisted ,
"Number of WMMA hazard V_NOPs hoisted from loops"  )

◆ updateGetPCBundle()

Variable Documentation

◆ EnableWMMAVnopHoisting

cl::opt< bool > EnableWMMAVnopHoisting("amdgpu-wmma-vnop-hoisting", cl::init(true), cl::Hidden, cl::desc("Hoist WMMA hazard V_NOPs from loops to preheaders")) ( "amdgpu-wmma-vnop-hoisting" ,
cl::init(true) ,
cl::Hidden ,
cl::desc("Hoist WMMA hazard V_NOPs from loops to preheaders")  )
static

◆ MFMAPaddingRatio

cl::opt< unsigned, false, MFMAPaddingRatioParser > MFMAPaddingRatio("amdgpu-mfma-padding-ratio", cl::init(0), cl::Hidden, cl::desc("Fill a percentage of the latency between " "neighboring MFMA with s_nops.")) ( "amdgpu-mfma-padding-ratio" ,
cl::init(0) ,
cl::Hidden ,
cl::desc("Fill a percentage of the latency between " "neighboring MFMA with s_nops.")  )
static

◆ NopPadding

cl::opt< unsigned > NopPadding("amdgpu-snop-padding", cl::init(0), cl::Hidden, cl::desc("Insert a s_nop x before every instruction")) ( "amdgpu-snop-padding" ,
cl::init(0) ,
cl::Hidden ,
cl::desc("Insert a s_nop x before every instruction")  )
static