blob: 24ebde5dc930cf263e115aab412022044e02c1ed [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;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000148 bool FlatInstOffsets;
149 bool FlatGlobalInsts;
150 bool FlatScratchInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000151 bool R600ALUInst;
152 bool CaymanISA;
153 bool CFALUBug;
154 bool HasVertexCache;
155 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000156 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000157
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000158 // Dummy feature to use for assembler in tablegen.
159 bool FeatureDisable;
160
Tom Stellard75aadc22012-12-11 21:25:42 +0000161 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000162 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000163 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000164
165public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000166 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
167 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000168 ~AMDGPUSubtarget() override;
169
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000170 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
171 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000172
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000173 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
174 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
175 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
176 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000177
Eric Christopherd9134482014-08-04 21:25:23 +0000178 const InstrItineraryData *getInstrItineraryData() const override {
179 return &InstrItins;
180 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000181
Matt Arsenault56684d42016-08-11 17:31:42 +0000182 // Nothing implemented, just prevent crashes on use.
183 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
184 return &TSInfo;
185 }
186
Craig Topperee7b0f32014-04-30 05:53:27 +0000187 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000188
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000189 bool isAmdHsaOS() const {
190 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000191 }
192
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000193 bool isMesa3DOS() const {
194 return TargetTriple.getOS() == Triple::Mesa3D;
195 }
196
Tom Stellarde88bbc32016-09-23 01:33:26 +0000197 bool isOpenCLEnv() const {
198 return TargetTriple.getEnvironment() == Triple::OpenCL;
199 }
200
Matt Arsenaultd782d052014-06-27 17:57:00 +0000201 Generation getGeneration() const {
202 return Gen;
203 }
204
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000205 unsigned getWavefrontSize() const {
206 return WavefrontSize;
207 }
208
209 int getLocalMemorySize() const {
210 return LocalMemorySize;
211 }
212
213 int getLDSBankCount() const {
214 return LDSBankCount;
215 }
216
217 unsigned getMaxPrivateElementSize() const {
218 return MaxPrivateElementSize;
219 }
220
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000221 AMDGPUAS getAMDGPUAS() const {
222 return AS;
223 }
224
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000225 bool has16BitInsts() const {
226 return Has16BitInsts;
227 }
228
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000229 bool hasVOP3PInsts() const {
230 return HasVOP3PInsts;
231 }
232
Matt Arsenaultd782d052014-06-27 17:57:00 +0000233 bool hasHWFP64() const {
234 return FP64;
235 }
236
Matt Arsenaultb035a572015-01-29 19:34:25 +0000237 bool hasFastFMAF32() const {
238 return FastFMAF32;
239 }
240
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000241 bool hasHalfRate64Ops() const {
242 return HalfRate64Ops;
243 }
244
Matt Arsenault88701812016-06-09 23:42:48 +0000245 bool hasAddr64() const {
246 return (getGeneration() < VOLCANIC_ISLANDS);
247 }
248
Matt Arsenaultfae02982014-03-17 18:58:11 +0000249 bool hasBFE() const {
250 return (getGeneration() >= EVERGREEN);
251 }
252
Matt Arsenault6e439652014-06-10 19:00:20 +0000253 bool hasBFI() const {
254 return (getGeneration() >= EVERGREEN);
255 }
256
Matt Arsenaultfae02982014-03-17 18:58:11 +0000257 bool hasBFM() const {
258 return hasBFE();
259 }
260
Matt Arsenault60425062014-06-10 19:18:28 +0000261 bool hasBCNT(unsigned Size) const {
262 if (Size == 32)
263 return (getGeneration() >= EVERGREEN);
264
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000265 if (Size == 64)
266 return (getGeneration() >= SOUTHERN_ISLANDS);
267
268 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000269 }
270
Tom Stellard50122a52014-04-07 19:45:41 +0000271 bool hasMulU24() const {
272 return (getGeneration() >= EVERGREEN);
273 }
274
275 bool hasMulI24() const {
276 return (getGeneration() >= SOUTHERN_ISLANDS ||
277 hasCaymanISA());
278 }
279
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000280 bool hasFFBL() const {
281 return (getGeneration() >= EVERGREEN);
282 }
283
284 bool hasFFBH() const {
285 return (getGeneration() >= EVERGREEN);
286 }
287
Matt Arsenault10268f92017-02-27 22:40:39 +0000288 bool hasMed3_16() const {
289 return getGeneration() >= GFX9;
290 }
291
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000292 bool hasMin3Max3_16() const {
293 return getGeneration() >= GFX9;
294 }
295
Jan Vesely808fff52015-04-30 17:15:56 +0000296 bool hasCARRY() const {
297 return (getGeneration() >= EVERGREEN);
298 }
299
300 bool hasBORROW() const {
301 return (getGeneration() >= EVERGREEN);
302 }
303
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000304 bool hasCaymanISA() const {
305 return CaymanISA;
306 }
307
Wei Ding205bfdb2017-02-10 02:15:29 +0000308 TrapHandlerAbi getTrapHandlerAbi() const {
309 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
310 }
311
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000312 bool isPromoteAllocaEnabled() const {
313 return EnablePromoteAlloca;
314 }
315
Matt Arsenault706f9302015-07-06 16:01:58 +0000316 bool unsafeDSOffsetFoldingEnabled() const {
317 return EnableUnsafeDSOffsetFolding;
318 }
319
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000320 bool dumpCode() const {
321 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000322 }
323
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000324 /// Return the amount of LDS that can be used that will not restrict the
325 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000326 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
327 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000328
329 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
330 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000331 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000332
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000333 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
334 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
335 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
336 }
337
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000338 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000339 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000340 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000341
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000342 bool hasFP32Denormals() const {
343 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000344 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000345
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000346 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000347 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000348 }
349
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000350 bool hasFPExceptions() const {
351 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000352 }
353
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000354 bool enableDX10Clamp() const {
355 return DX10Clamp;
356 }
357
358 bool enableIEEEBit(const MachineFunction &MF) const {
359 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
360 }
361
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000362 bool useFlatForGlobal() const {
363 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000364 }
365
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000366 bool hasUnalignedBufferAccess() const {
367 return UnalignedBufferAccess;
368 }
369
Tom Stellard64a9d082016-10-14 18:10:39 +0000370 bool hasUnalignedScratchAccess() const {
371 return UnalignedScratchAccess;
372 }
373
Matt Arsenaulte823d922017-02-18 18:29:53 +0000374 bool hasApertureRegs() const {
375 return HasApertureRegs;
376 }
377
Wei Ding205bfdb2017-02-10 02:15:29 +0000378 bool isTrapHandlerEnabled() const {
379 return TrapHandler;
380 }
381
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000382 bool isXNACKEnabled() const {
383 return EnableXNACK;
384 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000385
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000386 bool hasFlatAddressSpace() const {
387 return FlatAddressSpace;
388 }
389
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000390 bool hasFlatInstOffsets() const {
391 return FlatInstOffsets;
392 }
393
394 bool hasFlatGlobalInsts() const {
395 return FlatGlobalInsts;
396 }
397
398 bool hasFlatScratchInsts() const {
399 return FlatScratchInsts;
400 }
401
Marek Olsak7dadd862017-05-23 17:14:34 +0000402 bool has32BitLiteralSMRDOffset() const {
403 return getGeneration() == SEA_ISLANDS;
404 }
405
Tom Stellard2f3f9852017-01-25 01:25:13 +0000406 bool isMesaKernel(const MachineFunction &MF) const {
407 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
408 }
409
410 // Covers VS/PS/CS graphics shaders
411 bool isMesaGfxShader(const MachineFunction &MF) const {
412 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
413 }
414
415 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
416 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000417 }
418
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000419 bool hasFminFmaxLegacy() const {
420 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
421 }
422
Stanislav Mekhanoshin53a21292017-05-23 19:54:48 +0000423 bool hasSDWA() const {
424 return HasSDWA;
425 }
426
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000427 /// \brief Returns the offset in bytes from the start of the input buffer
428 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000429 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
430 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000431 }
432
Tom Stellardb2869eb2016-09-09 19:28:00 +0000433 unsigned getAlignmentForImplicitArgPtr() const {
434 return isAmdHsaOS() ? 8 : 4;
435 }
436
Tom Stellard2f3f9852017-01-25 01:25:13 +0000437 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
438 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000439 return 16;
440 if (isAmdHsaOS() && isOpenCLEnv())
441 return 32;
442 return 0;
443 }
444
Matt Arsenault869fec22017-04-17 19:48:24 +0000445 // Scratch is allocated in 256 dword per wave blocks for the entire
446 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
447 // is 4-byte aligned.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000448 unsigned getStackAlignment() const {
Matt Arsenault869fec22017-04-17 19:48:24 +0000449 return 4;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000450 }
Tom Stellard347ac792015-06-26 21:15:07 +0000451
Craig Topper5656db42014-04-29 07:57:24 +0000452 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000453 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000454 }
455
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000456 bool enableSubRegLiveness() const override {
457 return true;
458 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000459
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000460 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
461 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
462
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000463 /// \returns Number of execution units per compute unit supported by the
464 /// subtarget.
465 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000466 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000467 }
468
469 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000470 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000471 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000472 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
473 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000474 }
475
476 /// \returns Maximum number of waves per compute unit supported by the
477 /// subtarget without any kind of limitation.
478 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000479 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000480 }
481
482 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000483 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000484 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000485 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
486 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000487 }
488
489 /// \returns Minimum number of waves per execution unit supported by the
490 /// subtarget.
491 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000492 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000493 }
494
495 /// \returns Maximum number of waves per execution unit supported by the
496 /// subtarget without any kind of limitation.
497 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000498 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000499 }
500
501 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000502 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000503 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000504 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
505 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000506 }
507
508 /// \returns Minimum flat work group size supported by the subtarget.
509 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000510 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000511 }
512
513 /// \returns Maximum flat work group size supported by the subtarget.
514 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000515 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000516 }
517
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000518 /// \returns Number of waves per work group supported by the subtarget and
519 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000520 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000521 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
522 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000523 }
524
525 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
526 /// for function \p F, or minimum/maximum flat work group sizes explicitly
527 /// requested using "amdgpu-flat-work-group-size" attribute attached to
528 /// function \p F.
529 ///
530 /// \returns Subtarget's default values if explicitly requested values cannot
531 /// be converted to integer, or violate subtarget's specifications.
532 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
533
534 /// \returns Subtarget's default pair of minimum/maximum number of waves per
535 /// execution unit for function \p F, or minimum/maximum number of waves per
536 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
537 /// attached to function \p F.
538 ///
539 /// \returns Subtarget's default values if explicitly requested values cannot
540 /// be converted to integer, violate subtarget's specifications, or are not
541 /// compatible with minimum/maximum number of waves limited by flat work group
542 /// size, register usage, and/or lds usage.
543 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000544
545 /// Creates value range metadata on an workitemid.* inrinsic call or load.
546 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000547};
548
549class R600Subtarget final : public AMDGPUSubtarget {
550private:
551 R600InstrInfo InstrInfo;
552 R600FrameLowering FrameLowering;
553 R600TargetLowering TLInfo;
554
555public:
556 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
557 const TargetMachine &TM);
558
559 const R600InstrInfo *getInstrInfo() const override {
560 return &InstrInfo;
561 }
562
563 const R600FrameLowering *getFrameLowering() const override {
564 return &FrameLowering;
565 }
566
567 const R600TargetLowering *getTargetLowering() const override {
568 return &TLInfo;
569 }
570
571 const R600RegisterInfo *getRegisterInfo() const override {
572 return &InstrInfo.getRegisterInfo();
573 }
574
575 bool hasCFAluBug() const {
576 return CFALUBug;
577 }
578
579 bool hasVertexCache() const {
580 return HasVertexCache;
581 }
582
583 short getTexVTXClauseSize() const {
584 return TexVTXClauseSize;
585 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000586};
587
588class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000589private:
590 SIInstrInfo InstrInfo;
591 SIFrameLowering FrameLowering;
592 SITargetLowering TLInfo;
593 std::unique_ptr<GISelAccessor> GISel;
594
595public:
596 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
597 const TargetMachine &TM);
598
599 const SIInstrInfo *getInstrInfo() const override {
600 return &InstrInfo;
601 }
602
603 const SIFrameLowering *getFrameLowering() const override {
604 return &FrameLowering;
605 }
606
607 const SITargetLowering *getTargetLowering() const override {
608 return &TLInfo;
609 }
610
611 const CallLowering *getCallLowering() const override {
612 assert(GISel && "Access to GlobalISel APIs not set");
613 return GISel->getCallLowering();
614 }
615
Tom Stellardca166212017-01-30 21:56:46 +0000616 const InstructionSelector *getInstructionSelector() const override {
617 assert(GISel && "Access to GlobalISel APIs not set");
618 return GISel->getInstructionSelector();
619 }
620
621 const LegalizerInfo *getLegalizerInfo() const override {
622 assert(GISel && "Access to GlobalISel APIs not set");
623 return GISel->getLegalizerInfo();
624 }
625
626 const RegisterBankInfo *getRegBankInfo() const override {
627 assert(GISel && "Access to GlobalISel APIs not set");
628 return GISel->getRegBankInfo();
629 }
630
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000631 const SIRegisterInfo *getRegisterInfo() const override {
632 return &InstrInfo.getRegisterInfo();
633 }
634
635 void setGISelAccessor(GISelAccessor &GISel) {
636 this->GISel.reset(&GISel);
637 }
638
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000639 // XXX - Why is this here if it isn't in the default pass set?
640 bool enableEarlyIfConversion() const override {
641 return true;
642 }
643
Tom Stellard83f0bce2015-01-29 16:55:25 +0000644 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000645 unsigned NumRegionInstrs) const override;
646
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000647 bool isVGPRSpillingEnabled(const Function& F) const;
648
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000649 unsigned getMaxNumUserSGPRs() const {
650 return 16;
651 }
652
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000653 bool hasSMemRealTime() const {
654 return HasSMemRealTime;
655 }
656
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000657 bool hasMovrel() const {
658 return HasMovrel;
659 }
660
661 bool hasVGPRIndexMode() const {
662 return HasVGPRIndexMode;
663 }
664
Marek Olsake22fdb92017-03-21 17:00:32 +0000665 bool useVGPRIndexMode(bool UserEnable) const {
666 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
667 }
668
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000669 bool hasScalarCompareEq64() const {
670 return getGeneration() >= VOLCANIC_ISLANDS;
671 }
672
Matt Arsenault7b647552016-10-28 21:55:15 +0000673 bool hasScalarStores() const {
674 return HasScalarStores;
675 }
676
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000677 bool hasInv2PiInlineImm() const {
678 return HasInv2PiInlineImm;
679 }
680
Sam Kolton07dbde22017-01-20 10:01:25 +0000681 bool hasDPP() const {
682 return HasDPP;
683 }
684
Tom Stellardde008d32016-01-21 04:28:34 +0000685 bool enableSIScheduler() const {
686 return EnableSIScheduler;
687 }
688
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000689 bool debuggerSupported() const {
690 return debuggerInsertNops() && debuggerReserveRegs() &&
691 debuggerEmitPrologue();
692 }
693
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000694 bool debuggerInsertNops() const {
695 return DebuggerInsertNops;
696 }
697
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000698 bool debuggerReserveRegs() const {
699 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000700 }
701
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000702 bool debuggerEmitPrologue() const {
703 return DebuggerEmitPrologue;
704 }
705
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000706 bool loadStoreOptEnabled() const {
707 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000708 }
709
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000710 bool hasSGPRInitBug() const {
711 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000712 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000713
Tom Stellardb133fbb2016-10-27 23:05:31 +0000714 bool has12DWordStoreHazard() const {
715 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
716 }
717
Matt Arsenaulte823d922017-02-18 18:29:53 +0000718 bool hasSMovFedHazard() const {
719 return getGeneration() >= AMDGPUSubtarget::GFX9;
720 }
721
722 bool hasReadM0Hazard() const {
723 return getGeneration() >= AMDGPUSubtarget::GFX9;
724 }
725
Tom Stellard2f3f9852017-01-25 01:25:13 +0000726 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000727
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000728 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
729 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
730
731 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
732 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000733
734 /// \returns True if waitcnt instruction is needed before barrier instruction,
735 /// false otherwise.
736 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000737 return getGeneration() < GFX9;
738 }
739
740 /// \returns true if the flat_scratch register should be initialized with the
741 /// pointer to the wave's scratch memory rather than a size and offset.
742 bool flatScratchIsPointer() const {
743 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000744 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000745
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000746 /// \returns SGPR allocation granularity supported by the subtarget.
747 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000748 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000749 }
750
751 /// \returns SGPR encoding granularity supported by the subtarget.
752 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000753 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000754 }
755
756 /// \returns Total number of SGPRs supported by the subtarget.
757 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000758 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000759 }
760
761 /// \returns Addressable number of SGPRs supported by the subtarget.
762 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000763 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000764 }
765
766 /// \returns Minimum number of SGPRs that meets the given number of waves per
767 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000768 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
769 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
770 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000771
772 /// \returns Maximum number of SGPRs that meets the given number of waves per
773 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000774 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
775 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
776 Addressable);
777 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000778
779 /// \returns Reserved number of SGPRs for given function \p MF.
780 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
781
782 /// \returns Maximum number of SGPRs that meets number of waves per execution
783 /// unit requirement for function \p MF, or number of SGPRs explicitly
784 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
785 ///
786 /// \returns Value that meets number of waves per execution unit requirement
787 /// if explicitly requested value cannot be converted to integer, violates
788 /// subtarget's specifications, or does not meet number of waves per execution
789 /// unit requirement.
790 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
791
792 /// \returns VGPR allocation granularity supported by the subtarget.
793 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000794 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000795 }
796
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000797 /// \returns VGPR encoding granularity supported by the subtarget.
798 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000799 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000800 }
801
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000802 /// \returns Total number of VGPRs supported by the subtarget.
803 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000804 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000805 }
806
807 /// \returns Addressable number of VGPRs supported by the subtarget.
808 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000809 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000810 }
811
812 /// \returns Minimum number of VGPRs that meets given number of waves per
813 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000814 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
815 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
816 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000817
818 /// \returns Maximum number of VGPRs that meets given number of waves per
819 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000820 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
821 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
822 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000823
824 /// \returns Reserved number of VGPRs for given function \p MF.
825 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
826 return debuggerReserveRegs() ? 4 : 0;
827 }
828
829 /// \returns Maximum number of VGPRs that meets number of waves per execution
830 /// unit requirement for function \p MF, or number of VGPRs explicitly
831 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
832 ///
833 /// \returns Value that meets number of waves per execution unit requirement
834 /// if explicitly requested value cannot be converted to integer, violates
835 /// subtarget's specifications, or does not meet number of waves per execution
836 /// unit requirement.
837 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000838};
839
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000840} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000841
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000842#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H