36 void SIFrameLowering::emitFlatScratchInit(
const SISubtarget &
ST,
57 unsigned FlatScratchInitReg
64 unsigned FlatScrInitLo = TRI->getSubReg(FlatScratchInitReg, AMDGPU::sub0);
65 unsigned FlatScrInitHi = TRI->getSubReg(FlatScratchInitReg, AMDGPU::sub1);
72 BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADD_U32), AMDGPU::FLAT_SCR_LO)
73 .addReg(FlatScrInitLo)
74 .
addReg(ScratchWaveOffsetReg);
75 BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADDC_U32), AMDGPU::FLAT_SCR_HI)
76 .addReg(FlatScrInitHi)
83 BuildMI(MBB, I, DL, TII->get(AMDGPU::COPY), AMDGPU::FLAT_SCR_LO)
88 BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADD_U32), FlatScrInitLo)
89 .addReg(FlatScrInitLo)
90 .
addReg(ScratchWaveOffsetReg);
93 BuildMI(MBB, I, DL, TII->get(AMDGPU::S_LSHR_B32), AMDGPU::FLAT_SCR_HI)
98 unsigned SIFrameLowering::getReservedPrivateSegmentBufferReg(
108 if (ScratchRsrcReg == AMDGPU::NoRegister ||
110 return AMDGPU::NoRegister;
114 return ScratchRsrcReg;
129 AllSGPR128s = AllSGPR128s.
slice(
std::min(static_cast<unsigned>(AllSGPR128s.
size()), NumPreloaded));
143 return ScratchRsrcReg;
148 std::pair<unsigned, unsigned>
149 SIFrameLowering::getReservedPrivateSegmentWaveByteOffsetReg(
159 if (ScratchWaveOffsetReg == AMDGPU::NoRegister ||
162 return std::make_pair(AMDGPU::NoRegister, AMDGPU::NoRegister);
167 return std::make_pair(ScratchWaveOffsetReg, SPReg);
172 if (NumPreloaded > AllSGPRs.
size())
173 return std::make_pair(ScratchWaveOffsetReg, SPReg);
175 AllSGPRs = AllSGPRs.
slice(NumPreloaded);
191 unsigned ReservedRegCount = 13;
193 if (AllSGPRs.
size() < ReservedRegCount)
194 return std::make_pair(ScratchWaveOffsetReg, SPReg);
196 bool HandledScratchWaveOffsetReg =
203 if (!HandledScratchWaveOffsetReg) {
204 HandledScratchWaveOffsetReg =
true;
208 ScratchWaveOffsetReg =
Reg;
214 return std::make_pair(ScratchWaveOffsetReg, SPReg);
224 emitDebuggerPrologue(MF, MBB);
226 assert(&MF.
front() == &MBB &&
"Shrink-wrapping not yet supported");
249 if (MFI->hasFlatScratchInit())
250 emitFlatScratchInit(ST, MF, MBB);
252 unsigned SPReg = MFI->getStackPtrOffsetReg();
253 if (SPReg != AMDGPU::SP_REG) {
260 if (StackSize == 0) {
262 .addReg(MFI->getScratchWaveOffsetReg());
265 .addReg(MFI->getScratchWaveOffsetReg())
270 unsigned ScratchRsrcReg
271 = getReservedPrivateSegmentBufferReg(ST, TII, TRI, MFI, MF);
273 unsigned ScratchWaveOffsetReg;
274 std::tie(ScratchWaveOffsetReg, SPReg)
275 = getReservedPrivateSegmentWaveByteOffsetReg(ST, TII, TRI, MFI, MF);
280 if (ScratchWaveOffsetReg == AMDGPU::NoRegister) {
281 assert(ScratchRsrcReg == AMDGPU::NoRegister);
289 unsigned PreloadedPrivateBufferReg = AMDGPU::NoRegister;
295 bool OffsetRegUsed = MRI.
isPhysRegUsed(ScratchWaveOffsetReg);
296 bool ResourceRegUsed = ScratchRsrcReg != AMDGPU::NoRegister &&
302 assert(PreloadedScratchWaveOffsetReg != AMDGPU::NoRegister &&
303 "scratch wave offset input is required");
304 MRI.
addLiveIn(PreloadedScratchWaveOffsetReg);
305 MBB.
addLiveIn(PreloadedScratchWaveOffsetReg);
308 if (ResourceRegUsed && PreloadedPrivateBufferReg != AMDGPU::NoRegister) {
310 MRI.
addLiveIn(PreloadedPrivateBufferReg);
311 MBB.
addLiveIn(PreloadedPrivateBufferReg);
316 if (&OtherBB == &MBB)
320 OtherBB.addLiveIn(ScratchWaveOffsetReg);
323 OtherBB.addLiveIn(ScratchRsrcReg);
332 bool CopyBuffer = ResourceRegUsed &&
333 PreloadedPrivateBufferReg != AMDGPU::NoRegister &&
335 ScratchRsrcReg != PreloadedPrivateBufferReg;
340 bool CopyBufferFirst = TRI->isSubRegisterEq(PreloadedPrivateBufferReg,
341 ScratchWaveOffsetReg);
342 if (CopyBuffer && CopyBufferFirst) {
343 BuildMI(MBB, I, DL, TII->
get(AMDGPU::COPY), ScratchRsrcReg)
348 PreloadedScratchWaveOffsetReg != ScratchWaveOffsetReg) {
349 BuildMI(MBB, I, DL, TII->
get(AMDGPU::COPY), ScratchWaveOffsetReg)
350 .addReg(PreloadedScratchWaveOffsetReg,
354 if (CopyBuffer && !CopyBufferFirst) {
355 BuildMI(MBB, I, DL, TII->
get(AMDGPU::COPY), ScratchRsrcReg)
359 if (ResourceRegUsed && (ST.
isMesaGfxShader(MF) || (PreloadedPrivateBufferReg == AMDGPU::NoRegister))) {
361 const MCInstrDesc &SMovB32 = TII->get(AMDGPU::S_MOV_B32);
363 unsigned Rsrc2 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub2);
364 unsigned Rsrc3 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub3);
367 uint64_t Rsrc23 = TII->getScratchRsrcWords23();
369 if (MFI->hasImplicitBufferPtr()) {
370 unsigned Rsrc01 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub0_sub1);
373 const MCInstrDesc &Mov64 = TII->get(AMDGPU::S_MOV_B64);
375 BuildMI(MBB, I, DL, Mov64, Rsrc01)
376 .
addReg(MFI->getImplicitBufferPtrUserSGPR())
379 const MCInstrDesc &LoadDwordX2 = TII->get(AMDGPU::S_LOAD_DWORDX2_IMM);
383 AMDGPUASI.CONSTANT_ADDRESS);
385 auto MMO = MF.getMachineMemOperand(PtrInfo,
390 BuildMI(MBB, I, DL, LoadDwordX2, Rsrc01)
391 .
addReg(MFI->getImplicitBufferPtrUserSGPR())
398 unsigned Rsrc0 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub0);
399 unsigned Rsrc1 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub1);
401 BuildMI(MBB, I, DL, SMovB32, Rsrc0)
405 BuildMI(MBB, I, DL, SMovB32, Rsrc1)
411 BuildMI(MBB, I, DL, SMovB32, Rsrc2)
412 .
addImm(Rsrc23 & 0xffffffff)
415 BuildMI(MBB, I, DL, SMovB32, Rsrc3)
439 bool NeedFP =
hasFP(MF);
445 BuildMI(MBB, MBBI, DL, TII->
get(AMDGPU::COPY), FramePtrReg)
451 if (NumBytes != 0 &&
hasSP(MF)) {
452 BuildMI(MBB, MBBI, DL, TII->
get(AMDGPU::S_ADD_U32), StackPtrReg)
466 if (StackPtrReg == AMDGPU::NoRegister)
480 if (NumBytes != 0 &&
hasSP(MF)) {
481 BuildMI(MBB, MBBI, DL, TII->
get(AMDGPU::S_SUB_U32), StackPtrReg)
499 unsigned &FrameReg)
const {
518 bool AllSGPRSpilledToVGPRs =
false;
521 AllSGPRSpilledToVGPRs =
true;
533 for (
auto I = MBB.
begin(),
E = MBB.
end(); I !=
E; I = Next) {
537 if (TII->isSGPRSpill(MI)) {
538 int FI = TII->getNamedOperand(MI, AMDGPU::OpName::addr)->getIndex();
542 assert(Spilled &&
"failed to spill SGPR to VGPR when allocated");
544 AllSGPRSpilledToVGPRs =
false;
557 assert(RS &&
"RegScavenger required if spilling");
573 TRI.getSpillSize(AMDGPU::SGPR_32RegClass), 0,
false);
589 for (
unsigned i = 0; i < 3; ++i) {
597 unsigned WorkGroupIDVGPR =
599 BuildMI(MBB, I, DL, TII->
get(AMDGPU::V_MOV_B32_e32), WorkGroupIDVGPR)
600 .addReg(WorkGroupIDSGPR);
604 TII->storeRegToStackSlot(MBB, I, WorkGroupIDVGPR,
false,
605 WorkGroupIDObjectIdx, &AMDGPU::VGPR_32RegClass, TRI);
614 TII->storeRegToStackSlot(MBB, I, WorkItemIDVGPR,
false,
615 WorkItemIDObjectIdx, &AMDGPU::VGPR_32RegClass, TRI);
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool eliminateSGPRToVGPRSpillFrameIndex(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS) const
Special case of eliminateFrameIndex.
Interface definition for SIRegisterInfo.
int getDebuggerWorkGroupIDStackObjectIndex(unsigned Dim) const
AMDGPU specific subclass of TargetSubtarget.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
unsigned getNumPreloadedSGPRs() const
bool hasSpilledVGPRs() const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Describe properties that are true of each instruction in the target description file.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
void removeSGPRToVGPRFrameIndices(MachineFrameInfo &MFI)
const SIInstrInfo * getInstrInfo() const override
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
unsigned getScratchWaveOffsetReg() const
static IntegerType * getInt64Ty(LLVMContext &C)
bool isAmdCodeObjectV2(const MachineFunction &MF) const
unsigned getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses...
bool spillSGPRToVGPR() const
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
bool hasSpilledSGPRs() const
unsigned reservedPrivateSegmentWaveByteOffsetReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch wave offset in case spilling is needed...
void setScratchRSrcReg(unsigned Reg)
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
const HexagonInstrInfo * TII
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool flatScratchIsPointer() const
static bool allStackObjectsAreDead(const MachineFrameInfo &MFI)
Reg
All possible values of the reg field in the ModR/M byte.
The memory access is dereferenceable (i.e., doesn't trap).
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool isMesaGfxShader(const MachineFunction &MF) const
unsigned getWorkItemIDVGPR(unsigned Dim) const
bool hasNonSpillStackObjects() const
const MachineBasicBlock & front() const
int getObjectIndexBegin() const
Return the minimum frame object index.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
int getDebuggerWorkItemIDStackObjectIndex(unsigned Dim) const
unsigned getWorkGroupIDSGPR(unsigned Dim) const
static ArrayRef< MCPhysReg > getAllSGPR128(const SISubtarget &ST, const MachineFunction &MF)
size_t size() const
size - Get the array size.
const SIRegisterInfo & getRegisterInfo() const
bool allocateSGPRSpillToVGPR(MachineFunction &MF, int FI)
Reserve a slice of a VGPR to support spilling for FrameIndex FI.
Class to represent pointers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
bool hasSGPRInitBug() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool isCompute(CallingConv::ID cc)
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
This file declares the machine register scavenger class.
unsigned const MachineRegisterInfo * MRI
unsigned getFrameRegister(const MachineFunction &MF) const override
unsigned getPreloadedValue(const MachineFunction &MF, enum PreloadedValue Value) const
Returns the physical register that Value is stored in.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
void setScratchWaveOffsetReg(unsigned Reg)
This class contains a discriminated union of information about pointers in memory operands...
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
bool hasCalls() const
Return true if the current function has any function calls.
static ArrayRef< MCPhysReg > getAllSGPRs(const SISubtarget &ST, const MachineFunction &MF)
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
AMDGPUAS getAMDGPUAS() const
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
bool isEntryFunction() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
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.
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
void emitEntryFunctionPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const
The memory access always returns the same value (or traps).
unsigned getWavefrontSize() const
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch buffer in case spilling is needed...
unsigned getFrameOffsetReg() const
unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const
unsigned getStackPtrOffsetReg() const
bool hasSP(const MachineFunction &MF) const
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
int getObjectIndexEnd() const
Return one past the maximum frame object index.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool debuggerEmitPrologue() const
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...