32 #define DEBUG_TYPE "amdgpu-nsa-reassign" 35 "Number of NSA instructions with non-sequential address found");
37 "Number of NSA instructions changed to sequential");
51 StringRef getPassName()
const override {
return "GCN NSA Reassign"; }
89 unsigned StartReg)
const;
91 bool canAssign(
unsigned StartReg,
unsigned NumRegs)
const;
107 char GCNNSAReassign::ID = 0;
113 unsigned StartReg)
const {
114 unsigned NumRegs = Intervals.size();
116 for (
unsigned N = 0;
N < NumRegs; ++
N)
117 if (VRM->hasPhys(Intervals[
N]->reg))
118 LRM->unassign(*Intervals[N]);
120 for (
unsigned N = 0; N < NumRegs; ++
N)
121 if (LRM->checkInterference(*Intervals[N], StartReg + N))
124 for (
unsigned N = 0; N < NumRegs; ++
N)
125 LRM->assign(*Intervals[N], StartReg + N);
130 bool GCNNSAReassign::canAssign(
unsigned StartReg,
unsigned NumRegs)
const {
131 for (
unsigned N = 0;
N < NumRegs; ++
N) {
132 unsigned Reg = StartReg +
N;
133 if (!
MRI->isAllocatable(Reg))
136 for (
unsigned I = 0; CSRegs[
I]; ++
I)
137 if (
TRI->isSubRegisterEq(Reg, CSRegs[
I]) &&
138 !LRM->isPhysRegUsed(CSRegs[I]))
147 unsigned NumRegs = Intervals.
size();
149 if (NumRegs > MaxNumVGPRs)
151 unsigned MaxReg = MaxNumVGPRs - NumRegs + AMDGPU::VGPR0;
153 for (
unsigned Reg = AMDGPU::VGPR0;
Reg <= MaxReg; ++
Reg) {
154 if (!canAssign(
Reg, NumRegs))
157 if (tryAssignRegisters(Intervals,
Reg))
164 GCNNSAReassign::NSA_Status
167 if (!Info || Info->
MIMGEncoding != AMDGPU::MIMGEncGfx10NSA)
168 return NSA_Status::NOT_NSA;
173 unsigned VgprBase = 0;
179 return NSA_Status::FIXED;
181 Register PhysReg = VRM->getPhys(Reg);
185 return NSA_Status::FIXED;
195 if (
MRI->getRegClass(Reg) != &AMDGPU::VGPR_32RegClass || Op.
getSubReg())
196 return NSA_Status::FIXED;
201 return NSA_Status::FIXED;
203 for (
auto U :
MRI->use_nodbg_operands(Reg)) {
205 return NSA_Status::FIXED;
208 return NSA_Status::FIXED;
211 if (!LIS->hasInterval(Reg))
212 return NSA_Status::FIXED;
217 else if (VgprBase +
I != PhysReg)
221 return NSA ? NSA_Status::NON_CONTIGUOUS : NSA_Status::CONTIGUOUS;
230 TRI =
ST->getRegisterInfo();
231 VRM = &getAnalysis<VirtRegMap>();
232 LRM = &getAnalysis<LiveRegMatrix>();
233 LIS = &getAnalysis<LiveIntervals>();
236 MaxNumVGPRs =
ST->getMaxNumVGPRs(MF);
237 MaxNumVGPRs = std::min(
ST->getMaxNumVGPRs(MFI->getOccupancy()), MaxNumVGPRs);
238 CSRegs =
MRI->getCalleeSavedRegs();
240 using Candidate = std::pair<const MachineInstr*, bool>;
244 switch (CheckNSA(MI)) {
247 case NSA_Status::CONTIGUOUS:
248 Candidates.
push_back(std::make_pair(&MI,
true));
250 case NSA_Status::NON_CONTIGUOUS:
251 Candidates.
push_back(std::make_pair(&MI,
false));
252 ++NumNSAInstructions;
258 bool Changed =
false;
259 for (
auto &
C : Candidates) {
264 if (CheckNSA(*MI,
true) == NSA_Status::CONTIGUOUS) {
282 if (
llvm::find(Intervals, LI) != Intervals.end()) {
287 Intervals.push_back(LI);
293 if (Intervals.empty())
297 <<
"\tOriginal allocation:\t";
298 for(
auto *LI : Intervals)
302 bool Success = scavengeRegs(Intervals);
305 if (VRM->hasPhys(Intervals.back()->reg))
311 return LIS->getInstructionIndex(*C.first) <
I;
313 for (
auto E = Candidates.end(); Success &&
I !=
E &&
314 LIS->getInstructionIndex(*
I->first) < MaxInd; ++
I) {
315 if (
I->second && CheckNSA(*
I->first,
true) < NSA_Status::CONTIGUOUS) {
324 if (VRM->hasPhys(Intervals[
I]->reg))
325 LRM->unassign(*Intervals[I]);
328 LRM->assign(*Intervals[I], OrigRegs[I]);
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AMDGPU specific subclass of TargetSubtarget.
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
This class represents lattice values for constants.
void push_back(const T &Elt)
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
LiveInterval - This class represents the liveness of a register, or stack slot.
unsigned getSubReg() const
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void initializeGCNNSAReassignPass(PassRegistry &)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Analysis containing CSE Info
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
SlotIndex endIndex() const
endNumber - return the maximum point of the range of the whole, exclusive.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Align max(MaybeAlign Lhs, Align Rhs)
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
INITIALIZE_PASS_BEGIN(GCNNSAReassign, DEBUG_TYPE, "GCN NSA Reassign", false, false) INITIALIZE_PASS_END(GCNNSAReassign
void setPreservesAll()
Set by analyses that do not transform their input at all.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SlotIndex beginIndex() const
beginIndex - Return the lowest numbered slot covered.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
SlotIndex - An opaque wrapper around machine indexes.
Wrapper class representing virtual and physical registers.