blob: bbe690039442fc87d2176d255a181646f1c52cfc [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 Stellard2f3f9852017-01-25 01:25:13 +0000315 bool isMesaKernel(const MachineFunction &MF) const {
316 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
317 }
318
319 // Covers VS/PS/CS graphics shaders
320 bool isMesaGfxShader(const MachineFunction &MF) const {
321 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
322 }
323
324 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
325 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000326 }
327
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000328 /// \brief Returns the offset in bytes from the start of the input buffer
329 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000330 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
331 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000332 }
333
Tom Stellardb2869eb2016-09-09 19:28:00 +0000334 unsigned getAlignmentForImplicitArgPtr() const {
335 return isAmdHsaOS() ? 8 : 4;
336 }
337
Tom Stellard2f3f9852017-01-25 01:25:13 +0000338 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
339 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000340 return 16;
341 if (isAmdHsaOS() && isOpenCLEnv())
342 return 32;
343 return 0;
344 }
345
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000346 unsigned getStackAlignment() const {
347 // Scratch is allocated in 256 dword per wave blocks.
348 return 4 * 256 / getWavefrontSize();
349 }
Tom Stellard347ac792015-06-26 21:15:07 +0000350
Craig Topper5656db42014-04-29 07:57:24 +0000351 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000352 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000353 }
354
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000355 bool enableSubRegLiveness() const override {
356 return true;
357 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000358
359 /// \returns Number of execution units per compute unit supported by the
360 /// subtarget.
361 unsigned getEUsPerCU() const {
362 return 4;
363 }
364
365 /// \returns Maximum number of work groups per compute unit supported by the
366 /// subtarget and limited by given flat work group size.
367 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
368 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
369 return 8;
370 return getWavesPerWorkGroup(FlatWorkGroupSize) == 1 ? 40 : 16;
371 }
372
373 /// \returns Maximum number of waves per compute unit supported by the
374 /// subtarget without any kind of limitation.
375 unsigned getMaxWavesPerCU() const {
376 return getMaxWavesPerEU() * getEUsPerCU();
377 }
378
379 /// \returns Maximum number of waves per compute unit supported by the
380 /// subtarget and limited by given flat work group size.
381 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
382 return getWavesPerWorkGroup(FlatWorkGroupSize);
383 }
384
385 /// \returns Minimum number of waves per execution unit supported by the
386 /// subtarget.
387 unsigned getMinWavesPerEU() const {
388 return 1;
389 }
390
391 /// \returns Maximum number of waves per execution unit supported by the
392 /// subtarget without any kind of limitation.
393 unsigned getMaxWavesPerEU() const {
394 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
395 return 8;
396 // FIXME: Need to take scratch memory into account.
397 return 10;
398 }
399
400 /// \returns Maximum number of waves per execution unit supported by the
401 /// subtarget and limited by given flat work group size.
402 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
403 return alignTo(getMaxWavesPerCU(FlatWorkGroupSize), getEUsPerCU()) /
404 getEUsPerCU();
405 }
406
407 /// \returns Minimum flat work group size supported by the subtarget.
408 unsigned getMinFlatWorkGroupSize() const {
409 return 1;
410 }
411
412 /// \returns Maximum flat work group size supported by the subtarget.
413 unsigned getMaxFlatWorkGroupSize() const {
414 return 2048;
415 }
416
417 /// \returns Number of waves per work group given the flat work group size.
418 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
419 return alignTo(FlatWorkGroupSize, getWavefrontSize()) / getWavefrontSize();
420 }
421
Alexander Timofeev18009562016-12-08 17:28:47 +0000422 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
423 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
424
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000425 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
426 /// for function \p F, or minimum/maximum flat work group sizes explicitly
427 /// requested using "amdgpu-flat-work-group-size" attribute attached to
428 /// function \p F.
429 ///
430 /// \returns Subtarget's default values if explicitly requested values cannot
431 /// be converted to integer, or violate subtarget's specifications.
432 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
433
434 /// \returns Subtarget's default pair of minimum/maximum number of waves per
435 /// execution unit for function \p F, or minimum/maximum number of waves per
436 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
437 /// attached to function \p F.
438 ///
439 /// \returns Subtarget's default values if explicitly requested values cannot
440 /// be converted to integer, violate subtarget's specifications, or are not
441 /// compatible with minimum/maximum number of waves limited by flat work group
442 /// size, register usage, and/or lds usage.
443 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000444};
445
446class R600Subtarget final : public AMDGPUSubtarget {
447private:
448 R600InstrInfo InstrInfo;
449 R600FrameLowering FrameLowering;
450 R600TargetLowering TLInfo;
451
452public:
453 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
454 const TargetMachine &TM);
455
456 const R600InstrInfo *getInstrInfo() const override {
457 return &InstrInfo;
458 }
459
460 const R600FrameLowering *getFrameLowering() const override {
461 return &FrameLowering;
462 }
463
464 const R600TargetLowering *getTargetLowering() const override {
465 return &TLInfo;
466 }
467
468 const R600RegisterInfo *getRegisterInfo() const override {
469 return &InstrInfo.getRegisterInfo();
470 }
471
472 bool hasCFAluBug() const {
473 return CFALUBug;
474 }
475
476 bool hasVertexCache() const {
477 return HasVertexCache;
478 }
479
480 short getTexVTXClauseSize() const {
481 return TexVTXClauseSize;
482 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000483};
484
485class SISubtarget final : public AMDGPUSubtarget {
486public:
487 enum {
Marek Olsak355a8642016-08-05 21:23:29 +0000488 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
489 // doesn't spill SGPRs as much as when 80 is set.
490 FIXED_SGPR_COUNT_FOR_INIT_BUG = 96
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000491 };
492
493private:
494 SIInstrInfo InstrInfo;
495 SIFrameLowering FrameLowering;
496 SITargetLowering TLInfo;
497 std::unique_ptr<GISelAccessor> GISel;
498
499public:
500 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
501 const TargetMachine &TM);
502
503 const SIInstrInfo *getInstrInfo() const override {
504 return &InstrInfo;
505 }
506
507 const SIFrameLowering *getFrameLowering() const override {
508 return &FrameLowering;
509 }
510
511 const SITargetLowering *getTargetLowering() const override {
512 return &TLInfo;
513 }
514
515 const CallLowering *getCallLowering() const override {
516 assert(GISel && "Access to GlobalISel APIs not set");
517 return GISel->getCallLowering();
518 }
519
520 const SIRegisterInfo *getRegisterInfo() const override {
521 return &InstrInfo.getRegisterInfo();
522 }
523
524 void setGISelAccessor(GISelAccessor &GISel) {
525 this->GISel.reset(&GISel);
526 }
527
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000528 // XXX - Why is this here if it isn't in the default pass set?
529 bool enableEarlyIfConversion() const override {
530 return true;
531 }
532
Tom Stellard83f0bce2015-01-29 16:55:25 +0000533 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000534 unsigned NumRegionInstrs) const override;
535
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000536 bool isVGPRSpillingEnabled(const Function& F) const;
537
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000538 unsigned getMaxNumUserSGPRs() const {
539 return 16;
540 }
541
542 bool hasFlatAddressSpace() const {
543 return FlatAddressSpace;
544 }
545
546 bool hasSMemRealTime() const {
547 return HasSMemRealTime;
548 }
549
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000550 bool hasMovrel() const {
551 return HasMovrel;
552 }
553
554 bool hasVGPRIndexMode() const {
555 return HasVGPRIndexMode;
556 }
557
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000558 bool hasScalarCompareEq64() const {
559 return getGeneration() >= VOLCANIC_ISLANDS;
560 }
561
Matt Arsenault7b647552016-10-28 21:55:15 +0000562 bool hasScalarStores() const {
563 return HasScalarStores;
564 }
565
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000566 bool hasInv2PiInlineImm() const {
567 return HasInv2PiInlineImm;
568 }
569
Sam Kolton07dbde22017-01-20 10:01:25 +0000570 bool hasSDWA() const {
571 return HasSDWA;
572 }
573
574 bool hasDPP() const {
575 return HasDPP;
576 }
577
Tom Stellardde008d32016-01-21 04:28:34 +0000578 bool enableSIScheduler() const {
579 return EnableSIScheduler;
580 }
581
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000582 bool debuggerSupported() const {
583 return debuggerInsertNops() && debuggerReserveRegs() &&
584 debuggerEmitPrologue();
585 }
586
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000587 bool debuggerInsertNops() const {
588 return DebuggerInsertNops;
589 }
590
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000591 bool debuggerReserveRegs() const {
592 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000593 }
594
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000595 bool debuggerEmitPrologue() const {
596 return DebuggerEmitPrologue;
597 }
598
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000599 bool loadStoreOptEnabled() const {
600 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000601 }
602
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000603 bool hasSGPRInitBug() const {
604 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000605 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000606
Tom Stellardb133fbb2016-10-27 23:05:31 +0000607 bool has12DWordStoreHazard() const {
608 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
609 }
610
Tom Stellard2f3f9852017-01-25 01:25:13 +0000611 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000612
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000613 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
614 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
615
616 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
617 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000618
619 /// \returns True if waitcnt instruction is needed before barrier instruction,
620 /// false otherwise.
621 bool needWaitcntBeforeBarrier() const {
622 return true;
623 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000624
625 unsigned getMaxNumSGPRs() const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000626};
627
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000628} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000629
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000630#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H