32 PrivateSegmentBuffer(
false),
35 KernargSegmentPtr(
false),
37 FlatScratchInit(
false),
42 PrivateSegmentWaveByteOffset(
false),
46 ImplicitBufferPtr(
false),
47 ImplicitArgPtr(
false),
48 GITPtrHigh(0xffffffff),
49 HighBitsOf32BitAddress(0) {
61 KernargSegmentPtr =
true;
71 ScratchRSrcReg = AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3;
72 ScratchWaveOffsetReg = AMDGPU::SGPR4;
73 FrameOffsetReg = AMDGPU::SGPR5;
74 StackPtrOffsetReg = AMDGPU::SGPR32;
81 if (F.hasFnAttribute(
"amdgpu-implicitarg-ptr"))
82 ImplicitArgPtr =
true;
84 if (F.hasFnAttribute(
"amdgpu-implicitarg-ptr")) {
85 KernargSegmentPtr =
true;
100 if (F.hasFnAttribute(
"amdgpu-work-group-id-x"))
103 if (F.hasFnAttribute(
"amdgpu-work-group-id-y"))
106 if (F.hasFnAttribute(
"amdgpu-work-group-id-z"))
109 if (F.hasFnAttribute(
"amdgpu-work-item-id-x"))
112 if (F.hasFnAttribute(
"amdgpu-work-item-id-y"))
115 if (F.hasFnAttribute(
"amdgpu-work-item-id-z"))
128 PrivateSegmentWaveByteOffset =
true;
138 if (isAmdHsaOrMesa) {
139 PrivateSegmentBuffer =
true;
141 if (F.hasFnAttribute(
"amdgpu-dispatch-ptr"))
144 if (F.hasFnAttribute(
"amdgpu-queue-ptr"))
147 if (F.hasFnAttribute(
"amdgpu-dispatch-id"))
150 ImplicitBufferPtr =
true;
153 if (F.hasFnAttribute(
"amdgpu-kernarg-segment-ptr"))
154 KernargSegmentPtr =
true;
159 if (HasStackObjects || F.hasFnAttribute(
"amdgpu-flat-scratch"))
160 FlatScratchInit =
true;
163 Attribute A = F.getFnAttribute(
"amdgpu-git-ptr-high");
168 A = F.getFnAttribute(
"amdgpu-32bit-address-high-bits");
185 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_128RegClass));
192 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
199 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
207 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
214 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
221 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
228 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
234 for (
unsigned I = 0; CSRegs[
I]; ++
I) {
235 if (CSRegs[
I] == Reg)
245 std::vector<SpilledReg> &SpillLanes = SGPRToVGPRSpills[FI];
248 if (!SpillLanes.empty())
258 assert(Size >= 4 && Size <= 64 &&
"invalid sgpr spill size");
259 assert(TRI->spillSGPRToVGPR() &&
"not spilling SGPRs to VGPRs");
261 int NumLanes = Size / 4;
263 const MCPhysReg *CSRegs = TRI->getCalleeSavedRegs(&MF);
267 for (
int I = 0;
I < NumLanes; ++
I, ++NumVGPRSpillLanes) {
269 unsigned VGPRIndex = (NumVGPRSpillLanes % WaveSize);
271 if (VGPRIndex == 0) {
272 LaneVGPR = TRI->findUnusedRegister(MRI, &AMDGPU::VGPR_32RegClass, MF);
273 if (LaneVGPR == AMDGPU::NoRegister) {
276 SGPRToVGPRSpills.erase(FI);
277 NumVGPRSpillLanes -=
I;
292 BB.addLiveIn(LaneVGPR);
294 LaneVGPR = SpillVGPRs.back().VGPR;
297 SpillLanes.push_back(
SpilledReg(LaneVGPR, VGPRIndex));
304 for (
auto &R : SGPRToVGPRSpills)
314 return AMDGPU::VGPR0;
317 return AMDGPU::VGPR1;
320 return AMDGPU::VGPR2;
325 MCPhysReg SIMachineFunctionInfo::getNextUserSGPR()
const {
326 assert(NumSystemSGPRs == 0 &&
"System SGPRs must be added after user SGPRs");
327 return AMDGPU::SGPR0 + NumUserSGPRs;
330 MCPhysReg SIMachineFunctionInfo::getNextSystemSGPR()
const {
331 return AMDGPU::SGPR0 + NumUserSGPRs + NumSystemSGPRs;
unsigned addImplicitBufferPtr(const SIRegisterInfo &TRI)
ArgDescriptor DispatchPtr
Interface definition for SIRegisterInfo.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const
Inverse of getMaxLocalMemWithWaveCount.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
void removeSGPRToVGPRFrameIndices(MachineFrameInfo &MFI)
unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI)
bool hasWorkItemIDZ() const
unsigned const TargetRegisterInfo * TRI
SIMachineFunctionInfo(const MachineFunction &MF)
bool hasWorkItemIDX() const
Calling convention used for Mesa/AMDPAL geometry shaders.
bool isMesaGfxShader(const Function &F) const
unsigned addDispatchID(const SIRegisterInfo &TRI)
bool isEntryFunction() const
SPIR_KERNEL - Calling convention for SPIR kernel functions.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
void limitOccupancy(const MachineFunction &MF)
ArgDescriptor PrivateSegmentWaveByteOffset
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
unsigned getMaxWavesPerEU() const
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool allocateSGPRSpillToVGPR(MachineFunction &MF, int FI)
Reserve a slice of a VGPR to support spilling for FrameIndex FI.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
bool debuggerEmitPrologue() const
std::pair< unsigned, unsigned > getWavesPerEU(const Function &F) const
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack object.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static ArgDescriptor createRegister(unsigned Reg)
unsigned addQueuePtr(const SIRegisterInfo &TRI)
bool hasWorkItemIDY() const
Generation getGeneration() const
Calling convention used for Mesa/AMDPAL pixel shaders.
int CreateSpillStackObject(uint64_t Size, unsigned Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned addDispatchPtr(const SIRegisterInfo &TRI)
bool hasFlatAddressSpace() const
unsigned getWavefrontSize() const
unsigned getLDSSize() const
unsigned getAlignmentForImplicitArgPtr() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
ArgDescriptor PrivateSegmentBuffer
unsigned addPrivateSegmentBuffer(const SIRegisterInfo &TRI)
unsigned addFlatScratchInit(const SIRegisterInfo &TRI)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
unsigned getInitialPSInputAddr(const Function &F)
Provides AMDGPU specific target descriptions.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
StringRef getValueAsString() const
Return the attribute's value as a string.
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
ArgDescriptor KernargSegmentPtr
bool isAmdHsaOrMesa(const Function &F) const
static bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg)
unsigned getRegister() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArgDescriptor FlatScratchInit
unsigned getWorkItemIDVGPR(unsigned Dim) const
StringRef - Represent a constant reference to a string, i.e.
ArgDescriptor ImplicitBufferPtr
std::pair< unsigned, unsigned > getFlatWorkGroupSizes(const Function &F) const
Calling convention for AMDGPU code object kernels.
bool hasCalls() const
Return true if the current function has any function calls.
const SIRegisterInfo * getRegisterInfo() const override