31 PrivateSegmentBuffer(
false),
34 KernargSegmentPtr(
false),
36 FlatScratchInit(
false),
41 PrivateSegmentWaveByteOffset(
false),
45 ImplicitBufferPtr(
false),
46 ImplicitArgPtr(
false),
47 GITPtrHigh(0xffffffff),
48 HighBitsOf32BitAddress(0),
60 KernargSegmentPtr =
true;
70 ScratchRSrcReg = AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3;
71 ScratchWaveOffsetReg = AMDGPU::SGPR33;
74 FrameOffsetReg = AMDGPU::SGPR34;
75 StackPtrOffsetReg = AMDGPU::SGPR32;
82 if (F.hasFnAttribute(
"amdgpu-implicitarg-ptr"))
83 ImplicitArgPtr =
true;
85 if (F.hasFnAttribute(
"amdgpu-implicitarg-ptr")) {
86 KernargSegmentPtr =
true;
92 if (F.hasFnAttribute(
"amdgpu-work-group-id-x"))
95 if (F.hasFnAttribute(
"amdgpu-work-group-id-y"))
98 if (F.hasFnAttribute(
"amdgpu-work-group-id-z"))
101 if (F.hasFnAttribute(
"amdgpu-work-item-id-x"))
104 if (F.hasFnAttribute(
"amdgpu-work-item-id-y"))
107 if (F.hasFnAttribute(
"amdgpu-work-item-id-z"))
119 PrivateSegmentWaveByteOffset =
true;
129 if (isAmdHsaOrMesa) {
130 PrivateSegmentBuffer =
true;
132 if (F.hasFnAttribute(
"amdgpu-dispatch-ptr"))
135 if (F.hasFnAttribute(
"amdgpu-queue-ptr"))
138 if (F.hasFnAttribute(
"amdgpu-dispatch-id"))
141 ImplicitBufferPtr =
true;
144 if (F.hasFnAttribute(
"amdgpu-kernarg-segment-ptr"))
145 KernargSegmentPtr =
true;
150 if (!HasStackObjects)
162 FlatScratchInit =
true;
165 Attribute A = F.getFnAttribute(
"amdgpu-git-ptr-high");
170 A = F.getFnAttribute(
"amdgpu-32bit-address-high-bits");
175 S = F.getFnAttribute(
"amdgpu-gds-size").getValueAsString();
191 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SGPR_128RegClass));
198 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
205 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
213 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
220 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
227 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
234 getNextUserSGPR(), AMDGPU::sub0, &AMDGPU::SReg_64RegClass));
240 for (
unsigned I = 0; CSRegs[
I]; ++
I) {
241 if (CSRegs[
I] == Reg)
253 unsigned NumNeed)
const {
256 return NumVGPRSpillLanes + NumNeed <= WaveSize * SpillVGPRs.size();
262 std::vector<SpilledReg> &SpillLanes = SGPRToVGPRSpills[FI];
265 if (!SpillLanes.empty())
275 assert(Size >= 4 && Size <= 64 &&
"invalid sgpr spill size");
276 assert(TRI->spillSGPRToVGPR() &&
"not spilling SGPRs to VGPRs");
278 int NumLanes = Size / 4;
284 for (
int I = 0;
I < NumLanes; ++
I, ++NumVGPRSpillLanes) {
286 unsigned VGPRIndex = (NumVGPRSpillLanes % WaveSize);
288 if (VGPRIndex == 0) {
289 LaneVGPR = TRI->findUnusedRegister(MRI, &AMDGPU::VGPR_32RegClass, MF);
290 if (LaneVGPR == AMDGPU::NoRegister) {
293 SGPRToVGPRSpills.erase(FI);
294 NumVGPRSpillLanes -=
I;
309 BB.addLiveIn(LaneVGPR);
311 LaneVGPR = SpillVGPRs.back().VGPR;
314 SpillLanes.push_back(
SpilledReg(LaneVGPR, VGPRIndex));
332 auto &Spill = VGPRToAGPRSpills[FI];
335 if (!Spill.Lanes.empty())
336 return Spill.FullyAllocated;
339 unsigned NumLanes =
Size / 4;
340 Spill.Lanes.resize(NumLanes, AMDGPU::NoRegister);
343 isAGPRtoVGPR ? AMDGPU::VGPR_32RegClass : AMDGPU::AGPR_32RegClass;
346 auto &SpillRegs = isAGPRtoVGPR ? SpillAGPR : SpillVGPR;
348 Spill.FullyAllocated =
true;
353 OtherUsedRegs.
resize(TRI->getNumRegs());
368 for (
unsigned I = 0;
I < NumLanes; ++
I) {
375 if (NextSpillReg == Regs.
end()) {
376 Spill.FullyAllocated =
false;
380 OtherUsedRegs.
set(*NextSpillReg);
382 Spill.Lanes[
I] = *NextSpillReg++;
385 return Spill.FullyAllocated;
390 for (
auto &R : SGPRToVGPRSpills) {
402 for (
auto &R : VGPRToAGPRSpills) {
403 if (R.second.FullyAllocated)
408 MCPhysReg SIMachineFunctionInfo::getNextUserSGPR()
const {
409 assert(NumSystemSGPRs == 0 &&
"System SGPRs must be added after user SGPRs");
410 return AMDGPU::SGPR0 + NumUserSGPRs;
413 MCPhysReg SIMachineFunctionInfo::getNextSystemSGPR()
const {
414 return AMDGPU::SGPR0 + NumUserSGPRs + NumSystemSGPRs;
439 if (
Arg.isRegister()) {
unsigned addImplicitBufferPtr(const SIRegisterInfo &TRI)
unsigned getFrameOffsetReg() const
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
unsigned getScratchWaveOffsetReg() const
Optional< SIArgument > PrivateSegmentWaveByteOffset
ArgDescriptor DispatchPtr
Interface definition for SIRegisterInfo.
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Register getRegister() const
ArgDescriptor WorkGroupInfo
bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR)
Reserve AGPRs or VGPRs to support spilling for FrameIndex FI.
ArgDescriptor WorkItemIDZ
AMDGPU specific subclass of TargetSubtarget.
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
This class represents lattice values for constants.
unsigned getStackPtrOffsetReg() const
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.
Optional< SIArgument > KernargSegmentPtr
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
ArgDescriptor PrivateSegmentSize
unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI)
ArgDescriptor WorkItemIDX
Optional< SIArgument > PrivateSegmentSize
ArgDescriptor WorkItemIDY
ArgDescriptor WorkGroupIDX
static SIArgument createArgument(bool IsReg)
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.
void removeDeadFrameIndices(MachineFrameInfo &MFI)
SIMachineFunctionInfo(const MachineFunction &MF)
uint64_t getExplicitKernArgSize() const
Optional< SIArgument > WorkItemIDY
Calling convention used for Mesa/AMDPAL geometry shaders.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
bool isMesaGfxShader(const Function &F) const
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)
unsigned addDispatchID(const SIRegisterInfo &TRI)
bool isEntryFunction() const
Optional< SIArgument > DispatchPtr
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static yaml::StringValue regToString(unsigned Reg, const TargetRegisterInfo &TRI)
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
ArgDescriptor WorkGroupIDY
ArgDescriptor WorkGroupIDZ
Optional< SIArgument > ImplicitArgPtr
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
bool haveFreeLanesForSGPRSpill(const MachineFunction &MF, unsigned NumLane) const
returns true if NumLanes slots are available in VGPRs already used for SGPR spilling.
Optional< SIArgument > FlatScratchInit
bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI)
void limitOccupancy(const MachineFunction &MF)
uint32_t get32BitAddressHighBits() const
Align getAlignmentForImplicitArgPtr() const
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.
int getObjectIndexBegin() const
Return the minimum frame object index.
unsigned getMaxWavesPerEU() const
int getObjectIndexEnd() const
Return one past the maximum frame object index.
int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
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...
Optional< SIArgument > WorkItemIDX
std::pair< unsigned, unsigned > getWavesPerEU(const Function &F) const
iterator_range< SmallVectorImpl< MCPhysReg >::const_iterator > getRegisters() const
unsigned const MachineRegisterInfo * MRI
Optional< SIArgument > QueuePtr
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.
Optional< SIArgument > DispatchID
AMDGPU::SIModeRegisterDefaults getMode() const
unsigned addQueuePtr(const SIRegisterInfo &TRI)
Generation getGeneration() const
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
AMDGPU::SIModeRegisterDefaults Mode
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
AMDGPUFunctionArgInfo & getArgInfo()
void setStackID(int ObjectIdx, uint8_t ID)
Optional< SIArgument > WorkGroupIDZ
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
uint64_t ExplicitKernArgSize
unsigned addDispatchPtr(const SIRegisterInfo &TRI)
bool hasFlatAddressSpace() const
unsigned getWavefrontSize() const
ArgDescriptor ImplicitArgPtr
Align max(MaybeAlign Lhs, Align Rhs)
unsigned LDSSize
Number of bytes in the LDS that are being used.
bool hasNoSignedZerosFPMath() const
unsigned getLDSSize() const
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Calling convention used for Mesa/AMDPAL pixel shaders.
unsigned getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses...
Optional< unsigned > Mask
Optional< SIArgument > PrivateSegmentBuffer
const Function & getFunction() const
Return the LLVM function that this machine code represents.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
Optional< SIArgument > WorkItemIDZ
Optional< SIArgument > WorkGroupIDY
unsigned computeOccupancy(const MachineFunction &MF, unsigned LDSSize=0, unsigned NumSGPRs=0, unsigned NumVGPRs=0) const
Return occupancy for the given function.
A wrapper around std::string which contains a source range that's being set during parsing...
ArgDescriptor PrivateSegmentBuffer
bool isMemoryBound() const
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.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
void mappingImpl(yaml::IO &YamlIO) override
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Optional< SIArgument > ImplicitBufferPtr
StringRef getValueAsString() const
Return the attribute's value as a string.
ArgDescriptor KernargSegmentPtr
bool isAmdHsaOrMesa(const Function &F) const
uint32_t HighBitsOf32BitAddress
static bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg)
Optional< SIArgument > WorkGroupInfo
uint64_t ExplicitKernArgSize
unsigned getMaxKernArgAlign() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool needsWaveLimiter() const
static Optional< yaml::SIArgumentInfo > convertArgumentInfo(const AMDGPUFunctionArgInfo &ArgInfo, const TargetRegisterInfo &TRI)
A raw_ostream that writes to an std::string.
ArgDescriptor FlatScratchInit
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
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.
SIMachineFunctionInfo()=default
void setBitsInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsInMask - Add '1' bits from Mask to this vector.
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
Optional< int > FramePointerSaveIndex
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
Optional< SIArgument > WorkGroupIDX
bool hasCalls() const
Return true if the current function has any function calls.
bool hasNonSpillStackObjects() const
const SIRegisterInfo * getRegisterInfo() const override