13#ifndef LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H
14#define LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H
63 std::list<MachineInstr*> EmittedInstrs;
68 std::list<MachineInstr *> EmittedVALUInstrs;
73 static constexpr unsigned MaxVALULookAhead = 18;
77 bool HasPendingWMMACoexecHazard =
false;
88 bool RunLdsBranchVmemWARHazardFixup;
99 std::optional<unsigned> CurrentCoExecStage;
102 unsigned CoExecWindowStartCycle = 0;
105 unsigned CyclesUntilTRANS = 0;
108 unsigned CyclesUntilVALU = 0;
112 std::array<char, AMDGPU::MaxCoExecStages> CoExecWindowLog;
115 void dumpCoExecWindow()
const;
118 bool hasCoExecWindowModel()
const;
149 void schedulerAdvanceCycle();
152 void schedulerReset();
160 void resetClause()
const {
165 void addClauseInst(
const MachineInstr &
MI)
const;
169 unsigned getMFMAPipelineWaitStates(
const MachineInstr &
MI)
const;
173 void processBundle();
177 void runOnInstruction(MachineInstr *
MI);
182 int getWaitStatesSinceVALU(
IsHazardFn IsHazard,
int Limit)
const;
183 int getWaitStatesSinceDef(
unsigned Reg,
IsHazardFn IsHazardDef,
185 int getWaitStatesSinceSetReg(
IsHazardFn IsHazard,
int Limit)
const;
187 int checkSoftClauseHazards(MachineInstr *SMEM)
const;
188 int checkSMRDHazards(MachineInstr *SMRD)
const;
189 int checkVMEMHazards(MachineInstr *VMEM)
const;
190 int checkDPPHazards(MachineInstr *
DPP)
const;
191 int checkDivFMasHazards(MachineInstr *DivFMas)
const;
192 int checkGetRegHazards(MachineInstr *GetRegInstr)
const;
193 int checkSetRegHazards(MachineInstr *SetRegInstr)
const;
194 int createsVALUHazard(
const MachineInstr &
MI)
const;
195 int checkVALUHazards(MachineInstr *VALU)
const;
196 int checkVALUHazardsHelper(
const MachineOperand &Def,
197 const MachineRegisterInfo &MRI)
const;
198 int checkUniformWindowVALUHazardsHelper(
Register Reg)
const;
199 int checkSOFFSETWindowVALUHazardsHelper(
Register Reg)
const;
200 int checkRWLaneHazards(MachineInstr *RWLane)
const;
201 int checkRFEHazards(MachineInstr *RFE)
const;
202 int checkInlineAsmHazards(MachineInstr *IA)
const;
203 int checkReadM0Hazards(MachineInstr *SMovRel)
const;
204 int checkNSAtoVMEMHazard(MachineInstr *
MI)
const;
205 int checkFPAtomicToDenormModeHazard(MachineInstr *
MI)
const;
209 int WaitStatesNeeded,
bool IsHoisting =
false);
210 void fixHazards(MachineInstr *
MI);
211 bool fixVcmpxPermlaneHazards(MachineInstr *
MI);
212 bool fixVMEMtoScalarWriteHazards(MachineInstr *
MI);
213 bool fixSMEMtoVectorWriteHazards(MachineInstr *
MI);
214 bool fixVcmpxExecWARHazard(MachineInstr *
MI);
215 bool fixLdsBranchVmemWARHazard(MachineInstr *
MI);
216 bool fixLdsDirectVALUHazard(MachineInstr *
MI);
217 bool fixLdsDirectVMEMHazard(MachineInstr *
MI);
218 bool fixVALUPartialForwardingHazard(MachineInstr *
MI);
219 bool fixVALUTransUseHazard(MachineInstr *
MI);
220 bool fixVALUTransCoexecutionHazards(MachineInstr *
MI);
221 bool fixWMMAHazards(MachineInstr *
MI);
222 int checkWMMACoexecutionHazards(MachineInstr *
MI)
const;
223 bool fixWMMACoexecutionHazards(MachineInstr *
MI);
224 bool tryHoistWMMAVnopsFromLoop(MachineInstr *
MI,
int WaitStatesNeeded);
225 bool hasWMMAHazardInLoop(MachineLoop *L, MachineInstr *
MI,
226 bool IncludeSubloops =
true);
227 bool hasWMMAToWMMARegOverlap(
const MachineInstr &WMMA,
228 const MachineInstr &
MI)
const;
229 bool hasWMMAToVALURegOverlap(
const MachineInstr &WMMA,
230 const MachineInstr &
MI)
const;
231 bool isCoexecutionHazardFor(
const MachineInstr &
I,
232 const MachineInstr &
MI)
const;
233 bool fixShift64HighRegBug(MachineInstr *
MI);
234 bool fixVALUMaskWriteHazard(MachineInstr *
MI);
235 bool fixRequiredExportPriority(MachineInstr *
MI);
236 bool fixGetRegWaitIdle(MachineInstr *
MI);
237 bool fixDsAtomicAsyncBarrierArriveB64(MachineInstr *
MI);
238 bool fixScratchBaseForwardingHazard(MachineInstr *
MI);
239 bool fixSetRegMode(MachineInstr *
MI);
240 bool fixTDM(MachineInstr *
MI);
242 int checkMAIHazards(MachineInstr *
MI)
const;
243 int checkMAIHazards908(MachineInstr *
MI)
const;
244 int checkMAIHazards90A(MachineInstr *
MI)
const;
260 int checkMFMAPadding(MachineInstr *
MI)
const;
261 int checkMAIVALUHazards(MachineInstr *
MI)
const;
262 int checkMAILdStHazards(MachineInstr *
MI)
const;
263 int checkPermlaneHazards(MachineInstr *
MI)
const;
268 MachineLoopInfo *MLI =
nullptr);
272 MachineLoopInfo *MLI =
nullptr);
306 return CurrentCoExecStage;
311 return ActiveCoExecInfo;
334 void Reset()
override;
Shared types for co-execution modeling used by GCNHazardRecognizer and the schedulers.
This file implements the BitVector class.
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)
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
BitVector & reset()
Reset all bits in the bitvector.
unsigned getHazardWaitStates(MachineInstr *MI) const
Returns the number of wait states until all hazards for MI are resolved.
unsigned PreEmitNoopsCommon(MachineInstr *) const
OperatingMode
Operating mode for the hazard recognizer.
void EmitNoop() override
EmitNoop - This callback is invoked when a noop was added to the instruction stream.
bool inCoExecWindow() const
Returns true if currently inside a WMMA co-execution window.
void Reset() override
Reset - This callback is invoked when a new block of instructions is about to be schedule.
unsigned PreEmitNoops(MachineInstr *) override
This overload will be used when the hazard recognizer is being used by a non-scheduling pass,...
std::optional< unsigned > getCurrentCoExecStage() const
Returns the current stage within the co-execution window, or nullopt.
const AMDGPU::CoExecInfo & getActiveCoExecInfo() const
Returns the active co-execution info (slot masks, preferences).
void EmitInstruction(SUnit *SU) override
EmitInstruction - This callback is invoked when an instruction is emitted, to advance the hazard stat...
function_ref< bool(const MachineInstr &)> IsHazardFn
void AdvanceCycle() override
AdvanceCycle - This callback is invoked whenever the next top-down instruction to be scheduled cannot...
bool isPostRA() const
Returns true if running in post-RA scheduling mode.
function_ref< unsigned int(const MachineInstr &)> GetNumWaitStatesFn
bool ShouldPreferAnother(SUnit *SU) const override
ShouldPreferAnother - This callback may be invoked if getHazardType returns NoHazard.
bool hasPhysRegs() const
Returns true if instruction operands are physical registers, so that hazards defined by register depe...
function_ref< bool(const MachineInstr &, int WaitStates)> IsExpiredFn
bool isSchedulerMode() const
Returns true if running as a scheduler (pre-RA or post-RA).
GCNHazardRecognizer(const MachineFunction &MF, OperatingMode Mode, MachineLoopInfo *MLI=nullptr)
Construct with explicit operating mode.
OperatingMode getOperatingMode() const
Returns the current operating mode.
static AMDGPU::CoExecMaskT getCoExecMaskForMI(const MachineInstr &MI, const SIInstrInfo &TII)
Get the CoExecMask for a given instruction.
HazardType getHazardType(SUnit *SU, int Stalls) override
getHazardType - Return the hazard type of emitting this node.
void RecedeCycle() override
RecedeCycle - This callback is invoked whenever the next bottom-up instruction to be scheduled cannot...
bool isHazardRecognizerMode() const
Returns true if running as the standalone hazard recognizer pass.
bool atIssueLimit() const override
atIssueLimit - Return true if no more instructions may be issued in this cycle.
bool isPreRA() const
Returns true if running in pre-RA scheduling mode.
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Scheduling unit. This is a node in the scheduling DAG.
ScheduleHazardRecognizer()=default
Provide an instruction scheduling machine model to CodeGen passes.
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Co-execution characteristics for a multi-cycle instruction.