blob: e543cae07ada09069533adfc13587db458957578 [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
Tom Stellard2f3f9852017-01-25 01:25:13 +0000402 bool isMesaKernel(const MachineFunction &MF) const {
403 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
404 }
405
406 // Covers VS/PS/CS graphics shaders
407 bool isMesaGfxShader(const MachineFunction &MF) const {
408 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
409 }
410
411 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
412 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000413 }
414
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000415 bool hasFminFmaxLegacy() const {
416 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
417 }
418
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000419 /// \brief Returns the offset in bytes from the start of the input buffer
420 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000421 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
422 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000423 }
424
Tom Stellardb2869eb2016-09-09 19:28:00 +0000425 unsigned getAlignmentForImplicitArgPtr() const {
426 return isAmdHsaOS() ? 8 : 4;
427 }
428
Tom Stellard2f3f9852017-01-25 01:25:13 +0000429 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
430 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000431 return 16;
432 if (isAmdHsaOS() && isOpenCLEnv())
433 return 32;
434 return 0;
435 }
436
Matt Arsenault869fec22017-04-17 19:48:24 +0000437 // Scratch is allocated in 256 dword per wave blocks for the entire
438 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
439 // is 4-byte aligned.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000440 unsigned getStackAlignment() const {
Matt Arsenault869fec22017-04-17 19:48:24 +0000441 return 4;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000442 }
Tom Stellard347ac792015-06-26 21:15:07 +0000443
Craig Topper5656db42014-04-29 07:57:24 +0000444 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000445 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000446 }
447
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000448 bool enableSubRegLiveness() const override {
449 return true;
450 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000451
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000452 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
453 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
454
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000455 /// \returns Number of execution units per compute unit supported by the
456 /// subtarget.
457 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000458 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000459 }
460
461 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000462 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000463 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000464 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
465 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000466 }
467
468 /// \returns Maximum number of waves per compute unit supported by the
469 /// subtarget without any kind of limitation.
470 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000471 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000472 }
473
474 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000475 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000476 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000477 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
478 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000479 }
480
481 /// \returns Minimum number of waves per execution unit supported by the
482 /// subtarget.
483 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000484 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000485 }
486
487 /// \returns Maximum number of waves per execution unit supported by the
488 /// subtarget without any kind of limitation.
489 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000490 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000491 }
492
493 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000494 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000495 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000496 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
497 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000498 }
499
500 /// \returns Minimum flat work group size supported by the subtarget.
501 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000502 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000503 }
504
505 /// \returns Maximum flat work group size supported by the subtarget.
506 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000507 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000508 }
509
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000510 /// \returns Number of waves per work group supported by the subtarget and
511 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000512 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000513 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
514 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000515 }
516
517 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
518 /// for function \p F, or minimum/maximum flat work group sizes explicitly
519 /// requested using "amdgpu-flat-work-group-size" attribute attached to
520 /// function \p F.
521 ///
522 /// \returns Subtarget's default values if explicitly requested values cannot
523 /// be converted to integer, or violate subtarget's specifications.
524 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
525
526 /// \returns Subtarget's default pair of minimum/maximum number of waves per
527 /// execution unit for function \p F, or minimum/maximum number of waves per
528 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
529 /// attached to function \p F.
530 ///
531 /// \returns Subtarget's default values if explicitly requested values cannot
532 /// be converted to integer, violate subtarget's specifications, or are not
533 /// compatible with minimum/maximum number of waves limited by flat work group
534 /// size, register usage, and/or lds usage.
535 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000536
537 /// Creates value range metadata on an workitemid.* inrinsic call or load.
538 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000539};
540
541class R600Subtarget final : public AMDGPUSubtarget {
542private:
543 R600InstrInfo InstrInfo;
544 R600FrameLowering FrameLowering;
545 R600TargetLowering TLInfo;
546
547public:
548 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
549 const TargetMachine &TM);
550
551 const R600InstrInfo *getInstrInfo() const override {
552 return &InstrInfo;
553 }
554
555 const R600FrameLowering *getFrameLowering() const override {
556 return &FrameLowering;
557 }
558
559 const R600TargetLowering *getTargetLowering() const override {
560 return &TLInfo;
561 }
562
563 const R600RegisterInfo *getRegisterInfo() const override {
564 return &InstrInfo.getRegisterInfo();
565 }
566
567 bool hasCFAluBug() const {
568 return CFALUBug;
569 }
570
571 bool hasVertexCache() const {
572 return HasVertexCache;
573 }
574
575 short getTexVTXClauseSize() const {
576 return TexVTXClauseSize;
577 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000578};
579
580class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000581private:
582 SIInstrInfo InstrInfo;
583 SIFrameLowering FrameLowering;
584 SITargetLowering TLInfo;
585 std::unique_ptr<GISelAccessor> GISel;
586
587public:
588 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
589 const TargetMachine &TM);
590
591 const SIInstrInfo *getInstrInfo() const override {
592 return &InstrInfo;
593 }
594
595 const SIFrameLowering *getFrameLowering() const override {
596 return &FrameLowering;
597 }
598
599 const SITargetLowering *getTargetLowering() const override {
600 return &TLInfo;
601 }
602
603 const CallLowering *getCallLowering() const override {
604 assert(GISel && "Access to GlobalISel APIs not set");
605 return GISel->getCallLowering();
606 }
607
Tom Stellardca166212017-01-30 21:56:46 +0000608 const InstructionSelector *getInstructionSelector() const override {
609 assert(GISel && "Access to GlobalISel APIs not set");
610 return GISel->getInstructionSelector();
611 }
612
613 const LegalizerInfo *getLegalizerInfo() const override {
614 assert(GISel && "Access to GlobalISel APIs not set");
615 return GISel->getLegalizerInfo();
616 }
617
618 const RegisterBankInfo *getRegBankInfo() const override {
619 assert(GISel && "Access to GlobalISel APIs not set");
620 return GISel->getRegBankInfo();
621 }
622
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000623 const SIRegisterInfo *getRegisterInfo() const override {
624 return &InstrInfo.getRegisterInfo();
625 }
626
627 void setGISelAccessor(GISelAccessor &GISel) {
628 this->GISel.reset(&GISel);
629 }
630
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000631 // XXX - Why is this here if it isn't in the default pass set?
632 bool enableEarlyIfConversion() const override {
633 return true;
634 }
635
Tom Stellard83f0bce2015-01-29 16:55:25 +0000636 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000637 unsigned NumRegionInstrs) const override;
638
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000639 bool isVGPRSpillingEnabled(const Function& F) const;
640
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000641 unsigned getMaxNumUserSGPRs() const {
642 return 16;
643 }
644
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000645 bool hasSMemRealTime() const {
646 return HasSMemRealTime;
647 }
648
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000649 bool hasMovrel() const {
650 return HasMovrel;
651 }
652
653 bool hasVGPRIndexMode() const {
654 return HasVGPRIndexMode;
655 }
656
Marek Olsake22fdb92017-03-21 17:00:32 +0000657 bool useVGPRIndexMode(bool UserEnable) const {
658 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
659 }
660
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000661 bool hasScalarCompareEq64() const {
662 return getGeneration() >= VOLCANIC_ISLANDS;
663 }
664
Matt Arsenault7b647552016-10-28 21:55:15 +0000665 bool hasScalarStores() const {
666 return HasScalarStores;
667 }
668
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000669 bool hasInv2PiInlineImm() const {
670 return HasInv2PiInlineImm;
671 }
672
Sam Kolton07dbde22017-01-20 10:01:25 +0000673 bool hasSDWA() const {
674 return HasSDWA;
675 }
676
677 bool hasDPP() const {
678 return HasDPP;
679 }
680
Tom Stellardde008d32016-01-21 04:28:34 +0000681 bool enableSIScheduler() const {
682 return EnableSIScheduler;
683 }
684
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000685 bool debuggerSupported() const {
686 return debuggerInsertNops() && debuggerReserveRegs() &&
687 debuggerEmitPrologue();
688 }
689
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000690 bool debuggerInsertNops() const {
691 return DebuggerInsertNops;
692 }
693
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000694 bool debuggerReserveRegs() const {
695 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000696 }
697
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000698 bool debuggerEmitPrologue() const {
699 return DebuggerEmitPrologue;
700 }
701
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000702 bool loadStoreOptEnabled() const {
703 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000704 }
705
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000706 bool hasSGPRInitBug() const {
707 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000708 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000709
Tom Stellardb133fbb2016-10-27 23:05:31 +0000710 bool has12DWordStoreHazard() const {
711 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
712 }
713
Matt Arsenaulte823d922017-02-18 18:29:53 +0000714 bool hasSMovFedHazard() const {
715 return getGeneration() >= AMDGPUSubtarget::GFX9;
716 }
717
718 bool hasReadM0Hazard() const {
719 return getGeneration() >= AMDGPUSubtarget::GFX9;
720 }
721
Tom Stellard2f3f9852017-01-25 01:25:13 +0000722 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000723
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000724 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
725 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
726
727 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
728 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000729
730 /// \returns True if waitcnt instruction is needed before barrier instruction,
731 /// false otherwise.
732 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000733 return getGeneration() < GFX9;
734 }
735
736 /// \returns true if the flat_scratch register should be initialized with the
737 /// pointer to the wave's scratch memory rather than a size and offset.
738 bool flatScratchIsPointer() const {
739 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000740 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000741
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000742 /// \returns SGPR allocation granularity supported by the subtarget.
743 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000744 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000745 }
746
747 /// \returns SGPR encoding granularity supported by the subtarget.
748 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000749 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000750 }
751
752 /// \returns Total number of SGPRs supported by the subtarget.
753 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000754 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000755 }
756
757 /// \returns Addressable number of SGPRs supported by the subtarget.
758 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000759 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000760 }
761
762 /// \returns Minimum number of SGPRs that meets the given number of waves per
763 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000764 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
765 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
766 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000767
768 /// \returns Maximum number of SGPRs that meets the given number of waves per
769 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000770 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
771 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
772 Addressable);
773 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000774
775 /// \returns Reserved number of SGPRs for given function \p MF.
776 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
777
778 /// \returns Maximum number of SGPRs that meets number of waves per execution
779 /// unit requirement for function \p MF, or number of SGPRs explicitly
780 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
781 ///
782 /// \returns Value that meets number of waves per execution unit requirement
783 /// if explicitly requested value cannot be converted to integer, violates
784 /// subtarget's specifications, or does not meet number of waves per execution
785 /// unit requirement.
786 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
787
788 /// \returns VGPR allocation granularity supported by the subtarget.
789 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000790 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000791 }
792
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000793 /// \returns VGPR encoding granularity supported by the subtarget.
794 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000795 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000796 }
797
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000798 /// \returns Total number of VGPRs supported by the subtarget.
799 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000800 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000801 }
802
803 /// \returns Addressable number of VGPRs supported by the subtarget.
804 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000805 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000806 }
807
808 /// \returns Minimum number of VGPRs that meets given number of waves per
809 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000810 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
811 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
812 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000813
814 /// \returns Maximum number of VGPRs that meets given number of waves per
815 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000816 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
817 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
818 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000819
820 /// \returns Reserved number of VGPRs for given function \p MF.
821 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
822 return debuggerReserveRegs() ? 4 : 0;
823 }
824
825 /// \returns Maximum number of VGPRs that meets number of waves per execution
826 /// unit requirement for function \p MF, or number of VGPRs explicitly
827 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
828 ///
829 /// \returns Value that meets number of waves per execution unit requirement
830 /// if explicitly requested value cannot be converted to integer, violates
831 /// subtarget's specifications, or does not meet number of waves per execution
832 /// unit requirement.
833 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000834};
835
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000836} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000837
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000838#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H