blob: c055b8c5f79a4d682664831e2128b337a5bd278c [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"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000026#include "llvm/ADT/Triple.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000027#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000028#include "llvm/CodeGen/MachineFunction.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000029#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000030#include "llvm/MC/MCInstrItineraries.h"
31#include "llvm/Support/MathExtras.h"
32#include <cassert>
33#include <cstdint>
34#include <memory>
35#include <utility>
Tom Stellard75aadc22012-12-11 21:25:42 +000036
37#define GET_SUBTARGETINFO_HEADER
38#include "AMDGPUGenSubtargetInfo.inc"
39
Tom Stellard75aadc22012-12-11 21:25:42 +000040namespace llvm {
41
Matt Arsenault43e92fe2016-06-24 06:30:11 +000042class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000043
Tom Stellard75aadc22012-12-11 21:25:42 +000044class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000045public:
46 enum Generation {
47 R600 = 0,
48 R700,
49 EVERGREEN,
50 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000051 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000052 SEA_ISLANDS,
53 VOLCANIC_ISLANDS,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000054 };
55
Marek Olsak4d00dd22015-03-09 15:48:09 +000056 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000057 ISAVersion0_0_0,
58 ISAVersion7_0_0,
59 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +000060 ISAVersion7_0_2,
Tom Stellard347ac792015-06-26 21:15:07 +000061 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000062 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +000063 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +000064 ISAVersion8_0_3,
65 ISAVersion8_0_4,
66 ISAVersion8_1_0,
Tom Stellard347ac792015-06-26 21:15:07 +000067 };
68
Matt Arsenault43e92fe2016-06-24 06:30:11 +000069protected:
70 // Basic subtarget description.
71 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +000072 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000073 unsigned IsaVersion;
74 unsigned WavefrontSize;
75 int LocalMemorySize;
76 int LDSBankCount;
77 unsigned MaxPrivateElementSize;
78
79 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +000080 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +000081 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000082
83 // Dynamially set bits that enable features.
84 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +000085 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000086 bool FPExceptions;
Changpeng Fangb41574a2015-12-22 20:55:23 +000087 bool FlatForGlobal;
Matt Arsenault7aad8fd2017-01-24 22:02:15 +000088 bool NoAddr64;
Tom Stellard64a9d082016-10-14 18:10:39 +000089 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +000090 bool UnalignedBufferAccess;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000091 bool EnableXNACK;
92 bool DebuggerInsertNops;
93 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +000094 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000095
96 // Used as options.
97 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000098 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +000099 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000100 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000101 bool EnableSIScheduler;
102 bool DumpCode;
103
104 // Subtarget statically properties set by tablegen
105 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000106 bool IsGCN;
107 bool GCN1Encoding;
108 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000109 bool CIInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000110 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000111 bool HasSMemRealTime;
112 bool Has16BitInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000113 bool HasMovrel;
114 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000115 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000116 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000117 bool HasSDWA;
118 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000119 bool FlatAddressSpace;
120 bool R600ALUInst;
121 bool CaymanISA;
122 bool CFALUBug;
123 bool HasVertexCache;
124 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000125 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000126
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000127 // Dummy feature to use for assembler in tablegen.
128 bool FeatureDisable;
129
Tom Stellard75aadc22012-12-11 21:25:42 +0000130 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000131 SelectionDAGTargetInfo TSInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +0000132
133public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000134 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
135 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000136 ~AMDGPUSubtarget() override;
137
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000138 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
139 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000140
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000141 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
142 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
143 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
144 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000145
Eric Christopherd9134482014-08-04 21:25:23 +0000146 const InstrItineraryData *getInstrItineraryData() const override {
147 return &InstrItins;
148 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000149
Matt Arsenault56684d42016-08-11 17:31:42 +0000150 // Nothing implemented, just prevent crashes on use.
151 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
152 return &TSInfo;
153 }
154
Craig Topperee7b0f32014-04-30 05:53:27 +0000155 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000156
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000157 bool isAmdHsaOS() const {
158 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000159 }
160
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000161 bool isMesa3DOS() const {
162 return TargetTriple.getOS() == Triple::Mesa3D;
163 }
164
Tom Stellarde88bbc32016-09-23 01:33:26 +0000165 bool isOpenCLEnv() const {
166 return TargetTriple.getEnvironment() == Triple::OpenCL;
167 }
168
Matt Arsenaultd782d052014-06-27 17:57:00 +0000169 Generation getGeneration() const {
170 return Gen;
171 }
172
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000173 unsigned getWavefrontSize() const {
174 return WavefrontSize;
175 }
176
177 int getLocalMemorySize() const {
178 return LocalMemorySize;
179 }
180
181 int getLDSBankCount() const {
182 return LDSBankCount;
183 }
184
185 unsigned getMaxPrivateElementSize() const {
186 return MaxPrivateElementSize;
187 }
188
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000189 bool has16BitInsts() const {
190 return Has16BitInsts;
191 }
192
Matt Arsenaultd782d052014-06-27 17:57:00 +0000193 bool hasHWFP64() const {
194 return FP64;
195 }
196
Matt Arsenaultb035a572015-01-29 19:34:25 +0000197 bool hasFastFMAF32() const {
198 return FastFMAF32;
199 }
200
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000201 bool hasHalfRate64Ops() const {
202 return HalfRate64Ops;
203 }
204
Matt Arsenault88701812016-06-09 23:42:48 +0000205 bool hasAddr64() const {
206 return (getGeneration() < VOLCANIC_ISLANDS);
207 }
208
Matt Arsenaultfae02982014-03-17 18:58:11 +0000209 bool hasBFE() const {
210 return (getGeneration() >= EVERGREEN);
211 }
212
Matt Arsenault6e439652014-06-10 19:00:20 +0000213 bool hasBFI() const {
214 return (getGeneration() >= EVERGREEN);
215 }
216
Matt Arsenaultfae02982014-03-17 18:58:11 +0000217 bool hasBFM() const {
218 return hasBFE();
219 }
220
Matt Arsenault60425062014-06-10 19:18:28 +0000221 bool hasBCNT(unsigned Size) const {
222 if (Size == 32)
223 return (getGeneration() >= EVERGREEN);
224
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000225 if (Size == 64)
226 return (getGeneration() >= SOUTHERN_ISLANDS);
227
228 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000229 }
230
Tom Stellard50122a52014-04-07 19:45:41 +0000231 bool hasMulU24() const {
232 return (getGeneration() >= EVERGREEN);
233 }
234
235 bool hasMulI24() const {
236 return (getGeneration() >= SOUTHERN_ISLANDS ||
237 hasCaymanISA());
238 }
239
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000240 bool hasFFBL() const {
241 return (getGeneration() >= EVERGREEN);
242 }
243
244 bool hasFFBH() const {
245 return (getGeneration() >= EVERGREEN);
246 }
247
Jan Vesely808fff52015-04-30 17:15:56 +0000248 bool hasCARRY() const {
249 return (getGeneration() >= EVERGREEN);
250 }
251
252 bool hasBORROW() const {
253 return (getGeneration() >= EVERGREEN);
254 }
255
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000256 bool hasCaymanISA() const {
257 return CaymanISA;
258 }
259
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000260 bool isPromoteAllocaEnabled() const {
261 return EnablePromoteAlloca;
262 }
263
Matt Arsenault706f9302015-07-06 16:01:58 +0000264 bool unsafeDSOffsetFoldingEnabled() const {
265 return EnableUnsafeDSOffsetFolding;
266 }
267
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000268 bool dumpCode() const {
269 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000270 }
271
Wei Ding3cb2a1e2016-10-19 22:34:49 +0000272 bool enableIEEEBit(const MachineFunction &MF) const {
273 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
274 }
275
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000276 /// Return the amount of LDS that can be used that will not restrict the
277 /// occupancy lower than WaveCount.
278 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount) const;
279
280 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
281 /// the given LDS memory size is the only constraint.
282 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes) const;
283
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000284 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000285 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000286 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000287
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000288 bool hasFP32Denormals() const {
289 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000290 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000291
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000292 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000293 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000294 }
295
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000296 bool hasFPExceptions() const {
297 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000298 }
299
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000300 bool useFlatForGlobal() const {
301 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000302 }
303
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000304 bool hasUnalignedBufferAccess() const {
305 return UnalignedBufferAccess;
306 }
307
Tom Stellard64a9d082016-10-14 18:10:39 +0000308 bool hasUnalignedScratchAccess() const {
309 return UnalignedScratchAccess;
310 }
311
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000312 bool isXNACKEnabled() const {
313 return EnableXNACK;
314 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000315
Tom Stellard2f3f9852017-01-25 01:25:13 +0000316 bool isMesaKernel(const MachineFunction &MF) const {
317 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
318 }
319
320 // Covers VS/PS/CS graphics shaders
321 bool isMesaGfxShader(const MachineFunction &MF) const {
322 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
323 }
324
325 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
326 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000327 }
328
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000329 /// \brief Returns the offset in bytes from the start of the input buffer
330 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000331 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
332 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000333 }
334
Tom Stellardb2869eb2016-09-09 19:28:00 +0000335 unsigned getAlignmentForImplicitArgPtr() const {
336 return isAmdHsaOS() ? 8 : 4;
337 }
338
Tom Stellard2f3f9852017-01-25 01:25:13 +0000339 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
340 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000341 return 16;
342 if (isAmdHsaOS() && isOpenCLEnv())
343 return 32;
344 return 0;
345 }
346
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000347 unsigned getStackAlignment() const {
348 // Scratch is allocated in 256 dword per wave blocks.
349 return 4 * 256 / getWavefrontSize();
350 }
Tom Stellard347ac792015-06-26 21:15:07 +0000351
Craig Topper5656db42014-04-29 07:57:24 +0000352 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000353 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000354 }
355
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000356 bool enableSubRegLiveness() const override {
357 return true;
358 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000359
360 /// \returns Number of execution units per compute unit supported by the
361 /// subtarget.
362 unsigned getEUsPerCU() const {
363 return 4;
364 }
365
366 /// \returns Maximum number of work groups per compute unit supported by the
367 /// subtarget and limited by given flat work group size.
368 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
369 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
370 return 8;
371 return getWavesPerWorkGroup(FlatWorkGroupSize) == 1 ? 40 : 16;
372 }
373
374 /// \returns Maximum number of waves per compute unit supported by the
375 /// subtarget without any kind of limitation.
376 unsigned getMaxWavesPerCU() const {
377 return getMaxWavesPerEU() * getEUsPerCU();
378 }
379
380 /// \returns Maximum number of waves per compute unit supported by the
381 /// subtarget and limited by given flat work group size.
382 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
383 return getWavesPerWorkGroup(FlatWorkGroupSize);
384 }
385
386 /// \returns Minimum number of waves per execution unit supported by the
387 /// subtarget.
388 unsigned getMinWavesPerEU() const {
389 return 1;
390 }
391
392 /// \returns Maximum number of waves per execution unit supported by the
393 /// subtarget without any kind of limitation.
394 unsigned getMaxWavesPerEU() const {
395 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
396 return 8;
397 // FIXME: Need to take scratch memory into account.
398 return 10;
399 }
400
401 /// \returns Maximum number of waves per execution unit supported by the
402 /// subtarget and limited by given flat work group size.
403 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
404 return alignTo(getMaxWavesPerCU(FlatWorkGroupSize), getEUsPerCU()) /
405 getEUsPerCU();
406 }
407
408 /// \returns Minimum flat work group size supported by the subtarget.
409 unsigned getMinFlatWorkGroupSize() const {
410 return 1;
411 }
412
413 /// \returns Maximum flat work group size supported by the subtarget.
414 unsigned getMaxFlatWorkGroupSize() const {
415 return 2048;
416 }
417
418 /// \returns Number of waves per work group given the flat work group size.
419 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
420 return alignTo(FlatWorkGroupSize, getWavefrontSize()) / getWavefrontSize();
421 }
422
Alexander Timofeev18009562016-12-08 17:28:47 +0000423 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
424 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
425
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000426 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
427 /// for function \p F, or minimum/maximum flat work group sizes explicitly
428 /// requested using "amdgpu-flat-work-group-size" attribute attached to
429 /// function \p F.
430 ///
431 /// \returns Subtarget's default values if explicitly requested values cannot
432 /// be converted to integer, or violate subtarget's specifications.
433 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
434
435 /// \returns Subtarget's default pair of minimum/maximum number of waves per
436 /// execution unit for function \p F, or minimum/maximum number of waves per
437 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
438 /// attached to function \p F.
439 ///
440 /// \returns Subtarget's default values if explicitly requested values cannot
441 /// be converted to integer, violate subtarget's specifications, or are not
442 /// compatible with minimum/maximum number of waves limited by flat work group
443 /// size, register usage, and/or lds usage.
444 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000445};
446
447class R600Subtarget final : public AMDGPUSubtarget {
448private:
449 R600InstrInfo InstrInfo;
450 R600FrameLowering FrameLowering;
451 R600TargetLowering TLInfo;
452
453public:
454 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
455 const TargetMachine &TM);
456
457 const R600InstrInfo *getInstrInfo() const override {
458 return &InstrInfo;
459 }
460
461 const R600FrameLowering *getFrameLowering() const override {
462 return &FrameLowering;
463 }
464
465 const R600TargetLowering *getTargetLowering() const override {
466 return &TLInfo;
467 }
468
469 const R600RegisterInfo *getRegisterInfo() const override {
470 return &InstrInfo.getRegisterInfo();
471 }
472
473 bool hasCFAluBug() const {
474 return CFALUBug;
475 }
476
477 bool hasVertexCache() const {
478 return HasVertexCache;
479 }
480
481 short getTexVTXClauseSize() const {
482 return TexVTXClauseSize;
483 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000484};
485
486class SISubtarget final : public AMDGPUSubtarget {
487public:
488 enum {
Marek Olsak355a8642016-08-05 21:23:29 +0000489 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
490 // doesn't spill SGPRs as much as when 80 is set.
491 FIXED_SGPR_COUNT_FOR_INIT_BUG = 96
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000492 };
493
494private:
495 SIInstrInfo InstrInfo;
496 SIFrameLowering FrameLowering;
497 SITargetLowering TLInfo;
498 std::unique_ptr<GISelAccessor> GISel;
499
500public:
501 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
502 const TargetMachine &TM);
503
504 const SIInstrInfo *getInstrInfo() const override {
505 return &InstrInfo;
506 }
507
508 const SIFrameLowering *getFrameLowering() const override {
509 return &FrameLowering;
510 }
511
512 const SITargetLowering *getTargetLowering() const override {
513 return &TLInfo;
514 }
515
516 const CallLowering *getCallLowering() const override {
517 assert(GISel && "Access to GlobalISel APIs not set");
518 return GISel->getCallLowering();
519 }
520
521 const SIRegisterInfo *getRegisterInfo() const override {
522 return &InstrInfo.getRegisterInfo();
523 }
524
525 void setGISelAccessor(GISelAccessor &GISel) {
526 this->GISel.reset(&GISel);
527 }
528
Tom Stellard83f0bce2015-01-29 16:55:25 +0000529 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000530 unsigned NumRegionInstrs) const override;
531
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000532 bool isVGPRSpillingEnabled(const Function& F) const;
533
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000534 unsigned getMaxNumUserSGPRs() const {
535 return 16;
536 }
537
538 bool hasFlatAddressSpace() const {
539 return FlatAddressSpace;
540 }
541
542 bool hasSMemRealTime() const {
543 return HasSMemRealTime;
544 }
545
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000546 bool hasMovrel() const {
547 return HasMovrel;
548 }
549
550 bool hasVGPRIndexMode() const {
551 return HasVGPRIndexMode;
552 }
553
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000554 bool hasScalarCompareEq64() const {
555 return getGeneration() >= VOLCANIC_ISLANDS;
556 }
557
Matt Arsenault7b647552016-10-28 21:55:15 +0000558 bool hasScalarStores() const {
559 return HasScalarStores;
560 }
561
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000562 bool hasInv2PiInlineImm() const {
563 return HasInv2PiInlineImm;
564 }
565
Sam Kolton07dbde22017-01-20 10:01:25 +0000566 bool hasSDWA() const {
567 return HasSDWA;
568 }
569
570 bool hasDPP() const {
571 return HasDPP;
572 }
573
Tom Stellardde008d32016-01-21 04:28:34 +0000574 bool enableSIScheduler() const {
575 return EnableSIScheduler;
576 }
577
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000578 bool debuggerSupported() const {
579 return debuggerInsertNops() && debuggerReserveRegs() &&
580 debuggerEmitPrologue();
581 }
582
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000583 bool debuggerInsertNops() const {
584 return DebuggerInsertNops;
585 }
586
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000587 bool debuggerReserveRegs() const {
588 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000589 }
590
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000591 bool debuggerEmitPrologue() const {
592 return DebuggerEmitPrologue;
593 }
594
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000595 bool loadStoreOptEnabled() const {
596 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000597 }
598
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000599 bool hasSGPRInitBug() const {
600 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000601 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000602
Tom Stellardb133fbb2016-10-27 23:05:31 +0000603 bool has12DWordStoreHazard() const {
604 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
605 }
606
Tom Stellard2f3f9852017-01-25 01:25:13 +0000607 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000608
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000609 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
610 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
611
612 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
613 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000614
615 /// \returns True if waitcnt instruction is needed before barrier instruction,
616 /// false otherwise.
617 bool needWaitcntBeforeBarrier() const {
618 return true;
619 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000620
621 unsigned getMaxNumSGPRs() const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000622};
623
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000624} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000625
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000626#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H