30#define DEBUG_TYPE "si-pre-allocate-wwm-regs"
38class SIPreAllocateWWMRegs {
48 std::vector<unsigned> RegsToRewrite;
82 "SI Pre-allocate WWM Registers",
false,
false)
89char SIPreAllocateWWMRegsLegacy::
ID = 0;
94 return new SIPreAllocateWWMRegsLegacy();
102 if (!
TRI->isVGPR(*
MRI, Reg))
105 if (VRM->hasPhys(Reg))
110 for (
MCRegister PhysReg : RegClassInfo.getOrder(
MRI->getRegClass(Reg))) {
111 if (!
MRI->isPhysRegUsed(PhysReg,
true) &&
113 Matrix->assign(LI, PhysReg);
115 RegsToRewrite.push_back(Reg);
137 if (!VRM->hasPhys(VirtReg))
140 Register PhysReg = VRM->getPhys(VirtReg);
143 PhysReg =
TRI->getSubReg(PhysReg,
SubReg);
155 for (
unsigned Reg : RegsToRewrite) {
156 LIS->removeInterval(Reg);
158 const Register PhysReg = VRM->getPhys(Reg);
164 RegsToRewrite.clear();
167 MRI->freezeReservedRegs();
174 unsigned Opc =
MI.getOpcode();
176 if (
Opc == AMDGPU::ENTER_STRICT_WWM ||
Opc == AMDGPU::ENTER_STRICT_WQM) {
177 dbgs() <<
"Entering ";
179 assert(
Opc == AMDGPU::EXIT_STRICT_WWM ||
Opc == AMDGPU::EXIT_STRICT_WQM);
180 dbgs() <<
"Exiting ";
183 if (
Opc == AMDGPU::ENTER_STRICT_WWM ||
Opc == AMDGPU::EXIT_STRICT_WWM) {
184 dbgs() <<
"Strict WWM ";
186 assert(
Opc == AMDGPU::ENTER_STRICT_WQM ||
Opc == AMDGPU::EXIT_STRICT_WQM);
187 dbgs() <<
"Strict WQM ";
190 dbgs() <<
"region: " <<
MI;
195bool SIPreAllocateWWMRegsLegacy::runOnMachineFunction(
MachineFunction &MF) {
196 auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
197 auto *
Matrix = &getAnalysis<LiveRegMatrixWrapperLegacy>().getLRM();
198 auto *VRM = &getAnalysis<VirtRegMapWrapperLegacy>().getVRM();
199 return SIPreAllocateWWMRegs(LIS,
Matrix, VRM).run(MF);
207 TII =
ST.getInstrInfo();
208 TRI = &
TII->getRegisterInfo();
211 RegClassInfo.runOnMachineFunction(MF);
213 bool PreallocateSGPRSpillVGPRs =
217 bool RegsAssigned =
false;
229 if (
MI.getOpcode() == AMDGPU::SI_SPILL_S32_TO_VGPR) {
230 if (PreallocateSGPRSpillVGPRs)
231 RegsAssigned |= processDef(
MI.getOperand(0));
235 if (
MI.getOpcode() == AMDGPU::ENTER_STRICT_WWM ||
236 MI.getOpcode() == AMDGPU::ENTER_STRICT_WQM) {
242 if (
MI.getOpcode() == AMDGPU::EXIT_STRICT_WWM ||
243 MI.getOpcode() == AMDGPU::EXIT_STRICT_WQM) {
254 RegsAssigned |= processDef(DefOpnd);
272 SIPreAllocateWWMRegs(LIS,
Matrix, VRM).
run(MF);
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
SI Pre allocate WWM Registers
static cl::opt< bool > EnablePreallocateSGPRSpillVGPRs("amdgpu-prealloc-sgpr-spill-vgprs", cl::init(false), cl::Hidden)
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
FunctionPass class - This class is used to implement most global optimizations.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
LiveInterval - This class represents the liveness of a register, or stack slot.
@ IK_Free
No interference, go ahead and assign.
Wrapper class representing physical registers. Should be passed by value.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
LLVM_ABI void setIsRenamable(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
void reserveWWMRegister(Register Reg)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI VirtRegMap run(MachineFunction &MF, MachineFunctionAnalysisManager &MAM)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createSIPreAllocateWWMRegsLegacyPass()
char & SIPreAllocateWWMRegsLegacyID