blob: 83eda9bfbb67c57a6ecd5068475b109ce2e2b896 [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.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000277 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
278 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000279
280 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
281 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000282 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000283
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
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000316 bool hasFlatAddressSpace() const {
317 return FlatAddressSpace;
318 }
319
Tom Stellard2f3f9852017-01-25 01:25:13 +0000320 bool isMesaKernel(const MachineFunction &MF) const {
321 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
322 }
323
324 // Covers VS/PS/CS graphics shaders
325 bool isMesaGfxShader(const MachineFunction &MF) const {
326 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
327 }
328
329 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
330 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000331 }
332
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000333 bool hasFminFmaxLegacy() const {
334 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
335 }
336
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000337 /// \brief Returns the offset in bytes from the start of the input buffer
338 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000339 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
340 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000341 }
342
Tom Stellardb2869eb2016-09-09 19:28:00 +0000343 unsigned getAlignmentForImplicitArgPtr() const {
344 return isAmdHsaOS() ? 8 : 4;
345 }
346
Tom Stellard2f3f9852017-01-25 01:25:13 +0000347 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
348 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000349 return 16;
350 if (isAmdHsaOS() && isOpenCLEnv())
351 return 32;
352 return 0;
353 }
354
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000355 unsigned getStackAlignment() const {
356 // Scratch is allocated in 256 dword per wave blocks.
357 return 4 * 256 / getWavefrontSize();
358 }
Tom Stellard347ac792015-06-26 21:15:07 +0000359
Craig Topper5656db42014-04-29 07:57:24 +0000360 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000361 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000362 }
363
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000364 bool enableSubRegLiveness() const override {
365 return true;
366 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000367
368 /// \returns Number of execution units per compute unit supported by the
369 /// subtarget.
370 unsigned getEUsPerCU() const {
371 return 4;
372 }
373
374 /// \returns Maximum number of work groups per compute unit supported by the
375 /// subtarget and limited by given flat work group size.
376 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
377 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
378 return 8;
379 return getWavesPerWorkGroup(FlatWorkGroupSize) == 1 ? 40 : 16;
380 }
381
382 /// \returns Maximum number of waves per compute unit supported by the
383 /// subtarget without any kind of limitation.
384 unsigned getMaxWavesPerCU() const {
385 return getMaxWavesPerEU() * getEUsPerCU();
386 }
387
388 /// \returns Maximum number of waves per compute unit supported by the
389 /// subtarget and limited by given flat work group size.
390 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
391 return getWavesPerWorkGroup(FlatWorkGroupSize);
392 }
393
394 /// \returns Minimum number of waves per execution unit supported by the
395 /// subtarget.
396 unsigned getMinWavesPerEU() const {
397 return 1;
398 }
399
400 /// \returns Maximum number of waves per execution unit supported by the
401 /// subtarget without any kind of limitation.
402 unsigned getMaxWavesPerEU() const {
403 if (getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
404 return 8;
405 // FIXME: Need to take scratch memory into account.
406 return 10;
407 }
408
409 /// \returns Maximum number of waves per execution unit supported by the
410 /// subtarget and limited by given flat work group size.
411 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
412 return alignTo(getMaxWavesPerCU(FlatWorkGroupSize), getEUsPerCU()) /
413 getEUsPerCU();
414 }
415
416 /// \returns Minimum flat work group size supported by the subtarget.
417 unsigned getMinFlatWorkGroupSize() const {
418 return 1;
419 }
420
421 /// \returns Maximum flat work group size supported by the subtarget.
422 unsigned getMaxFlatWorkGroupSize() const {
423 return 2048;
424 }
425
426 /// \returns Number of waves per work group given the flat work group size.
427 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
428 return alignTo(FlatWorkGroupSize, getWavefrontSize()) / getWavefrontSize();
429 }
430
Alexander Timofeev18009562016-12-08 17:28:47 +0000431 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
432 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
433
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000434 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
435 /// for function \p F, or minimum/maximum flat work group sizes explicitly
436 /// requested using "amdgpu-flat-work-group-size" attribute attached to
437 /// function \p F.
438 ///
439 /// \returns Subtarget's default values if explicitly requested values cannot
440 /// be converted to integer, or violate subtarget's specifications.
441 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
442
443 /// \returns Subtarget's default pair of minimum/maximum number of waves per
444 /// execution unit for function \p F, or minimum/maximum number of waves per
445 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
446 /// attached to function \p F.
447 ///
448 /// \returns Subtarget's default values if explicitly requested values cannot
449 /// be converted to integer, violate subtarget's specifications, or are not
450 /// compatible with minimum/maximum number of waves limited by flat work group
451 /// size, register usage, and/or lds usage.
452 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000453};
454
455class R600Subtarget final : public AMDGPUSubtarget {
456private:
457 R600InstrInfo InstrInfo;
458 R600FrameLowering FrameLowering;
459 R600TargetLowering TLInfo;
460
461public:
462 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
463 const TargetMachine &TM);
464
465 const R600InstrInfo *getInstrInfo() const override {
466 return &InstrInfo;
467 }
468
469 const R600FrameLowering *getFrameLowering() const override {
470 return &FrameLowering;
471 }
472
473 const R600TargetLowering *getTargetLowering() const override {
474 return &TLInfo;
475 }
476
477 const R600RegisterInfo *getRegisterInfo() const override {
478 return &InstrInfo.getRegisterInfo();
479 }
480
481 bool hasCFAluBug() const {
482 return CFALUBug;
483 }
484
485 bool hasVertexCache() const {
486 return HasVertexCache;
487 }
488
489 short getTexVTXClauseSize() const {
490 return TexVTXClauseSize;
491 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000492};
493
494class SISubtarget final : public AMDGPUSubtarget {
495public:
496 enum {
Marek Olsak355a8642016-08-05 21:23:29 +0000497 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
498 // doesn't spill SGPRs as much as when 80 is set.
499 FIXED_SGPR_COUNT_FOR_INIT_BUG = 96
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000500 };
501
502private:
503 SIInstrInfo InstrInfo;
504 SIFrameLowering FrameLowering;
505 SITargetLowering TLInfo;
506 std::unique_ptr<GISelAccessor> GISel;
507
508public:
509 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
510 const TargetMachine &TM);
511
512 const SIInstrInfo *getInstrInfo() const override {
513 return &InstrInfo;
514 }
515
516 const SIFrameLowering *getFrameLowering() const override {
517 return &FrameLowering;
518 }
519
520 const SITargetLowering *getTargetLowering() const override {
521 return &TLInfo;
522 }
523
524 const CallLowering *getCallLowering() const override {
525 assert(GISel && "Access to GlobalISel APIs not set");
526 return GISel->getCallLowering();
527 }
528
Tom Stellardca166212017-01-30 21:56:46 +0000529 const InstructionSelector *getInstructionSelector() const override {
530 assert(GISel && "Access to GlobalISel APIs not set");
531 return GISel->getInstructionSelector();
532 }
533
534 const LegalizerInfo *getLegalizerInfo() const override {
535 assert(GISel && "Access to GlobalISel APIs not set");
536 return GISel->getLegalizerInfo();
537 }
538
539 const RegisterBankInfo *getRegBankInfo() const override {
540 assert(GISel && "Access to GlobalISel APIs not set");
541 return GISel->getRegBankInfo();
542 }
543
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000544 const SIRegisterInfo *getRegisterInfo() const override {
545 return &InstrInfo.getRegisterInfo();
546 }
547
548 void setGISelAccessor(GISelAccessor &GISel) {
549 this->GISel.reset(&GISel);
550 }
551
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000552 // XXX - Why is this here if it isn't in the default pass set?
553 bool enableEarlyIfConversion() const override {
554 return true;
555 }
556
Tom Stellard83f0bce2015-01-29 16:55:25 +0000557 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000558 unsigned NumRegionInstrs) const override;
559
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000560 bool isVGPRSpillingEnabled(const Function& F) const;
561
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000562 unsigned getMaxNumUserSGPRs() const {
563 return 16;
564 }
565
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000566 bool hasSMemRealTime() const {
567 return HasSMemRealTime;
568 }
569
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000570 bool hasMovrel() const {
571 return HasMovrel;
572 }
573
574 bool hasVGPRIndexMode() const {
575 return HasVGPRIndexMode;
576 }
577
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000578 bool hasScalarCompareEq64() const {
579 return getGeneration() >= VOLCANIC_ISLANDS;
580 }
581
Matt Arsenault7b647552016-10-28 21:55:15 +0000582 bool hasScalarStores() const {
583 return HasScalarStores;
584 }
585
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000586 bool hasInv2PiInlineImm() const {
587 return HasInv2PiInlineImm;
588 }
589
Sam Kolton07dbde22017-01-20 10:01:25 +0000590 bool hasSDWA() const {
591 return HasSDWA;
592 }
593
594 bool hasDPP() const {
595 return HasDPP;
596 }
597
Tom Stellardde008d32016-01-21 04:28:34 +0000598 bool enableSIScheduler() const {
599 return EnableSIScheduler;
600 }
601
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000602 bool debuggerSupported() const {
603 return debuggerInsertNops() && debuggerReserveRegs() &&
604 debuggerEmitPrologue();
605 }
606
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000607 bool debuggerInsertNops() const {
608 return DebuggerInsertNops;
609 }
610
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000611 bool debuggerReserveRegs() const {
612 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000613 }
614
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000615 bool debuggerEmitPrologue() const {
616 return DebuggerEmitPrologue;
617 }
618
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000619 bool loadStoreOptEnabled() const {
620 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000621 }
622
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000623 bool hasSGPRInitBug() const {
624 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000625 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000626
Tom Stellardb133fbb2016-10-27 23:05:31 +0000627 bool has12DWordStoreHazard() const {
628 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
629 }
630
Tom Stellard2f3f9852017-01-25 01:25:13 +0000631 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000632
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000633 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
634 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
635
636 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
637 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000638
639 /// \returns True if waitcnt instruction is needed before barrier instruction,
640 /// false otherwise.
641 bool needWaitcntBeforeBarrier() const {
642 return true;
643 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000644
645 unsigned getMaxNumSGPRs() const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000646};
647
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000648} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000649
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000650#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H