blob: b99c36ab225be08e6dd63365a9f68a690bd2ca10 [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
Wei Dingf2cce022017-02-22 23:22:19 +000077 enum TrapID {
78 TrapIDHardwareReserved = 0,
79 TrapIDHSADebugTrap = 1,
80 TrapIDLLVMTrap = 2,
81 TrapIDLLVMDebugTrap = 3,
82 TrapIDDebugBreakpoint = 7,
83 TrapIDDebugReserved8 = 8,
84 TrapIDDebugReservedFE = 0xfe,
85 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +000086 };
87
88 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +000089 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +000090 };
91
Matt Arsenault43e92fe2016-06-24 06:30:11 +000092protected:
93 // Basic subtarget description.
94 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +000095 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000096 unsigned IsaVersion;
97 unsigned WavefrontSize;
98 int LocalMemorySize;
99 int LDSBankCount;
100 unsigned MaxPrivateElementSize;
101
102 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000103 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000104 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000105
106 // Dynamially set bits that enable features.
107 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000108 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000109 bool FPExceptions;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000110 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000111 bool FlatForGlobal;
Tom Stellard64a9d082016-10-14 18:10:39 +0000112 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000113 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000114 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000115 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000116 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000117 bool DebuggerInsertNops;
118 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000119 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000120
121 // Used as options.
122 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000123 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000124 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000125 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000126 bool EnableSIScheduler;
127 bool DumpCode;
128
129 // Subtarget statically properties set by tablegen
130 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000131 bool IsGCN;
132 bool GCN1Encoding;
133 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000134 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000135 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000136 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000137 bool HasSMemRealTime;
138 bool Has16BitInsts;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000139 bool HasVOP3PInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000140 bool HasMovrel;
141 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000142 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000143 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000144 bool HasSDWA;
145 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000146 bool FlatAddressSpace;
147 bool R600ALUInst;
148 bool CaymanISA;
149 bool CFALUBug;
150 bool HasVertexCache;
151 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000152 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000153
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000154 // Dummy feature to use for assembler in tablegen.
155 bool FeatureDisable;
156
Tom Stellard75aadc22012-12-11 21:25:42 +0000157 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000158 SelectionDAGTargetInfo TSInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +0000159
160public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000161 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
162 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000163 ~AMDGPUSubtarget() override;
164
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000165 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
166 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000167
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000168 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
169 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
170 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
171 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000172
Eric Christopherd9134482014-08-04 21:25:23 +0000173 const InstrItineraryData *getInstrItineraryData() const override {
174 return &InstrItins;
175 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000176
Matt Arsenault56684d42016-08-11 17:31:42 +0000177 // Nothing implemented, just prevent crashes on use.
178 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
179 return &TSInfo;
180 }
181
Craig Topperee7b0f32014-04-30 05:53:27 +0000182 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000183
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000184 bool isAmdHsaOS() const {
185 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000186 }
187
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000188 bool isMesa3DOS() const {
189 return TargetTriple.getOS() == Triple::Mesa3D;
190 }
191
Tom Stellarde88bbc32016-09-23 01:33:26 +0000192 bool isOpenCLEnv() const {
193 return TargetTriple.getEnvironment() == Triple::OpenCL;
194 }
195
Matt Arsenaultd782d052014-06-27 17:57:00 +0000196 Generation getGeneration() const {
197 return Gen;
198 }
199
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000200 unsigned getWavefrontSize() const {
201 return WavefrontSize;
202 }
203
204 int getLocalMemorySize() const {
205 return LocalMemorySize;
206 }
207
208 int getLDSBankCount() const {
209 return LDSBankCount;
210 }
211
212 unsigned getMaxPrivateElementSize() const {
213 return MaxPrivateElementSize;
214 }
215
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000216 bool has16BitInsts() const {
217 return Has16BitInsts;
218 }
219
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000220 bool hasVOP3PInsts() const {
221 return HasVOP3PInsts;
222 }
223
Matt Arsenaultd782d052014-06-27 17:57:00 +0000224 bool hasHWFP64() const {
225 return FP64;
226 }
227
Matt Arsenaultb035a572015-01-29 19:34:25 +0000228 bool hasFastFMAF32() const {
229 return FastFMAF32;
230 }
231
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000232 bool hasHalfRate64Ops() const {
233 return HalfRate64Ops;
234 }
235
Matt Arsenault88701812016-06-09 23:42:48 +0000236 bool hasAddr64() const {
237 return (getGeneration() < VOLCANIC_ISLANDS);
238 }
239
Matt Arsenaultfae02982014-03-17 18:58:11 +0000240 bool hasBFE() const {
241 return (getGeneration() >= EVERGREEN);
242 }
243
Matt Arsenault6e439652014-06-10 19:00:20 +0000244 bool hasBFI() const {
245 return (getGeneration() >= EVERGREEN);
246 }
247
Matt Arsenaultfae02982014-03-17 18:58:11 +0000248 bool hasBFM() const {
249 return hasBFE();
250 }
251
Matt Arsenault60425062014-06-10 19:18:28 +0000252 bool hasBCNT(unsigned Size) const {
253 if (Size == 32)
254 return (getGeneration() >= EVERGREEN);
255
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000256 if (Size == 64)
257 return (getGeneration() >= SOUTHERN_ISLANDS);
258
259 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000260 }
261
Tom Stellard50122a52014-04-07 19:45:41 +0000262 bool hasMulU24() const {
263 return (getGeneration() >= EVERGREEN);
264 }
265
266 bool hasMulI24() const {
267 return (getGeneration() >= SOUTHERN_ISLANDS ||
268 hasCaymanISA());
269 }
270
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000271 bool hasFFBL() const {
272 return (getGeneration() >= EVERGREEN);
273 }
274
275 bool hasFFBH() const {
276 return (getGeneration() >= EVERGREEN);
277 }
278
Matt Arsenault10268f92017-02-27 22:40:39 +0000279 bool hasMed3_16() const {
280 return getGeneration() >= GFX9;
281 }
282
Jan Vesely808fff52015-04-30 17:15:56 +0000283 bool hasCARRY() const {
284 return (getGeneration() >= EVERGREEN);
285 }
286
287 bool hasBORROW() const {
288 return (getGeneration() >= EVERGREEN);
289 }
290
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000291 bool hasCaymanISA() const {
292 return CaymanISA;
293 }
294
Wei Ding205bfdb2017-02-10 02:15:29 +0000295 TrapHandlerAbi getTrapHandlerAbi() const {
296 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
297 }
298
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000299 bool isPromoteAllocaEnabled() const {
300 return EnablePromoteAlloca;
301 }
302
Matt Arsenault706f9302015-07-06 16:01:58 +0000303 bool unsafeDSOffsetFoldingEnabled() const {
304 return EnableUnsafeDSOffsetFolding;
305 }
306
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000307 bool dumpCode() const {
308 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000309 }
310
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000311 /// Return the amount of LDS that can be used that will not restrict the
312 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000313 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
314 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000315
316 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
317 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000318 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000319
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000320 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000321 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000322 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000323
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000324 bool hasFP32Denormals() const {
325 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000326 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000327
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000328 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000329 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000330 }
331
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000332 bool hasFPExceptions() const {
333 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000334 }
335
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000336 bool enableDX10Clamp() const {
337 return DX10Clamp;
338 }
339
340 bool enableIEEEBit(const MachineFunction &MF) const {
341 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
342 }
343
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000344 bool useFlatForGlobal() const {
345 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000346 }
347
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000348 bool hasUnalignedBufferAccess() const {
349 return UnalignedBufferAccess;
350 }
351
Tom Stellard64a9d082016-10-14 18:10:39 +0000352 bool hasUnalignedScratchAccess() const {
353 return UnalignedScratchAccess;
354 }
355
Matt Arsenaulte823d922017-02-18 18:29:53 +0000356 bool hasApertureRegs() const {
357 return HasApertureRegs;
358 }
359
Wei Ding205bfdb2017-02-10 02:15:29 +0000360 bool isTrapHandlerEnabled() const {
361 return TrapHandler;
362 }
363
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000364 bool isXNACKEnabled() const {
365 return EnableXNACK;
366 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000367
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000368 bool hasFlatAddressSpace() const {
369 return FlatAddressSpace;
370 }
371
Tom Stellard2f3f9852017-01-25 01:25:13 +0000372 bool isMesaKernel(const MachineFunction &MF) const {
373 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
374 }
375
376 // Covers VS/PS/CS graphics shaders
377 bool isMesaGfxShader(const MachineFunction &MF) const {
378 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
379 }
380
381 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
382 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000383 }
384
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000385 bool hasFminFmaxLegacy() const {
386 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
387 }
388
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000389 /// \brief Returns the offset in bytes from the start of the input buffer
390 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000391 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
392 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000393 }
394
Tom Stellardb2869eb2016-09-09 19:28:00 +0000395 unsigned getAlignmentForImplicitArgPtr() const {
396 return isAmdHsaOS() ? 8 : 4;
397 }
398
Tom Stellard2f3f9852017-01-25 01:25:13 +0000399 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
400 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000401 return 16;
402 if (isAmdHsaOS() && isOpenCLEnv())
403 return 32;
404 return 0;
405 }
406
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000407 unsigned getStackAlignment() const {
408 // Scratch is allocated in 256 dword per wave blocks.
409 return 4 * 256 / getWavefrontSize();
410 }
Tom Stellard347ac792015-06-26 21:15:07 +0000411
Craig Topper5656db42014-04-29 07:57:24 +0000412 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000413 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000414 }
415
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000416 bool enableSubRegLiveness() const override {
417 return true;
418 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000419
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000420 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
421 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
422
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000423 /// \returns Number of execution units per compute unit supported by the
424 /// subtarget.
425 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000426 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000427 }
428
429 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000430 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000431 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000432 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
433 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000434 }
435
436 /// \returns Maximum number of waves per compute unit supported by the
437 /// subtarget without any kind of limitation.
438 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000439 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000440 }
441
442 /// \returns Maximum number of waves per compute 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 getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000445 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
446 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000447 }
448
449 /// \returns Minimum number of waves per execution unit supported by the
450 /// subtarget.
451 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000452 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000453 }
454
455 /// \returns Maximum number of waves per execution unit supported by the
456 /// subtarget without any kind of limitation.
457 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000458 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000459 }
460
461 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000462 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000463 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000464 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
465 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000466 }
467
468 /// \returns Minimum flat work group size supported by the subtarget.
469 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000470 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000471 }
472
473 /// \returns Maximum flat work group size supported by the subtarget.
474 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000475 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000476 }
477
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000478 /// \returns Number of waves per work group supported by the subtarget and
479 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000480 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000481 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
482 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000483 }
484
485 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
486 /// for function \p F, or minimum/maximum flat work group sizes explicitly
487 /// requested using "amdgpu-flat-work-group-size" attribute attached to
488 /// function \p F.
489 ///
490 /// \returns Subtarget's default values if explicitly requested values cannot
491 /// be converted to integer, or violate subtarget's specifications.
492 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
493
494 /// \returns Subtarget's default pair of minimum/maximum number of waves per
495 /// execution unit for function \p F, or minimum/maximum number of waves per
496 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
497 /// attached to function \p F.
498 ///
499 /// \returns Subtarget's default values if explicitly requested values cannot
500 /// be converted to integer, violate subtarget's specifications, or are not
501 /// compatible with minimum/maximum number of waves limited by flat work group
502 /// size, register usage, and/or lds usage.
503 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000504};
505
506class R600Subtarget final : public AMDGPUSubtarget {
507private:
508 R600InstrInfo InstrInfo;
509 R600FrameLowering FrameLowering;
510 R600TargetLowering TLInfo;
511
512public:
513 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
514 const TargetMachine &TM);
515
516 const R600InstrInfo *getInstrInfo() const override {
517 return &InstrInfo;
518 }
519
520 const R600FrameLowering *getFrameLowering() const override {
521 return &FrameLowering;
522 }
523
524 const R600TargetLowering *getTargetLowering() const override {
525 return &TLInfo;
526 }
527
528 const R600RegisterInfo *getRegisterInfo() const override {
529 return &InstrInfo.getRegisterInfo();
530 }
531
532 bool hasCFAluBug() const {
533 return CFALUBug;
534 }
535
536 bool hasVertexCache() const {
537 return HasVertexCache;
538 }
539
540 short getTexVTXClauseSize() const {
541 return TexVTXClauseSize;
542 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000543};
544
545class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000546private:
547 SIInstrInfo InstrInfo;
548 SIFrameLowering FrameLowering;
549 SITargetLowering TLInfo;
550 std::unique_ptr<GISelAccessor> GISel;
551
552public:
553 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
554 const TargetMachine &TM);
555
556 const SIInstrInfo *getInstrInfo() const override {
557 return &InstrInfo;
558 }
559
560 const SIFrameLowering *getFrameLowering() const override {
561 return &FrameLowering;
562 }
563
564 const SITargetLowering *getTargetLowering() const override {
565 return &TLInfo;
566 }
567
568 const CallLowering *getCallLowering() const override {
569 assert(GISel && "Access to GlobalISel APIs not set");
570 return GISel->getCallLowering();
571 }
572
Tom Stellardca166212017-01-30 21:56:46 +0000573 const InstructionSelector *getInstructionSelector() const override {
574 assert(GISel && "Access to GlobalISel APIs not set");
575 return GISel->getInstructionSelector();
576 }
577
578 const LegalizerInfo *getLegalizerInfo() const override {
579 assert(GISel && "Access to GlobalISel APIs not set");
580 return GISel->getLegalizerInfo();
581 }
582
583 const RegisterBankInfo *getRegBankInfo() const override {
584 assert(GISel && "Access to GlobalISel APIs not set");
585 return GISel->getRegBankInfo();
586 }
587
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000588 const SIRegisterInfo *getRegisterInfo() const override {
589 return &InstrInfo.getRegisterInfo();
590 }
591
592 void setGISelAccessor(GISelAccessor &GISel) {
593 this->GISel.reset(&GISel);
594 }
595
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000596 // XXX - Why is this here if it isn't in the default pass set?
597 bool enableEarlyIfConversion() const override {
598 return true;
599 }
600
Tom Stellard83f0bce2015-01-29 16:55:25 +0000601 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000602 unsigned NumRegionInstrs) const override;
603
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000604 bool isVGPRSpillingEnabled(const Function& F) const;
605
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000606 unsigned getMaxNumUserSGPRs() const {
607 return 16;
608 }
609
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000610 bool hasSMemRealTime() const {
611 return HasSMemRealTime;
612 }
613
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000614 bool hasMovrel() const {
615 return HasMovrel;
616 }
617
618 bool hasVGPRIndexMode() const {
619 return HasVGPRIndexMode;
620 }
621
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000622 bool hasScalarCompareEq64() const {
623 return getGeneration() >= VOLCANIC_ISLANDS;
624 }
625
Matt Arsenault7b647552016-10-28 21:55:15 +0000626 bool hasScalarStores() const {
627 return HasScalarStores;
628 }
629
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000630 bool hasInv2PiInlineImm() const {
631 return HasInv2PiInlineImm;
632 }
633
Sam Kolton07dbde22017-01-20 10:01:25 +0000634 bool hasSDWA() const {
635 return HasSDWA;
636 }
637
638 bool hasDPP() const {
639 return HasDPP;
640 }
641
Tom Stellardde008d32016-01-21 04:28:34 +0000642 bool enableSIScheduler() const {
643 return EnableSIScheduler;
644 }
645
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000646 bool debuggerSupported() const {
647 return debuggerInsertNops() && debuggerReserveRegs() &&
648 debuggerEmitPrologue();
649 }
650
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000651 bool debuggerInsertNops() const {
652 return DebuggerInsertNops;
653 }
654
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000655 bool debuggerReserveRegs() const {
656 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000657 }
658
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000659 bool debuggerEmitPrologue() const {
660 return DebuggerEmitPrologue;
661 }
662
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000663 bool loadStoreOptEnabled() const {
664 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000665 }
666
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000667 bool hasSGPRInitBug() const {
668 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000669 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000670
Tom Stellardb133fbb2016-10-27 23:05:31 +0000671 bool has12DWordStoreHazard() const {
672 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
673 }
674
Matt Arsenaulte823d922017-02-18 18:29:53 +0000675 bool hasSMovFedHazard() const {
676 return getGeneration() >= AMDGPUSubtarget::GFX9;
677 }
678
679 bool hasReadM0Hazard() const {
680 return getGeneration() >= AMDGPUSubtarget::GFX9;
681 }
682
Tom Stellard2f3f9852017-01-25 01:25:13 +0000683 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000684
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000685 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
686 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
687
688 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
689 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000690
691 /// \returns True if waitcnt instruction is needed before barrier instruction,
692 /// false otherwise.
693 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000694 return getGeneration() < GFX9;
695 }
696
697 /// \returns true if the flat_scratch register should be initialized with the
698 /// pointer to the wave's scratch memory rather than a size and offset.
699 bool flatScratchIsPointer() const {
700 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000701 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000702
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000703 /// \returns SGPR allocation granularity supported by the subtarget.
704 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000705 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000706 }
707
708 /// \returns SGPR encoding granularity supported by the subtarget.
709 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000710 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000711 }
712
713 /// \returns Total number of SGPRs supported by the subtarget.
714 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000715 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000716 }
717
718 /// \returns Addressable number of SGPRs supported by the subtarget.
719 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000720 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000721 }
722
723 /// \returns Minimum number of SGPRs that meets the given number of waves per
724 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000725 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
726 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
727 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000728
729 /// \returns Maximum number of SGPRs that meets the given number of waves per
730 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000731 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
732 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
733 Addressable);
734 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000735
736 /// \returns Reserved number of SGPRs for given function \p MF.
737 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
738
739 /// \returns Maximum number of SGPRs that meets number of waves per execution
740 /// unit requirement for function \p MF, or number of SGPRs explicitly
741 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
742 ///
743 /// \returns Value that meets number of waves per execution unit requirement
744 /// if explicitly requested value cannot be converted to integer, violates
745 /// subtarget's specifications, or does not meet number of waves per execution
746 /// unit requirement.
747 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
748
749 /// \returns VGPR allocation granularity supported by the subtarget.
750 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000751 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000752 }
753
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000754 /// \returns VGPR encoding granularity supported by the subtarget.
755 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000756 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000757 }
758
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000759 /// \returns Total number of VGPRs supported by the subtarget.
760 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000761 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000762 }
763
764 /// \returns Addressable number of VGPRs supported by the subtarget.
765 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000766 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000767 }
768
769 /// \returns Minimum number of VGPRs that meets given number of waves per
770 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000771 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
772 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
773 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000774
775 /// \returns Maximum number of VGPRs that meets given number of waves per
776 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000777 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
778 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
779 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000780
781 /// \returns Reserved number of VGPRs for given function \p MF.
782 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
783 return debuggerReserveRegs() ? 4 : 0;
784 }
785
786 /// \returns Maximum number of VGPRs that meets number of waves per execution
787 /// unit requirement for function \p MF, or number of VGPRs explicitly
788 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
789 ///
790 /// \returns Value that meets number of waves per execution unit requirement
791 /// if explicitly requested value cannot be converted to integer, violates
792 /// subtarget's specifications, or does not meet number of waves per execution
793 /// unit requirement.
794 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000795};
796
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000797} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000798
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000799#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H