blob: a5cda817ac11c415b311f733aa2b482577ffcb22 [file] [log] [blame]
Matt Arsenault0c90e952015-11-06 18:17:45 +00001//=====-- AMDGPUSubtarget.h - Define Subtarget for AMDGPU ------*- C++ -*-====//
Tom Stellard75aadc22012-12-11 21:25:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//==-----------------------------------------------------------------------===//
9//
10/// \file
11/// \brief AMDGPU specific subclass of TargetSubtarget.
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault0c90e952015-11-06 18:17:45 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
Matt Arsenaultf59e5382015-11-06 18:23:00 +000017
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000018#include "AMDGPU.h"
Matt Arsenault43e92fe2016-06-24 06:30:11 +000019#include "R600InstrInfo.h"
20#include "R600ISelLowering.h"
21#include "R600FrameLowering.h"
22#include "SIInstrInfo.h"
23#include "SIISelLowering.h"
24#include "SIFrameLowering.h"
Valery Pykhtinfd4c4102017-03-21 13:15:46 +000025#include "SIMachineFunctionInfo.h"
Tom Stellard347ac792015-06-26 21:15:07 +000026#include "Utils/AMDGPUBaseInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000027#include "llvm/ADT/Triple.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000028#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000029#include "llvm/CodeGen/MachineFunction.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000030#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000031#include "llvm/MC/MCInstrItineraries.h"
32#include "llvm/Support/MathExtras.h"
33#include <cassert>
34#include <cstdint>
35#include <memory>
36#include <utility>
Tom Stellard75aadc22012-12-11 21:25:42 +000037
38#define GET_SUBTARGETINFO_HEADER
39#include "AMDGPUGenSubtargetInfo.inc"
40
Tom Stellard75aadc22012-12-11 21:25:42 +000041namespace llvm {
42
Matt Arsenault43e92fe2016-06-24 06:30:11 +000043class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000044
Tom Stellard75aadc22012-12-11 21:25:42 +000045class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000046public:
47 enum Generation {
48 R600 = 0,
49 R700,
50 EVERGREEN,
51 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000052 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000053 SEA_ISLANDS,
54 VOLCANIC_ISLANDS,
Matt Arsenaulte823d922017-02-18 18:29:53 +000055 GFX9,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000056 };
57
Marek Olsak4d00dd22015-03-09 15:48:09 +000058 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000059 ISAVersion0_0_0,
60 ISAVersion7_0_0,
61 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +000062 ISAVersion7_0_2,
Tom Stellard347ac792015-06-26 21:15:07 +000063 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000064 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +000065 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +000066 ISAVersion8_0_3,
67 ISAVersion8_0_4,
68 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +000069 ISAVersion9_0_0,
70 ISAVersion9_0_1
Tom Stellard347ac792015-06-26 21:15:07 +000071 };
72
Wei Ding205bfdb2017-02-10 02:15:29 +000073 enum TrapHandlerAbi {
74 TrapHandlerAbiNone = 0,
75 TrapHandlerAbiHsa = 1
76 };
77
Wei Dingf2cce022017-02-22 23:22:19 +000078 enum TrapID {
79 TrapIDHardwareReserved = 0,
80 TrapIDHSADebugTrap = 1,
81 TrapIDLLVMTrap = 2,
82 TrapIDLLVMDebugTrap = 3,
83 TrapIDDebugBreakpoint = 7,
84 TrapIDDebugReserved8 = 8,
85 TrapIDDebugReservedFE = 0xfe,
86 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +000087 };
88
89 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +000090 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +000091 };
92
Matt Arsenault43e92fe2016-06-24 06:30:11 +000093protected:
94 // Basic subtarget description.
95 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +000096 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000097 unsigned IsaVersion;
98 unsigned WavefrontSize;
99 int LocalMemorySize;
100 int LDSBankCount;
101 unsigned MaxPrivateElementSize;
102
103 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000104 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000105 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000106
107 // Dynamially set bits that enable features.
108 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000109 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000110 bool FPExceptions;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000111 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000112 bool FlatForGlobal;
Tom Stellard64a9d082016-10-14 18:10:39 +0000113 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000114 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000115 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000116 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000117 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000118 bool DebuggerInsertNops;
119 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000120 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000121
122 // Used as options.
123 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000124 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000125 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000126 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000127 bool EnableSIScheduler;
128 bool DumpCode;
129
130 // Subtarget statically properties set by tablegen
131 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000132 bool IsGCN;
133 bool GCN1Encoding;
134 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000135 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000136 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000137 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000138 bool HasSMemRealTime;
139 bool Has16BitInsts;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000140 bool HasVOP3PInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000141 bool HasMovrel;
142 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000143 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000144 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000145 bool HasSDWA;
146 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000147 bool FlatAddressSpace;
148 bool R600ALUInst;
149 bool CaymanISA;
150 bool CFALUBug;
151 bool HasVertexCache;
152 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000153 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000154
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000155 // Dummy feature to use for assembler in tablegen.
156 bool FeatureDisable;
157
Tom Stellard75aadc22012-12-11 21:25:42 +0000158 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000159 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000160 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000161
162public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000163 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
164 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000165 ~AMDGPUSubtarget() override;
166
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000167 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
168 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000169
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000170 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
171 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
172 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
173 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000174
Eric Christopherd9134482014-08-04 21:25:23 +0000175 const InstrItineraryData *getInstrItineraryData() const override {
176 return &InstrItins;
177 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000178
Matt Arsenault56684d42016-08-11 17:31:42 +0000179 // Nothing implemented, just prevent crashes on use.
180 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
181 return &TSInfo;
182 }
183
Craig Topperee7b0f32014-04-30 05:53:27 +0000184 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000185
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000186 bool isAmdHsaOS() const {
187 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000188 }
189
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000190 bool isMesa3DOS() const {
191 return TargetTriple.getOS() == Triple::Mesa3D;
192 }
193
Tom Stellarde88bbc32016-09-23 01:33:26 +0000194 bool isOpenCLEnv() const {
195 return TargetTriple.getEnvironment() == Triple::OpenCL;
196 }
197
Matt Arsenaultd782d052014-06-27 17:57:00 +0000198 Generation getGeneration() const {
199 return Gen;
200 }
201
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000202 unsigned getWavefrontSize() const {
203 return WavefrontSize;
204 }
205
206 int getLocalMemorySize() const {
207 return LocalMemorySize;
208 }
209
210 int getLDSBankCount() const {
211 return LDSBankCount;
212 }
213
214 unsigned getMaxPrivateElementSize() const {
215 return MaxPrivateElementSize;
216 }
217
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000218 AMDGPUAS getAMDGPUAS() const {
219 return AS;
220 }
221
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000222 bool has16BitInsts() const {
223 return Has16BitInsts;
224 }
225
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000226 bool hasVOP3PInsts() const {
227 return HasVOP3PInsts;
228 }
229
Matt Arsenaultd782d052014-06-27 17:57:00 +0000230 bool hasHWFP64() const {
231 return FP64;
232 }
233
Matt Arsenaultb035a572015-01-29 19:34:25 +0000234 bool hasFastFMAF32() const {
235 return FastFMAF32;
236 }
237
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000238 bool hasHalfRate64Ops() const {
239 return HalfRate64Ops;
240 }
241
Matt Arsenault88701812016-06-09 23:42:48 +0000242 bool hasAddr64() const {
243 return (getGeneration() < VOLCANIC_ISLANDS);
244 }
245
Matt Arsenaultfae02982014-03-17 18:58:11 +0000246 bool hasBFE() const {
247 return (getGeneration() >= EVERGREEN);
248 }
249
Matt Arsenault6e439652014-06-10 19:00:20 +0000250 bool hasBFI() const {
251 return (getGeneration() >= EVERGREEN);
252 }
253
Matt Arsenaultfae02982014-03-17 18:58:11 +0000254 bool hasBFM() const {
255 return hasBFE();
256 }
257
Matt Arsenault60425062014-06-10 19:18:28 +0000258 bool hasBCNT(unsigned Size) const {
259 if (Size == 32)
260 return (getGeneration() >= EVERGREEN);
261
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000262 if (Size == 64)
263 return (getGeneration() >= SOUTHERN_ISLANDS);
264
265 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000266 }
267
Tom Stellard50122a52014-04-07 19:45:41 +0000268 bool hasMulU24() const {
269 return (getGeneration() >= EVERGREEN);
270 }
271
272 bool hasMulI24() const {
273 return (getGeneration() >= SOUTHERN_ISLANDS ||
274 hasCaymanISA());
275 }
276
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000277 bool hasFFBL() const {
278 return (getGeneration() >= EVERGREEN);
279 }
280
281 bool hasFFBH() const {
282 return (getGeneration() >= EVERGREEN);
283 }
284
Matt Arsenault10268f92017-02-27 22:40:39 +0000285 bool hasMed3_16() const {
286 return getGeneration() >= GFX9;
287 }
288
Jan Vesely808fff52015-04-30 17:15:56 +0000289 bool hasCARRY() const {
290 return (getGeneration() >= EVERGREEN);
291 }
292
293 bool hasBORROW() const {
294 return (getGeneration() >= EVERGREEN);
295 }
296
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000297 bool hasCaymanISA() const {
298 return CaymanISA;
299 }
300
Wei Ding205bfdb2017-02-10 02:15:29 +0000301 TrapHandlerAbi getTrapHandlerAbi() const {
302 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
303 }
304
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000305 bool isPromoteAllocaEnabled() const {
306 return EnablePromoteAlloca;
307 }
308
Matt Arsenault706f9302015-07-06 16:01:58 +0000309 bool unsafeDSOffsetFoldingEnabled() const {
310 return EnableUnsafeDSOffsetFolding;
311 }
312
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000313 bool dumpCode() const {
314 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000315 }
316
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000317 /// Return the amount of LDS that can be used that will not restrict the
318 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000319 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
320 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000321
322 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
323 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000324 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000325
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000326 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
327 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
328 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
329 }
330
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000331 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000332 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000333 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000334
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000335 bool hasFP32Denormals() const {
336 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000337 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000338
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000339 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000340 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000341 }
342
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000343 bool hasFPExceptions() const {
344 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000345 }
346
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000347 bool enableDX10Clamp() const {
348 return DX10Clamp;
349 }
350
351 bool enableIEEEBit(const MachineFunction &MF) const {
352 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
353 }
354
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000355 bool useFlatForGlobal() const {
356 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000357 }
358
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000359 bool hasUnalignedBufferAccess() const {
360 return UnalignedBufferAccess;
361 }
362
Tom Stellard64a9d082016-10-14 18:10:39 +0000363 bool hasUnalignedScratchAccess() const {
364 return UnalignedScratchAccess;
365 }
366
Matt Arsenaulte823d922017-02-18 18:29:53 +0000367 bool hasApertureRegs() const {
368 return HasApertureRegs;
369 }
370
Wei Ding205bfdb2017-02-10 02:15:29 +0000371 bool isTrapHandlerEnabled() const {
372 return TrapHandler;
373 }
374
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000375 bool isXNACKEnabled() const {
376 return EnableXNACK;
377 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000378
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000379 bool hasFlatAddressSpace() const {
380 return FlatAddressSpace;
381 }
382
Tom Stellard2f3f9852017-01-25 01:25:13 +0000383 bool isMesaKernel(const MachineFunction &MF) const {
384 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
385 }
386
387 // Covers VS/PS/CS graphics shaders
388 bool isMesaGfxShader(const MachineFunction &MF) const {
389 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
390 }
391
392 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
393 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000394 }
395
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000396 bool hasFminFmaxLegacy() const {
397 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
398 }
399
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000400 /// \brief Returns the offset in bytes from the start of the input buffer
401 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000402 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
403 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000404 }
405
Tom Stellardb2869eb2016-09-09 19:28:00 +0000406 unsigned getAlignmentForImplicitArgPtr() const {
407 return isAmdHsaOS() ? 8 : 4;
408 }
409
Tom Stellard2f3f9852017-01-25 01:25:13 +0000410 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
411 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000412 return 16;
413 if (isAmdHsaOS() && isOpenCLEnv())
414 return 32;
415 return 0;
416 }
417
Matt Arsenault869fec22017-04-17 19:48:24 +0000418 // Scratch is allocated in 256 dword per wave blocks for the entire
419 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
420 // is 4-byte aligned.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000421 unsigned getStackAlignment() const {
Matt Arsenault869fec22017-04-17 19:48:24 +0000422 return 4;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000423 }
Tom Stellard347ac792015-06-26 21:15:07 +0000424
Craig Topper5656db42014-04-29 07:57:24 +0000425 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000426 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000427 }
428
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000429 bool enableSubRegLiveness() const override {
430 return true;
431 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000432
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000433 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
434 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
435
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000436 /// \returns Number of execution units per compute unit supported by the
437 /// subtarget.
438 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000439 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000440 }
441
442 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000443 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000444 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000445 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
446 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000447 }
448
449 /// \returns Maximum number of waves per compute unit supported by the
450 /// subtarget without any kind of limitation.
451 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000452 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000453 }
454
455 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000456 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000457 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000458 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
459 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000460 }
461
462 /// \returns Minimum number of waves per execution unit supported by the
463 /// subtarget.
464 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000465 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000466 }
467
468 /// \returns Maximum number of waves per execution unit supported by the
469 /// subtarget without any kind of limitation.
470 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000471 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000472 }
473
474 /// \returns Maximum number of waves per execution 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 getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000477 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
478 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000479 }
480
481 /// \returns Minimum flat work group size supported by the subtarget.
482 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000483 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000484 }
485
486 /// \returns Maximum flat work group size supported by the subtarget.
487 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000488 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000489 }
490
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000491 /// \returns Number of waves per work group supported by the subtarget and
492 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000493 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000494 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
495 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000496 }
497
498 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
499 /// for function \p F, or minimum/maximum flat work group sizes explicitly
500 /// requested using "amdgpu-flat-work-group-size" attribute attached to
501 /// function \p F.
502 ///
503 /// \returns Subtarget's default values if explicitly requested values cannot
504 /// be converted to integer, or violate subtarget's specifications.
505 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
506
507 /// \returns Subtarget's default pair of minimum/maximum number of waves per
508 /// execution unit for function \p F, or minimum/maximum number of waves per
509 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
510 /// attached to function \p F.
511 ///
512 /// \returns Subtarget's default values if explicitly requested values cannot
513 /// be converted to integer, violate subtarget's specifications, or are not
514 /// compatible with minimum/maximum number of waves limited by flat work group
515 /// size, register usage, and/or lds usage.
516 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000517
518 /// Creates value range metadata on an workitemid.* inrinsic call or load.
519 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000520};
521
522class R600Subtarget final : public AMDGPUSubtarget {
523private:
524 R600InstrInfo InstrInfo;
525 R600FrameLowering FrameLowering;
526 R600TargetLowering TLInfo;
527
528public:
529 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
530 const TargetMachine &TM);
531
532 const R600InstrInfo *getInstrInfo() const override {
533 return &InstrInfo;
534 }
535
536 const R600FrameLowering *getFrameLowering() const override {
537 return &FrameLowering;
538 }
539
540 const R600TargetLowering *getTargetLowering() const override {
541 return &TLInfo;
542 }
543
544 const R600RegisterInfo *getRegisterInfo() const override {
545 return &InstrInfo.getRegisterInfo();
546 }
547
548 bool hasCFAluBug() const {
549 return CFALUBug;
550 }
551
552 bool hasVertexCache() const {
553 return HasVertexCache;
554 }
555
556 short getTexVTXClauseSize() const {
557 return TexVTXClauseSize;
558 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000559};
560
561class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000562private:
563 SIInstrInfo InstrInfo;
564 SIFrameLowering FrameLowering;
565 SITargetLowering TLInfo;
566 std::unique_ptr<GISelAccessor> GISel;
567
568public:
569 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
570 const TargetMachine &TM);
571
572 const SIInstrInfo *getInstrInfo() const override {
573 return &InstrInfo;
574 }
575
576 const SIFrameLowering *getFrameLowering() const override {
577 return &FrameLowering;
578 }
579
580 const SITargetLowering *getTargetLowering() const override {
581 return &TLInfo;
582 }
583
584 const CallLowering *getCallLowering() const override {
585 assert(GISel && "Access to GlobalISel APIs not set");
586 return GISel->getCallLowering();
587 }
588
Tom Stellardca166212017-01-30 21:56:46 +0000589 const InstructionSelector *getInstructionSelector() const override {
590 assert(GISel && "Access to GlobalISel APIs not set");
591 return GISel->getInstructionSelector();
592 }
593
594 const LegalizerInfo *getLegalizerInfo() const override {
595 assert(GISel && "Access to GlobalISel APIs not set");
596 return GISel->getLegalizerInfo();
597 }
598
599 const RegisterBankInfo *getRegBankInfo() const override {
600 assert(GISel && "Access to GlobalISel APIs not set");
601 return GISel->getRegBankInfo();
602 }
603
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000604 const SIRegisterInfo *getRegisterInfo() const override {
605 return &InstrInfo.getRegisterInfo();
606 }
607
608 void setGISelAccessor(GISelAccessor &GISel) {
609 this->GISel.reset(&GISel);
610 }
611
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000612 // XXX - Why is this here if it isn't in the default pass set?
613 bool enableEarlyIfConversion() const override {
614 return true;
615 }
616
Tom Stellard83f0bce2015-01-29 16:55:25 +0000617 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000618 unsigned NumRegionInstrs) const override;
619
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000620 bool isVGPRSpillingEnabled(const Function& F) const;
621
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000622 unsigned getMaxNumUserSGPRs() const {
623 return 16;
624 }
625
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000626 bool hasSMemRealTime() const {
627 return HasSMemRealTime;
628 }
629
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000630 bool hasMovrel() const {
631 return HasMovrel;
632 }
633
634 bool hasVGPRIndexMode() const {
635 return HasVGPRIndexMode;
636 }
637
Marek Olsake22fdb92017-03-21 17:00:32 +0000638 bool useVGPRIndexMode(bool UserEnable) const {
639 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
640 }
641
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000642 bool hasScalarCompareEq64() const {
643 return getGeneration() >= VOLCANIC_ISLANDS;
644 }
645
Matt Arsenault7b647552016-10-28 21:55:15 +0000646 bool hasScalarStores() const {
647 return HasScalarStores;
648 }
649
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000650 bool hasInv2PiInlineImm() const {
651 return HasInv2PiInlineImm;
652 }
653
Sam Kolton07dbde22017-01-20 10:01:25 +0000654 bool hasSDWA() const {
655 return HasSDWA;
656 }
657
658 bool hasDPP() const {
659 return HasDPP;
660 }
661
Tom Stellardde008d32016-01-21 04:28:34 +0000662 bool enableSIScheduler() const {
663 return EnableSIScheduler;
664 }
665
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000666 bool debuggerSupported() const {
667 return debuggerInsertNops() && debuggerReserveRegs() &&
668 debuggerEmitPrologue();
669 }
670
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000671 bool debuggerInsertNops() const {
672 return DebuggerInsertNops;
673 }
674
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000675 bool debuggerReserveRegs() const {
676 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000677 }
678
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000679 bool debuggerEmitPrologue() const {
680 return DebuggerEmitPrologue;
681 }
682
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000683 bool loadStoreOptEnabled() const {
684 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000685 }
686
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000687 bool hasSGPRInitBug() const {
688 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000689 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000690
Tom Stellardb133fbb2016-10-27 23:05:31 +0000691 bool has12DWordStoreHazard() const {
692 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
693 }
694
Matt Arsenaulte823d922017-02-18 18:29:53 +0000695 bool hasSMovFedHazard() const {
696 return getGeneration() >= AMDGPUSubtarget::GFX9;
697 }
698
699 bool hasReadM0Hazard() const {
700 return getGeneration() >= AMDGPUSubtarget::GFX9;
701 }
702
Tom Stellard2f3f9852017-01-25 01:25:13 +0000703 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000704
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000705 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
706 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
707
708 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
709 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000710
711 /// \returns True if waitcnt instruction is needed before barrier instruction,
712 /// false otherwise.
713 bool needWaitcntBeforeBarrier() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000714 return getGeneration() < GFX9;
715 }
716
717 /// \returns true if the flat_scratch register should be initialized with the
718 /// pointer to the wave's scratch memory rather than a size and offset.
719 bool flatScratchIsPointer() const {
720 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000721 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000722
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000723 /// \returns SGPR allocation granularity supported by the subtarget.
724 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000725 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000726 }
727
728 /// \returns SGPR encoding granularity supported by the subtarget.
729 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000730 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000731 }
732
733 /// \returns Total number of SGPRs supported by the subtarget.
734 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000735 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000736 }
737
738 /// \returns Addressable number of SGPRs supported by the subtarget.
739 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000740 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000741 }
742
743 /// \returns Minimum number of SGPRs that meets the given number of waves per
744 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000745 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
746 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
747 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000748
749 /// \returns Maximum number of SGPRs that meets the given number of waves per
750 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000751 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
752 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
753 Addressable);
754 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000755
756 /// \returns Reserved number of SGPRs for given function \p MF.
757 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
758
759 /// \returns Maximum number of SGPRs that meets number of waves per execution
760 /// unit requirement for function \p MF, or number of SGPRs explicitly
761 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
762 ///
763 /// \returns Value that meets number of waves per execution unit requirement
764 /// if explicitly requested value cannot be converted to integer, violates
765 /// subtarget's specifications, or does not meet number of waves per execution
766 /// unit requirement.
767 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
768
769 /// \returns VGPR allocation granularity supported by the subtarget.
770 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000771 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());;
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000772 }
773
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000774 /// \returns VGPR encoding granularity supported by the subtarget.
775 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000776 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000777 }
778
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000779 /// \returns Total number of VGPRs supported by the subtarget.
780 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000781 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000782 }
783
784 /// \returns Addressable number of VGPRs supported by the subtarget.
785 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000786 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000787 }
788
789 /// \returns Minimum number of VGPRs that meets given number of waves per
790 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000791 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
792 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
793 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000794
795 /// \returns Maximum number of VGPRs that meets given number of waves per
796 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000797 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
798 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
799 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000800
801 /// \returns Reserved number of VGPRs for given function \p MF.
802 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
803 return debuggerReserveRegs() ? 4 : 0;
804 }
805
806 /// \returns Maximum number of VGPRs that meets number of waves per execution
807 /// unit requirement for function \p MF, or number of VGPRs explicitly
808 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
809 ///
810 /// \returns Value that meets number of waves per execution unit requirement
811 /// if explicitly requested value cannot be converted to integer, violates
812 /// subtarget's specifications, or does not meet number of waves per execution
813 /// unit requirement.
814 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000815};
816
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000817} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000818
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000819#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H