blob: 4bd4d41d7523aadc543d7d0c1322baaaf20bc16f [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;
Tom Stellard75aadc22012-12-11 21:25:42 +0000160
161public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000162 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
163 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000164 ~AMDGPUSubtarget() override;
165
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000166 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
167 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000168
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000169 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
170 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
171 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
172 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000173
Eric Christopherd9134482014-08-04 21:25:23 +0000174 const InstrItineraryData *getInstrItineraryData() const override {
175 return &InstrItins;
176 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000177
Matt Arsenault56684d42016-08-11 17:31:42 +0000178 // Nothing implemented, just prevent crashes on use.
179 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
180 return &TSInfo;
181 }
182
Craig Topperee7b0f32014-04-30 05:53:27 +0000183 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000184
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000185 bool isAmdHsaOS() const {
186 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000187 }
188
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000189 bool isMesa3DOS() const {
190 return TargetTriple.getOS() == Triple::Mesa3D;
191 }
192
Tom Stellarde88bbc32016-09-23 01:33:26 +0000193 bool isOpenCLEnv() const {
194 return TargetTriple.getEnvironment() == Triple::OpenCL;
195 }
196
Matt Arsenaultd782d052014-06-27 17:57:00 +0000197 Generation getGeneration() const {
198 return Gen;
199 }
200
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000201 unsigned getWavefrontSize() const {
202 return WavefrontSize;
203 }
204
205 int getLocalMemorySize() const {
206 return LocalMemorySize;
207 }
208
209 int getLDSBankCount() const {
210 return LDSBankCount;
211 }
212
213 unsigned getMaxPrivateElementSize() const {
214 return MaxPrivateElementSize;
215 }
216
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000217 bool has16BitInsts() const {
218 return Has16BitInsts;
219 }
220
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000221 bool hasVOP3PInsts() const {
222 return HasVOP3PInsts;
223 }
224
Matt Arsenaultd782d052014-06-27 17:57:00 +0000225 bool hasHWFP64() const {
226 return FP64;
227 }
228
Matt Arsenaultb035a572015-01-29 19:34:25 +0000229 bool hasFastFMAF32() const {
230 return FastFMAF32;
231 }
232
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000233 bool hasHalfRate64Ops() const {
234 return HalfRate64Ops;
235 }
236
Matt Arsenault88701812016-06-09 23:42:48 +0000237 bool hasAddr64() const {
238 return (getGeneration() < VOLCANIC_ISLANDS);
239 }
240
Matt Arsenaultfae02982014-03-17 18:58:11 +0000241 bool hasBFE() const {
242 return (getGeneration() >= EVERGREEN);
243 }
244
Matt Arsenault6e439652014-06-10 19:00:20 +0000245 bool hasBFI() const {
246 return (getGeneration() >= EVERGREEN);
247 }
248
Matt Arsenaultfae02982014-03-17 18:58:11 +0000249 bool hasBFM() const {
250 return hasBFE();
251 }
252
Matt Arsenault60425062014-06-10 19:18:28 +0000253 bool hasBCNT(unsigned Size) const {
254 if (Size == 32)
255 return (getGeneration() >= EVERGREEN);
256
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000257 if (Size == 64)
258 return (getGeneration() >= SOUTHERN_ISLANDS);
259
260 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000261 }
262
Tom Stellard50122a52014-04-07 19:45:41 +0000263 bool hasMulU24() const {
264 return (getGeneration() >= EVERGREEN);
265 }
266
267 bool hasMulI24() const {
268 return (getGeneration() >= SOUTHERN_ISLANDS ||
269 hasCaymanISA());
270 }
271
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000272 bool hasFFBL() const {
273 return (getGeneration() >= EVERGREEN);
274 }
275
276 bool hasFFBH() const {
277 return (getGeneration() >= EVERGREEN);
278 }
279
Matt Arsenault10268f92017-02-27 22:40:39 +0000280 bool hasMed3_16() const {
281 return getGeneration() >= GFX9;
282 }
283
Jan Vesely808fff52015-04-30 17:15:56 +0000284 bool hasCARRY() const {
285 return (getGeneration() >= EVERGREEN);
286 }
287
288 bool hasBORROW() const {
289 return (getGeneration() >= EVERGREEN);
290 }
291
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000292 bool hasCaymanISA() const {
293 return CaymanISA;
294 }
295
Wei Ding205bfdb2017-02-10 02:15:29 +0000296 TrapHandlerAbi getTrapHandlerAbi() const {
297 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
298 }
299
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000300 bool isPromoteAllocaEnabled() const {
301 return EnablePromoteAlloca;
302 }
303
Matt Arsenault706f9302015-07-06 16:01:58 +0000304 bool unsafeDSOffsetFoldingEnabled() const {
305 return EnableUnsafeDSOffsetFolding;
306 }
307
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000308 bool dumpCode() const {
309 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000310 }
311
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000312 /// Return the amount of LDS that can be used that will not restrict the
313 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000314 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
315 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000316
317 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
318 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000319 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000320
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000321 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
322 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
323 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
324 }
325
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000326 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000327 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000328 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000329
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000330 bool hasFP32Denormals() const {
331 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000332 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000333
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000334 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000335 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000336 }
337
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000338 bool hasFPExceptions() const {
339 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000340 }
341
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000342 bool enableDX10Clamp() const {
343 return DX10Clamp;
344 }
345
346 bool enableIEEEBit(const MachineFunction &MF) const {
347 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
348 }
349
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000350 bool useFlatForGlobal() const {
351 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000352 }
353
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000354 bool hasUnalignedBufferAccess() const {
355 return UnalignedBufferAccess;
356 }
357
Tom Stellard64a9d082016-10-14 18:10:39 +0000358 bool hasUnalignedScratchAccess() const {
359 return UnalignedScratchAccess;
360 }
361
Matt Arsenaulte823d922017-02-18 18:29:53 +0000362 bool hasApertureRegs() const {
363 return HasApertureRegs;
364 }
365
Wei Ding205bfdb2017-02-10 02:15:29 +0000366 bool isTrapHandlerEnabled() const {
367 return TrapHandler;
368 }
369
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000370 bool isXNACKEnabled() const {
371 return EnableXNACK;
372 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000373
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000374 bool hasFlatAddressSpace() const {
375 return FlatAddressSpace;
376 }
377
Tom Stellard2f3f9852017-01-25 01:25:13 +0000378 bool isMesaKernel(const MachineFunction &MF) const {
379 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
380 }
381
382 // Covers VS/PS/CS graphics shaders
383 bool isMesaGfxShader(const MachineFunction &MF) const {
384 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
385 }
386
387 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
388 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000389 }
390
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000391 bool hasFminFmaxLegacy() const {
392 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
393 }
394
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000395 /// \brief Returns the offset in bytes from the start of the input buffer
396 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000397 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
398 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000399 }
400
Tom Stellardb2869eb2016-09-09 19:28:00 +0000401 unsigned getAlignmentForImplicitArgPtr() const {
402 return isAmdHsaOS() ? 8 : 4;
403 }
404
Tom Stellard2f3f9852017-01-25 01:25:13 +0000405 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
406 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000407 return 16;
408 if (isAmdHsaOS() && isOpenCLEnv())
409 return 32;
410 return 0;
411 }
412
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000413 unsigned getStackAlignment() const {
414 // Scratch is allocated in 256 dword per wave blocks.
415 return 4 * 256 / getWavefrontSize();
416 }
Tom Stellard347ac792015-06-26 21:15:07 +0000417
Craig Topper5656db42014-04-29 07:57:24 +0000418 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000419 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000420 }
421
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000422 bool enableSubRegLiveness() const override {
423 return true;
424 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000425
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000426 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
427 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
428
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000429 /// \returns Number of execution units per compute unit supported by the
430 /// subtarget.
431 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000432 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000433 }
434
435 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000436 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000437 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000438 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
439 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000440 }
441
442 /// \returns Maximum number of waves per compute unit supported by the
443 /// subtarget without any kind of limitation.
444 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000445 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000446 }
447
448 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000449 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000450 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000451 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
452 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000453 }
454
455 /// \returns Minimum number of waves per execution unit supported by the
456 /// subtarget.
457 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000458 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000459 }
460
461 /// \returns Maximum number of waves per execution unit supported by the
462 /// subtarget without any kind of limitation.
463 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000464 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000465 }
466
467 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000468 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000469 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000470 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
471 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000472 }
473
474 /// \returns Minimum flat work group size supported by the subtarget.
475 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000476 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000477 }
478
479 /// \returns Maximum flat work group size supported by the subtarget.
480 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000481 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000482 }
483
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000484 /// \returns Number of waves per work group supported by the subtarget and
485 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000486 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000487 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
488 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000489 }
490
491 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
492 /// for function \p F, or minimum/maximum flat work group sizes explicitly
493 /// requested using "amdgpu-flat-work-group-size" attribute attached to
494 /// function \p F.
495 ///
496 /// \returns Subtarget's default values if explicitly requested values cannot
497 /// be converted to integer, or violate subtarget's specifications.
498 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
499
500 /// \returns Subtarget's default pair of minimum/maximum number of waves per
501 /// execution unit for function \p F, or minimum/maximum number of waves per
502 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
503 /// attached to function \p F.
504 ///
505 /// \returns Subtarget's default values if explicitly requested values cannot
506 /// be converted to integer, violate subtarget's specifications, or are not
507 /// compatible with minimum/maximum number of waves limited by flat work group
508 /// size, register usage, and/or lds usage.
509 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000510};
511
512class R600Subtarget final : public AMDGPUSubtarget {
513private:
514 R600InstrInfo InstrInfo;
515 R600FrameLowering FrameLowering;
516 R600TargetLowering TLInfo;
517
518public:
519 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
520 const TargetMachine &TM);
521
522 const R600InstrInfo *getInstrInfo() const override {
523 return &InstrInfo;
524 }
525
526 const R600FrameLowering *getFrameLowering() const override {
527 return &FrameLowering;
528 }
529
530 const R600TargetLowering *getTargetLowering() const override {
531 return &TLInfo;
532 }
533
534 const R600RegisterInfo *getRegisterInfo() const override {
535 return &InstrInfo.getRegisterInfo();
536 }
537
538 bool hasCFAluBug() const {
539 return CFALUBug;
540 }
541
542 bool hasVertexCache() const {
543 return HasVertexCache;
544 }
545
546 short getTexVTXClauseSize() const {
547 return TexVTXClauseSize;
548 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000549};
550
551class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000552private:
553 SIInstrInfo InstrInfo;
554 SIFrameLowering FrameLowering;
555 SITargetLowering TLInfo;
556 std::unique_ptr<GISelAccessor> GISel;
557
558public:
559 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
560 const TargetMachine &TM);
561
562 const SIInstrInfo *getInstrInfo() const override {
563 return &InstrInfo;
564 }
565
566 const SIFrameLowering *getFrameLowering() const override {
567 return &FrameLowering;
568 }
569
570 const SITargetLowering *getTargetLowering() const override {
571 return &TLInfo;
572 }
573
574 const CallLowering *getCallLowering() const override {
575 assert(GISel && "Access to GlobalISel APIs not set");
576 return GISel->getCallLowering();
577 }
578
Tom Stellardca166212017-01-30 21:56:46 +0000579 const InstructionSelector *getInstructionSelector() const override {
580 assert(GISel && "Access to GlobalISel APIs not set");
581 return GISel->getInstructionSelector();
582 }
583
584 const LegalizerInfo *getLegalizerInfo() const override {
585 assert(GISel && "Access to GlobalISel APIs not set");
586 return GISel->getLegalizerInfo();
587 }
588
589 const RegisterBankInfo *getRegBankInfo() const override {
590 assert(GISel && "Access to GlobalISel APIs not set");
591 return GISel->getRegBankInfo();
592 }
593
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000594 const SIRegisterInfo *getRegisterInfo() const override {
595 return &InstrInfo.getRegisterInfo();
596 }
597
598 void setGISelAccessor(GISelAccessor &GISel) {
599 this->GISel.reset(&GISel);
600 }
601
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000602 // XXX - Why is this here if it isn't in the default pass set?
603 bool enableEarlyIfConversion() const override {
604 return true;
605 }
606
Tom Stellard83f0bce2015-01-29 16:55:25 +0000607 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000608 unsigned NumRegionInstrs) const override;
609
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000610 bool isVGPRSpillingEnabled(const Function& F) const;
611
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000612 unsigned getMaxNumUserSGPRs() const {
613 return 16;
614 }
615
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000616 bool hasSMemRealTime() const {
617 return HasSMemRealTime;
618 }
619
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000620 bool hasMovrel() const {
621 return HasMovrel;
622 }
623
624 bool hasVGPRIndexMode() const {
625 return HasVGPRIndexMode;
626 }
627
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000628 bool hasScalarCompareEq64() const {
629 return getGeneration() >= VOLCANIC_ISLANDS;
630 }
631
Matt Arsenault7b647552016-10-28 21:55:15 +0000632 bool hasScalarStores() const {
633 return HasScalarStores;
634 }
635
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000636 bool hasInv2PiInlineImm() const {
637 return HasInv2PiInlineImm;
638 }
639
Sam Kolton07dbde22017-01-20 10:01:25 +0000640 bool hasSDWA() const {
641 return HasSDWA;
642 }
643
644 bool hasDPP() const {
645 return HasDPP;
646 }
647
Tom Stellardde008d32016-01-21 04:28:34 +0000648 bool enableSIScheduler() const {
649 return EnableSIScheduler;
650 }
651
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000652 bool debuggerSupported() const {
653 return debuggerInsertNops() && debuggerReserveRegs() &&
654 debuggerEmitPrologue();
655 }
656
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000657 bool debuggerInsertNops() const {
658 return DebuggerInsertNops;
659 }
660
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000661 bool debuggerReserveRegs() const {
662 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000663 }
664
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000665 bool debuggerEmitPrologue() const {
666 return DebuggerEmitPrologue;
667 }
668
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000669 bool loadStoreOptEnabled() const {
670 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000671 }
672
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000673 bool hasSGPRInitBug() const {
674 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000675 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000676
Tom Stellardb133fbb2016-10-27 23:05:31 +0000677 bool has12DWordStoreHazard() const {
678 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
679 }
680
Matt Arsenaulte823d922017-02-18 18:29:53 +0000681 bool hasSMovFedHazard() const {
682 return getGeneration() >= AMDGPUSubtarget::GFX9;
683 }
684
685 bool hasReadM0Hazard() const {
686 return getGeneration() >= AMDGPUSubtarget::GFX9;
687 }
688
Tom Stellard2f3f9852017-01-25 01:25:13 +0000689 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000690
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000691 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
692 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
693
694 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
695 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000696
697 /// \returns True if waitcnt instruction is needed before barrier instruction,
698 /// false otherwise.
699 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000700 return getGeneration() < GFX9;
701 }
702
703 /// \returns true if the flat_scratch register should be initialized with the
704 /// pointer to the wave's scratch memory rather than a size and offset.
705 bool flatScratchIsPointer() const {
706 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000707 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000708
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000709 /// \returns SGPR allocation granularity supported by the subtarget.
710 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000711 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000712 }
713
714 /// \returns SGPR encoding granularity supported by the subtarget.
715 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000716 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000717 }
718
719 /// \returns Total number of SGPRs supported by the subtarget.
720 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000721 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000722 }
723
724 /// \returns Addressable number of SGPRs supported by the subtarget.
725 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000726 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000727 }
728
729 /// \returns Minimum 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 getMinNumSGPRs(unsigned WavesPerEU) const {
732 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
733 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000734
735 /// \returns Maximum number of SGPRs that meets the given number of waves per
736 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000737 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
738 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
739 Addressable);
740 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000741
742 /// \returns Reserved number of SGPRs for given function \p MF.
743 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
744
745 /// \returns Maximum number of SGPRs that meets number of waves per execution
746 /// unit requirement for function \p MF, or number of SGPRs explicitly
747 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
748 ///
749 /// \returns Value that meets number of waves per execution unit requirement
750 /// if explicitly requested value cannot be converted to integer, violates
751 /// subtarget's specifications, or does not meet number of waves per execution
752 /// unit requirement.
753 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
754
755 /// \returns VGPR allocation granularity supported by the subtarget.
756 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000757 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000758 }
759
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000760 /// \returns VGPR encoding granularity supported by the subtarget.
761 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000762 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000763 }
764
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000765 /// \returns Total number of VGPRs supported by the subtarget.
766 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000767 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000768 }
769
770 /// \returns Addressable number of VGPRs supported by the subtarget.
771 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000772 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000773 }
774
775 /// \returns Minimum 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 getMinNumVGPRs(unsigned WavesPerEU) const {
778 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
779 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000780
781 /// \returns Maximum number of VGPRs that meets given number of waves per
782 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000783 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
784 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
785 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000786
787 /// \returns Reserved number of VGPRs for given function \p MF.
788 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
789 return debuggerReserveRegs() ? 4 : 0;
790 }
791
792 /// \returns Maximum number of VGPRs that meets number of waves per execution
793 /// unit requirement for function \p MF, or number of VGPRs explicitly
794 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
795 ///
796 /// \returns Value that meets number of waves per execution unit requirement
797 /// if explicitly requested value cannot be converted to integer, violates
798 /// subtarget's specifications, or does not meet number of waves per execution
799 /// unit requirement.
800 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000801};
802
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000803} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000804
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000805#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H