blob: c8414f978083d0ec7d93dfee55cb23c79ad10fbd [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;
Tom Stellard64a9d082016-10-14 18:10:39 +000088 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +000089 bool UnalignedBufferAccess;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000090 bool EnableXNACK;
91 bool DebuggerInsertNops;
92 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +000093 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000094
95 // Used as options.
96 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000097 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +000098 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +000099 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000100 bool EnableSIScheduler;
101 bool DumpCode;
102
103 // Subtarget statically properties set by tablegen
104 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000105 bool IsGCN;
106 bool GCN1Encoding;
107 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000108 bool CIInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000109 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000110 bool HasSMemRealTime;
111 bool Has16BitInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000112 bool HasMovrel;
113 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000114 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000115 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000116 bool HasSDWA;
117 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000118 bool FlatAddressSpace;
119 bool R600ALUInst;
120 bool CaymanISA;
121 bool CFALUBug;
122 bool HasVertexCache;
123 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000124 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000125
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000126 // Dummy feature to use for assembler in tablegen.
127 bool FeatureDisable;
128
Tom Stellard75aadc22012-12-11 21:25:42 +0000129 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000130 SelectionDAGTargetInfo TSInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +0000131
132public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000133 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
134 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000135 ~AMDGPUSubtarget() override;
136
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000137 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
138 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000139
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000140 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
141 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
142 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
143 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000144
Eric Christopherd9134482014-08-04 21:25:23 +0000145 const InstrItineraryData *getInstrItineraryData() const override {
146 return &InstrItins;
147 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000148
Matt Arsenault56684d42016-08-11 17:31:42 +0000149 // Nothing implemented, just prevent crashes on use.
150 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
151 return &TSInfo;
152 }
153
Craig Topperee7b0f32014-04-30 05:53:27 +0000154 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000155
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000156 bool isAmdHsaOS() const {
157 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000158 }
159
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000160 bool isMesa3DOS() const {
161 return TargetTriple.getOS() == Triple::Mesa3D;
162 }
163
Tom Stellarde88bbc32016-09-23 01:33:26 +0000164 bool isOpenCLEnv() const {
165 return TargetTriple.getEnvironment() == Triple::OpenCL;
166 }
167
Matt Arsenaultd782d052014-06-27 17:57:00 +0000168 Generation getGeneration() const {
169 return Gen;
170 }
171
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000172 unsigned getWavefrontSize() const {
173 return WavefrontSize;
174 }
175
176 int getLocalMemorySize() const {
177 return LocalMemorySize;
178 }
179
180 int getLDSBankCount() const {
181 return LDSBankCount;
182 }
183
184 unsigned getMaxPrivateElementSize() const {
185 return MaxPrivateElementSize;
186 }
187
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000188 bool has16BitInsts() const {
189 return Has16BitInsts;
190 }
191
Matt Arsenaultd782d052014-06-27 17:57:00 +0000192 bool hasHWFP64() const {
193 return FP64;
194 }
195
Matt Arsenaultb035a572015-01-29 19:34:25 +0000196 bool hasFastFMAF32() const {
197 return FastFMAF32;
198 }
199
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000200 bool hasHalfRate64Ops() const {
201 return HalfRate64Ops;
202 }
203
Matt Arsenault88701812016-06-09 23:42:48 +0000204 bool hasAddr64() const {
205 return (getGeneration() < VOLCANIC_ISLANDS);
206 }
207
Matt Arsenaultfae02982014-03-17 18:58:11 +0000208 bool hasBFE() const {
209 return (getGeneration() >= EVERGREEN);
210 }
211
Matt Arsenault6e439652014-06-10 19:00:20 +0000212 bool hasBFI() const {
213 return (getGeneration() >= EVERGREEN);
214 }
215
Matt Arsenaultfae02982014-03-17 18:58:11 +0000216 bool hasBFM() const {
217 return hasBFE();
218 }
219
Matt Arsenault60425062014-06-10 19:18:28 +0000220 bool hasBCNT(unsigned Size) const {
221 if (Size == 32)
222 return (getGeneration() >= EVERGREEN);
223
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000224 if (Size == 64)
225 return (getGeneration() >= SOUTHERN_ISLANDS);
226
227 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000228 }
229
Tom Stellard50122a52014-04-07 19:45:41 +0000230 bool hasMulU24() const {
231 return (getGeneration() >= EVERGREEN);
232 }
233
234 bool hasMulI24() const {
235 return (getGeneration() >= SOUTHERN_ISLANDS ||
236 hasCaymanISA());
237 }
238
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000239 bool hasFFBL() const {
240 return (getGeneration() >= EVERGREEN);
241 }
242
243 bool hasFFBH() const {
244 return (getGeneration() >= EVERGREEN);
245 }
246
Jan Vesely808fff52015-04-30 17:15:56 +0000247 bool hasCARRY() const {
248 return (getGeneration() >= EVERGREEN);
249 }
250
251 bool hasBORROW() const {
252 return (getGeneration() >= EVERGREEN);
253 }
254
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000255 bool hasCaymanISA() const {
256 return CaymanISA;
257 }
258
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000259 bool isPromoteAllocaEnabled() const {
260 return EnablePromoteAlloca;
261 }
262
Matt Arsenault706f9302015-07-06 16:01:58 +0000263 bool unsafeDSOffsetFoldingEnabled() const {
264 return EnableUnsafeDSOffsetFolding;
265 }
266
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000267 bool dumpCode() const {
268 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000269 }
270
Wei Ding3cb2a1e2016-10-19 22:34:49 +0000271 bool enableIEEEBit(const MachineFunction &MF) const {
272 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
273 }
274
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000275 /// Return the amount of LDS that can be used that will not restrict the
276 /// occupancy lower than WaveCount.
277 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount) const;
278
279 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
280 /// the given LDS memory size is the only constraint.
281 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes) const;
282
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000283 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000284 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000285 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000286
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000287 bool hasFP32Denormals() const {
288 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000289 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000290
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000291 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000292 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000293 }
294
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000295 bool hasFPExceptions() const {
296 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000297 }
298
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000299 bool useFlatForGlobal() const {
300 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000301 }
302
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000303 bool hasUnalignedBufferAccess() const {
304 return UnalignedBufferAccess;
305 }
306
Tom Stellard64a9d082016-10-14 18:10:39 +0000307 bool hasUnalignedScratchAccess() const {
308 return UnalignedScratchAccess;
309 }
310
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000311 bool isXNACKEnabled() const {
312 return EnableXNACK;
313 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000314
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000315 bool isAmdCodeObjectV2() const {
316 return isAmdHsaOS() || isMesa3DOS();
317 }
318
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000319 /// \brief Returns the offset in bytes from the start of the input buffer
320 /// of the first explicit kernel argument.
321 unsigned getExplicitKernelArgOffset() const {
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000322 return isAmdCodeObjectV2() ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000323 }
324
Tom Stellardb2869eb2016-09-09 19:28:00 +0000325 unsigned getAlignmentForImplicitArgPtr() const {
326 return isAmdHsaOS() ? 8 : 4;
327 }
328
Tom Stellarde88bbc32016-09-23 01:33:26 +0000329 unsigned getImplicitArgNumBytes() const {
330 if (isMesa3DOS())
331 return 16;
332 if (isAmdHsaOS() && isOpenCLEnv())
333 return 32;
334 return 0;
335 }
336
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000337 unsigned getStackAlignment() const {
338 // Scratch is allocated in 256 dword per wave blocks.
339 return 4 * 256 / getWavefrontSize();
340 }
Tom Stellard347ac792015-06-26 21:15:07 +0000341
Craig Topper5656db42014-04-29 07:57:24 +0000342 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000343 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000344 }
345
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000346 bool enableSubRegLiveness() const override {
347 return true;
348 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000349
350 /// \returns Number of execution units per compute unit supported by the
351 /// subtarget.
352 unsigned getEUsPerCU() const {
353 return 4;
354 }
355
356 /// \returns Maximum number of work groups per compute unit supported by the
357 /// subtarget and limited by given flat work group size.
358 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
359 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
360 return 8;
361 return getWavesPerWorkGroup(FlatWorkGroupSize) == 1 ? 40 : 16;
362 }
363
364 /// \returns Maximum number of waves per compute unit supported by the
365 /// subtarget without any kind of limitation.
366 unsigned getMaxWavesPerCU() const {
367 return getMaxWavesPerEU() * getEUsPerCU();
368 }
369
370 /// \returns Maximum number of waves per compute unit supported by the
371 /// subtarget and limited by given flat work group size.
372 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
373 return getWavesPerWorkGroup(FlatWorkGroupSize);
374 }
375
376 /// \returns Minimum number of waves per execution unit supported by the
377 /// subtarget.
378 unsigned getMinWavesPerEU() const {
379 return 1;
380 }
381
382 /// \returns Maximum number of waves per execution unit supported by the
383 /// subtarget without any kind of limitation.
384 unsigned getMaxWavesPerEU() const {
385 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
386 return 8;
387 // FIXME: Need to take scratch memory into account.
388 return 10;
389 }
390
391 /// \returns Maximum number of waves per execution unit supported by the
392 /// subtarget and limited by given flat work group size.
393 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
394 return alignTo(getMaxWavesPerCU(FlatWorkGroupSize), getEUsPerCU()) /
395 getEUsPerCU();
396 }
397
398 /// \returns Minimum flat work group size supported by the subtarget.
399 unsigned getMinFlatWorkGroupSize() const {
400 return 1;
401 }
402
403 /// \returns Maximum flat work group size supported by the subtarget.
404 unsigned getMaxFlatWorkGroupSize() const {
405 return 2048;
406 }
407
408 /// \returns Number of waves per work group given the flat work group size.
409 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
410 return alignTo(FlatWorkGroupSize, getWavefrontSize()) / getWavefrontSize();
411 }
412
Alexander Timofeev18009562016-12-08 17:28:47 +0000413 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
414 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
415
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000416 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
417 /// for function \p F, or minimum/maximum flat work group sizes explicitly
418 /// requested using "amdgpu-flat-work-group-size" attribute attached to
419 /// function \p F.
420 ///
421 /// \returns Subtarget's default values if explicitly requested values cannot
422 /// be converted to integer, or violate subtarget's specifications.
423 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
424
425 /// \returns Subtarget's default pair of minimum/maximum number of waves per
426 /// execution unit for function \p F, or minimum/maximum number of waves per
427 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
428 /// attached to function \p F.
429 ///
430 /// \returns Subtarget's default values if explicitly requested values cannot
431 /// be converted to integer, violate subtarget's specifications, or are not
432 /// compatible with minimum/maximum number of waves limited by flat work group
433 /// size, register usage, and/or lds usage.
434 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000435};
436
437class R600Subtarget final : public AMDGPUSubtarget {
438private:
439 R600InstrInfo InstrInfo;
440 R600FrameLowering FrameLowering;
441 R600TargetLowering TLInfo;
442
443public:
444 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
445 const TargetMachine &TM);
446
447 const R600InstrInfo *getInstrInfo() const override {
448 return &InstrInfo;
449 }
450
451 const R600FrameLowering *getFrameLowering() const override {
452 return &FrameLowering;
453 }
454
455 const R600TargetLowering *getTargetLowering() const override {
456 return &TLInfo;
457 }
458
459 const R600RegisterInfo *getRegisterInfo() const override {
460 return &InstrInfo.getRegisterInfo();
461 }
462
463 bool hasCFAluBug() const {
464 return CFALUBug;
465 }
466
467 bool hasVertexCache() const {
468 return HasVertexCache;
469 }
470
471 short getTexVTXClauseSize() const {
472 return TexVTXClauseSize;
473 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000474};
475
476class SISubtarget final : public AMDGPUSubtarget {
477public:
478 enum {
Marek Olsak355a8642016-08-05 21:23:29 +0000479 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
480 // doesn't spill SGPRs as much as when 80 is set.
481 FIXED_SGPR_COUNT_FOR_INIT_BUG = 96
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000482 };
483
484private:
485 SIInstrInfo InstrInfo;
486 SIFrameLowering FrameLowering;
487 SITargetLowering TLInfo;
488 std::unique_ptr<GISelAccessor> GISel;
489
490public:
491 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
492 const TargetMachine &TM);
493
494 const SIInstrInfo *getInstrInfo() const override {
495 return &InstrInfo;
496 }
497
498 const SIFrameLowering *getFrameLowering() const override {
499 return &FrameLowering;
500 }
501
502 const SITargetLowering *getTargetLowering() const override {
503 return &TLInfo;
504 }
505
506 const CallLowering *getCallLowering() const override {
507 assert(GISel && "Access to GlobalISel APIs not set");
508 return GISel->getCallLowering();
509 }
510
511 const SIRegisterInfo *getRegisterInfo() const override {
512 return &InstrInfo.getRegisterInfo();
513 }
514
515 void setGISelAccessor(GISelAccessor &GISel) {
516 this->GISel.reset(&GISel);
517 }
518
Tom Stellard83f0bce2015-01-29 16:55:25 +0000519 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000520 unsigned NumRegionInstrs) const override;
521
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000522 bool isVGPRSpillingEnabled(const Function& F) const;
523
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000524 unsigned getMaxNumUserSGPRs() const {
525 return 16;
526 }
527
528 bool hasFlatAddressSpace() const {
529 return FlatAddressSpace;
530 }
531
532 bool hasSMemRealTime() const {
533 return HasSMemRealTime;
534 }
535
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000536 bool hasMovrel() const {
537 return HasMovrel;
538 }
539
540 bool hasVGPRIndexMode() const {
541 return HasVGPRIndexMode;
542 }
543
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000544 bool hasScalarCompareEq64() const {
545 return getGeneration() >= VOLCANIC_ISLANDS;
546 }
547
Matt Arsenault7b647552016-10-28 21:55:15 +0000548 bool hasScalarStores() const {
549 return HasScalarStores;
550 }
551
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000552 bool hasInv2PiInlineImm() const {
553 return HasInv2PiInlineImm;
554 }
555
Sam Kolton07dbde22017-01-20 10:01:25 +0000556 bool hasSDWA() const {
557 return HasSDWA;
558 }
559
560 bool hasDPP() const {
561 return HasDPP;
562 }
563
Tom Stellardde008d32016-01-21 04:28:34 +0000564 bool enableSIScheduler() const {
565 return EnableSIScheduler;
566 }
567
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000568 bool debuggerSupported() const {
569 return debuggerInsertNops() && debuggerReserveRegs() &&
570 debuggerEmitPrologue();
571 }
572
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000573 bool debuggerInsertNops() const {
574 return DebuggerInsertNops;
575 }
576
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000577 bool debuggerReserveRegs() const {
578 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000579 }
580
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000581 bool debuggerEmitPrologue() const {
582 return DebuggerEmitPrologue;
583 }
584
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000585 bool loadStoreOptEnabled() const {
586 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000587 }
588
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000589 bool hasSGPRInitBug() const {
590 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000591 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000592
Tom Stellardb133fbb2016-10-27 23:05:31 +0000593 bool has12DWordStoreHazard() const {
594 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
595 }
596
Tom Stellarde88bbc32016-09-23 01:33:26 +0000597 unsigned getKernArgSegmentSize(unsigned ExplictArgBytes) const;
598
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000599 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
600 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
601
602 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
603 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000604
605 /// \returns True if waitcnt instruction is needed before barrier instruction,
606 /// false otherwise.
607 bool needWaitcntBeforeBarrier() const {
608 return true;
609 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000610
611 unsigned getMaxNumSGPRs() const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000612};
613
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000614} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000615
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000616#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H