blob: 846ee5de057d2dee37a76e0e71c7e215a3eb4848 [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;
Tom Stellard96468902014-09-24 01:33:17 +000076
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000077 // Feature bits required for inputs passed in user SGPRs.
78 bool PrivateSegmentBuffer : 1;
Matt Arsenault49affb82015-11-25 20:55:12 +000079 bool DispatchPtr : 1;
80 bool QueuePtr : 1;
81 bool DispatchID : 1;
82 bool KernargSegmentPtr : 1;
83 bool FlatScratchInit : 1;
84 bool GridWorkgroupCountX : 1;
85 bool GridWorkgroupCountY : 1;
86 bool GridWorkgroupCountZ : 1;
Tom Stellardc149dc02013-11-27 21:23:35 +000087
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000088 // Feature bits required for inputs passed in system SGPRs.
Matt Arsenault49affb82015-11-25 20:55:12 +000089 bool WorkGroupIDX : 1; // Always initialized.
90 bool WorkGroupIDY : 1;
91 bool WorkGroupIDZ : 1;
92 bool WorkGroupInfo : 1;
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000093 bool PrivateSegmentWaveByteOffset : 1;
Matt Arsenault49affb82015-11-25 20:55:12 +000094
95 bool WorkItemIDX : 1; // Always initialized.
96 bool WorkItemIDY : 1;
97 bool WorkItemIDZ : 1;
98
Matt Arsenault26f8f3d2015-11-30 21:16:03 +000099
100 MCPhysReg getNextUserSGPR() const {
101 assert(NumSystemSGPRs == 0 && "System SGPRs must be added after user SGPRs");
102 return AMDGPU::SGPR0 + NumUserSGPRs;
103 }
104
105 MCPhysReg getNextSystemSGPR() const {
106 return AMDGPU::SGPR0 + NumUserSGPRs + NumSystemSGPRs;
107 }
108
Matt Arsenault49affb82015-11-25 20:55:12 +0000109public:
Tom Stellardc149dc02013-11-27 21:23:35 +0000110 struct SpilledReg {
111 unsigned VGPR;
112 int Lane;
113 SpilledReg(unsigned R, int L) : VGPR (R), Lane (L) { }
114 SpilledReg() : VGPR(0), Lane(-1) { }
115 bool hasLane() { return Lane != -1;}
116 };
117
Tom Stellardc149dc02013-11-27 21:23:35 +0000118 // SIMachineFunctionInfo definition
119
Tom Stellard75aadc22012-12-11 21:25:42 +0000120 SIMachineFunctionInfo(const MachineFunction &MF);
Tom Stellardc5cf2f02014-08-21 20:40:54 +0000121 SpilledReg getSpilledReg(MachineFunction *MF, unsigned FrameIndex,
122 unsigned SubIdx);
Tom Stellard96468902014-09-24 01:33:17 +0000123 bool hasCalculatedTID() const { return TIDReg != AMDGPU::NoRegister; };
124 unsigned getTIDReg() const { return TIDReg; };
125 void setTIDReg(unsigned Reg) { TIDReg = Reg; }
Matt Arsenault5b22dfa2015-11-05 05:27:10 +0000126
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000127 // Add user SGPRs.
128 unsigned addPrivateSegmentBuffer(const SIRegisterInfo &TRI);
129 unsigned addDispatchPtr(const SIRegisterInfo &TRI);
130 unsigned addQueuePtr(const SIRegisterInfo &TRI);
131 unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI);
132
133 // Add system SGPRs.
134 unsigned addWorkGroupIDX() {
135 WorkGroupIDXSystemSGPR = getNextSystemSGPR();
136 NumSystemSGPRs += 1;
137 return WorkGroupIDXSystemSGPR;
138 }
139
140 unsigned addWorkGroupIDY() {
141 WorkGroupIDYSystemSGPR = getNextSystemSGPR();
142 NumSystemSGPRs += 1;
143 return WorkGroupIDYSystemSGPR;
144 }
145
146 unsigned addWorkGroupIDZ() {
147 WorkGroupIDZSystemSGPR = getNextSystemSGPR();
148 NumSystemSGPRs += 1;
149 return WorkGroupIDZSystemSGPR;
150 }
151
152 unsigned addWorkGroupInfo() {
153 WorkGroupInfoSystemSGPR = getNextSystemSGPR();
154 NumSystemSGPRs += 1;
155 return WorkGroupInfoSystemSGPR;
156 }
157
158 unsigned addPrivateSegmentWaveByteOffset() {
159 PrivateSegmentWaveByteOffsetSystemSGPR = getNextSystemSGPR();
160 NumSystemSGPRs += 1;
161 return PrivateSegmentWaveByteOffsetSystemSGPR;
162 }
163
164 bool hasPrivateSegmentBuffer() const {
165 return PrivateSegmentBuffer;
166 }
167
Matt Arsenault49affb82015-11-25 20:55:12 +0000168 bool hasDispatchPtr() const {
169 return DispatchPtr;
170 }
171
172 bool hasQueuePtr() const {
173 return QueuePtr;
174 }
175
176 bool hasDispatchID() const {
177 return DispatchID;
178 }
179
180 bool hasKernargSegmentPtr() const {
181 return KernargSegmentPtr;
182 }
183
184 bool hasFlatScratchInit() const {
185 return FlatScratchInit;
186 }
187
188 bool hasGridWorkgroupCountX() const {
189 return GridWorkgroupCountX;
190 }
191
192 bool hasGridWorkgroupCountY() const {
193 return GridWorkgroupCountY;
194 }
195
196 bool hasGridWorkgroupCountZ() const {
197 return GridWorkgroupCountZ;
198 }
199
200 bool hasWorkGroupIDX() const {
201 return WorkGroupIDX;
202 }
203
204 bool hasWorkGroupIDY() const {
205 return WorkGroupIDY;
206 }
207
208 bool hasWorkGroupIDZ() const {
209 return WorkGroupIDZ;
210 }
211
212 bool hasWorkGroupInfo() const {
213 return WorkGroupInfo;
214 }
215
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000216 bool hasPrivateSegmentWaveByteOffset() const {
217 return PrivateSegmentWaveByteOffset;
218 }
219
Matt Arsenault49affb82015-11-25 20:55:12 +0000220 bool hasWorkItemIDX() const {
221 return WorkItemIDX;
222 }
223
224 bool hasWorkItemIDY() const {
225 return WorkItemIDY;
226 }
227
228 bool hasWorkItemIDZ() const {
229 return WorkItemIDZ;
230 }
231
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000232 unsigned getNumUserSGPRs() const {
233 return NumUserSGPRs;
234 }
235
236 unsigned getNumPreloadedSGPRs() const {
237 return NumUserSGPRs + NumSystemSGPRs;
238 }
239
240 unsigned getPrivateSegmentWaveByteOffsetSystemSGPR() const {
241 return PrivateSegmentWaveByteOffsetSystemSGPR;
242 }
243
Matt Arsenault49affb82015-11-25 20:55:12 +0000244 /// \brief Returns the physical register reserved for use as the resource
245 /// descriptor for scratch accesses.
246 unsigned getScratchRSrcReg() const {
247 return ScratchRSrcReg;
248 }
249
Matt Arsenault26f8f3d2015-11-30 21:16:03 +0000250 void setScratchRSrcReg(unsigned Reg) {
251 assert(Reg != AMDGPU::NoRegister && "Should never be unset");
252 ScratchRSrcReg = Reg;
253 }
254
255 unsigned getScratchWaveOffsetReg() const {
256 return ScratchWaveOffsetReg;
257 }
258
259 void setScratchWaveOffsetReg(unsigned Reg) {
260 assert(Reg != AMDGPU::NoRegister && "Should never be unset");
261 ScratchWaveOffsetReg = Reg;
262 }
Matt Arsenault49affb82015-11-25 20:55:12 +0000263
Matt Arsenault5b22dfa2015-11-05 05:27:10 +0000264 bool hasSpilledSGPRs() const {
265 return HasSpilledSGPRs;
266 }
267
268 void setHasSpilledSGPRs(bool Spill = true) {
269 HasSpilledSGPRs = Spill;
270 }
271
272 bool hasSpilledVGPRs() const {
273 return HasSpilledVGPRs;
274 }
275
276 void setHasSpilledVGPRs(bool Spill = true) {
277 HasSpilledVGPRs = Spill;
278 }
Tom Stellard96468902014-09-24 01:33:17 +0000279
Marek Olsakfccabaf2016-01-13 11:45:36 +0000280 unsigned getPSInputAddr() const {
281 return PSInputAddr;
282 }
283
284 bool isPSInputAllocated(unsigned Index) const {
285 return PSInputAddr & (1 << Index);
286 }
287
288 void markPSInputAllocated(unsigned Index) {
289 PSInputAddr |= 1 << Index;
290 }
291
Marek Olsak8e9cc632016-01-13 17:23:09 +0000292 bool returnsVoid() const {
293 return ReturnsVoid;
294 }
295
296 void setIfReturnsVoid(bool Value) {
297 ReturnsVoid = Value;
298 }
299
Tom Stellard96468902014-09-24 01:33:17 +0000300 unsigned getMaximumWorkGroupSize(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000301};
302
303} // End namespace llvm
304
305
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000306#endif