25#define DEBUG_TYPE "amdgpu-set-wave-priority"
28 "amdgpu-set-wave-priority-valu-insts-threshold",
29 cl::desc(
"VALU instruction count threshold for adjusting wave priority"),
36 unsigned NumVALUInstsAtStart = 0;
37 bool MayReachVMEMLoad =
false;
43class AMDGPUSetWavePriority {
48 MachineInstr *BuildSetprioMI(MachineBasicBlock &
MBB,
50 unsigned priority)
const;
52 const SIInstrInfo *TII;
59 AMDGPUSetWavePriorityLegacy() : MachineFunctionPass(ID) {}
61 StringRef getPassName()
const override {
return "Set wave priority"; }
67 return AMDGPUSetWavePriority().run(MF);
76char AMDGPUSetWavePriorityLegacy::ID = 0;
79 return new AMDGPUSetWavePriorityLegacy();
85 unsigned priority)
const {
93 MBBInfoSet &MBBInfos) {
95 if (!MBBInfos[Pred].MayReachVMEMLoad)
98 if (MBBInfos[Succ].MayReachVMEMLoad)
112 if (!AMDGPUSetWavePriority().
run(MF))
119 const unsigned HighPriority = 3;
120 const unsigned LowPriority = 0;
127 TII = ST.getInstrInfo();
130 Attribute A =
F.getFnAttribute(
"amdgpu-wave-priority-threshold");
132 A.getValueAsString().getAsInteger(0, VALUInstsThreshold);
143 unsigned MaxNumVALUInstsInMiddle = 0;
144 unsigned NumVALUInstsAtEnd = 0;
148 MBBInfo &Info = MBBInfos[
MBB];
149 Info.NumVALUInstsAtStart = 0;
150 MaxNumVALUInstsInMiddle = 0;
151 NumVALUInstsAtEnd = 0;
152 Info.LastVMEMLoad = &
MI;
155 MaxNumVALUInstsInMiddle =
156 std::max(MaxNumVALUInstsInMiddle, NumVALUInstsAtEnd);
157 NumVALUInstsAtEnd = 0;
160 ++MBBInfos[
MBB].NumVALUInstsAtStart;
165 bool SuccsMayReachVMEMLoad =
false;
166 unsigned NumFollowingVALUInsts = 0;
168 const MBBInfo &SuccInfo = MBBInfos[Succ];
169 SuccsMayReachVMEMLoad |= SuccInfo.MayReachVMEMLoad;
170 NumFollowingVALUInsts =
171 std::max(NumFollowingVALUInsts, SuccInfo.NumVALUInstsAtStart);
175 Info.NumVALUInstsAtStart += NumFollowingVALUInsts;
176 NumVALUInstsAtEnd += NumFollowingVALUInsts;
178 unsigned MaxNumVALUInsts =
179 std::max(MaxNumVALUInstsInMiddle, NumVALUInstsAtEnd);
180 Info.MayReachVMEMLoad =
181 SuccsMayReachVMEMLoad ||
182 (
Info.LastVMEMLoad && MaxNumVALUInsts >= VALUInstsThreshold);
186 if (!MBBInfos[&Entry].MayReachVMEMLoad)
194 BuildSetprioMI(Entry,
I, HighPriority);
198 SmallPtrSet<MachineBasicBlock *, 16> PriorityLoweringBlocks;
199 for (MachineBasicBlock &
MBB : MF) {
200 if (MBBInfos[&
MBB].MayReachVMEMLoad) {
208 if (MBBInfos[Pred].MayReachVMEMLoad)
209 PriorityLoweringBlocks.
insert(Pred);
223 for (MachineBasicBlock *
MBB : PriorityLoweringBlocks) {
224 MachineInstr *LastVMEMLoad = MBBInfos[
MBB].LastVMEMLoad;
static cl::opt< unsigned > DefaultVALUInstsThreshold("amdgpu-set-wave-priority-valu-insts-threshold", cl::desc("VALU instruction count threshold for adjusting wave priority"), cl::init(100), cl::Hidden)
static bool CanLowerPriorityDirectlyInPredecessors(const MachineBasicBlock &MBB, MBBInfoSet &MBBInfos)
static bool isVMEMLoad(const MachineInstr &MI)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
Interface definition for SIInstrInfo.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Functions, function parameters, and return types can have attributes to indicate how they should be t...
FunctionPass class - This class is used to implement most global optimizations.
iterator_range< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static bool isDS(const MachineInstr &MI)
static bool isVMEM(const MachineInstr &MI)
static bool isVALU(const MachineInstr &MI, bool AllowLDSDMA)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
initializer< Ty > init(const Ty &Val)
DXILDebugInfoMap run(Module &M)
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createAMDGPUSetWavePriorityPass()
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
auto post_order(const T &G)
Post-order traversal of a graph.