blob: 2cc48a7f9f20b61d6e6453b40b59d84a130678ea [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"
Quentin Colombet61d71a12017-08-15 22:31:51 +000019#include "AMDGPUCallLowering.h"
Matt Arsenault43e92fe2016-06-24 06:30:11 +000020#include "R600FrameLowering.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000021#include "R600ISelLowering.h"
22#include "R600InstrInfo.h"
Matt Arsenault43e92fe2016-06-24 06:30:11 +000023#include "SIFrameLowering.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000024#include "SIISelLowering.h"
25#include "SIInstrInfo.h"
Valery Pykhtinfd4c4102017-03-21 13:15:46 +000026#include "SIMachineFunctionInfo.h"
Tom Stellard347ac792015-06-26 21:15:07 +000027#include "Utils/AMDGPUBaseInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000028#include "llvm/ADT/Triple.h"
Quentin Colombet61d71a12017-08-15 22:31:51 +000029#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
30#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
31#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000032#include "llvm/CodeGen/MachineFunction.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000033#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000034#include "llvm/MC/MCInstrItineraries.h"
35#include "llvm/Support/MathExtras.h"
36#include <cassert>
37#include <cstdint>
38#include <memory>
39#include <utility>
Tom Stellard75aadc22012-12-11 21:25:42 +000040
41#define GET_SUBTARGETINFO_HEADER
42#include "AMDGPUGenSubtargetInfo.inc"
43
Tom Stellard75aadc22012-12-11 21:25:42 +000044namespace llvm {
45
Matt Arsenault43e92fe2016-06-24 06:30:11 +000046class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000047
Tom Stellard75aadc22012-12-11 21:25:42 +000048class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000049public:
50 enum Generation {
51 R600 = 0,
52 R700,
53 EVERGREEN,
54 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000055 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000056 SEA_ISLANDS,
57 VOLCANIC_ISLANDS,
Matt Arsenaulte823d922017-02-18 18:29:53 +000058 GFX9,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000059 };
60
Marek Olsak4d00dd22015-03-09 15:48:09 +000061 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000062 ISAVersion0_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +000063 ISAVersion6_0_0,
64 ISAVersion6_0_1,
Tom Stellard347ac792015-06-26 21:15:07 +000065 ISAVersion7_0_0,
66 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +000067 ISAVersion7_0_2,
Wei Ding7c3e5112017-06-10 03:53:19 +000068 ISAVersion7_0_3,
Tom Stellard347ac792015-06-26 21:15:07 +000069 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000070 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +000071 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +000072 ISAVersion8_0_3,
73 ISAVersion8_0_4,
74 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +000075 ISAVersion9_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +000076 ISAVersion9_0_1,
77 ISAVersion9_0_2,
78 ISAVersion9_0_3
Tom Stellard347ac792015-06-26 21:15:07 +000079 };
80
Wei Ding205bfdb2017-02-10 02:15:29 +000081 enum TrapHandlerAbi {
82 TrapHandlerAbiNone = 0,
83 TrapHandlerAbiHsa = 1
84 };
85
Wei Dingf2cce022017-02-22 23:22:19 +000086 enum TrapID {
87 TrapIDHardwareReserved = 0,
88 TrapIDHSADebugTrap = 1,
89 TrapIDLLVMTrap = 2,
90 TrapIDLLVMDebugTrap = 3,
91 TrapIDDebugBreakpoint = 7,
92 TrapIDDebugReserved8 = 8,
93 TrapIDDebugReservedFE = 0xfe,
94 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +000095 };
96
97 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +000098 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +000099 };
100
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000101protected:
102 // Basic subtarget description.
103 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000104 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000105 unsigned IsaVersion;
106 unsigned WavefrontSize;
107 int LocalMemorySize;
108 int LDSBankCount;
109 unsigned MaxPrivateElementSize;
110
111 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000112 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000113 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000114
115 // Dynamially set bits that enable features.
116 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000117 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000118 bool FPExceptions;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000119 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000120 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000121 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000122 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000123 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000124 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000125 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000126 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000127 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000128 bool DebuggerInsertNops;
129 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000130 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000131
132 // Used as options.
133 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000134 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000135 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000136 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000137 bool EnableSIScheduler;
138 bool DumpCode;
139
140 // Subtarget statically properties set by tablegen
141 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000142 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000143 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000144 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000145 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000146 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000147 bool HasSMemRealTime;
148 bool Has16BitInsts;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000149 bool HasIntClamp;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000150 bool HasVOP3PInsts;
Matt Arsenault28f52e52017-10-25 07:00:51 +0000151 bool HasMadMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000152 bool HasMovrel;
153 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000154 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000155 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000156 bool HasSDWA;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000157 bool HasSDWAOmod;
158 bool HasSDWAScalar;
159 bool HasSDWASdst;
160 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000161 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000162 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000163 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000164 bool FlatInstOffsets;
165 bool FlatGlobalInsts;
166 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000167 bool AddNoCarryInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000168 bool R600ALUInst;
169 bool CaymanISA;
170 bool CFALUBug;
171 bool HasVertexCache;
172 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000173 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000174
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000175 // Dummy feature to use for assembler in tablegen.
176 bool FeatureDisable;
177
Tom Stellard75aadc22012-12-11 21:25:42 +0000178 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000179 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000180 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000181
182public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000183 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
184 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000185 ~AMDGPUSubtarget() override;
186
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000187 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
188 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000189
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000190 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
191 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
192 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
193 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000194
Eric Christopherd9134482014-08-04 21:25:23 +0000195 const InstrItineraryData *getInstrItineraryData() const override {
196 return &InstrItins;
197 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000198
Matt Arsenault56684d42016-08-11 17:31:42 +0000199 // Nothing implemented, just prevent crashes on use.
200 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
201 return &TSInfo;
202 }
203
Craig Topperee7b0f32014-04-30 05:53:27 +0000204 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000205
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000206 bool isAmdHsaOS() const {
207 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000208 }
209
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000210 bool isMesa3DOS() const {
211 return TargetTriple.getOS() == Triple::Mesa3D;
212 }
213
Tom Stellarde88bbc32016-09-23 01:33:26 +0000214 bool isOpenCLEnv() const {
Yaxun Liua618acf2017-06-01 21:31:53 +0000215 return TargetTriple.getEnvironment() == Triple::OpenCL ||
216 TargetTriple.getEnvironmentName() == "amdgizcl";
Tom Stellarde88bbc32016-09-23 01:33:26 +0000217 }
218
Tim Renouf9f7ead32017-09-29 09:48:12 +0000219 bool isAmdPalOS() const {
220 return TargetTriple.getOS() == Triple::AMDPAL;
221 }
222
Matt Arsenaultd782d052014-06-27 17:57:00 +0000223 Generation getGeneration() const {
224 return Gen;
225 }
226
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000227 unsigned getWavefrontSize() const {
228 return WavefrontSize;
229 }
230
231 int getLocalMemorySize() const {
232 return LocalMemorySize;
233 }
234
235 int getLDSBankCount() const {
236 return LDSBankCount;
237 }
238
239 unsigned getMaxPrivateElementSize() const {
240 return MaxPrivateElementSize;
241 }
242
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000243 AMDGPUAS getAMDGPUAS() const {
244 return AS;
245 }
246
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000247 bool has16BitInsts() const {
248 return Has16BitInsts;
249 }
250
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000251 bool hasIntClamp() const {
252 return HasIntClamp;
253 }
254
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000255 bool hasVOP3PInsts() const {
256 return HasVOP3PInsts;
257 }
258
Matt Arsenaultd782d052014-06-27 17:57:00 +0000259 bool hasHWFP64() const {
260 return FP64;
261 }
262
Matt Arsenaultb035a572015-01-29 19:34:25 +0000263 bool hasFastFMAF32() const {
264 return FastFMAF32;
265 }
266
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000267 bool hasHalfRate64Ops() const {
268 return HalfRate64Ops;
269 }
270
Matt Arsenault88701812016-06-09 23:42:48 +0000271 bool hasAddr64() const {
272 return (getGeneration() < VOLCANIC_ISLANDS);
273 }
274
Matt Arsenaultfae02982014-03-17 18:58:11 +0000275 bool hasBFE() const {
276 return (getGeneration() >= EVERGREEN);
277 }
278
Matt Arsenault6e439652014-06-10 19:00:20 +0000279 bool hasBFI() const {
280 return (getGeneration() >= EVERGREEN);
281 }
282
Matt Arsenaultfae02982014-03-17 18:58:11 +0000283 bool hasBFM() const {
284 return hasBFE();
285 }
286
Matt Arsenault60425062014-06-10 19:18:28 +0000287 bool hasBCNT(unsigned Size) const {
288 if (Size == 32)
289 return (getGeneration() >= EVERGREEN);
290
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000291 if (Size == 64)
292 return (getGeneration() >= SOUTHERN_ISLANDS);
293
294 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000295 }
296
Tom Stellard50122a52014-04-07 19:45:41 +0000297 bool hasMulU24() const {
298 return (getGeneration() >= EVERGREEN);
299 }
300
301 bool hasMulI24() const {
302 return (getGeneration() >= SOUTHERN_ISLANDS ||
303 hasCaymanISA());
304 }
305
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000306 bool hasFFBL() const {
307 return (getGeneration() >= EVERGREEN);
308 }
309
310 bool hasFFBH() const {
311 return (getGeneration() >= EVERGREEN);
312 }
313
Matt Arsenault10268f92017-02-27 22:40:39 +0000314 bool hasMed3_16() const {
315 return getGeneration() >= GFX9;
316 }
317
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000318 bool hasMin3Max3_16() const {
319 return getGeneration() >= GFX9;
320 }
321
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000322 bool hasMadMixInsts() const {
Matt Arsenault28f52e52017-10-25 07:00:51 +0000323 return HasMadMixInsts;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000324 }
325
Marek Olsakb953cc32017-11-09 01:52:23 +0000326 bool hasSBufferLoadStoreAtomicDwordxN() const {
327 // Only use the "x1" variants on GFX9 or don't use the buffer variants.
328 // For x2 and higher variants, if the accessed region spans 2 VM pages and
329 // the second page is unmapped, the hw hangs.
330 // TODO: There is one future GFX9 chip that doesn't have this bug.
331 return getGeneration() != GFX9;
332 }
333
Jan Vesely808fff52015-04-30 17:15:56 +0000334 bool hasCARRY() const {
335 return (getGeneration() >= EVERGREEN);
336 }
337
338 bool hasBORROW() const {
339 return (getGeneration() >= EVERGREEN);
340 }
341
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000342 bool hasCaymanISA() const {
343 return CaymanISA;
344 }
345
Wei Ding205bfdb2017-02-10 02:15:29 +0000346 TrapHandlerAbi getTrapHandlerAbi() const {
347 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
348 }
349
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000350 bool isPromoteAllocaEnabled() const {
351 return EnablePromoteAlloca;
352 }
353
Matt Arsenault706f9302015-07-06 16:01:58 +0000354 bool unsafeDSOffsetFoldingEnabled() const {
355 return EnableUnsafeDSOffsetFolding;
356 }
357
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000358 bool dumpCode() const {
359 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000360 }
361
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000362 /// Return the amount of LDS that can be used that will not restrict the
363 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000364 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
365 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000366
367 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
368 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000369 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000370
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000371 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
372 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
373 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
374 }
375
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000376 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000377 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000378 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000379
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000380 bool hasFP32Denormals() const {
381 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000382 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000383
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000384 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000385 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000386 }
387
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000388 bool supportsMinMaxDenormModes() const {
389 return getGeneration() >= AMDGPUSubtarget::GFX9;
390 }
391
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000392 bool hasFPExceptions() const {
393 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000394 }
395
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000396 bool enableDX10Clamp() const {
397 return DX10Clamp;
398 }
399
400 bool enableIEEEBit(const MachineFunction &MF) const {
401 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
402 }
403
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000404 bool useFlatForGlobal() const {
405 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000406 }
407
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000408 bool hasAutoWaitcntBeforeBarrier() const {
409 return AutoWaitcntBeforeBarrier;
410 }
411
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000412 bool hasCodeObjectV3() const {
413 return CodeObjectV3;
414 }
415
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000416 bool hasUnalignedBufferAccess() const {
417 return UnalignedBufferAccess;
418 }
419
Tom Stellard64a9d082016-10-14 18:10:39 +0000420 bool hasUnalignedScratchAccess() const {
421 return UnalignedScratchAccess;
422 }
423
Matt Arsenaulte823d922017-02-18 18:29:53 +0000424 bool hasApertureRegs() const {
425 return HasApertureRegs;
426 }
427
Wei Ding205bfdb2017-02-10 02:15:29 +0000428 bool isTrapHandlerEnabled() const {
429 return TrapHandler;
430 }
431
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000432 bool isXNACKEnabled() const {
433 return EnableXNACK;
434 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000435
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000436 bool hasFlatAddressSpace() const {
437 return FlatAddressSpace;
438 }
439
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000440 bool hasFlatInstOffsets() const {
441 return FlatInstOffsets;
442 }
443
444 bool hasFlatGlobalInsts() const {
445 return FlatGlobalInsts;
446 }
447
448 bool hasFlatScratchInsts() const {
449 return FlatScratchInsts;
450 }
451
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000452 bool hasD16LoadStore() const {
453 return getGeneration() >= GFX9;
454 }
455
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000456 bool hasAddNoCarry() const {
457 return AddNoCarryInsts;
458 }
459
Tom Stellard2f3f9852017-01-25 01:25:13 +0000460 bool isMesaKernel(const MachineFunction &MF) const {
461 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
462 }
463
464 // Covers VS/PS/CS graphics shaders
465 bool isMesaGfxShader(const MachineFunction &MF) const {
466 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
467 }
468
469 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
470 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000471 }
472
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000473 bool hasMad64_32() const {
474 return getGeneration() >= SEA_ISLANDS;
475 }
476
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000477 bool hasFminFmaxLegacy() const {
478 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
479 }
480
Stanislav Mekhanoshin53a21292017-05-23 19:54:48 +0000481 bool hasSDWA() const {
482 return HasSDWA;
483 }
484
Sam Kolton3c4933f2017-06-22 06:26:41 +0000485 bool hasSDWAOmod() const {
486 return HasSDWAOmod;
487 }
488
489 bool hasSDWAScalar() const {
490 return HasSDWAScalar;
491 }
492
493 bool hasSDWASdst() const {
494 return HasSDWASdst;
495 }
496
497 bool hasSDWAMac() const {
498 return HasSDWAMac;
499 }
500
Sam Koltona179d252017-06-27 15:02:23 +0000501 bool hasSDWAOutModsVOPC() const {
502 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000503 }
504
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000505 /// \brief Returns the offset in bytes from the start of the input buffer
506 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000507 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
508 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000509 }
510
Tom Stellardb2869eb2016-09-09 19:28:00 +0000511 unsigned getAlignmentForImplicitArgPtr() const {
512 return isAmdHsaOS() ? 8 : 4;
513 }
514
Tom Stellard2f3f9852017-01-25 01:25:13 +0000515 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
516 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000517 return 16;
518 if (isAmdHsaOS() && isOpenCLEnv())
519 return 32;
520 return 0;
521 }
522
Matt Arsenault869fec22017-04-17 19:48:24 +0000523 // Scratch is allocated in 256 dword per wave blocks for the entire
524 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
525 // is 4-byte aligned.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000526 unsigned getStackAlignment() const {
Matt Arsenault869fec22017-04-17 19:48:24 +0000527 return 4;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000528 }
Tom Stellard347ac792015-06-26 21:15:07 +0000529
Craig Topper5656db42014-04-29 07:57:24 +0000530 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000531 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000532 }
533
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000534 bool enableSubRegLiveness() const override {
535 return true;
536 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000537
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000538 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
539 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
540
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000541 /// \returns Number of execution units per compute unit supported by the
542 /// subtarget.
543 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000544 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000545 }
546
547 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000548 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000549 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000550 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
551 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000552 }
553
554 /// \returns Maximum number of waves per compute unit supported by the
555 /// subtarget without any kind of limitation.
556 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000557 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000558 }
559
560 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000561 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000562 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000563 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
564 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000565 }
566
567 /// \returns Minimum number of waves per execution unit supported by the
568 /// subtarget.
569 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000570 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000571 }
572
573 /// \returns Maximum number of waves per execution unit supported by the
574 /// subtarget without any kind of limitation.
575 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000576 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000577 }
578
579 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000580 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000581 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000582 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
583 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000584 }
585
586 /// \returns Minimum flat work group size supported by the subtarget.
587 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000588 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000589 }
590
591 /// \returns Maximum flat work group size supported by the subtarget.
592 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000593 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000594 }
595
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000596 /// \returns Number of waves per work group supported by the subtarget and
597 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000598 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000599 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
600 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000601 }
602
Matt Arsenaultb7918022017-10-23 17:09:35 +0000603 /// \returns Default range flat work group size for a calling convention.
604 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
605
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000606 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
607 /// for function \p F, or minimum/maximum flat work group sizes explicitly
608 /// requested using "amdgpu-flat-work-group-size" attribute attached to
609 /// function \p F.
610 ///
611 /// \returns Subtarget's default values if explicitly requested values cannot
612 /// be converted to integer, or violate subtarget's specifications.
613 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
614
615 /// \returns Subtarget's default pair of minimum/maximum number of waves per
616 /// execution unit for function \p F, or minimum/maximum number of waves per
617 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
618 /// attached to function \p F.
619 ///
620 /// \returns Subtarget's default values if explicitly requested values cannot
621 /// be converted to integer, violate subtarget's specifications, or are not
622 /// compatible with minimum/maximum number of waves limited by flat work group
623 /// size, register usage, and/or lds usage.
624 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000625
626 /// Creates value range metadata on an workitemid.* inrinsic call or load.
627 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000628};
629
630class R600Subtarget final : public AMDGPUSubtarget {
631private:
632 R600InstrInfo InstrInfo;
633 R600FrameLowering FrameLowering;
634 R600TargetLowering TLInfo;
635
636public:
637 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
638 const TargetMachine &TM);
639
640 const R600InstrInfo *getInstrInfo() const override {
641 return &InstrInfo;
642 }
643
644 const R600FrameLowering *getFrameLowering() const override {
645 return &FrameLowering;
646 }
647
648 const R600TargetLowering *getTargetLowering() const override {
649 return &TLInfo;
650 }
651
652 const R600RegisterInfo *getRegisterInfo() const override {
653 return &InstrInfo.getRegisterInfo();
654 }
655
656 bool hasCFAluBug() const {
657 return CFALUBug;
658 }
659
660 bool hasVertexCache() const {
661 return HasVertexCache;
662 }
663
664 short getTexVTXClauseSize() const {
665 return TexVTXClauseSize;
666 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000667};
668
669class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000670private:
671 SIInstrInfo InstrInfo;
672 SIFrameLowering FrameLowering;
673 SITargetLowering TLInfo;
Quentin Colombet61d71a12017-08-15 22:31:51 +0000674
675 /// GlobalISel related APIs.
676 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
677 std::unique_ptr<InstructionSelector> InstSelector;
678 std::unique_ptr<LegalizerInfo> Legalizer;
679 std::unique_ptr<RegisterBankInfo> RegBankInfo;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000680
681public:
682 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
683 const TargetMachine &TM);
684
685 const SIInstrInfo *getInstrInfo() const override {
686 return &InstrInfo;
687 }
688
689 const SIFrameLowering *getFrameLowering() const override {
690 return &FrameLowering;
691 }
692
693 const SITargetLowering *getTargetLowering() const override {
694 return &TLInfo;
695 }
696
697 const CallLowering *getCallLowering() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000698 return CallLoweringInfo.get();
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000699 }
700
Tom Stellardca166212017-01-30 21:56:46 +0000701 const InstructionSelector *getInstructionSelector() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000702 return InstSelector.get();
Tom Stellardca166212017-01-30 21:56:46 +0000703 }
704
705 const LegalizerInfo *getLegalizerInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000706 return Legalizer.get();
Tom Stellardca166212017-01-30 21:56:46 +0000707 }
708
709 const RegisterBankInfo *getRegBankInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000710 return RegBankInfo.get();
Tom Stellardca166212017-01-30 21:56:46 +0000711 }
712
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000713 const SIRegisterInfo *getRegisterInfo() const override {
714 return &InstrInfo.getRegisterInfo();
715 }
716
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000717 // XXX - Why is this here if it isn't in the default pass set?
718 bool enableEarlyIfConversion() const override {
719 return true;
720 }
721
Tom Stellard83f0bce2015-01-29 16:55:25 +0000722 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000723 unsigned NumRegionInstrs) const override;
724
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000725 bool isVGPRSpillingEnabled(const Function& F) const;
726
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000727 unsigned getMaxNumUserSGPRs() const {
728 return 16;
729 }
730
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000731 bool hasSMemRealTime() const {
732 return HasSMemRealTime;
733 }
734
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000735 bool hasMovrel() const {
736 return HasMovrel;
737 }
738
739 bool hasVGPRIndexMode() const {
740 return HasVGPRIndexMode;
741 }
742
Marek Olsake22fdb92017-03-21 17:00:32 +0000743 bool useVGPRIndexMode(bool UserEnable) const {
744 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
745 }
746
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000747 bool hasScalarCompareEq64() const {
748 return getGeneration() >= VOLCANIC_ISLANDS;
749 }
750
Matt Arsenault7b647552016-10-28 21:55:15 +0000751 bool hasScalarStores() const {
752 return HasScalarStores;
753 }
754
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000755 bool hasInv2PiInlineImm() const {
756 return HasInv2PiInlineImm;
757 }
758
Sam Kolton07dbde22017-01-20 10:01:25 +0000759 bool hasDPP() const {
760 return HasDPP;
761 }
762
Tom Stellardde008d32016-01-21 04:28:34 +0000763 bool enableSIScheduler() const {
764 return EnableSIScheduler;
765 }
766
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000767 bool debuggerSupported() const {
768 return debuggerInsertNops() && debuggerReserveRegs() &&
769 debuggerEmitPrologue();
770 }
771
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000772 bool debuggerInsertNops() const {
773 return DebuggerInsertNops;
774 }
775
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000776 bool debuggerReserveRegs() const {
777 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000778 }
779
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000780 bool debuggerEmitPrologue() const {
781 return DebuggerEmitPrologue;
782 }
783
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000784 bool loadStoreOptEnabled() const {
785 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000786 }
787
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000788 bool hasSGPRInitBug() const {
789 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000790 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000791
Tom Stellardb133fbb2016-10-27 23:05:31 +0000792 bool has12DWordStoreHazard() const {
793 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
794 }
795
Matt Arsenaulte823d922017-02-18 18:29:53 +0000796 bool hasSMovFedHazard() const {
797 return getGeneration() >= AMDGPUSubtarget::GFX9;
798 }
799
800 bool hasReadM0Hazard() const {
801 return getGeneration() >= AMDGPUSubtarget::GFX9;
802 }
803
Matt Arsenault9166ce82017-07-28 15:52:08 +0000804 unsigned getKernArgSegmentSize(const MachineFunction &MF,
805 unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000806
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000807 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
808 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
809
810 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
811 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000812
Matt Arsenaulte823d922017-02-18 18:29:53 +0000813 /// \returns true if the flat_scratch register should be initialized with the
814 /// pointer to the wave's scratch memory rather than a size and offset.
815 bool flatScratchIsPointer() const {
816 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000817 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000818
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000819 /// \returns SGPR allocation granularity supported by the subtarget.
820 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000821 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000822 }
823
824 /// \returns SGPR encoding granularity supported by the subtarget.
825 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000826 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000827 }
828
829 /// \returns Total number of SGPRs supported by the subtarget.
830 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000831 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000832 }
833
834 /// \returns Addressable number of SGPRs supported by the subtarget.
835 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000836 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000837 }
838
839 /// \returns Minimum number of SGPRs that meets the given number of waves per
840 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000841 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
842 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
843 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000844
845 /// \returns Maximum number of SGPRs that meets the given number of waves per
846 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000847 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
848 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
849 Addressable);
850 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000851
852 /// \returns Reserved number of SGPRs for given function \p MF.
853 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
854
855 /// \returns Maximum number of SGPRs that meets number of waves per execution
856 /// unit requirement for function \p MF, or number of SGPRs explicitly
857 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
858 ///
859 /// \returns Value that meets number of waves per execution unit requirement
860 /// if explicitly requested value cannot be converted to integer, violates
861 /// subtarget's specifications, or does not meet number of waves per execution
862 /// unit requirement.
863 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
864
865 /// \returns VGPR allocation granularity supported by the subtarget.
866 unsigned getVGPRAllocGranule() const {
Mandeep Singh Grang5e1697e2017-06-06 05:08:36 +0000867 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000868 }
869
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000870 /// \returns VGPR encoding granularity supported by the subtarget.
871 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000872 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000873 }
874
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000875 /// \returns Total number of VGPRs supported by the subtarget.
876 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000877 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000878 }
879
880 /// \returns Addressable number of VGPRs supported by the subtarget.
881 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000882 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000883 }
884
885 /// \returns Minimum number of VGPRs that meets given number of waves per
886 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000887 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
888 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
889 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000890
891 /// \returns Maximum number of VGPRs that meets given number of waves per
892 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000893 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
894 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
895 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000896
897 /// \returns Reserved number of VGPRs for given function \p MF.
898 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
899 return debuggerReserveRegs() ? 4 : 0;
900 }
901
902 /// \returns Maximum number of VGPRs that meets number of waves per execution
903 /// unit requirement for function \p MF, or number of VGPRs explicitly
904 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
905 ///
906 /// \returns Value that meets number of waves per execution unit requirement
907 /// if explicitly requested value cannot be converted to integer, violates
908 /// subtarget's specifications, or does not meet number of waves per execution
909 /// unit requirement.
910 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000911
912 void getPostRAMutations(
913 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
914 const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000915};
916
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000917} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000918
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000919#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H