blob: 54cfa70b765788ba8a49e3ecf9611d482e8676a8 [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 "R600FrameLowering.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000020#include "R600ISelLowering.h"
21#include "R600InstrInfo.h"
Matt Arsenault43e92fe2016-06-24 06:30:11 +000022#include "SIFrameLowering.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000023#include "SIISelLowering.h"
24#include "SIInstrInfo.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;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000113 bool AutoWaitcntBeforeBarrier;
Tom Stellard64a9d082016-10-14 18:10:39 +0000114 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000115 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000116 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000117 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000118 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000119 bool DebuggerInsertNops;
120 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000121 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000122
123 // Used as options.
124 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000125 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000126 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000127 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000128 bool EnableSIScheduler;
129 bool DumpCode;
130
131 // Subtarget statically properties set by tablegen
132 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000133 bool IsGCN;
134 bool GCN1Encoding;
135 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000136 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000137 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000138 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000139 bool HasSMemRealTime;
140 bool Has16BitInsts;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000141 bool HasVOP3PInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000142 bool HasMovrel;
143 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000144 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000145 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000146 bool HasSDWA;
147 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000148 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000149 bool FlatInstOffsets;
150 bool FlatGlobalInsts;
151 bool FlatScratchInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000152 bool R600ALUInst;
153 bool CaymanISA;
154 bool CFALUBug;
155 bool HasVertexCache;
156 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000157 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000158
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000159 // Dummy feature to use for assembler in tablegen.
160 bool FeatureDisable;
161
Tom Stellard75aadc22012-12-11 21:25:42 +0000162 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000163 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000164 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000165
166public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000167 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
168 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000169 ~AMDGPUSubtarget() override;
170
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000171 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
172 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000173
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000174 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
175 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
176 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
177 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000178
Eric Christopherd9134482014-08-04 21:25:23 +0000179 const InstrItineraryData *getInstrItineraryData() const override {
180 return &InstrItins;
181 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000182
Matt Arsenault56684d42016-08-11 17:31:42 +0000183 // Nothing implemented, just prevent crashes on use.
184 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
185 return &TSInfo;
186 }
187
Craig Topperee7b0f32014-04-30 05:53:27 +0000188 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000189
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000190 bool isAmdHsaOS() const {
191 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000192 }
193
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000194 bool isMesa3DOS() const {
195 return TargetTriple.getOS() == Triple::Mesa3D;
196 }
197
Tom Stellarde88bbc32016-09-23 01:33:26 +0000198 bool isOpenCLEnv() const {
Yaxun Liua618acf2017-06-01 21:31:53 +0000199 return TargetTriple.getEnvironment() == Triple::OpenCL ||
200 TargetTriple.getEnvironmentName() == "amdgizcl";
Tom Stellarde88bbc32016-09-23 01:33:26 +0000201 }
202
Matt Arsenaultd782d052014-06-27 17:57:00 +0000203 Generation getGeneration() const {
204 return Gen;
205 }
206
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000207 unsigned getWavefrontSize() const {
208 return WavefrontSize;
209 }
210
211 int getLocalMemorySize() const {
212 return LocalMemorySize;
213 }
214
215 int getLDSBankCount() const {
216 return LDSBankCount;
217 }
218
219 unsigned getMaxPrivateElementSize() const {
220 return MaxPrivateElementSize;
221 }
222
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000223 AMDGPUAS getAMDGPUAS() const {
224 return AS;
225 }
226
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000227 bool has16BitInsts() const {
228 return Has16BitInsts;
229 }
230
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000231 bool hasVOP3PInsts() const {
232 return HasVOP3PInsts;
233 }
234
Matt Arsenaultd782d052014-06-27 17:57:00 +0000235 bool hasHWFP64() const {
236 return FP64;
237 }
238
Matt Arsenaultb035a572015-01-29 19:34:25 +0000239 bool hasFastFMAF32() const {
240 return FastFMAF32;
241 }
242
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000243 bool hasHalfRate64Ops() const {
244 return HalfRate64Ops;
245 }
246
Matt Arsenault88701812016-06-09 23:42:48 +0000247 bool hasAddr64() const {
248 return (getGeneration() < VOLCANIC_ISLANDS);
249 }
250
Matt Arsenaultfae02982014-03-17 18:58:11 +0000251 bool hasBFE() const {
252 return (getGeneration() >= EVERGREEN);
253 }
254
Matt Arsenault6e439652014-06-10 19:00:20 +0000255 bool hasBFI() const {
256 return (getGeneration() >= EVERGREEN);
257 }
258
Matt Arsenaultfae02982014-03-17 18:58:11 +0000259 bool hasBFM() const {
260 return hasBFE();
261 }
262
Matt Arsenault60425062014-06-10 19:18:28 +0000263 bool hasBCNT(unsigned Size) const {
264 if (Size == 32)
265 return (getGeneration() >= EVERGREEN);
266
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000267 if (Size == 64)
268 return (getGeneration() >= SOUTHERN_ISLANDS);
269
270 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000271 }
272
Tom Stellard50122a52014-04-07 19:45:41 +0000273 bool hasMulU24() const {
274 return (getGeneration() >= EVERGREEN);
275 }
276
277 bool hasMulI24() const {
278 return (getGeneration() >= SOUTHERN_ISLANDS ||
279 hasCaymanISA());
280 }
281
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000282 bool hasFFBL() const {
283 return (getGeneration() >= EVERGREEN);
284 }
285
286 bool hasFFBH() const {
287 return (getGeneration() >= EVERGREEN);
288 }
289
Matt Arsenault10268f92017-02-27 22:40:39 +0000290 bool hasMed3_16() const {
291 return getGeneration() >= GFX9;
292 }
293
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000294 bool hasMin3Max3_16() const {
295 return getGeneration() >= GFX9;
296 }
297
Jan Vesely808fff52015-04-30 17:15:56 +0000298 bool hasCARRY() const {
299 return (getGeneration() >= EVERGREEN);
300 }
301
302 bool hasBORROW() const {
303 return (getGeneration() >= EVERGREEN);
304 }
305
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000306 bool hasCaymanISA() const {
307 return CaymanISA;
308 }
309
Wei Ding205bfdb2017-02-10 02:15:29 +0000310 TrapHandlerAbi getTrapHandlerAbi() const {
311 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
312 }
313
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000314 bool isPromoteAllocaEnabled() const {
315 return EnablePromoteAlloca;
316 }
317
Matt Arsenault706f9302015-07-06 16:01:58 +0000318 bool unsafeDSOffsetFoldingEnabled() const {
319 return EnableUnsafeDSOffsetFolding;
320 }
321
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000322 bool dumpCode() const {
323 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000324 }
325
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000326 /// Return the amount of LDS that can be used that will not restrict the
327 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000328 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
329 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000330
331 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
332 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000333 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000334
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000335 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
336 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
337 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
338 }
339
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000340 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000341 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000342 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000343
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000344 bool hasFP32Denormals() const {
345 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000346 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000347
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000348 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000349 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000350 }
351
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000352 bool hasFPExceptions() const {
353 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000354 }
355
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000356 bool enableDX10Clamp() const {
357 return DX10Clamp;
358 }
359
360 bool enableIEEEBit(const MachineFunction &MF) const {
361 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
362 }
363
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000364 bool useFlatForGlobal() const {
365 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000366 }
367
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000368 bool hasAutoWaitcntBeforeBarrier() const {
369 return AutoWaitcntBeforeBarrier;
370 }
371
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000372 bool hasUnalignedBufferAccess() const {
373 return UnalignedBufferAccess;
374 }
375
Tom Stellard64a9d082016-10-14 18:10:39 +0000376 bool hasUnalignedScratchAccess() const {
377 return UnalignedScratchAccess;
378 }
379
Matt Arsenaulte823d922017-02-18 18:29:53 +0000380 bool hasApertureRegs() const {
381 return HasApertureRegs;
382 }
383
Wei Ding205bfdb2017-02-10 02:15:29 +0000384 bool isTrapHandlerEnabled() const {
385 return TrapHandler;
386 }
387
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000388 bool isXNACKEnabled() const {
389 return EnableXNACK;
390 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000391
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000392 bool hasFlatAddressSpace() const {
393 return FlatAddressSpace;
394 }
395
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000396 bool hasFlatInstOffsets() const {
397 return FlatInstOffsets;
398 }
399
400 bool hasFlatGlobalInsts() const {
401 return FlatGlobalInsts;
402 }
403
404 bool hasFlatScratchInsts() const {
405 return FlatScratchInsts;
406 }
407
Tom Stellard2f3f9852017-01-25 01:25:13 +0000408 bool isMesaKernel(const MachineFunction &MF) const {
409 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
410 }
411
412 // Covers VS/PS/CS graphics shaders
413 bool isMesaGfxShader(const MachineFunction &MF) const {
414 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
415 }
416
417 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
418 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000419 }
420
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000421 bool hasFminFmaxLegacy() const {
422 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
423 }
424
Stanislav Mekhanoshin53a21292017-05-23 19:54:48 +0000425 bool hasSDWA() const {
426 return HasSDWA;
427 }
428
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000429 /// \brief Returns the offset in bytes from the start of the input buffer
430 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000431 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
432 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000433 }
434
Tom Stellardb2869eb2016-09-09 19:28:00 +0000435 unsigned getAlignmentForImplicitArgPtr() const {
436 return isAmdHsaOS() ? 8 : 4;
437 }
438
Tom Stellard2f3f9852017-01-25 01:25:13 +0000439 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
440 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000441 return 16;
442 if (isAmdHsaOS() && isOpenCLEnv())
443 return 32;
444 return 0;
445 }
446
Matt Arsenault869fec22017-04-17 19:48:24 +0000447 // Scratch is allocated in 256 dword per wave blocks for the entire
448 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
449 // is 4-byte aligned.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000450 unsigned getStackAlignment() const {
Matt Arsenault869fec22017-04-17 19:48:24 +0000451 return 4;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000452 }
Tom Stellard347ac792015-06-26 21:15:07 +0000453
Craig Topper5656db42014-04-29 07:57:24 +0000454 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000455 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000456 }
457
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000458 bool enableSubRegLiveness() const override {
459 return true;
460 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000461
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000462 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
463 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
464
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000465 /// \returns Number of execution units per compute unit supported by the
466 /// subtarget.
467 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000468 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000469 }
470
471 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000472 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000473 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000474 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
475 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000476 }
477
478 /// \returns Maximum number of waves per compute unit supported by the
479 /// subtarget without any kind of limitation.
480 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000481 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000482 }
483
484 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000485 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000486 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000487 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
488 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000489 }
490
491 /// \returns Minimum number of waves per execution unit supported by the
492 /// subtarget.
493 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000494 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000495 }
496
497 /// \returns Maximum number of waves per execution unit supported by the
498 /// subtarget without any kind of limitation.
499 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000500 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000501 }
502
503 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000504 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000505 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000506 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
507 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000508 }
509
510 /// \returns Minimum flat work group size supported by the subtarget.
511 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000512 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000513 }
514
515 /// \returns Maximum flat work group size supported by the subtarget.
516 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000517 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000518 }
519
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000520 /// \returns Number of waves per work group supported by the subtarget and
521 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000522 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000523 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
524 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000525 }
526
527 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
528 /// for function \p F, or minimum/maximum flat work group sizes explicitly
529 /// requested using "amdgpu-flat-work-group-size" attribute attached to
530 /// function \p F.
531 ///
532 /// \returns Subtarget's default values if explicitly requested values cannot
533 /// be converted to integer, or violate subtarget's specifications.
534 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
535
536 /// \returns Subtarget's default pair of minimum/maximum number of waves per
537 /// execution unit for function \p F, or minimum/maximum number of waves per
538 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
539 /// attached to function \p F.
540 ///
541 /// \returns Subtarget's default values if explicitly requested values cannot
542 /// be converted to integer, violate subtarget's specifications, or are not
543 /// compatible with minimum/maximum number of waves limited by flat work group
544 /// size, register usage, and/or lds usage.
545 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000546
547 /// Creates value range metadata on an workitemid.* inrinsic call or load.
548 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000549};
550
551class R600Subtarget final : public AMDGPUSubtarget {
552private:
553 R600InstrInfo InstrInfo;
554 R600FrameLowering FrameLowering;
555 R600TargetLowering TLInfo;
556
557public:
558 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
559 const TargetMachine &TM);
560
561 const R600InstrInfo *getInstrInfo() const override {
562 return &InstrInfo;
563 }
564
565 const R600FrameLowering *getFrameLowering() const override {
566 return &FrameLowering;
567 }
568
569 const R600TargetLowering *getTargetLowering() const override {
570 return &TLInfo;
571 }
572
573 const R600RegisterInfo *getRegisterInfo() const override {
574 return &InstrInfo.getRegisterInfo();
575 }
576
577 bool hasCFAluBug() const {
578 return CFALUBug;
579 }
580
581 bool hasVertexCache() const {
582 return HasVertexCache;
583 }
584
585 short getTexVTXClauseSize() const {
586 return TexVTXClauseSize;
587 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000588};
589
590class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000591private:
592 SIInstrInfo InstrInfo;
593 SIFrameLowering FrameLowering;
594 SITargetLowering TLInfo;
595 std::unique_ptr<GISelAccessor> GISel;
596
597public:
598 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
599 const TargetMachine &TM);
600
601 const SIInstrInfo *getInstrInfo() const override {
602 return &InstrInfo;
603 }
604
605 const SIFrameLowering *getFrameLowering() const override {
606 return &FrameLowering;
607 }
608
609 const SITargetLowering *getTargetLowering() const override {
610 return &TLInfo;
611 }
612
613 const CallLowering *getCallLowering() const override {
614 assert(GISel && "Access to GlobalISel APIs not set");
615 return GISel->getCallLowering();
616 }
617
Tom Stellardca166212017-01-30 21:56:46 +0000618 const InstructionSelector *getInstructionSelector() const override {
619 assert(GISel && "Access to GlobalISel APIs not set");
620 return GISel->getInstructionSelector();
621 }
622
623 const LegalizerInfo *getLegalizerInfo() const override {
624 assert(GISel && "Access to GlobalISel APIs not set");
625 return GISel->getLegalizerInfo();
626 }
627
628 const RegisterBankInfo *getRegBankInfo() const override {
629 assert(GISel && "Access to GlobalISel APIs not set");
630 return GISel->getRegBankInfo();
631 }
632
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000633 const SIRegisterInfo *getRegisterInfo() const override {
634 return &InstrInfo.getRegisterInfo();
635 }
636
637 void setGISelAccessor(GISelAccessor &GISel) {
638 this->GISel.reset(&GISel);
639 }
640
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000641 // XXX - Why is this here if it isn't in the default pass set?
642 bool enableEarlyIfConversion() const override {
643 return true;
644 }
645
Tom Stellard83f0bce2015-01-29 16:55:25 +0000646 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000647 unsigned NumRegionInstrs) const override;
648
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000649 bool isVGPRSpillingEnabled(const Function& F) const;
650
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000651 unsigned getMaxNumUserSGPRs() const {
652 return 16;
653 }
654
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000655 bool hasSMemRealTime() const {
656 return HasSMemRealTime;
657 }
658
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000659 bool hasMovrel() const {
660 return HasMovrel;
661 }
662
663 bool hasVGPRIndexMode() const {
664 return HasVGPRIndexMode;
665 }
666
Marek Olsake22fdb92017-03-21 17:00:32 +0000667 bool useVGPRIndexMode(bool UserEnable) const {
668 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
669 }
670
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000671 bool hasScalarCompareEq64() const {
672 return getGeneration() >= VOLCANIC_ISLANDS;
673 }
674
Matt Arsenault7b647552016-10-28 21:55:15 +0000675 bool hasScalarStores() const {
676 return HasScalarStores;
677 }
678
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000679 bool hasInv2PiInlineImm() const {
680 return HasInv2PiInlineImm;
681 }
682
Sam Kolton07dbde22017-01-20 10:01:25 +0000683 bool hasDPP() const {
684 return HasDPP;
685 }
686
Tom Stellardde008d32016-01-21 04:28:34 +0000687 bool enableSIScheduler() const {
688 return EnableSIScheduler;
689 }
690
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000691 bool debuggerSupported() const {
692 return debuggerInsertNops() && debuggerReserveRegs() &&
693 debuggerEmitPrologue();
694 }
695
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000696 bool debuggerInsertNops() const {
697 return DebuggerInsertNops;
698 }
699
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000700 bool debuggerReserveRegs() const {
701 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000702 }
703
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000704 bool debuggerEmitPrologue() const {
705 return DebuggerEmitPrologue;
706 }
707
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000708 bool loadStoreOptEnabled() const {
709 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000710 }
711
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000712 bool hasSGPRInitBug() const {
713 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000714 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000715
Tom Stellardb133fbb2016-10-27 23:05:31 +0000716 bool has12DWordStoreHazard() const {
717 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
718 }
719
Matt Arsenaulte823d922017-02-18 18:29:53 +0000720 bool hasSMovFedHazard() const {
721 return getGeneration() >= AMDGPUSubtarget::GFX9;
722 }
723
724 bool hasReadM0Hazard() const {
725 return getGeneration() >= AMDGPUSubtarget::GFX9;
726 }
727
Tom Stellard2f3f9852017-01-25 01:25:13 +0000728 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000729
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000730 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
731 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
732
733 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
734 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000735
Matt Arsenaulte823d922017-02-18 18:29:53 +0000736 /// \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 {
Mandeep Singh Grang5e1697e2017-06-06 05:08:36 +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