25#define DEBUG_TYPE "amdgpu-set-wave-priority"
31 unsigned NumVALUInstsAtStart = 0;
32 bool MayReachVMEMLoad =
false;
38class AMDGPUSetWavePriority {
45 unsigned priority)
const;
56 StringRef getPassName()
const override {
return "Set wave priority"; }
62 return AMDGPUSetWavePriority().run(MF);
71char AMDGPUSetWavePriorityLegacy::ID = 0;
74 return new AMDGPUSetWavePriorityLegacy();
80 unsigned priority)
const {
88 MBBInfoSet &MBBInfos) {
90 if (!MBBInfos[
Pred].MayReachVMEMLoad)
93 if (MBBInfos[Succ].MayReachVMEMLoad)
107 if (!AMDGPUSetWavePriority().
run(MF))
114 const unsigned HighPriority = 3;
115 const unsigned LowPriority = 0;
122 TII = ST.getInstrInfo();
124 unsigned VALUInstsThreshold =
125 ST.getCLOpts().set_wave_priority_valu_insts_threshold;
126 Attribute A =
F.getFnAttribute(
"amdgpu-wave-priority-threshold");
128 A.getValueAsString().getAsInteger(0, VALUInstsThreshold);
139 unsigned MaxNumVALUInstsInMiddle = 0;
140 unsigned NumVALUInstsAtEnd = 0;
144 MBBInfo &Info = MBBInfos[
MBB];
145 Info.NumVALUInstsAtStart = 0;
146 MaxNumVALUInstsInMiddle = 0;
147 NumVALUInstsAtEnd = 0;
148 Info.LastVMEMLoad = &
MI;
151 MaxNumVALUInstsInMiddle =
152 std::max(MaxNumVALUInstsInMiddle, NumVALUInstsAtEnd);
153 NumVALUInstsAtEnd = 0;
156 ++MBBInfos[
MBB].NumVALUInstsAtStart;
161 bool SuccsMayReachVMEMLoad =
false;
162 unsigned NumFollowingVALUInsts = 0;
164 const MBBInfo &SuccInfo = MBBInfos[Succ];
165 SuccsMayReachVMEMLoad |= SuccInfo.MayReachVMEMLoad;
166 NumFollowingVALUInsts =
167 std::max(NumFollowingVALUInsts, SuccInfo.NumVALUInstsAtStart);
171 Info.NumVALUInstsAtStart += NumFollowingVALUInsts;
172 NumVALUInstsAtEnd += NumFollowingVALUInsts;
174 unsigned MaxNumVALUInsts =
175 std::max(MaxNumVALUInstsInMiddle, NumVALUInstsAtEnd);
176 Info.MayReachVMEMLoad =
177 SuccsMayReachVMEMLoad ||
178 (
Info.LastVMEMLoad && MaxNumVALUInsts >= VALUInstsThreshold);
182 if (!MBBInfos[&Entry].MayReachVMEMLoad)
190 BuildSetprioMI(Entry,
I, HighPriority);
194 SmallPtrSet<MachineBasicBlock *, 16> PriorityLoweringBlocks;
195 for (MachineBasicBlock &
MBB : MF) {
196 if (MBBInfos[&
MBB].MayReachVMEMLoad) {
204 if (MBBInfos[
Pred].MayReachVMEMLoad)
219 for (MachineBasicBlock *
MBB : PriorityLoweringBlocks) {
220 MachineInstr *LastVMEMLoad = MBBInfos[
MBB].LastVMEMLoad;
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.
Represent a constant reference to a string, i.e.
LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)
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.