LLVM 20.0.0git
Typedefs | Functions | Variables
GCNHazardRecognizer.cpp File Reference
#include "GCNHazardRecognizer.h"
#include "GCNSubtarget.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "SIMachineFunctionInfo.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/ScheduleDAG.h"
#include "llvm/TargetParser/TargetParser.h"

Go to the source code of this file.

Typedefs

using HazardFnResult = enum { HazardFound, HazardExpired, NoHazardFound }
 
using IsExpiredFn = function_ref< bool(const MachineInstr &, int WaitStates)>
 
using GetNumWaitStatesFn = function_ref< unsigned int(const MachineInstr &)>
 

Functions

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 isDGEMM (unsigned Opcode)
 
static bool isXDL (const GCNSubtarget &ST, const MachineInstr &MI)
 
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 State, function_ref< HazardFnResult(StateT &, const MachineInstr &)> IsHazard, function_ref< void(StateT &, const MachineInstr &)> UpdateState, const MachineBasicBlock *MBB, MachineBasicBlock::const_reverse_instr_iterator I, DenseSet< const MachineBasicBlock * > &Visited)
 
static int getWaitStatesSince (GCNHazardRecognizer::IsHazardFn IsHazard, const MachineBasicBlock *MBB, MachineBasicBlock::const_reverse_instr_iterator I, int WaitStates, IsExpiredFn IsExpired, DenseSet< const MachineBasicBlock * > &Visited, GetNumWaitStatesFn GetNumWaitStates=SIInstrInfo::getNumWaitStates)
 
static int getWaitStatesSince (GCNHazardRecognizer::IsHazardFn IsHazard, const MachineInstr *MI, IsExpiredFn IsExpired)
 
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 MachineOperandgetDstSelForwardingOperand (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 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)
 
static int GFX940_SMFMA_N_PassWriteVgprVALUWawWaitStates (int NumPasses)
 
static int GFX940_XDL_N_PassWriteVgprVALUWawWaitStates (int NumPasses)
 
static int GFX940_XDL_N_PassWriteVgprVALUMemExpReadWaitStates (int NumPasses)
 
static int GFX940_SMFMA_N_PassWriteVgprVALUMemExpReadWaitStates (int NumPasses)
 
static void updateGetPCBundle (MachineInstr *NewMI)
 
static std::optional< unsignedsgprPairNumber (Register Reg, const SIRegisterInfo &TRI)
 
static bool ensureEntrySetPrio (MachineFunction *MF, int Priority, const SIInstrInfo &TII)
 

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< unsignedMaxExhaustiveHazardSearch ("amdgpu-max-exhaustive-hazard-search", cl::init(128), cl::Hidden, cl::desc("Maximum function size for exhausive hazard search"))
 

Typedef Documentation

◆ GetNumWaitStatesFn

Definition at line 461 of file GCNHazardRecognizer.cpp.

◆ HazardFnResult

using HazardFnResult = enum { HazardFound, HazardExpired, NoHazardFound }

Definition at line 458 of file GCNHazardRecognizer.cpp.

◆ IsExpiredFn

using IsExpiredFn = function_ref<bool(const MachineInstr &, int WaitStates)>

Definition at line 460 of file GCNHazardRecognizer.cpp.

Function Documentation

◆ addRegsToSet()

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

Definition at line 608 of file GCNHazardRecognizer.cpp.

References addRegUnits(), and TRI.

◆ addRegUnits()

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

Definition at line 602 of file GCNHazardRecognizer.cpp.

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

Referenced by addRegsToSet().

◆ breaksSMEMSoftClause()

static bool breaksSMEMSoftClause ( MachineInstr MI)
static

Definition at line 621 of file GCNHazardRecognizer.cpp.

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

◆ breaksVMEMSoftClause()

static bool breaksVMEMSoftClause ( MachineInstr MI)
static

◆ consumesDstSelForwardingOperand()

static 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 948 of file GCNHazardRecognizer.cpp.

References TRI.

◆ ensureEntrySetPrio()

static bool ensureEntrySetPrio ( MachineFunction MF,
int  Priority,
const SIInstrInfo TII 
)
static

◆ getDstSelForwardingOperand()

static 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 902 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()

static unsigned getHWReg ( const SIInstrInfo TII,
const MachineInstr RegInstr 
)
static

◆ getWaitStatesSince() [1/2]

static int getWaitStatesSince ( GCNHazardRecognizer::IsHazardFn  IsHazard,
const MachineBasicBlock MBB,
MachineBasicBlock::const_reverse_instr_iterator  I,
int  WaitStates,
IsExpiredFn  IsExpired,
DenseSet< const MachineBasicBlock * > &  Visited,
GetNumWaitStatesFn  GetNumWaitStates = SIInstrInfo::getNumWaitStates 
)
static

◆ getWaitStatesSince() [2/2]

static int getWaitStatesSince ( GCNHazardRecognizer::IsHazardFn  IsHazard,
const MachineInstr MI,
IsExpiredFn  IsExpired 
)
static

Definition at line 544 of file GCNHazardRecognizer.cpp.

References getWaitStatesSince(), and MI.

◆ GFX940_SMFMA_N_PassWritesVGPROverlappedSMFMASrcCWaitStates()

static int GFX940_SMFMA_N_PassWritesVGPROverlappedSMFMASrcCWaitStates ( int  NumPasses)
static

Definition at line 2280 of file GCNHazardRecognizer.cpp.

◆ GFX940_SMFMA_N_PassWritesVGPROverlappedSrcABWaitStates()

static int GFX940_SMFMA_N_PassWritesVGPROverlappedSrcABWaitStates ( int  NumPasses)
static

Definition at line 2289 of file GCNHazardRecognizer.cpp.

◆ GFX940_SMFMA_N_PassWriteVgprVALUMemExpReadWaitStates()

static int GFX940_SMFMA_N_PassWriteVgprVALUMemExpReadWaitStates ( int  NumPasses)
static

Definition at line 2619 of file GCNHazardRecognizer.cpp.

◆ GFX940_SMFMA_N_PassWriteVgprVALUWawWaitStates()

static int GFX940_SMFMA_N_PassWriteVgprVALUWawWaitStates ( int  NumPasses)
static

Definition at line 2595 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWritesVGPROverlappedSGEMMDGEMMSrcCWaitStates()

static int GFX940_XDL_N_PassWritesVGPROverlappedSGEMMDGEMMSrcCWaitStates ( int  NumPasses,
bool  IsGFX950 
)
static

Definition at line 2269 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWritesVGPROverlappedSrcABWaitStates()

static int GFX940_XDL_N_PassWritesVGPROverlappedSrcABWaitStates ( int  NumPasses)
static

Definition at line 2297 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWritesVGPROverlappedXDLOrSMFMASrcCWaitStates()

static int GFX940_XDL_N_PassWritesVGPROverlappedXDLOrSMFMASrcCWaitStates ( int  NumPasses,
bool  IsGFX950 
)
static

Definition at line 2258 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWriteVgprVALUMemExpReadWaitStates()

static int GFX940_XDL_N_PassWriteVgprVALUMemExpReadWaitStates ( int  NumPasses)
static

Definition at line 2611 of file GCNHazardRecognizer.cpp.

◆ GFX940_XDL_N_PassWriteVgprVALUWawWaitStates()

static int GFX940_XDL_N_PassWriteVgprVALUWawWaitStates ( int  NumPasses)
static

Definition at line 2603 of file GCNHazardRecognizer.cpp.

◆ hasHazard()

template<typename StateT >
static bool hasHazard ( StateT  State,
function_ref< HazardFnResult(StateT &, const MachineInstr &)>  IsHazard,
function_ref< void(StateT &, const MachineInstr &)>  UpdateState,
const MachineBasicBlock MBB,
MachineBasicBlock::const_reverse_instr_iterator  I,
DenseSet< const MachineBasicBlock * > &  Visited 
)
static

◆ insertNoopsInBundle()

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

Definition at line 268 of file GCNHazardRecognizer.cpp.

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

◆ isDGEMM()

static bool isDGEMM ( unsigned  Opcode)
static

Definition at line 120 of file GCNHazardRecognizer.cpp.

References llvm::AMDGPU::getMAIIsDGEMM().

Referenced by isXDL().

◆ isDivFMas()

static bool isDivFMas ( unsigned  Opcode)
static

◆ isLdsDma()

static bool isLdsDma ( const MachineInstr MI)
static

◆ isPermlane()

static bool isPermlane ( const MachineInstr MI)
static

Definition at line 165 of file GCNHazardRecognizer.cpp.

References MI.

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

◆ isRFE()

static bool isRFE ( unsigned  Opcode)
static

◆ isRWLane()

static bool isRWLane ( unsigned  Opcode)
static

◆ isSendMsgTraceDataOrGDS()

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

◆ isSGetReg()

static bool isSGetReg ( unsigned  Opcode)
static

◆ isSMovRel()

static bool isSMovRel ( unsigned  Opcode)
static

◆ isSSetReg()

static bool isSSetReg ( unsigned  Opcode)
static

◆ isStoreCountWaitZero()

static bool isStoreCountWaitZero ( const MachineInstr I)
static

Definition at line 1460 of file GCNHazardRecognizer.cpp.

References I.

◆ isVCmpXWritesExec()

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

Definition at line 1221 of file GCNHazardRecognizer.cpp.

References MI, TII, and TRI.

◆ isXDL()

static bool isXDL ( const GCNSubtarget ST,
const MachineInstr MI 
)
static

◆ sgprPairNumber()

static std::optional< unsigned > sgprPairNumber ( Register  Reg,
const SIRegisterInfo TRI 
)
static

Definition at line 3108 of file GCNHazardRecognizer.cpp.

References TRI.

◆ shouldRunLdsBranchVmemWARHazardFixup()

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

◆ updateGetPCBundle()

static void updateGetPCBundle ( MachineInstr NewMI)
static

Variable Documentation

◆ MaxExhaustiveHazardSearch

cl::opt< unsigned > MaxExhaustiveHazardSearch("amdgpu-max-exhaustive-hazard-search", cl::init(128), cl::Hidden, cl::desc("Maximum function size for exhausive hazard search")) ( "amdgpu-max-exhaustive-hazard-search"  ,
cl::init(128)  ,
cl::Hidden  ,
cl::desc("Maximum function size for exhausive hazard search")   
)
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