blob: 36bc2498781fedd4ace2b856403c3fc1ea8da50a [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"
Valery Pykhtinfd4c4102017-03-21 13:15:46 +000025#include "SIMachineFunctionInfo.h"
Tom Stellard347ac792015-06-26 21:15:07 +000026#include "Utils/AMDGPUBaseInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000027#include "llvm/ADT/Triple.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000028#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000029#include "llvm/CodeGen/MachineFunction.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000030#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000031#include "llvm/MC/MCInstrItineraries.h"
32#include "llvm/Support/MathExtras.h"
33#include <cassert>
34#include <cstdint>
35#include <memory>
36#include <utility>
Tom Stellard75aadc22012-12-11 21:25:42 +000037
38#define GET_SUBTARGETINFO_HEADER
39#include "AMDGPUGenSubtargetInfo.inc"
40
Tom Stellard75aadc22012-12-11 21:25:42 +000041namespace llvm {
42
Matt Arsenault43e92fe2016-06-24 06:30:11 +000043class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000044
Tom Stellard75aadc22012-12-11 21:25:42 +000045class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000046public:
47 enum Generation {
48 R600 = 0,
49 R700,
50 EVERGREEN,
51 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000052 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000053 SEA_ISLANDS,
54 VOLCANIC_ISLANDS,
Matt Arsenaulte823d922017-02-18 18:29:53 +000055 GFX9,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000056 };
57
Marek Olsak4d00dd22015-03-09 15:48:09 +000058 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000059 ISAVersion0_0_0,
60 ISAVersion7_0_0,
61 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +000062 ISAVersion7_0_2,
Tom Stellard347ac792015-06-26 21:15:07 +000063 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000064 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +000065 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +000066 ISAVersion8_0_3,
67 ISAVersion8_0_4,
68 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +000069 ISAVersion9_0_0,
70 ISAVersion9_0_1
Tom Stellard347ac792015-06-26 21:15:07 +000071 };
72
Wei Ding205bfdb2017-02-10 02:15:29 +000073 enum TrapHandlerAbi {
74 TrapHandlerAbiNone = 0,
75 TrapHandlerAbiHsa = 1
76 };
77
Wei Dingf2cce022017-02-22 23:22:19 +000078 enum TrapID {
79 TrapIDHardwareReserved = 0,
80 TrapIDHSADebugTrap = 1,
81 TrapIDLLVMTrap = 2,
82 TrapIDLLVMDebugTrap = 3,
83 TrapIDDebugBreakpoint = 7,
84 TrapIDDebugReserved8 = 8,
85 TrapIDDebugReservedFE = 0xfe,
86 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +000087 };
88
89 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +000090 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +000091 };
92
Matt Arsenault43e92fe2016-06-24 06:30:11 +000093protected:
94 // Basic subtarget description.
95 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +000096 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000097 unsigned IsaVersion;
98 unsigned WavefrontSize;
99 int LocalMemorySize;
100 int LDSBankCount;
101 unsigned MaxPrivateElementSize;
102
103 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000104 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000105 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000106
107 // Dynamially set bits that enable features.
108 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000109 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000110 bool FPExceptions;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000111 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000112 bool FlatForGlobal;
Tom Stellard64a9d082016-10-14 18:10:39 +0000113 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000114 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000115 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000116 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000117 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000118 bool DebuggerInsertNops;
119 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000120 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000121
122 // Used as options.
123 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000124 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000125 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000126 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000127 bool EnableSIScheduler;
128 bool DumpCode;
129
130 // Subtarget statically properties set by tablegen
131 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000132 bool IsGCN;
133 bool GCN1Encoding;
134 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000135 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000136 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000137 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000138 bool HasSMemRealTime;
139 bool Has16BitInsts;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000140 bool HasVOP3PInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000141 bool HasMovrel;
142 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000143 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000144 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000145 bool HasSDWA;
146 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000147 bool FlatAddressSpace;
148 bool R600ALUInst;
149 bool CaymanISA;
150 bool CFALUBug;
151 bool HasVertexCache;
152 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000153 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000154
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000155 // Dummy feature to use for assembler in tablegen.
156 bool FeatureDisable;
157
Tom Stellard75aadc22012-12-11 21:25:42 +0000158 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000159 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000160 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000161
162public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000163 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
164 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000165 ~AMDGPUSubtarget() override;
166
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000167 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
168 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000169
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000170 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
171 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
172 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
173 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000174
Eric Christopherd9134482014-08-04 21:25:23 +0000175 const InstrItineraryData *getInstrItineraryData() const override {
176 return &InstrItins;
177 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000178
Matt Arsenault56684d42016-08-11 17:31:42 +0000179 // Nothing implemented, just prevent crashes on use.
180 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
181 return &TSInfo;
182 }
183
Craig Topperee7b0f32014-04-30 05:53:27 +0000184 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000185
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000186 bool isAmdHsaOS() const {
187 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000188 }
189
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000190 bool isMesa3DOS() const {
191 return TargetTriple.getOS() == Triple::Mesa3D;
192 }
193
Tom Stellarde88bbc32016-09-23 01:33:26 +0000194 bool isOpenCLEnv() const {
195 return TargetTriple.getEnvironment() == Triple::OpenCL;
196 }
197
Matt Arsenaultd782d052014-06-27 17:57:00 +0000198 Generation getGeneration() const {
199 return Gen;
200 }
201
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000202 unsigned getWavefrontSize() const {
203 return WavefrontSize;
204 }
205
206 int getLocalMemorySize() const {
207 return LocalMemorySize;
208 }
209
210 int getLDSBankCount() const {
211 return LDSBankCount;
212 }
213
214 unsigned getMaxPrivateElementSize() const {
215 return MaxPrivateElementSize;
216 }
217
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000218 AMDGPUAS getAMDGPUAS() const {
219 return AS;
220 }
221
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000222 bool has16BitInsts() const {
223 return Has16BitInsts;
224 }
225
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000226 bool hasVOP3PInsts() const {
227 return HasVOP3PInsts;
228 }
229
Matt Arsenaultd782d052014-06-27 17:57:00 +0000230 bool hasHWFP64() const {
231 return FP64;
232 }
233
Matt Arsenaultb035a572015-01-29 19:34:25 +0000234 bool hasFastFMAF32() const {
235 return FastFMAF32;
236 }
237
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000238 bool hasHalfRate64Ops() const {
239 return HalfRate64Ops;
240 }
241
Matt Arsenault88701812016-06-09 23:42:48 +0000242 bool hasAddr64() const {
243 return (getGeneration() < VOLCANIC_ISLANDS);
244 }
245
Matt Arsenaultfae02982014-03-17 18:58:11 +0000246 bool hasBFE() const {
247 return (getGeneration() >= EVERGREEN);
248 }
249
Matt Arsenault6e439652014-06-10 19:00:20 +0000250 bool hasBFI() const {
251 return (getGeneration() >= EVERGREEN);
252 }
253
Matt Arsenaultfae02982014-03-17 18:58:11 +0000254 bool hasBFM() const {
255 return hasBFE();
256 }
257
Matt Arsenault60425062014-06-10 19:18:28 +0000258 bool hasBCNT(unsigned Size) const {
259 if (Size == 32)
260 return (getGeneration() >= EVERGREEN);
261
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000262 if (Size == 64)
263 return (getGeneration() >= SOUTHERN_ISLANDS);
264
265 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000266 }
267
Tom Stellard50122a52014-04-07 19:45:41 +0000268 bool hasMulU24() const {
269 return (getGeneration() >= EVERGREEN);
270 }
271
272 bool hasMulI24() const {
273 return (getGeneration() >= SOUTHERN_ISLANDS ||
274 hasCaymanISA());
275 }
276
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000277 bool hasFFBL() const {
278 return (getGeneration() >= EVERGREEN);
279 }
280
281 bool hasFFBH() const {
282 return (getGeneration() >= EVERGREEN);
283 }
284
Matt Arsenault10268f92017-02-27 22:40:39 +0000285 bool hasMed3_16() const {
286 return getGeneration() >= GFX9;
287 }
288
Jan Vesely808fff52015-04-30 17:15:56 +0000289 bool hasCARRY() const {
290 return (getGeneration() >= EVERGREEN);
291 }
292
293 bool hasBORROW() const {
294 return (getGeneration() >= EVERGREEN);
295 }
296
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000297 bool hasCaymanISA() const {
298 return CaymanISA;
299 }
300
Wei Ding205bfdb2017-02-10 02:15:29 +0000301 TrapHandlerAbi getTrapHandlerAbi() const {
302 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
303 }
304
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000305 bool isPromoteAllocaEnabled() const {
306 return EnablePromoteAlloca;
307 }
308
Matt Arsenault706f9302015-07-06 16:01:58 +0000309 bool unsafeDSOffsetFoldingEnabled() const {
310 return EnableUnsafeDSOffsetFolding;
311 }
312
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000313 bool dumpCode() const {
314 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000315 }
316
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000317 /// Return the amount of LDS that can be used that will not restrict the
318 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000319 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
320 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000321
322 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
323 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000324 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000325
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000326 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
327 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
328 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
329 }
330
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000331 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000332 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000333 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000334
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000335 bool hasFP32Denormals() const {
336 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000337 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000338
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000339 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000340 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000341 }
342
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000343 bool hasFPExceptions() const {
344 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000345 }
346
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000347 bool enableDX10Clamp() const {
348 return DX10Clamp;
349 }
350
351 bool enableIEEEBit(const MachineFunction &MF) const {
352 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
353 }
354
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000355 bool useFlatForGlobal() const {
356 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000357 }
358
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000359 bool hasUnalignedBufferAccess() const {
360 return UnalignedBufferAccess;
361 }
362
Tom Stellard64a9d082016-10-14 18:10:39 +0000363 bool hasUnalignedScratchAccess() const {
364 return UnalignedScratchAccess;
365 }
366
Matt Arsenaulte823d922017-02-18 18:29:53 +0000367 bool hasApertureRegs() const {
368 return HasApertureRegs;
369 }
370
Wei Ding205bfdb2017-02-10 02:15:29 +0000371 bool isTrapHandlerEnabled() const {
372 return TrapHandler;
373 }
374
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000375 bool isXNACKEnabled() const {
376 return EnableXNACK;
377 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000378
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000379 bool hasFlatAddressSpace() const {
380 return FlatAddressSpace;
381 }
382
Tom Stellard2f3f9852017-01-25 01:25:13 +0000383 bool isMesaKernel(const MachineFunction &MF) const {
384 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
385 }
386
387 // Covers VS/PS/CS graphics shaders
388 bool isMesaGfxShader(const MachineFunction &MF) const {
389 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
390 }
391
392 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
393 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000394 }
395
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000396 bool hasFminFmaxLegacy() const {
397 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
398 }
399
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000400 /// \brief Returns the offset in bytes from the start of the input buffer
401 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000402 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
403 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000404 }
405
Tom Stellardb2869eb2016-09-09 19:28:00 +0000406 unsigned getAlignmentForImplicitArgPtr() const {
407 return isAmdHsaOS() ? 8 : 4;
408 }
409
Tom Stellard2f3f9852017-01-25 01:25:13 +0000410 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
411 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000412 return 16;
413 if (isAmdHsaOS() && isOpenCLEnv())
414 return 32;
415 return 0;
416 }
417
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000418 unsigned getStackAlignment() const {
419 // Scratch is allocated in 256 dword per wave blocks.
420 return 4 * 256 / getWavefrontSize();
421 }
Tom Stellard347ac792015-06-26 21:15:07 +0000422
Craig Topper5656db42014-04-29 07:57:24 +0000423 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000424 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000425 }
426
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000427 bool enableSubRegLiveness() const override {
428 return true;
429 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000430
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000431 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
432 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
433
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000434 /// \returns Number of execution units per compute unit supported by the
435 /// subtarget.
436 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000437 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000438 }
439
440 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000441 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000442 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000443 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
444 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000445 }
446
447 /// \returns Maximum number of waves per compute unit supported by the
448 /// subtarget without any kind of limitation.
449 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000450 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000451 }
452
453 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000454 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000455 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000456 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
457 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000458 }
459
460 /// \returns Minimum number of waves per execution unit supported by the
461 /// subtarget.
462 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000463 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000464 }
465
466 /// \returns Maximum number of waves per execution unit supported by the
467 /// subtarget without any kind of limitation.
468 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000469 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000470 }
471
472 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000473 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000474 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000475 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
476 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000477 }
478
479 /// \returns Minimum flat work group size supported by the subtarget.
480 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000481 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000482 }
483
484 /// \returns Maximum flat work group size supported by the subtarget.
485 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000486 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000487 }
488
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000489 /// \returns Number of waves per work group supported by the subtarget and
490 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000491 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000492 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
493 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000494 }
495
496 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
497 /// for function \p F, or minimum/maximum flat work group sizes explicitly
498 /// requested using "amdgpu-flat-work-group-size" attribute attached to
499 /// function \p F.
500 ///
501 /// \returns Subtarget's default values if explicitly requested values cannot
502 /// be converted to integer, or violate subtarget's specifications.
503 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
504
505 /// \returns Subtarget's default pair of minimum/maximum number of waves per
506 /// execution unit for function \p F, or minimum/maximum number of waves per
507 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
508 /// attached to function \p F.
509 ///
510 /// \returns Subtarget's default values if explicitly requested values cannot
511 /// be converted to integer, violate subtarget's specifications, or are not
512 /// compatible with minimum/maximum number of waves limited by flat work group
513 /// size, register usage, and/or lds usage.
514 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000515
516 /// Creates value range metadata on an workitemid.* inrinsic call or load.
517 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000518};
519
520class R600Subtarget final : public AMDGPUSubtarget {
521private:
522 R600InstrInfo InstrInfo;
523 R600FrameLowering FrameLowering;
524 R600TargetLowering TLInfo;
525
526public:
527 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
528 const TargetMachine &TM);
529
530 const R600InstrInfo *getInstrInfo() const override {
531 return &InstrInfo;
532 }
533
534 const R600FrameLowering *getFrameLowering() const override {
535 return &FrameLowering;
536 }
537
538 const R600TargetLowering *getTargetLowering() const override {
539 return &TLInfo;
540 }
541
542 const R600RegisterInfo *getRegisterInfo() const override {
543 return &InstrInfo.getRegisterInfo();
544 }
545
546 bool hasCFAluBug() const {
547 return CFALUBug;
548 }
549
550 bool hasVertexCache() const {
551 return HasVertexCache;
552 }
553
554 short getTexVTXClauseSize() const {
555 return TexVTXClauseSize;
556 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000557};
558
559class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000560private:
561 SIInstrInfo InstrInfo;
562 SIFrameLowering FrameLowering;
563 SITargetLowering TLInfo;
564 std::unique_ptr<GISelAccessor> GISel;
565
566public:
567 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
568 const TargetMachine &TM);
569
570 const SIInstrInfo *getInstrInfo() const override {
571 return &InstrInfo;
572 }
573
574 const SIFrameLowering *getFrameLowering() const override {
575 return &FrameLowering;
576 }
577
578 const SITargetLowering *getTargetLowering() const override {
579 return &TLInfo;
580 }
581
582 const CallLowering *getCallLowering() const override {
583 assert(GISel && "Access to GlobalISel APIs not set");
584 return GISel->getCallLowering();
585 }
586
Tom Stellardca166212017-01-30 21:56:46 +0000587 const InstructionSelector *getInstructionSelector() const override {
588 assert(GISel && "Access to GlobalISel APIs not set");
589 return GISel->getInstructionSelector();
590 }
591
592 const LegalizerInfo *getLegalizerInfo() const override {
593 assert(GISel && "Access to GlobalISel APIs not set");
594 return GISel->getLegalizerInfo();
595 }
596
597 const RegisterBankInfo *getRegBankInfo() const override {
598 assert(GISel && "Access to GlobalISel APIs not set");
599 return GISel->getRegBankInfo();
600 }
601
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000602 const SIRegisterInfo *getRegisterInfo() const override {
603 return &InstrInfo.getRegisterInfo();
604 }
605
606 void setGISelAccessor(GISelAccessor &GISel) {
607 this->GISel.reset(&GISel);
608 }
609
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000610 // XXX - Why is this here if it isn't in the default pass set?
611 bool enableEarlyIfConversion() const override {
612 return true;
613 }
614
Tom Stellard83f0bce2015-01-29 16:55:25 +0000615 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000616 unsigned NumRegionInstrs) const override;
617
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000618 bool isVGPRSpillingEnabled(const Function& F) const;
619
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000620 unsigned getMaxNumUserSGPRs() const {
621 return 16;
622 }
623
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000624 bool hasSMemRealTime() const {
625 return HasSMemRealTime;
626 }
627
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000628 bool hasMovrel() const {
629 return HasMovrel;
630 }
631
632 bool hasVGPRIndexMode() const {
633 return HasVGPRIndexMode;
634 }
635
Marek Olsake22fdb92017-03-21 17:00:32 +0000636 bool useVGPRIndexMode(bool UserEnable) const {
637 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
638 }
639
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000640 bool hasScalarCompareEq64() const {
641 return getGeneration() >= VOLCANIC_ISLANDS;
642 }
643
Matt Arsenault7b647552016-10-28 21:55:15 +0000644 bool hasScalarStores() const {
645 return HasScalarStores;
646 }
647
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000648 bool hasInv2PiInlineImm() const {
649 return HasInv2PiInlineImm;
650 }
651
Sam Kolton07dbde22017-01-20 10:01:25 +0000652 bool hasSDWA() const {
653 return HasSDWA;
654 }
655
656 bool hasDPP() const {
657 return HasDPP;
658 }
659
Tom Stellardde008d32016-01-21 04:28:34 +0000660 bool enableSIScheduler() const {
661 return EnableSIScheduler;
662 }
663
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000664 bool debuggerSupported() const {
665 return debuggerInsertNops() && debuggerReserveRegs() &&
666 debuggerEmitPrologue();
667 }
668
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000669 bool debuggerInsertNops() const {
670 return DebuggerInsertNops;
671 }
672
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000673 bool debuggerReserveRegs() const {
674 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000675 }
676
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000677 bool debuggerEmitPrologue() const {
678 return DebuggerEmitPrologue;
679 }
680
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000681 bool loadStoreOptEnabled() const {
682 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000683 }
684
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000685 bool hasSGPRInitBug() const {
686 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000687 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000688
Tom Stellardb133fbb2016-10-27 23:05:31 +0000689 bool has12DWordStoreHazard() const {
690 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
691 }
692
Matt Arsenaulte823d922017-02-18 18:29:53 +0000693 bool hasSMovFedHazard() const {
694 return getGeneration() >= AMDGPUSubtarget::GFX9;
695 }
696
697 bool hasReadM0Hazard() const {
698 return getGeneration() >= AMDGPUSubtarget::GFX9;
699 }
700
Tom Stellard2f3f9852017-01-25 01:25:13 +0000701 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000702
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000703 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
704 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
705
706 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
707 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000708
709 /// \returns True if waitcnt instruction is needed before barrier instruction,
710 /// false otherwise.
711 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000712 return getGeneration() < GFX9;
713 }
714
715 /// \returns true if the flat_scratch register should be initialized with the
716 /// pointer to the wave's scratch memory rather than a size and offset.
717 bool flatScratchIsPointer() const {
718 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000719 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000720
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000721 /// \returns SGPR allocation granularity supported by the subtarget.
722 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000723 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000724 }
725
726 /// \returns SGPR encoding granularity supported by the subtarget.
727 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000728 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000729 }
730
731 /// \returns Total number of SGPRs supported by the subtarget.
732 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000733 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000734 }
735
736 /// \returns Addressable number of SGPRs supported by the subtarget.
737 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000738 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000739 }
740
741 /// \returns Minimum number of SGPRs that meets the given number of waves per
742 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000743 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
744 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
745 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000746
747 /// \returns Maximum number of SGPRs that meets the given number of waves per
748 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000749 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
750 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
751 Addressable);
752 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000753
754 /// \returns Reserved number of SGPRs for given function \p MF.
755 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
756
757 /// \returns Maximum number of SGPRs that meets number of waves per execution
758 /// unit requirement for function \p MF, or number of SGPRs explicitly
759 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
760 ///
761 /// \returns Value that meets number of waves per execution unit requirement
762 /// if explicitly requested value cannot be converted to integer, violates
763 /// subtarget's specifications, or does not meet number of waves per execution
764 /// unit requirement.
765 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
766
767 /// \returns VGPR allocation granularity supported by the subtarget.
768 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000769 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000770 }
771
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000772 /// \returns VGPR encoding granularity supported by the subtarget.
773 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000774 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000775 }
776
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000777 /// \returns Total number of VGPRs supported by the subtarget.
778 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000779 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000780 }
781
782 /// \returns Addressable number of VGPRs supported by the subtarget.
783 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000784 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000785 }
786
787 /// \returns Minimum number of VGPRs that meets given number of waves per
788 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000789 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
790 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
791 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000792
793 /// \returns Maximum number of VGPRs that meets given number of waves per
794 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000795 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
796 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
797 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000798
799 /// \returns Reserved number of VGPRs for given function \p MF.
800 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
801 return debuggerReserveRegs() ? 4 : 0;
802 }
803
804 /// \returns Maximum number of VGPRs that meets number of waves per execution
805 /// unit requirement for function \p MF, or number of VGPRs explicitly
806 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
807 ///
808 /// \returns Value that meets number of waves per execution unit requirement
809 /// if explicitly requested value cannot be converted to integer, violates
810 /// subtarget's specifications, or does not meet number of waves per execution
811 /// unit requirement.
812 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000813};
814
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000815} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000816
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000817#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H