blob: 985b1ea7a2ad0c6376019e4d4c34ab02266bfb9f [file] [log] [blame]
Matt Arsenault0c90e952015-11-06 18:17:45 +00001//=====-- AMDGPUSubtarget.h - Define Subtarget for AMDGPU ------*- C++ -*-====//
Tom Stellard75aadc22012-12-11 21:25:42 +00002//
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/// \brief AMDGPU specific subclass of TargetSubtarget.
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault0c90e952015-11-06 18:17:45 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
Matt Arsenaultf59e5382015-11-06 18:23:00 +000017
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000018#include "AMDGPU.h"
Matt Arsenault43e92fe2016-06-24 06:30:11 +000019#include "R600InstrInfo.h"
20#include "R600ISelLowering.h"
21#include "R600FrameLowering.h"
22#include "SIInstrInfo.h"
23#include "SIISelLowering.h"
24#include "SIFrameLowering.h"
Tom Stellard347ac792015-06-26 21:15:07 +000025#include "Utils/AMDGPUBaseInfo.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000026#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000027#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000028#include "llvm/Target/TargetSubtargetInfo.h"
29
30#define GET_SUBTARGETINFO_HEADER
31#include "AMDGPUGenSubtargetInfo.inc"
32
Tom Stellard75aadc22012-12-11 21:25:42 +000033namespace llvm {
34
Tom Stellarde99fb652015-01-20 19:33:04 +000035class SIMachineFunctionInfo;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000036class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000037
Tom Stellard75aadc22012-12-11 21:25:42 +000038class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000039public:
40 enum Generation {
41 R600 = 0,
42 R700,
43 EVERGREEN,
44 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000045 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000046 SEA_ISLANDS,
47 VOLCANIC_ISLANDS,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000048 };
49
Marek Olsak4d00dd22015-03-09 15:48:09 +000050 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000051 ISAVersion0_0_0,
52 ISAVersion7_0_0,
53 ISAVersion7_0_1,
54 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000055 ISAVersion8_0_1,
56 ISAVersion8_0_3
Tom Stellard347ac792015-06-26 21:15:07 +000057 };
58
Matt Arsenault43e92fe2016-06-24 06:30:11 +000059protected:
60 // Basic subtarget description.
61 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +000062 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000063 unsigned IsaVersion;
64 unsigned WavefrontSize;
65 int LocalMemorySize;
66 int LDSBankCount;
67 unsigned MaxPrivateElementSize;
68
69 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +000070 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +000071 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000072
73 // Dynamially set bits that enable features.
74 bool FP32Denormals;
75 bool FP64Denormals;
76 bool FPExceptions;
Changpeng Fangb41574a2015-12-22 20:55:23 +000077 bool FlatForGlobal;
Matt Arsenault7f681ac2016-07-01 23:03:44 +000078 bool UnalignedBufferAccess;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000079 bool EnableXNACK;
80 bool DebuggerInsertNops;
81 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +000082 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000083
84 // Used as options.
85 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000086 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +000087 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +000088 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000089 bool EnableSIScheduler;
90 bool DumpCode;
91
92 // Subtarget statically properties set by tablegen
93 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +000094 bool IsGCN;
95 bool GCN1Encoding;
96 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +000097 bool CIInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000098 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +000099 bool HasSMemRealTime;
100 bool Has16BitInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000101 bool FlatAddressSpace;
102 bool R600ALUInst;
103 bool CaymanISA;
104 bool CFALUBug;
105 bool HasVertexCache;
106 short TexVTXClauseSize;
Tom Stellard75aadc22012-12-11 21:25:42 +0000107
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000108 // Dummy feature to use for assembler in tablegen.
109 bool FeatureDisable;
110
Tom Stellard75aadc22012-12-11 21:25:42 +0000111 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000112 SelectionDAGTargetInfo TSInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +0000113
114public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000115 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
116 const TargetMachine &TM);
117 virtual ~AMDGPUSubtarget();
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000118 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
119 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000120
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000121 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
122 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
123 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
124 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000125
Eric Christopherd9134482014-08-04 21:25:23 +0000126 const InstrItineraryData *getInstrItineraryData() const override {
127 return &InstrItins;
128 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000129
Matt Arsenault56684d42016-08-11 17:31:42 +0000130 // Nothing implemented, just prevent crashes on use.
131 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
132 return &TSInfo;
133 }
134
Craig Topperee7b0f32014-04-30 05:53:27 +0000135 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000136
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000137 bool isAmdHsaOS() const {
138 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000139 }
140
141 Generation getGeneration() const {
142 return Gen;
143 }
144
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000145 unsigned getWavefrontSize() const {
146 return WavefrontSize;
147 }
148
149 int getLocalMemorySize() const {
150 return LocalMemorySize;
151 }
152
153 int getLDSBankCount() const {
154 return LDSBankCount;
155 }
156
157 unsigned getMaxPrivateElementSize() const {
158 return MaxPrivateElementSize;
159 }
160
Matt Arsenaultd782d052014-06-27 17:57:00 +0000161 bool hasHWFP64() const {
162 return FP64;
163 }
164
Matt Arsenaultb035a572015-01-29 19:34:25 +0000165 bool hasFastFMAF32() const {
166 return FastFMAF32;
167 }
168
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000169 bool hasHalfRate64Ops() const {
170 return HalfRate64Ops;
171 }
172
Matt Arsenault88701812016-06-09 23:42:48 +0000173 bool hasAddr64() const {
174 return (getGeneration() < VOLCANIC_ISLANDS);
175 }
176
Matt Arsenaultfae02982014-03-17 18:58:11 +0000177 bool hasBFE() const {
178 return (getGeneration() >= EVERGREEN);
179 }
180
Matt Arsenault6e439652014-06-10 19:00:20 +0000181 bool hasBFI() const {
182 return (getGeneration() >= EVERGREEN);
183 }
184
Matt Arsenaultfae02982014-03-17 18:58:11 +0000185 bool hasBFM() const {
186 return hasBFE();
187 }
188
Matt Arsenault60425062014-06-10 19:18:28 +0000189 bool hasBCNT(unsigned Size) const {
190 if (Size == 32)
191 return (getGeneration() >= EVERGREEN);
192
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000193 if (Size == 64)
194 return (getGeneration() >= SOUTHERN_ISLANDS);
195
196 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000197 }
198
Tom Stellard50122a52014-04-07 19:45:41 +0000199 bool hasMulU24() const {
200 return (getGeneration() >= EVERGREEN);
201 }
202
203 bool hasMulI24() const {
204 return (getGeneration() >= SOUTHERN_ISLANDS ||
205 hasCaymanISA());
206 }
207
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000208 bool hasFFBL() const {
209 return (getGeneration() >= EVERGREEN);
210 }
211
212 bool hasFFBH() const {
213 return (getGeneration() >= EVERGREEN);
214 }
215
Jan Vesely808fff52015-04-30 17:15:56 +0000216 bool hasCARRY() const {
217 return (getGeneration() >= EVERGREEN);
218 }
219
220 bool hasBORROW() const {
221 return (getGeneration() >= EVERGREEN);
222 }
223
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000224 bool hasCaymanISA() const {
225 return CaymanISA;
226 }
227
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000228 bool isPromoteAllocaEnabled() const {
229 return EnablePromoteAlloca;
230 }
231
Matt Arsenault706f9302015-07-06 16:01:58 +0000232 bool unsafeDSOffsetFoldingEnabled() const {
233 return EnableUnsafeDSOffsetFolding;
234 }
235
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000236 bool dumpCode() const {
237 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000238 }
239
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000240 /// Return the amount of LDS that can be used that will not restrict the
241 /// occupancy lower than WaveCount.
242 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount) const;
243
244 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
245 /// the given LDS memory size is the only constraint.
246 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes) const;
247
248
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000249 bool hasFP32Denormals() const {
250 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000251 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000252
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000253 bool hasFP64Denormals() const {
254 return FP64Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000255 }
256
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000257 bool hasFPExceptions() const {
258 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000259 }
260
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000261 bool useFlatForGlobal() const {
262 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000263 }
264
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000265 bool hasUnalignedBufferAccess() const {
266 return UnalignedBufferAccess;
267 }
268
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000269 bool isXNACKEnabled() const {
270 return EnableXNACK;
271 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000272
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000273 unsigned getMaxWavesPerCU() const {
274 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
275 return 10;
276
277 // FIXME: Not sure what this is for other subtagets.
278 return 8;
279 }
280
281 /// \brief Returns the offset in bytes from the start of the input buffer
282 /// of the first explicit kernel argument.
283 unsigned getExplicitKernelArgOffset() const {
284 return isAmdHsaOS() ? 0 : 36;
285 }
286
287 unsigned getStackAlignment() const {
288 // Scratch is allocated in 256 dword per wave blocks.
289 return 4 * 256 / getWavefrontSize();
290 }
Tom Stellard347ac792015-06-26 21:15:07 +0000291
Craig Topper5656db42014-04-29 07:57:24 +0000292 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000293 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000294 }
295
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000296 bool enableSubRegLiveness() const override {
297 return true;
298 }
299};
300
301class R600Subtarget final : public AMDGPUSubtarget {
302private:
303 R600InstrInfo InstrInfo;
304 R600FrameLowering FrameLowering;
305 R600TargetLowering TLInfo;
306
307public:
308 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
309 const TargetMachine &TM);
310
311 const R600InstrInfo *getInstrInfo() const override {
312 return &InstrInfo;
313 }
314
315 const R600FrameLowering *getFrameLowering() const override {
316 return &FrameLowering;
317 }
318
319 const R600TargetLowering *getTargetLowering() const override {
320 return &TLInfo;
321 }
322
323 const R600RegisterInfo *getRegisterInfo() const override {
324 return &InstrInfo.getRegisterInfo();
325 }
326
327 bool hasCFAluBug() const {
328 return CFALUBug;
329 }
330
331 bool hasVertexCache() const {
332 return HasVertexCache;
333 }
334
335 short getTexVTXClauseSize() const {
336 return TexVTXClauseSize;
337 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000338};
339
340class SISubtarget final : public AMDGPUSubtarget {
341public:
342 enum {
Marek Olsak355a8642016-08-05 21:23:29 +0000343 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
344 // doesn't spill SGPRs as much as when 80 is set.
345 FIXED_SGPR_COUNT_FOR_INIT_BUG = 96
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000346 };
347
348private:
349 SIInstrInfo InstrInfo;
350 SIFrameLowering FrameLowering;
351 SITargetLowering TLInfo;
352 std::unique_ptr<GISelAccessor> GISel;
353
354public:
355 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
356 const TargetMachine &TM);
357
358 const SIInstrInfo *getInstrInfo() const override {
359 return &InstrInfo;
360 }
361
362 const SIFrameLowering *getFrameLowering() const override {
363 return &FrameLowering;
364 }
365
366 const SITargetLowering *getTargetLowering() const override {
367 return &TLInfo;
368 }
369
370 const CallLowering *getCallLowering() const override {
371 assert(GISel && "Access to GlobalISel APIs not set");
372 return GISel->getCallLowering();
373 }
374
375 const SIRegisterInfo *getRegisterInfo() const override {
376 return &InstrInfo.getRegisterInfo();
377 }
378
379 void setGISelAccessor(GISelAccessor &GISel) {
380 this->GISel.reset(&GISel);
381 }
382
Tom Stellard83f0bce2015-01-29 16:55:25 +0000383 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000384 unsigned NumRegionInstrs) const override;
385
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000386 bool isVGPRSpillingEnabled(const Function& F) const;
387
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000388 unsigned getMaxNumUserSGPRs() const {
389 return 16;
390 }
391
392 bool hasFlatAddressSpace() const {
393 return FlatAddressSpace;
394 }
395
396 bool hasSMemRealTime() const {
397 return HasSMemRealTime;
398 }
399
400 bool has16BitInsts() const {
401 return Has16BitInsts;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000402 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000403
Tom Stellardde008d32016-01-21 04:28:34 +0000404 bool enableSIScheduler() const {
405 return EnableSIScheduler;
406 }
407
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000408 bool debuggerSupported() const {
409 return debuggerInsertNops() && debuggerReserveRegs() &&
410 debuggerEmitPrologue();
411 }
412
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000413 bool debuggerInsertNops() const {
414 return DebuggerInsertNops;
415 }
416
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000417 bool debuggerReserveRegs() const {
418 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000419 }
420
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000421 bool debuggerEmitPrologue() const {
422 return DebuggerEmitPrologue;
423 }
424
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000425 bool loadStoreOptEnabled() const {
426 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000427 }
428
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000429 bool hasSGPRInitBug() const {
430 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000431 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000432
433 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
434 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
435
436 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
437 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000438};
439
440} // End namespace llvm
441
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000442#endif