blob: 2f4e494faaf60824e18495765224708736fe0e80 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===- SIMachineFunctionInfo.h - SIMachineFunctionInfo interface -*- C++ -*-==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file
11//
12//===----------------------------------------------------------------------===//
13
14
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_R600_SIMACHINEFUNCTIONINFO_H
16#define LLVM_LIB_TARGET_R600_SIMACHINEFUNCTIONINFO_H
Tom Stellard75aadc22012-12-11 21:25:42 +000017
Vincent Lejeuneace6f732013-04-01 21:47:53 +000018#include "AMDGPUMachineFunction.h"
Tom Stellard96468902014-09-24 01:33:17 +000019#include "SIRegisterInfo.h"
Tom Stellardc149dc02013-11-27 21:23:35 +000020#include <map>
Tom Stellard75aadc22012-12-11 21:25:42 +000021
22namespace llvm {
23
Tom Stellardc149dc02013-11-27 21:23:35 +000024class MachineRegisterInfo;
25
Tom Stellard75aadc22012-12-11 21:25:42 +000026/// This class keeps track of the SPI_SP_INPUT_ADDR config register, which
27/// tells the hardware which interpolation parameters to load.
Vincent Lejeuneace6f732013-04-01 21:47:53 +000028class SIMachineFunctionInfo : public AMDGPUMachineFunction {
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000029 // FIXME: This should be removed and getPreloadedValue moved here.
30 friend struct SIRegisterInfo;
Craig Topper5656db42014-04-29 07:57:24 +000031 void anchor() override;
Tom Stellard96468902014-09-24 01:33:17 +000032
33 unsigned TIDReg;
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000034
35 // Registers that may be reserved for spilling purposes. These may be the same
36 // as the input registers.
Matt Arsenault49affb82015-11-25 20:55:12 +000037 unsigned ScratchRSrcReg;
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000038 unsigned ScratchWaveOffsetReg;
39
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;
52
53 // System SGPRs in allocation order.
54 unsigned WorkGroupIDXSystemSGPR;
55 unsigned WorkGroupIDYSystemSGPR;
56 unsigned WorkGroupIDZSystemSGPR;
57 unsigned WorkGroupInfoSystemSGPR;
58 unsigned PrivateSegmentWaveByteOffsetSystemSGPR;
Matt Arsenault49affb82015-11-25 20:55:12 +000059
Marek Olsakfccabaf2016-01-13 11:45:36 +000060 // Graphics info.
61 unsigned PSInputAddr;
Marek Olsak8e9cc632016-01-13 17:23:09 +000062 bool ReturnsVoid;
Marek Olsakfccabaf2016-01-13 11:45:36 +000063
Matt Arsenault49affb82015-11-25 20:55:12 +000064public:
65 // FIXME: Make private
66 unsigned LDSWaveSpillSize;
Marek Olsakfccabaf2016-01-13 11:45:36 +000067 unsigned PSInputEna;
Matt Arsenault49affb82015-11-25 20:55:12 +000068 std::map<unsigned, unsigned> LaneVGPRs;
69 unsigned ScratchOffsetReg;
70 unsigned NumUserSGPRs;
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000071 unsigned NumSystemSGPRs;
Matt Arsenault49affb82015-11-25 20:55:12 +000072
73private:
Matt Arsenault5b22dfa2015-11-05 05:27:10 +000074 bool HasSpilledSGPRs;
Tom Stellard42fb60e2015-01-14 15:42:31 +000075 bool HasSpilledVGPRs;
Matt Arsenault296b8492016-02-12 06:31:30 +000076 bool HasNonSpillStackObjects;
77 bool HasFlatInstructions;
Tom Stellard96468902014-09-24 01:33:17 +000078
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000079 // Feature bits required for inputs passed in user SGPRs.
80 bool PrivateSegmentBuffer : 1;
Matt Arsenault49affb82015-11-25 20:55:12 +000081 bool DispatchPtr : 1;
82 bool QueuePtr : 1;
83 bool DispatchID : 1;
84 bool KernargSegmentPtr : 1;
85 bool FlatScratchInit : 1;
86 bool GridWorkgroupCountX : 1;
87 bool GridWorkgroupCountY : 1;
88 bool GridWorkgroupCountZ : 1;
Tom Stellardc149dc02013-11-27 21:23:35 +000089
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000090 // Feature bits required for inputs passed in system SGPRs.
Matt Arsenault49affb82015-11-25 20:55:12 +000091 bool WorkGroupIDX : 1; // Always initialized.
92 bool WorkGroupIDY : 1;
93 bool WorkGroupIDZ : 1;
94 bool WorkGroupInfo : 1;
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000095 bool PrivateSegmentWaveByteOffset : 1;
Matt Arsenault49affb82015-11-25 20:55:12 +000096
97 bool WorkItemIDX : 1; // Always initialized.
98 bool WorkItemIDY : 1;
99 bool WorkItemIDZ : 1;
100
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000101
102 MCPhysReg getNextUserSGPR() const {
103 assert(NumSystemSGPRs == 0 && "System SGPRs must be added after user SGPRs");
104 return AMDGPU::SGPR0 + NumUserSGPRs;
105 }
106
107 MCPhysReg getNextSystemSGPR() const {
108 return AMDGPU::SGPR0 + NumUserSGPRs + NumSystemSGPRs;
109 }
110
Matt Arsenault49affb82015-11-25 20:55:12 +0000111public:
Tom Stellardc149dc02013-11-27 21:23:35 +0000112 struct SpilledReg {
113 unsigned VGPR;
114 int Lane;
115 SpilledReg(unsigned R, int L) : VGPR (R), Lane (L) { }
Tom Stellard649b5db2016-03-04 18:31:18 +0000116 SpilledReg() : VGPR(AMDGPU::NoRegister), Lane(-1) { }
Tom Stellardc149dc02013-11-27 21:23:35 +0000117 bool hasLane() { return Lane != -1;}
Tom Stellard649b5db2016-03-04 18:31:18 +0000118 bool hasReg() { return VGPR != AMDGPU::NoRegister;}
Tom Stellardc149dc02013-11-27 21:23:35 +0000119 };
120
Tom Stellardc149dc02013-11-27 21:23:35 +0000121 // SIMachineFunctionInfo definition
122
Tom Stellard75aadc22012-12-11 21:25:42 +0000123 SIMachineFunctionInfo(const MachineFunction &MF);
Tom Stellardc5cf2f02014-08-21 20:40:54 +0000124 SpilledReg getSpilledReg(MachineFunction *MF, unsigned FrameIndex,
125 unsigned SubIdx);
Tom Stellard96468902014-09-24 01:33:17 +0000126 bool hasCalculatedTID() const { return TIDReg != AMDGPU::NoRegister; };
127 unsigned getTIDReg() const { return TIDReg; };
128 void setTIDReg(unsigned Reg) { TIDReg = Reg; }
Matt Arsenault5b22dfa2015-11-05 05:27:10 +0000129
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000130 // Add user SGPRs.
131 unsigned addPrivateSegmentBuffer(const SIRegisterInfo &TRI);
132 unsigned addDispatchPtr(const SIRegisterInfo &TRI);
133 unsigned addQueuePtr(const SIRegisterInfo &TRI);
134 unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI);
Matt Arsenault296b8492016-02-12 06:31:30 +0000135 unsigned addFlatScratchInit(const SIRegisterInfo &TRI);
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000136
137 // Add system SGPRs.
138 unsigned addWorkGroupIDX() {
139 WorkGroupIDXSystemSGPR = getNextSystemSGPR();
140 NumSystemSGPRs += 1;
141 return WorkGroupIDXSystemSGPR;
142 }
143
144 unsigned addWorkGroupIDY() {
145 WorkGroupIDYSystemSGPR = getNextSystemSGPR();
146 NumSystemSGPRs += 1;
147 return WorkGroupIDYSystemSGPR;
148 }
149
150 unsigned addWorkGroupIDZ() {
151 WorkGroupIDZSystemSGPR = getNextSystemSGPR();
152 NumSystemSGPRs += 1;
153 return WorkGroupIDZSystemSGPR;
154 }
155
156 unsigned addWorkGroupInfo() {
157 WorkGroupInfoSystemSGPR = getNextSystemSGPR();
158 NumSystemSGPRs += 1;
159 return WorkGroupInfoSystemSGPR;
160 }
161
162 unsigned addPrivateSegmentWaveByteOffset() {
163 PrivateSegmentWaveByteOffsetSystemSGPR = getNextSystemSGPR();
164 NumSystemSGPRs += 1;
165 return PrivateSegmentWaveByteOffsetSystemSGPR;
166 }
167
168 bool hasPrivateSegmentBuffer() const {
169 return PrivateSegmentBuffer;
170 }
171
Matt Arsenault49affb82015-11-25 20:55:12 +0000172 bool hasDispatchPtr() const {
173 return DispatchPtr;
174 }
175
176 bool hasQueuePtr() const {
177 return QueuePtr;
178 }
179
180 bool hasDispatchID() const {
181 return DispatchID;
182 }
183
184 bool hasKernargSegmentPtr() const {
185 return KernargSegmentPtr;
186 }
187
188 bool hasFlatScratchInit() const {
189 return FlatScratchInit;
190 }
191
192 bool hasGridWorkgroupCountX() const {
193 return GridWorkgroupCountX;
194 }
195
196 bool hasGridWorkgroupCountY() const {
197 return GridWorkgroupCountY;
198 }
199
200 bool hasGridWorkgroupCountZ() const {
201 return GridWorkgroupCountZ;
202 }
203
204 bool hasWorkGroupIDX() const {
205 return WorkGroupIDX;
206 }
207
208 bool hasWorkGroupIDY() const {
209 return WorkGroupIDY;
210 }
211
212 bool hasWorkGroupIDZ() const {
213 return WorkGroupIDZ;
214 }
215
216 bool hasWorkGroupInfo() const {
217 return WorkGroupInfo;
218 }
219
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000220 bool hasPrivateSegmentWaveByteOffset() const {
221 return PrivateSegmentWaveByteOffset;
222 }
223
Matt Arsenault49affb82015-11-25 20:55:12 +0000224 bool hasWorkItemIDX() const {
225 return WorkItemIDX;
226 }
227
228 bool hasWorkItemIDY() const {
229 return WorkItemIDY;
230 }
231
232 bool hasWorkItemIDZ() const {
233 return WorkItemIDZ;
234 }
235
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000236 unsigned getNumUserSGPRs() const {
237 return NumUserSGPRs;
238 }
239
240 unsigned getNumPreloadedSGPRs() const {
241 return NumUserSGPRs + NumSystemSGPRs;
242 }
243
244 unsigned getPrivateSegmentWaveByteOffsetSystemSGPR() const {
245 return PrivateSegmentWaveByteOffsetSystemSGPR;
246 }
247
Matt Arsenault49affb82015-11-25 20:55:12 +0000248 /// \brief Returns the physical register reserved for use as the resource
249 /// descriptor for scratch accesses.
250 unsigned getScratchRSrcReg() const {
251 return ScratchRSrcReg;
252 }
253
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000254 void setScratchRSrcReg(unsigned Reg) {
255 assert(Reg != AMDGPU::NoRegister && "Should never be unset");
256 ScratchRSrcReg = Reg;
257 }
258
259 unsigned getScratchWaveOffsetReg() const {
260 return ScratchWaveOffsetReg;
261 }
262
263 void setScratchWaveOffsetReg(unsigned Reg) {
264 assert(Reg != AMDGPU::NoRegister && "Should never be unset");
265 ScratchWaveOffsetReg = Reg;
266 }
Matt Arsenault49affb82015-11-25 20:55:12 +0000267
Matt Arsenault5b22dfa2015-11-05 05:27:10 +0000268 bool hasSpilledSGPRs() const {
269 return HasSpilledSGPRs;
270 }
271
272 void setHasSpilledSGPRs(bool Spill = true) {
273 HasSpilledSGPRs = Spill;
274 }
275
276 bool hasSpilledVGPRs() const {
277 return HasSpilledVGPRs;
278 }
279
280 void setHasSpilledVGPRs(bool Spill = true) {
281 HasSpilledVGPRs = Spill;
282 }
Tom Stellard96468902014-09-24 01:33:17 +0000283
Matt Arsenault296b8492016-02-12 06:31:30 +0000284 bool hasNonSpillStackObjects() const {
285 return HasNonSpillStackObjects;
286 }
287
288 void setHasNonSpillStackObjects(bool StackObject = true) {
289 HasNonSpillStackObjects = StackObject;
290 }
291
292 bool hasFlatInstructions() const {
293 return HasFlatInstructions;
294 }
295
296 void setHasFlatInstructions(bool UseFlat = true) {
297 HasFlatInstructions = UseFlat;
298 }
299
Marek Olsakfccabaf2016-01-13 11:45:36 +0000300 unsigned getPSInputAddr() const {
301 return PSInputAddr;
302 }
303
304 bool isPSInputAllocated(unsigned Index) const {
305 return PSInputAddr & (1 << Index);
306 }
307
308 void markPSInputAllocated(unsigned Index) {
309 PSInputAddr |= 1 << Index;
310 }
311
Marek Olsak8e9cc632016-01-13 17:23:09 +0000312 bool returnsVoid() const {
313 return ReturnsVoid;
314 }
315
316 void setIfReturnsVoid(bool Value) {
317 ReturnsVoid = Value;
318 }
319
Tom Stellard96468902014-09-24 01:33:17 +0000320 unsigned getMaximumWorkGroupSize(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000321};
322
323} // End namespace llvm
324
325
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000326#endif