1 //===- SIMachineFunctionInfo.h - SIMachineFunctionInfo interface -*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_R600_SIMACHINEFUNCTIONINFO_H
16 #define LLVM_LIB_TARGET_R600_SIMACHINEFUNCTIONINFO_H
18 #include "AMDGPUMachineFunction.h"
19 #include "SIRegisterInfo.h"
24 class MachineRegisterInfo;
26 /// This class keeps track of the SPI_SP_INPUT_ADDR config register, which
27 /// tells the hardware which interpolation parameters to load.
28 class SIMachineFunctionInfo : public AMDGPUMachineFunction {
29 // FIXME: This should be removed and getPreloadedValue moved here.
30 friend struct SIRegisterInfo;
31 void anchor() override;
35 // Registers that may be reserved for spilling purposes. These may be the same
36 // as the input registers.
37 unsigned ScratchRSrcReg;
38 unsigned ScratchWaveOffsetReg;
40 // Input registers setup for the HSA ABI.
41 // User SGPRs in allocation order.
42 unsigned PrivateSegmentBufferUserSGPR;
43 unsigned DispatchPtrUserSGPR;
44 unsigned QueuePtrUserSGPR;
45 unsigned KernargSegmentPtrUserSGPR;
46 unsigned DispatchIDUserSGPR;
47 unsigned FlatScratchInitUserSGPR;
48 unsigned PrivateSegmentSizeUserSGPR;
49 unsigned GridWorkGroupCountXUserSGPR;
50 unsigned GridWorkGroupCountYUserSGPR;
51 unsigned GridWorkGroupCountZUserSGPR;
53 // System SGPRs in allocation order.
54 unsigned WorkGroupIDXSystemSGPR;
55 unsigned WorkGroupIDYSystemSGPR;
56 unsigned WorkGroupIDZSystemSGPR;
57 unsigned WorkGroupInfoSystemSGPR;
58 unsigned PrivateSegmentWaveByteOffsetSystemSGPR;
64 // FIXME: Make private
65 unsigned LDSWaveSpillSize;
67 std::map<unsigned, unsigned> LaneVGPRs;
68 unsigned ScratchOffsetReg;
69 unsigned NumUserSGPRs;
70 unsigned NumSystemSGPRs;
76 // Feature bits required for inputs passed in user SGPRs.
77 bool PrivateSegmentBuffer : 1;
81 bool KernargSegmentPtr : 1;
82 bool FlatScratchInit : 1;
83 bool GridWorkgroupCountX : 1;
84 bool GridWorkgroupCountY : 1;
85 bool GridWorkgroupCountZ : 1;
87 // Feature bits required for inputs passed in system SGPRs.
88 bool WorkGroupIDX : 1; // Always initialized.
89 bool WorkGroupIDY : 1;
90 bool WorkGroupIDZ : 1;
91 bool WorkGroupInfo : 1;
92 bool PrivateSegmentWaveByteOffset : 1;
94 bool WorkItemIDX : 1; // Always initialized.
99 MCPhysReg getNextUserSGPR() const {
100 assert(NumSystemSGPRs == 0 && "System SGPRs must be added after user SGPRs");
101 return AMDGPU::SGPR0 + NumUserSGPRs;
104 MCPhysReg getNextSystemSGPR() const {
105 return AMDGPU::SGPR0 + NumUserSGPRs + NumSystemSGPRs;
112 SpilledReg(unsigned R, int L) : VGPR (R), Lane (L) { }
113 SpilledReg() : VGPR(0), Lane(-1) { }
114 bool hasLane() { return Lane != -1;}
117 // SIMachineFunctionInfo definition
119 SIMachineFunctionInfo(const MachineFunction &MF);
120 SpilledReg getSpilledReg(MachineFunction *MF, unsigned FrameIndex,
122 bool hasCalculatedTID() const { return TIDReg != AMDGPU::NoRegister; };
123 unsigned getTIDReg() const { return TIDReg; };
124 void setTIDReg(unsigned Reg) { TIDReg = Reg; }
127 unsigned addPrivateSegmentBuffer(const SIRegisterInfo &TRI);
128 unsigned addDispatchPtr(const SIRegisterInfo &TRI);
129 unsigned addQueuePtr(const SIRegisterInfo &TRI);
130 unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI);
133 unsigned addWorkGroupIDX() {
134 WorkGroupIDXSystemSGPR = getNextSystemSGPR();
136 return WorkGroupIDXSystemSGPR;
139 unsigned addWorkGroupIDY() {
140 WorkGroupIDYSystemSGPR = getNextSystemSGPR();
142 return WorkGroupIDYSystemSGPR;
145 unsigned addWorkGroupIDZ() {
146 WorkGroupIDZSystemSGPR = getNextSystemSGPR();
148 return WorkGroupIDZSystemSGPR;
151 unsigned addWorkGroupInfo() {
152 WorkGroupInfoSystemSGPR = getNextSystemSGPR();
154 return WorkGroupInfoSystemSGPR;
157 unsigned addPrivateSegmentWaveByteOffset() {
158 PrivateSegmentWaveByteOffsetSystemSGPR = getNextSystemSGPR();
160 return PrivateSegmentWaveByteOffsetSystemSGPR;
163 bool hasPrivateSegmentBuffer() const {
164 return PrivateSegmentBuffer;
167 bool hasDispatchPtr() const {
171 bool hasQueuePtr() const {
175 bool hasDispatchID() const {
179 bool hasKernargSegmentPtr() const {
180 return KernargSegmentPtr;
183 bool hasFlatScratchInit() const {
184 return FlatScratchInit;
187 bool hasGridWorkgroupCountX() const {
188 return GridWorkgroupCountX;
191 bool hasGridWorkgroupCountY() const {
192 return GridWorkgroupCountY;
195 bool hasGridWorkgroupCountZ() const {
196 return GridWorkgroupCountZ;
199 bool hasWorkGroupIDX() const {
203 bool hasWorkGroupIDY() const {
207 bool hasWorkGroupIDZ() const {
211 bool hasWorkGroupInfo() const {
212 return WorkGroupInfo;
215 bool hasPrivateSegmentWaveByteOffset() const {
216 return PrivateSegmentWaveByteOffset;
219 bool hasWorkItemIDX() const {
223 bool hasWorkItemIDY() const {
227 bool hasWorkItemIDZ() const {
231 unsigned getNumUserSGPRs() const {
235 unsigned getNumPreloadedSGPRs() const {
236 return NumUserSGPRs + NumSystemSGPRs;
239 unsigned getPrivateSegmentWaveByteOffsetSystemSGPR() const {
240 return PrivateSegmentWaveByteOffsetSystemSGPR;
243 /// \brief Returns the physical register reserved for use as the resource
244 /// descriptor for scratch accesses.
245 unsigned getScratchRSrcReg() const {
246 return ScratchRSrcReg;
249 void setScratchRSrcReg(unsigned Reg) {
250 assert(Reg != AMDGPU::NoRegister && "Should never be unset");
251 ScratchRSrcReg = Reg;
254 unsigned getScratchWaveOffsetReg() const {
255 return ScratchWaveOffsetReg;
258 void setScratchWaveOffsetReg(unsigned Reg) {
259 assert(Reg != AMDGPU::NoRegister && "Should never be unset");
260 ScratchWaveOffsetReg = Reg;
263 bool hasSpilledSGPRs() const {
264 return HasSpilledSGPRs;
267 void setHasSpilledSGPRs(bool Spill = true) {
268 HasSpilledSGPRs = Spill;
271 bool hasSpilledVGPRs() const {
272 return HasSpilledVGPRs;
275 void setHasSpilledVGPRs(bool Spill = true) {
276 HasSpilledVGPRs = Spill;
279 unsigned getPSInputAddr() const {
283 bool isPSInputAllocated(unsigned Index) const {
284 return PSInputAddr & (1 << Index);
287 void markPSInputAllocated(unsigned Index) {
288 PSInputAddr |= 1 << Index;
291 unsigned getMaximumWorkGroupSize(const MachineFunction &MF) const;
294 } // End namespace llvm