blob: 433c295feaf88bf5480595b0bc27d4b232692bdb [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 Arsenault2021f082017-02-18 19:12:26 +0000130 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000131 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000132 bool HasSMemRealTime;
133 bool Has16BitInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000134 bool HasMovrel;
135 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000136 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000137 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000138 bool HasSDWA;
139 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000140 bool FlatAddressSpace;
141 bool R600ALUInst;
142 bool CaymanISA;
143 bool CFALUBug;
144 bool HasVertexCache;
145 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000146 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000147
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000148 // Dummy feature to use for assembler in tablegen.
149 bool FeatureDisable;
150
Tom Stellard75aadc22012-12-11 21:25:42 +0000151 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000152 SelectionDAGTargetInfo TSInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +0000153
154public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000155 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
156 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000157 ~AMDGPUSubtarget() override;
158
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000159 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
160 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000161
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000162 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
163 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
164 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
165 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000166
Eric Christopherd9134482014-08-04 21:25:23 +0000167 const InstrItineraryData *getInstrItineraryData() const override {
168 return &InstrItins;
169 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000170
Matt Arsenault56684d42016-08-11 17:31:42 +0000171 // Nothing implemented, just prevent crashes on use.
172 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
173 return &TSInfo;
174 }
175
Craig Topperee7b0f32014-04-30 05:53:27 +0000176 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000177
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000178 bool isAmdHsaOS() const {
179 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000180 }
181
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000182 bool isMesa3DOS() const {
183 return TargetTriple.getOS() == Triple::Mesa3D;
184 }
185
Tom Stellarde88bbc32016-09-23 01:33:26 +0000186 bool isOpenCLEnv() const {
187 return TargetTriple.getEnvironment() == Triple::OpenCL;
188 }
189
Matt Arsenaultd782d052014-06-27 17:57:00 +0000190 Generation getGeneration() const {
191 return Gen;
192 }
193
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000194 unsigned getWavefrontSize() const {
195 return WavefrontSize;
196 }
197
198 int getLocalMemorySize() const {
199 return LocalMemorySize;
200 }
201
202 int getLDSBankCount() const {
203 return LDSBankCount;
204 }
205
206 unsigned getMaxPrivateElementSize() const {
207 return MaxPrivateElementSize;
208 }
209
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000210 bool has16BitInsts() const {
211 return Has16BitInsts;
212 }
213
Matt Arsenaultd782d052014-06-27 17:57:00 +0000214 bool hasHWFP64() const {
215 return FP64;
216 }
217
Matt Arsenaultb035a572015-01-29 19:34:25 +0000218 bool hasFastFMAF32() const {
219 return FastFMAF32;
220 }
221
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000222 bool hasHalfRate64Ops() const {
223 return HalfRate64Ops;
224 }
225
Matt Arsenault88701812016-06-09 23:42:48 +0000226 bool hasAddr64() const {
227 return (getGeneration() < VOLCANIC_ISLANDS);
228 }
229
Matt Arsenaultfae02982014-03-17 18:58:11 +0000230 bool hasBFE() const {
231 return (getGeneration() >= EVERGREEN);
232 }
233
Matt Arsenault6e439652014-06-10 19:00:20 +0000234 bool hasBFI() const {
235 return (getGeneration() >= EVERGREEN);
236 }
237
Matt Arsenaultfae02982014-03-17 18:58:11 +0000238 bool hasBFM() const {
239 return hasBFE();
240 }
241
Matt Arsenault60425062014-06-10 19:18:28 +0000242 bool hasBCNT(unsigned Size) const {
243 if (Size == 32)
244 return (getGeneration() >= EVERGREEN);
245
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000246 if (Size == 64)
247 return (getGeneration() >= SOUTHERN_ISLANDS);
248
249 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000250 }
251
Tom Stellard50122a52014-04-07 19:45:41 +0000252 bool hasMulU24() const {
253 return (getGeneration() >= EVERGREEN);
254 }
255
256 bool hasMulI24() const {
257 return (getGeneration() >= SOUTHERN_ISLANDS ||
258 hasCaymanISA());
259 }
260
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000261 bool hasFFBL() const {
262 return (getGeneration() >= EVERGREEN);
263 }
264
265 bool hasFFBH() const {
266 return (getGeneration() >= EVERGREEN);
267 }
268
Jan Vesely808fff52015-04-30 17:15:56 +0000269 bool hasCARRY() const {
270 return (getGeneration() >= EVERGREEN);
271 }
272
273 bool hasBORROW() const {
274 return (getGeneration() >= EVERGREEN);
275 }
276
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000277 bool hasCaymanISA() const {
278 return CaymanISA;
279 }
280
Wei Ding205bfdb2017-02-10 02:15:29 +0000281 TrapHandlerAbi getTrapHandlerAbi() const {
282 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
283 }
284
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000285 bool isPromoteAllocaEnabled() const {
286 return EnablePromoteAlloca;
287 }
288
Matt Arsenault706f9302015-07-06 16:01:58 +0000289 bool unsafeDSOffsetFoldingEnabled() const {
290 return EnableUnsafeDSOffsetFolding;
291 }
292
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000293 bool dumpCode() const {
294 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000295 }
296
Wei Ding3cb2a1e2016-10-19 22:34:49 +0000297 bool enableIEEEBit(const MachineFunction &MF) const {
298 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
299 }
300
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000301 /// Return the amount of LDS that can be used that will not restrict the
302 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000303 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
304 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000305
306 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
307 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000308 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000309
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000310 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000311 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000312 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000313
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000314 bool hasFP32Denormals() const {
315 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000316 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000317
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000318 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000319 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000320 }
321
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000322 bool hasFPExceptions() const {
323 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000324 }
325
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000326 bool useFlatForGlobal() const {
327 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000328 }
329
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000330 bool hasUnalignedBufferAccess() const {
331 return UnalignedBufferAccess;
332 }
333
Tom Stellard64a9d082016-10-14 18:10:39 +0000334 bool hasUnalignedScratchAccess() const {
335 return UnalignedScratchAccess;
336 }
337
Matt Arsenaulte823d922017-02-18 18:29:53 +0000338 bool hasApertureRegs() const {
339 return HasApertureRegs;
340 }
341
Wei Ding205bfdb2017-02-10 02:15:29 +0000342 bool isTrapHandlerEnabled() const {
343 return TrapHandler;
344 }
345
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000346 bool isXNACKEnabled() const {
347 return EnableXNACK;
348 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000349
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000350 bool hasFlatAddressSpace() const {
351 return FlatAddressSpace;
352 }
353
Tom Stellard2f3f9852017-01-25 01:25:13 +0000354 bool isMesaKernel(const MachineFunction &MF) const {
355 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
356 }
357
358 // Covers VS/PS/CS graphics shaders
359 bool isMesaGfxShader(const MachineFunction &MF) const {
360 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
361 }
362
363 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
364 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000365 }
366
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000367 bool hasFminFmaxLegacy() const {
368 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
369 }
370
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000371 /// \brief Returns the offset in bytes from the start of the input buffer
372 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000373 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
374 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000375 }
376
Tom Stellardb2869eb2016-09-09 19:28:00 +0000377 unsigned getAlignmentForImplicitArgPtr() const {
378 return isAmdHsaOS() ? 8 : 4;
379 }
380
Tom Stellard2f3f9852017-01-25 01:25:13 +0000381 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
382 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000383 return 16;
384 if (isAmdHsaOS() && isOpenCLEnv())
385 return 32;
386 return 0;
387 }
388
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000389 unsigned getStackAlignment() const {
390 // Scratch is allocated in 256 dword per wave blocks.
391 return 4 * 256 / getWavefrontSize();
392 }
Tom Stellard347ac792015-06-26 21:15:07 +0000393
Craig Topper5656db42014-04-29 07:57:24 +0000394 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000395 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000396 }
397
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000398 bool enableSubRegLiveness() const override {
399 return true;
400 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000401
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000402 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
403 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
404
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000405 /// \returns Number of execution units per compute unit supported by the
406 /// subtarget.
407 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000408 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000409 }
410
411 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000412 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000413 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000414 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
415 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000416 }
417
418 /// \returns Maximum number of waves per compute unit supported by the
419 /// subtarget without any kind of limitation.
420 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000421 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000422 }
423
424 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000425 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000426 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000427 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
428 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000429 }
430
431 /// \returns Minimum number of waves per execution unit supported by the
432 /// subtarget.
433 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000434 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000435 }
436
437 /// \returns Maximum number of waves per execution unit supported by the
438 /// subtarget without any kind of limitation.
439 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000440 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000441 }
442
443 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000444 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000445 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000446 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
447 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000448 }
449
450 /// \returns Minimum flat work group size supported by the subtarget.
451 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000452 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000453 }
454
455 /// \returns Maximum flat work group size supported by the subtarget.
456 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000457 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000458 }
459
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000460 /// \returns Number of waves per work group supported by the subtarget and
461 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000462 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000463 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
464 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000465 }
466
467 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
468 /// for function \p F, or minimum/maximum flat work group sizes explicitly
469 /// requested using "amdgpu-flat-work-group-size" attribute attached to
470 /// function \p F.
471 ///
472 /// \returns Subtarget's default values if explicitly requested values cannot
473 /// be converted to integer, or violate subtarget's specifications.
474 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
475
476 /// \returns Subtarget's default pair of minimum/maximum number of waves per
477 /// execution unit for function \p F, or minimum/maximum number of waves per
478 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
479 /// attached to function \p F.
480 ///
481 /// \returns Subtarget's default values if explicitly requested values cannot
482 /// be converted to integer, violate subtarget's specifications, or are not
483 /// compatible with minimum/maximum number of waves limited by flat work group
484 /// size, register usage, and/or lds usage.
485 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000486};
487
488class R600Subtarget final : public AMDGPUSubtarget {
489private:
490 R600InstrInfo InstrInfo;
491 R600FrameLowering FrameLowering;
492 R600TargetLowering TLInfo;
493
494public:
495 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
496 const TargetMachine &TM);
497
498 const R600InstrInfo *getInstrInfo() const override {
499 return &InstrInfo;
500 }
501
502 const R600FrameLowering *getFrameLowering() const override {
503 return &FrameLowering;
504 }
505
506 const R600TargetLowering *getTargetLowering() const override {
507 return &TLInfo;
508 }
509
510 const R600RegisterInfo *getRegisterInfo() const override {
511 return &InstrInfo.getRegisterInfo();
512 }
513
514 bool hasCFAluBug() const {
515 return CFALUBug;
516 }
517
518 bool hasVertexCache() const {
519 return HasVertexCache;
520 }
521
522 short getTexVTXClauseSize() const {
523 return TexVTXClauseSize;
524 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000525};
526
527class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000528private:
529 SIInstrInfo InstrInfo;
530 SIFrameLowering FrameLowering;
531 SITargetLowering TLInfo;
532 std::unique_ptr<GISelAccessor> GISel;
533
534public:
535 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
536 const TargetMachine &TM);
537
538 const SIInstrInfo *getInstrInfo() const override {
539 return &InstrInfo;
540 }
541
542 const SIFrameLowering *getFrameLowering() const override {
543 return &FrameLowering;
544 }
545
546 const SITargetLowering *getTargetLowering() const override {
547 return &TLInfo;
548 }
549
550 const CallLowering *getCallLowering() const override {
551 assert(GISel && "Access to GlobalISel APIs not set");
552 return GISel->getCallLowering();
553 }
554
Tom Stellardca166212017-01-30 21:56:46 +0000555 const InstructionSelector *getInstructionSelector() const override {
556 assert(GISel && "Access to GlobalISel APIs not set");
557 return GISel->getInstructionSelector();
558 }
559
560 const LegalizerInfo *getLegalizerInfo() const override {
561 assert(GISel && "Access to GlobalISel APIs not set");
562 return GISel->getLegalizerInfo();
563 }
564
565 const RegisterBankInfo *getRegBankInfo() const override {
566 assert(GISel && "Access to GlobalISel APIs not set");
567 return GISel->getRegBankInfo();
568 }
569
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000570 const SIRegisterInfo *getRegisterInfo() const override {
571 return &InstrInfo.getRegisterInfo();
572 }
573
574 void setGISelAccessor(GISelAccessor &GISel) {
575 this->GISel.reset(&GISel);
576 }
577
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000578 // XXX - Why is this here if it isn't in the default pass set?
579 bool enableEarlyIfConversion() const override {
580 return true;
581 }
582
Tom Stellard83f0bce2015-01-29 16:55:25 +0000583 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000584 unsigned NumRegionInstrs) const override;
585
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000586 bool isVGPRSpillingEnabled(const Function& F) const;
587
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000588 unsigned getMaxNumUserSGPRs() const {
589 return 16;
590 }
591
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000592 bool hasSMemRealTime() const {
593 return HasSMemRealTime;
594 }
595
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000596 bool hasMovrel() const {
597 return HasMovrel;
598 }
599
600 bool hasVGPRIndexMode() const {
601 return HasVGPRIndexMode;
602 }
603
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000604 bool hasScalarCompareEq64() const {
605 return getGeneration() >= VOLCANIC_ISLANDS;
606 }
607
Matt Arsenault7b647552016-10-28 21:55:15 +0000608 bool hasScalarStores() const {
609 return HasScalarStores;
610 }
611
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000612 bool hasInv2PiInlineImm() const {
613 return HasInv2PiInlineImm;
614 }
615
Sam Kolton07dbde22017-01-20 10:01:25 +0000616 bool hasSDWA() const {
617 return HasSDWA;
618 }
619
620 bool hasDPP() const {
621 return HasDPP;
622 }
623
Tom Stellardde008d32016-01-21 04:28:34 +0000624 bool enableSIScheduler() const {
625 return EnableSIScheduler;
626 }
627
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000628 bool debuggerSupported() const {
629 return debuggerInsertNops() && debuggerReserveRegs() &&
630 debuggerEmitPrologue();
631 }
632
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000633 bool debuggerInsertNops() const {
634 return DebuggerInsertNops;
635 }
636
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000637 bool debuggerReserveRegs() const {
638 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000639 }
640
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000641 bool debuggerEmitPrologue() const {
642 return DebuggerEmitPrologue;
643 }
644
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000645 bool loadStoreOptEnabled() const {
646 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000647 }
648
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000649 bool hasSGPRInitBug() const {
650 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000651 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000652
Tom Stellardb133fbb2016-10-27 23:05:31 +0000653 bool has12DWordStoreHazard() const {
654 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
655 }
656
Matt Arsenaulte823d922017-02-18 18:29:53 +0000657 bool hasSMovFedHazard() const {
658 return getGeneration() >= AMDGPUSubtarget::GFX9;
659 }
660
661 bool hasReadM0Hazard() const {
662 return getGeneration() >= AMDGPUSubtarget::GFX9;
663 }
664
Tom Stellard2f3f9852017-01-25 01:25:13 +0000665 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000666
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000667 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
668 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
669
670 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
671 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000672
673 /// \returns True if waitcnt instruction is needed before barrier instruction,
674 /// false otherwise.
675 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000676 return getGeneration() < GFX9;
677 }
678
679 /// \returns true if the flat_scratch register should be initialized with the
680 /// pointer to the wave's scratch memory rather than a size and offset.
681 bool flatScratchIsPointer() const {
682 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000683 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000684
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000685 /// \returns SGPR allocation granularity supported by the subtarget.
686 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000687 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000688 }
689
690 /// \returns SGPR encoding granularity supported by the subtarget.
691 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000692 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000693 }
694
695 /// \returns Total number of SGPRs supported by the subtarget.
696 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000697 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000698 }
699
700 /// \returns Addressable number of SGPRs supported by the subtarget.
701 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000702 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000703 }
704
705 /// \returns Minimum number of SGPRs that meets the given number of waves per
706 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000707 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
708 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
709 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000710
711 /// \returns Maximum number of SGPRs that meets the given number of waves per
712 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000713 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
714 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
715 Addressable);
716 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000717
718 /// \returns Reserved number of SGPRs for given function \p MF.
719 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
720
721 /// \returns Maximum number of SGPRs that meets number of waves per execution
722 /// unit requirement for function \p MF, or number of SGPRs explicitly
723 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
724 ///
725 /// \returns Value that meets number of waves per execution unit requirement
726 /// if explicitly requested value cannot be converted to integer, violates
727 /// subtarget's specifications, or does not meet number of waves per execution
728 /// unit requirement.
729 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
730
731 /// \returns VGPR allocation granularity supported by the subtarget.
732 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000733 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000734 }
735
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000736 /// \returns VGPR encoding granularity supported by the subtarget.
737 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000738 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000739 }
740
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000741 /// \returns Total number of VGPRs supported by the subtarget.
742 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000743 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000744 }
745
746 /// \returns Addressable number of VGPRs supported by the subtarget.
747 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000748 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000749 }
750
751 /// \returns Minimum number of VGPRs that meets given number of waves per
752 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000753 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
754 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
755 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000756
757 /// \returns Maximum number of VGPRs that meets given number of waves per
758 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000759 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
760 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
761 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000762
763 /// \returns Reserved number of VGPRs for given function \p MF.
764 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
765 return debuggerReserveRegs() ? 4 : 0;
766 }
767
768 /// \returns Maximum number of VGPRs that meets number of waves per execution
769 /// unit requirement for function \p MF, or number of VGPRs explicitly
770 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
771 ///
772 /// \returns Value that meets number of waves per execution unit requirement
773 /// if explicitly requested value cannot be converted to integer, violates
774 /// subtarget's specifications, or does not meet number of waves per execution
775 /// unit requirement.
776 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000777};
778
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000779} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000780
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000781#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H