blob: dfdf29e7a12f4beaf764296ff8e317ea7e61797d [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,
Matt Arsenaulte823d922017-02-18 18:29:53 +000054 GFX9,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000055 };
56
Marek Olsak4d00dd22015-03-09 15:48:09 +000057 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000058 ISAVersion0_0_0,
59 ISAVersion7_0_0,
60 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +000061 ISAVersion7_0_2,
Tom Stellard347ac792015-06-26 21:15:07 +000062 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000063 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +000064 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +000065 ISAVersion8_0_3,
66 ISAVersion8_0_4,
67 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +000068 ISAVersion9_0_0,
69 ISAVersion9_0_1
Tom Stellard347ac792015-06-26 21:15:07 +000070 };
71
Wei Ding205bfdb2017-02-10 02:15:29 +000072 enum TrapHandlerAbi {
73 TrapHandlerAbiNone = 0,
74 TrapHandlerAbiHsa = 1
75 };
76
77 enum TrapCode {
78 TrapCodeBreakPoint = 0,
79 TrapCodeLLVMTrap = 1,
80 TrapCodeLLVMDebugTrap = 2,
81 TrapCodeHSADebugTrap = 3
82 };
83
84 enum TrapRegValues {
85 TrapCodeLLVMTrapRegValue = 1
86 };
87
Matt Arsenault43e92fe2016-06-24 06:30:11 +000088protected:
89 // Basic subtarget description.
90 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +000091 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000092 unsigned IsaVersion;
93 unsigned WavefrontSize;
94 int LocalMemorySize;
95 int LDSBankCount;
96 unsigned MaxPrivateElementSize;
97
98 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +000099 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000100 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000101
102 // Dynamially set bits that enable features.
103 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000104 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000105 bool FPExceptions;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000106 bool FlatForGlobal;
Tom Stellard64a9d082016-10-14 18:10:39 +0000107 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000108 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000109 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000110 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000111 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000112 bool DebuggerInsertNops;
113 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000114 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000115
116 // Used as options.
117 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000118 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000119 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000120 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000121 bool EnableSIScheduler;
122 bool DumpCode;
123
124 // Subtarget statically properties set by tablegen
125 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000126 bool IsGCN;
127 bool GCN1Encoding;
128 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000129 bool CIInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000130 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000131 bool HasSMemRealTime;
132 bool Has16BitInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000133 bool HasMovrel;
134 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000135 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000136 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000137 bool HasSDWA;
138 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000139 bool FlatAddressSpace;
140 bool R600ALUInst;
141 bool CaymanISA;
142 bool CFALUBug;
143 bool HasVertexCache;
144 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000145 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000146
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000147 // Dummy feature to use for assembler in tablegen.
148 bool FeatureDisable;
149
Tom Stellard75aadc22012-12-11 21:25:42 +0000150 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000151 SelectionDAGTargetInfo TSInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +0000152
153public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000154 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
155 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000156 ~AMDGPUSubtarget() override;
157
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000158 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
159 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000160
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000161 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
162 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
163 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
164 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000165
Eric Christopherd9134482014-08-04 21:25:23 +0000166 const InstrItineraryData *getInstrItineraryData() const override {
167 return &InstrItins;
168 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000169
Matt Arsenault56684d42016-08-11 17:31:42 +0000170 // Nothing implemented, just prevent crashes on use.
171 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
172 return &TSInfo;
173 }
174
Craig Topperee7b0f32014-04-30 05:53:27 +0000175 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000176
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000177 bool isAmdHsaOS() const {
178 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000179 }
180
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000181 bool isMesa3DOS() const {
182 return TargetTriple.getOS() == Triple::Mesa3D;
183 }
184
Tom Stellarde88bbc32016-09-23 01:33:26 +0000185 bool isOpenCLEnv() const {
186 return TargetTriple.getEnvironment() == Triple::OpenCL;
187 }
188
Matt Arsenaultd782d052014-06-27 17:57:00 +0000189 Generation getGeneration() const {
190 return Gen;
191 }
192
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000193 unsigned getWavefrontSize() const {
194 return WavefrontSize;
195 }
196
197 int getLocalMemorySize() const {
198 return LocalMemorySize;
199 }
200
201 int getLDSBankCount() const {
202 return LDSBankCount;
203 }
204
205 unsigned getMaxPrivateElementSize() const {
206 return MaxPrivateElementSize;
207 }
208
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000209 bool has16BitInsts() const {
210 return Has16BitInsts;
211 }
212
Matt Arsenaultd782d052014-06-27 17:57:00 +0000213 bool hasHWFP64() const {
214 return FP64;
215 }
216
Matt Arsenaultb035a572015-01-29 19:34:25 +0000217 bool hasFastFMAF32() const {
218 return FastFMAF32;
219 }
220
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000221 bool hasHalfRate64Ops() const {
222 return HalfRate64Ops;
223 }
224
Matt Arsenault88701812016-06-09 23:42:48 +0000225 bool hasAddr64() const {
226 return (getGeneration() < VOLCANIC_ISLANDS);
227 }
228
Matt Arsenaultfae02982014-03-17 18:58:11 +0000229 bool hasBFE() const {
230 return (getGeneration() >= EVERGREEN);
231 }
232
Matt Arsenault6e439652014-06-10 19:00:20 +0000233 bool hasBFI() const {
234 return (getGeneration() >= EVERGREEN);
235 }
236
Matt Arsenaultfae02982014-03-17 18:58:11 +0000237 bool hasBFM() const {
238 return hasBFE();
239 }
240
Matt Arsenault60425062014-06-10 19:18:28 +0000241 bool hasBCNT(unsigned Size) const {
242 if (Size == 32)
243 return (getGeneration() >= EVERGREEN);
244
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000245 if (Size == 64)
246 return (getGeneration() >= SOUTHERN_ISLANDS);
247
248 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000249 }
250
Tom Stellard50122a52014-04-07 19:45:41 +0000251 bool hasMulU24() const {
252 return (getGeneration() >= EVERGREEN);
253 }
254
255 bool hasMulI24() const {
256 return (getGeneration() >= SOUTHERN_ISLANDS ||
257 hasCaymanISA());
258 }
259
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000260 bool hasFFBL() const {
261 return (getGeneration() >= EVERGREEN);
262 }
263
264 bool hasFFBH() const {
265 return (getGeneration() >= EVERGREEN);
266 }
267
Jan Vesely808fff52015-04-30 17:15:56 +0000268 bool hasCARRY() const {
269 return (getGeneration() >= EVERGREEN);
270 }
271
272 bool hasBORROW() const {
273 return (getGeneration() >= EVERGREEN);
274 }
275
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000276 bool hasCaymanISA() const {
277 return CaymanISA;
278 }
279
Wei Ding205bfdb2017-02-10 02:15:29 +0000280 TrapHandlerAbi getTrapHandlerAbi() const {
281 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
282 }
283
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000284 bool isPromoteAllocaEnabled() const {
285 return EnablePromoteAlloca;
286 }
287
Matt Arsenault706f9302015-07-06 16:01:58 +0000288 bool unsafeDSOffsetFoldingEnabled() const {
289 return EnableUnsafeDSOffsetFolding;
290 }
291
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000292 bool dumpCode() const {
293 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000294 }
295
Wei Ding3cb2a1e2016-10-19 22:34:49 +0000296 bool enableIEEEBit(const MachineFunction &MF) const {
297 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
298 }
299
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000300 /// Return the amount of LDS that can be used that will not restrict the
301 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000302 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
303 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000304
305 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
306 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000307 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000308
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000309 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000310 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000311 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000312
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000313 bool hasFP32Denormals() const {
314 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000315 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000316
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000317 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000318 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000319 }
320
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000321 bool hasFPExceptions() const {
322 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000323 }
324
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000325 bool useFlatForGlobal() const {
326 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000327 }
328
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000329 bool hasUnalignedBufferAccess() const {
330 return UnalignedBufferAccess;
331 }
332
Tom Stellard64a9d082016-10-14 18:10:39 +0000333 bool hasUnalignedScratchAccess() const {
334 return UnalignedScratchAccess;
335 }
336
Matt Arsenaulte823d922017-02-18 18:29:53 +0000337 bool hasApertureRegs() const {
338 return HasApertureRegs;
339 }
340
Wei Ding205bfdb2017-02-10 02:15:29 +0000341 bool isTrapHandlerEnabled() const {
342 return TrapHandler;
343 }
344
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000345 bool isXNACKEnabled() const {
346 return EnableXNACK;
347 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000348
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000349 bool hasFlatAddressSpace() const {
350 return FlatAddressSpace;
351 }
352
Tom Stellard2f3f9852017-01-25 01:25:13 +0000353 bool isMesaKernel(const MachineFunction &MF) const {
354 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
355 }
356
357 // Covers VS/PS/CS graphics shaders
358 bool isMesaGfxShader(const MachineFunction &MF) const {
359 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
360 }
361
362 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
363 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000364 }
365
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000366 bool hasFminFmaxLegacy() const {
367 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
368 }
369
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000370 /// \brief Returns the offset in bytes from the start of the input buffer
371 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000372 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
373 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000374 }
375
Tom Stellardb2869eb2016-09-09 19:28:00 +0000376 unsigned getAlignmentForImplicitArgPtr() const {
377 return isAmdHsaOS() ? 8 : 4;
378 }
379
Tom Stellard2f3f9852017-01-25 01:25:13 +0000380 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
381 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000382 return 16;
383 if (isAmdHsaOS() && isOpenCLEnv())
384 return 32;
385 return 0;
386 }
387
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000388 unsigned getStackAlignment() const {
389 // Scratch is allocated in 256 dword per wave blocks.
390 return 4 * 256 / getWavefrontSize();
391 }
Tom Stellard347ac792015-06-26 21:15:07 +0000392
Craig Topper5656db42014-04-29 07:57:24 +0000393 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000394 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000395 }
396
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000397 bool enableSubRegLiveness() const override {
398 return true;
399 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000400
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000401 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
402 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
403
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000404 /// \returns Number of execution units per compute unit supported by the
405 /// subtarget.
406 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000407 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000408 }
409
410 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000411 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000412 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000413 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
414 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000415 }
416
417 /// \returns Maximum number of waves per compute unit supported by the
418 /// subtarget without any kind of limitation.
419 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000420 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000421 }
422
423 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000424 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000425 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000426 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
427 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000428 }
429
430 /// \returns Minimum number of waves per execution unit supported by the
431 /// subtarget.
432 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000433 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000434 }
435
436 /// \returns Maximum number of waves per execution unit supported by the
437 /// subtarget without any kind of limitation.
438 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000439 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000440 }
441
442 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000443 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000444 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000445 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
446 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000447 }
448
449 /// \returns Minimum flat work group size supported by the subtarget.
450 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000451 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000452 }
453
454 /// \returns Maximum flat work group size supported by the subtarget.
455 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000456 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000457 }
458
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000459 /// \returns Number of waves per work group supported by the subtarget and
460 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000461 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000462 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
463 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000464 }
465
466 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
467 /// for function \p F, or minimum/maximum flat work group sizes explicitly
468 /// requested using "amdgpu-flat-work-group-size" attribute attached to
469 /// function \p F.
470 ///
471 /// \returns Subtarget's default values if explicitly requested values cannot
472 /// be converted to integer, or violate subtarget's specifications.
473 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
474
475 /// \returns Subtarget's default pair of minimum/maximum number of waves per
476 /// execution unit for function \p F, or minimum/maximum number of waves per
477 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
478 /// attached to function \p F.
479 ///
480 /// \returns Subtarget's default values if explicitly requested values cannot
481 /// be converted to integer, violate subtarget's specifications, or are not
482 /// compatible with minimum/maximum number of waves limited by flat work group
483 /// size, register usage, and/or lds usage.
484 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000485};
486
487class R600Subtarget final : public AMDGPUSubtarget {
488private:
489 R600InstrInfo InstrInfo;
490 R600FrameLowering FrameLowering;
491 R600TargetLowering TLInfo;
492
493public:
494 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
495 const TargetMachine &TM);
496
497 const R600InstrInfo *getInstrInfo() const override {
498 return &InstrInfo;
499 }
500
501 const R600FrameLowering *getFrameLowering() const override {
502 return &FrameLowering;
503 }
504
505 const R600TargetLowering *getTargetLowering() const override {
506 return &TLInfo;
507 }
508
509 const R600RegisterInfo *getRegisterInfo() const override {
510 return &InstrInfo.getRegisterInfo();
511 }
512
513 bool hasCFAluBug() const {
514 return CFALUBug;
515 }
516
517 bool hasVertexCache() const {
518 return HasVertexCache;
519 }
520
521 short getTexVTXClauseSize() const {
522 return TexVTXClauseSize;
523 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000524};
525
526class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000527private:
528 SIInstrInfo InstrInfo;
529 SIFrameLowering FrameLowering;
530 SITargetLowering TLInfo;
531 std::unique_ptr<GISelAccessor> GISel;
532
533public:
534 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
535 const TargetMachine &TM);
536
537 const SIInstrInfo *getInstrInfo() const override {
538 return &InstrInfo;
539 }
540
541 const SIFrameLowering *getFrameLowering() const override {
542 return &FrameLowering;
543 }
544
545 const SITargetLowering *getTargetLowering() const override {
546 return &TLInfo;
547 }
548
549 const CallLowering *getCallLowering() const override {
550 assert(GISel && "Access to GlobalISel APIs not set");
551 return GISel->getCallLowering();
552 }
553
Tom Stellardca166212017-01-30 21:56:46 +0000554 const InstructionSelector *getInstructionSelector() const override {
555 assert(GISel && "Access to GlobalISel APIs not set");
556 return GISel->getInstructionSelector();
557 }
558
559 const LegalizerInfo *getLegalizerInfo() const override {
560 assert(GISel && "Access to GlobalISel APIs not set");
561 return GISel->getLegalizerInfo();
562 }
563
564 const RegisterBankInfo *getRegBankInfo() const override {
565 assert(GISel && "Access to GlobalISel APIs not set");
566 return GISel->getRegBankInfo();
567 }
568
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000569 const SIRegisterInfo *getRegisterInfo() const override {
570 return &InstrInfo.getRegisterInfo();
571 }
572
573 void setGISelAccessor(GISelAccessor &GISel) {
574 this->GISel.reset(&GISel);
575 }
576
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000577 // XXX - Why is this here if it isn't in the default pass set?
578 bool enableEarlyIfConversion() const override {
579 return true;
580 }
581
Tom Stellard83f0bce2015-01-29 16:55:25 +0000582 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000583 unsigned NumRegionInstrs) const override;
584
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000585 bool isVGPRSpillingEnabled(const Function& F) const;
586
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000587 unsigned getMaxNumUserSGPRs() const {
588 return 16;
589 }
590
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000591 bool hasSMemRealTime() const {
592 return HasSMemRealTime;
593 }
594
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000595 bool hasMovrel() const {
596 return HasMovrel;
597 }
598
599 bool hasVGPRIndexMode() const {
600 return HasVGPRIndexMode;
601 }
602
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000603 bool hasScalarCompareEq64() const {
604 return getGeneration() >= VOLCANIC_ISLANDS;
605 }
606
Matt Arsenault7b647552016-10-28 21:55:15 +0000607 bool hasScalarStores() const {
608 return HasScalarStores;
609 }
610
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000611 bool hasInv2PiInlineImm() const {
612 return HasInv2PiInlineImm;
613 }
614
Sam Kolton07dbde22017-01-20 10:01:25 +0000615 bool hasSDWA() const {
616 return HasSDWA;
617 }
618
619 bool hasDPP() const {
620 return HasDPP;
621 }
622
Tom Stellardde008d32016-01-21 04:28:34 +0000623 bool enableSIScheduler() const {
624 return EnableSIScheduler;
625 }
626
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000627 bool debuggerSupported() const {
628 return debuggerInsertNops() && debuggerReserveRegs() &&
629 debuggerEmitPrologue();
630 }
631
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000632 bool debuggerInsertNops() const {
633 return DebuggerInsertNops;
634 }
635
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000636 bool debuggerReserveRegs() const {
637 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000638 }
639
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000640 bool debuggerEmitPrologue() const {
641 return DebuggerEmitPrologue;
642 }
643
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000644 bool loadStoreOptEnabled() const {
645 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000646 }
647
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000648 bool hasSGPRInitBug() const {
649 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000650 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000651
Tom Stellardb133fbb2016-10-27 23:05:31 +0000652 bool has12DWordStoreHazard() const {
653 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
654 }
655
Matt Arsenaulte823d922017-02-18 18:29:53 +0000656 bool hasSMovFedHazard() const {
657 return getGeneration() >= AMDGPUSubtarget::GFX9;
658 }
659
660 bool hasReadM0Hazard() const {
661 return getGeneration() >= AMDGPUSubtarget::GFX9;
662 }
663
Tom Stellard2f3f9852017-01-25 01:25:13 +0000664 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000665
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000666 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
667 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
668
669 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
670 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000671
672 /// \returns True if waitcnt instruction is needed before barrier instruction,
673 /// false otherwise.
674 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000675 return getGeneration() < GFX9;
676 }
677
678 /// \returns true if the flat_scratch register should be initialized with the
679 /// pointer to the wave's scratch memory rather than a size and offset.
680 bool flatScratchIsPointer() const {
681 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000682 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000683
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000684 /// \returns SGPR allocation granularity supported by the subtarget.
685 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000686 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000687 }
688
689 /// \returns SGPR encoding granularity supported by the subtarget.
690 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000691 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000692 }
693
694 /// \returns Total number of SGPRs supported by the subtarget.
695 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000696 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000697 }
698
699 /// \returns Addressable number of SGPRs supported by the subtarget.
700 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000701 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000702 }
703
704 /// \returns Minimum number of SGPRs that meets the given number of waves per
705 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000706 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
707 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
708 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000709
710 /// \returns Maximum number of SGPRs that meets the given number of waves per
711 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000712 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
713 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
714 Addressable);
715 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000716
717 /// \returns Reserved number of SGPRs for given function \p MF.
718 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
719
720 /// \returns Maximum number of SGPRs that meets number of waves per execution
721 /// unit requirement for function \p MF, or number of SGPRs explicitly
722 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
723 ///
724 /// \returns Value that meets number of waves per execution unit requirement
725 /// if explicitly requested value cannot be converted to integer, violates
726 /// subtarget's specifications, or does not meet number of waves per execution
727 /// unit requirement.
728 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
729
730 /// \returns VGPR allocation granularity supported by the subtarget.
731 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000732 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000733 }
734
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000735 /// \returns VGPR encoding granularity supported by the subtarget.
736 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000737 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000738 }
739
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000740 /// \returns Total number of VGPRs supported by the subtarget.
741 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000742 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000743 }
744
745 /// \returns Addressable number of VGPRs supported by the subtarget.
746 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000747 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000748 }
749
750 /// \returns Minimum number of VGPRs that meets given number of waves per
751 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000752 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
753 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
754 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000755
756 /// \returns Maximum number of VGPRs that meets given number of waves per
757 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000758 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
759 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
760 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000761
762 /// \returns Reserved number of VGPRs for given function \p MF.
763 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
764 return debuggerReserveRegs() ? 4 : 0;
765 }
766
767 /// \returns Maximum number of VGPRs that meets number of waves per execution
768 /// unit requirement for function \p MF, or number of VGPRs explicitly
769 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
770 ///
771 /// \returns Value that meets number of waves per execution unit requirement
772 /// if explicitly requested value cannot be converted to integer, violates
773 /// subtarget's specifications, or does not meet number of waves per execution
774 /// unit requirement.
775 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000776};
777
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000778} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000779
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000780#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H