blob: 3bcb701af15ffbd5af15076e92ce0c4b914a51f7 [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,
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +000069 ISAVersion7_0_4,
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,
Yaxun Liu94add852016-10-26 16:37:56 +000073 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +000074 ISAVersion9_0_0,
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +000075 ISAVersion9_0_2
Tom Stellard347ac792015-06-26 21:15:07 +000076 };
77
Wei Ding205bfdb2017-02-10 02:15:29 +000078 enum TrapHandlerAbi {
79 TrapHandlerAbiNone = 0,
80 TrapHandlerAbiHsa = 1
81 };
82
Wei Dingf2cce022017-02-22 23:22:19 +000083 enum TrapID {
84 TrapIDHardwareReserved = 0,
85 TrapIDHSADebugTrap = 1,
86 TrapIDLLVMTrap = 2,
87 TrapIDLLVMDebugTrap = 3,
88 TrapIDDebugBreakpoint = 7,
89 TrapIDDebugReserved8 = 8,
90 TrapIDDebugReservedFE = 0xfe,
91 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +000092 };
93
94 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +000095 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +000096 };
97
Matt Arsenault43e92fe2016-06-24 06:30:11 +000098protected:
99 // Basic subtarget description.
100 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000101 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000102 unsigned IsaVersion;
103 unsigned WavefrontSize;
104 int LocalMemorySize;
105 int LDSBankCount;
106 unsigned MaxPrivateElementSize;
107
108 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000109 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000110 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000111
112 // Dynamially set bits that enable features.
113 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000114 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000115 bool FPExceptions;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000116 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000117 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000118 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000119 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000120 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000121 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000122 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000123 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000124 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000125 bool DebuggerInsertNops;
126 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000127 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000128
129 // Used as options.
Matt Arsenault45b98182017-11-15 00:45:43 +0000130 bool EnableHugePrivateBuffer;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000131 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000132 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000133 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000134 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000135 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000136 bool EnableDS128;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000137 bool DumpCode;
138
139 // Subtarget statically properties set by tablegen
140 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000141 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000142 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000143 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000144 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000145 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000146 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000147 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000148 bool HasSMemRealTime;
149 bool Has16BitInsts;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000150 bool HasIntClamp;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000151 bool HasVOP3PInsts;
Matt Arsenault28f52e52017-10-25 07:00:51 +0000152 bool HasMadMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000153 bool HasMovrel;
154 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000155 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000156 bool HasScalarAtomics;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000157 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000158 bool HasSDWA;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000159 bool HasSDWAOmod;
160 bool HasSDWAScalar;
161 bool HasSDWASdst;
162 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000163 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000164 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000165 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000166 bool FlatInstOffsets;
167 bool FlatGlobalInsts;
168 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000169 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000170 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000171 bool R600ALUInst;
172 bool CaymanISA;
173 bool CFALUBug;
174 bool HasVertexCache;
175 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000176 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000177
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000178 // Dummy feature to use for assembler in tablegen.
179 bool FeatureDisable;
180
Tom Stellard75aadc22012-12-11 21:25:42 +0000181 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000182 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000183 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000184
185public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000186 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
187 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000188 ~AMDGPUSubtarget() override;
189
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000190 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
191 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000192
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000193 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
194 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
195 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
196 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000197
Eric Christopherd9134482014-08-04 21:25:23 +0000198 const InstrItineraryData *getInstrItineraryData() const override {
199 return &InstrItins;
200 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000201
Matt Arsenault56684d42016-08-11 17:31:42 +0000202 // Nothing implemented, just prevent crashes on use.
203 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
204 return &TSInfo;
205 }
206
Craig Topperee7b0f32014-04-30 05:53:27 +0000207 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000208
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000209 bool isAmdHsaOS() const {
210 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000211 }
212
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000213 bool isMesa3DOS() const {
214 return TargetTriple.getOS() == Triple::Mesa3D;
215 }
216
Tim Renouf9f7ead32017-09-29 09:48:12 +0000217 bool isAmdPalOS() const {
218 return TargetTriple.getOS() == Triple::AMDPAL;
219 }
220
Matt Arsenaultd782d052014-06-27 17:57:00 +0000221 Generation getGeneration() const {
222 return Gen;
223 }
224
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000225 unsigned getWavefrontSize() const {
226 return WavefrontSize;
227 }
228
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000229 unsigned getWavefrontSizeLog2() const {
230 return Log2_32(WavefrontSize);
231 }
232
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000233 int getLocalMemorySize() const {
234 return LocalMemorySize;
235 }
236
237 int getLDSBankCount() const {
238 return LDSBankCount;
239 }
240
241 unsigned getMaxPrivateElementSize() const {
242 return MaxPrivateElementSize;
243 }
244
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000245 AMDGPUAS getAMDGPUAS() const {
246 return AS;
247 }
248
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000249 bool has16BitInsts() const {
250 return Has16BitInsts;
251 }
252
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000253 bool hasIntClamp() const {
254 return HasIntClamp;
255 }
256
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000257 bool hasVOP3PInsts() const {
258 return HasVOP3PInsts;
259 }
260
Jan Veselyd1c9b612017-12-04 22:57:29 +0000261 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000262 return FP64;
263 }
264
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000265 bool hasMIMG_R128() const {
266 return MIMG_R128;
267 }
268
Matt Arsenaultb035a572015-01-29 19:34:25 +0000269 bool hasFastFMAF32() const {
270 return FastFMAF32;
271 }
272
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000273 bool hasHalfRate64Ops() const {
274 return HalfRate64Ops;
275 }
276
Matt Arsenault88701812016-06-09 23:42:48 +0000277 bool hasAddr64() const {
278 return (getGeneration() < VOLCANIC_ISLANDS);
279 }
280
Matt Arsenaultfae02982014-03-17 18:58:11 +0000281 bool hasBFE() const {
282 return (getGeneration() >= EVERGREEN);
283 }
284
Matt Arsenault6e439652014-06-10 19:00:20 +0000285 bool hasBFI() const {
286 return (getGeneration() >= EVERGREEN);
287 }
288
Matt Arsenaultfae02982014-03-17 18:58:11 +0000289 bool hasBFM() const {
290 return hasBFE();
291 }
292
Matt Arsenault60425062014-06-10 19:18:28 +0000293 bool hasBCNT(unsigned Size) const {
294 if (Size == 32)
295 return (getGeneration() >= EVERGREEN);
296
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000297 if (Size == 64)
298 return (getGeneration() >= SOUTHERN_ISLANDS);
299
300 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000301 }
302
Tom Stellard50122a52014-04-07 19:45:41 +0000303 bool hasMulU24() const {
304 return (getGeneration() >= EVERGREEN);
305 }
306
307 bool hasMulI24() const {
308 return (getGeneration() >= SOUTHERN_ISLANDS ||
309 hasCaymanISA());
310 }
311
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000312 bool hasFFBL() const {
313 return (getGeneration() >= EVERGREEN);
314 }
315
316 bool hasFFBH() const {
317 return (getGeneration() >= EVERGREEN);
318 }
319
Matt Arsenault10268f92017-02-27 22:40:39 +0000320 bool hasMed3_16() const {
321 return getGeneration() >= GFX9;
322 }
323
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000324 bool hasMin3Max3_16() const {
325 return getGeneration() >= GFX9;
326 }
327
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000328 bool hasMadMixInsts() const {
Matt Arsenault28f52e52017-10-25 07:00:51 +0000329 return HasMadMixInsts;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000330 }
331
Jan Vesely808fff52015-04-30 17:15:56 +0000332 bool hasCARRY() const {
333 return (getGeneration() >= EVERGREEN);
334 }
335
336 bool hasBORROW() const {
337 return (getGeneration() >= EVERGREEN);
338 }
339
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000340 bool hasCaymanISA() const {
341 return CaymanISA;
342 }
343
Jan Vesely39aeab42017-12-04 23:07:28 +0000344 bool hasFMA() const {
345 return FMA;
346 }
347
Wei Ding205bfdb2017-02-10 02:15:29 +0000348 TrapHandlerAbi getTrapHandlerAbi() const {
349 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
350 }
351
Matt Arsenault45b98182017-11-15 00:45:43 +0000352 bool enableHugePrivateBuffer() const {
353 return EnableHugePrivateBuffer;
354 }
355
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000356 bool isPromoteAllocaEnabled() const {
357 return EnablePromoteAlloca;
358 }
359
Matt Arsenault706f9302015-07-06 16:01:58 +0000360 bool unsafeDSOffsetFoldingEnabled() const {
361 return EnableUnsafeDSOffsetFolding;
362 }
363
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000364 bool dumpCode() const {
365 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000366 }
367
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000368 /// Return the amount of LDS that can be used that will not restrict the
369 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000370 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
371 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000372
373 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
374 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000375 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000376
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000377 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
378 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
Matthias Braunf1caa282017-12-15 22:22:58 +0000379 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), MF.getFunction());
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000380 }
381
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000382 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000383 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000384 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000385
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000386 bool hasFP32Denormals() const {
387 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000388 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000389
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000390 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000391 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000392 }
393
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000394 bool supportsMinMaxDenormModes() const {
395 return getGeneration() >= AMDGPUSubtarget::GFX9;
396 }
397
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000398 bool hasFPExceptions() const {
399 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000400 }
401
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000402 bool enableDX10Clamp() const {
403 return DX10Clamp;
404 }
405
406 bool enableIEEEBit(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000407 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000408 }
409
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000410 bool useFlatForGlobal() const {
411 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000412 }
413
Farhana Aleena7cb3112018-03-09 17:41:39 +0000414 /// \returns If target supports ds_read/write_b128 and user enables generation
415 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000416 bool useDS128() const {
417 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000418 }
419
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000420 /// \returns If MUBUF instructions always perform range checking, even for
421 /// buffer resources used for private memory access.
422 bool privateMemoryResourceIsRangeChecked() const {
423 return getGeneration() < AMDGPUSubtarget::GFX9;
424 }
425
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000426 bool hasAutoWaitcntBeforeBarrier() const {
427 return AutoWaitcntBeforeBarrier;
428 }
429
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000430 bool hasCodeObjectV3() const {
431 return CodeObjectV3;
432 }
433
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000434 bool hasUnalignedBufferAccess() const {
435 return UnalignedBufferAccess;
436 }
437
Tom Stellard64a9d082016-10-14 18:10:39 +0000438 bool hasUnalignedScratchAccess() const {
439 return UnalignedScratchAccess;
440 }
441
Matt Arsenaulte823d922017-02-18 18:29:53 +0000442 bool hasApertureRegs() const {
443 return HasApertureRegs;
444 }
445
Wei Ding205bfdb2017-02-10 02:15:29 +0000446 bool isTrapHandlerEnabled() const {
447 return TrapHandler;
448 }
449
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000450 bool isXNACKEnabled() const {
451 return EnableXNACK;
452 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000453
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000454 bool hasFlatAddressSpace() const {
455 return FlatAddressSpace;
456 }
457
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000458 bool hasFlatInstOffsets() const {
459 return FlatInstOffsets;
460 }
461
462 bool hasFlatGlobalInsts() const {
463 return FlatGlobalInsts;
464 }
465
466 bool hasFlatScratchInsts() const {
467 return FlatScratchInsts;
468 }
469
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000470 bool hasD16LoadStore() const {
471 return getGeneration() >= GFX9;
472 }
473
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000474 /// Return if most LDS instructions have an m0 use that require m0 to be
475 /// iniitalized.
476 bool ldsRequiresM0Init() const {
477 return getGeneration() < GFX9;
478 }
479
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000480 bool hasAddNoCarry() const {
481 return AddNoCarryInsts;
482 }
483
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000484 bool hasUnpackedD16VMem() const {
485 return HasUnpackedD16VMem;
486 }
487
Tom Stellard2f3f9852017-01-25 01:25:13 +0000488 bool isMesaKernel(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000489 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction().getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000490 }
491
492 // Covers VS/PS/CS graphics shaders
493 bool isMesaGfxShader(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000494 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction().getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000495 }
496
497 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
498 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000499 }
500
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000501 bool hasMad64_32() const {
502 return getGeneration() >= SEA_ISLANDS;
503 }
504
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000505 bool hasFminFmaxLegacy() const {
506 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
507 }
508
Stanislav Mekhanoshin53a21292017-05-23 19:54:48 +0000509 bool hasSDWA() const {
510 return HasSDWA;
511 }
512
Sam Kolton3c4933f2017-06-22 06:26:41 +0000513 bool hasSDWAOmod() const {
514 return HasSDWAOmod;
515 }
516
517 bool hasSDWAScalar() const {
518 return HasSDWAScalar;
519 }
520
521 bool hasSDWASdst() const {
522 return HasSDWASdst;
523 }
524
525 bool hasSDWAMac() const {
526 return HasSDWAMac;
527 }
528
Sam Koltona179d252017-06-27 15:02:23 +0000529 bool hasSDWAOutModsVOPC() const {
530 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000531 }
532
Mark Searles2a19af62018-04-26 16:11:19 +0000533 bool vmemWriteNeedsExpWaitcnt() const {
534 return getGeneration() < SEA_ISLANDS;
535 }
536
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000537 /// \brief Returns the offset in bytes from the start of the input buffer
538 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000539 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
540 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000541 }
542
Tom Stellardb2869eb2016-09-09 19:28:00 +0000543 unsigned getAlignmentForImplicitArgPtr() const {
544 return isAmdHsaOS() ? 8 : 4;
545 }
546
Tony Tye7a893d42018-03-23 18:45:18 +0000547 /// \returns Number of bytes of arguments that are passed to a shader or
548 /// kernel in addition to the explicit ones declared for the function.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000549 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
550 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000551 return 16;
Tony Tye7a893d42018-03-23 18:45:18 +0000552 return AMDGPU::getIntegerAttribute(
553 MF.getFunction(), "amdgpu-implicitarg-num-bytes", 0);
Tom Stellarde88bbc32016-09-23 01:33:26 +0000554 }
555
Matt Arsenault869fec22017-04-17 19:48:24 +0000556 // Scratch is allocated in 256 dword per wave blocks for the entire
557 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
558 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000559 //
560 // Only 4-byte alignment is really needed to access anything. Transformations
561 // on the pointer value itself may rely on the alignment / known low bits of
562 // the pointer. Set this to something above the minimum to avoid needing
563 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000564 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000565 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000566 }
Tom Stellard347ac792015-06-26 21:15:07 +0000567
Craig Topper5656db42014-04-29 07:57:24 +0000568 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000569 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000570 }
571
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000572 bool enableSubRegLiveness() const override {
573 return true;
574 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000575
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000576 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
577 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
578
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000579 /// \returns Number of execution units per compute unit supported by the
580 /// subtarget.
581 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000582 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000583 }
584
585 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000586 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000587 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000588 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
589 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000590 }
591
592 /// \returns Maximum number of waves per compute unit supported by the
593 /// subtarget without any kind of limitation.
594 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000595 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000596 }
597
598 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000599 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000600 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000601 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
602 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000603 }
604
605 /// \returns Minimum number of waves per execution unit supported by the
606 /// subtarget.
607 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000608 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000609 }
610
611 /// \returns Maximum number of waves per execution unit supported by the
612 /// subtarget without any kind of limitation.
613 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000614 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000615 }
616
617 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000618 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000619 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000620 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
621 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000622 }
623
624 /// \returns Minimum flat work group size supported by the subtarget.
625 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000626 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000627 }
628
629 /// \returns Maximum flat work group size supported by the subtarget.
630 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000631 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000632 }
633
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000634 /// \returns Number of waves per work group supported by the subtarget and
635 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000636 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000637 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
638 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000639 }
640
Matt Arsenaultb7918022017-10-23 17:09:35 +0000641 /// \returns Default range flat work group size for a calling convention.
642 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
643
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000644 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
645 /// for function \p F, or minimum/maximum flat work group sizes explicitly
646 /// requested using "amdgpu-flat-work-group-size" attribute attached to
647 /// function \p F.
648 ///
649 /// \returns Subtarget's default values if explicitly requested values cannot
650 /// be converted to integer, or violate subtarget's specifications.
651 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
652
653 /// \returns Subtarget's default pair of minimum/maximum number of waves per
654 /// execution unit for function \p F, or minimum/maximum number of waves per
655 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
656 /// attached to function \p F.
657 ///
658 /// \returns Subtarget's default values if explicitly requested values cannot
659 /// be converted to integer, violate subtarget's specifications, or are not
660 /// compatible with minimum/maximum number of waves limited by flat work group
661 /// size, register usage, and/or lds usage.
662 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000663
664 /// Creates value range metadata on an workitemid.* inrinsic call or load.
665 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000666};
667
668class R600Subtarget final : public AMDGPUSubtarget {
669private:
670 R600InstrInfo InstrInfo;
671 R600FrameLowering FrameLowering;
672 R600TargetLowering TLInfo;
673
674public:
675 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
676 const TargetMachine &TM);
677
678 const R600InstrInfo *getInstrInfo() const override {
679 return &InstrInfo;
680 }
681
682 const R600FrameLowering *getFrameLowering() const override {
683 return &FrameLowering;
684 }
685
686 const R600TargetLowering *getTargetLowering() const override {
687 return &TLInfo;
688 }
689
690 const R600RegisterInfo *getRegisterInfo() const override {
691 return &InstrInfo.getRegisterInfo();
692 }
693
694 bool hasCFAluBug() const {
695 return CFALUBug;
696 }
697
698 bool hasVertexCache() const {
699 return HasVertexCache;
700 }
701
702 short getTexVTXClauseSize() const {
703 return TexVTXClauseSize;
704 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000705};
706
707class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000708private:
709 SIInstrInfo InstrInfo;
710 SIFrameLowering FrameLowering;
711 SITargetLowering TLInfo;
Quentin Colombet61d71a12017-08-15 22:31:51 +0000712
713 /// GlobalISel related APIs.
714 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
715 std::unique_ptr<InstructionSelector> InstSelector;
716 std::unique_ptr<LegalizerInfo> Legalizer;
717 std::unique_ptr<RegisterBankInfo> RegBankInfo;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000718
719public:
720 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
Matt Arsenaultc3fe46b2018-03-08 16:24:16 +0000721 const GCNTargetMachine &TM);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000722
723 const SIInstrInfo *getInstrInfo() const override {
724 return &InstrInfo;
725 }
726
727 const SIFrameLowering *getFrameLowering() const override {
728 return &FrameLowering;
729 }
730
731 const SITargetLowering *getTargetLowering() const override {
732 return &TLInfo;
733 }
734
735 const CallLowering *getCallLowering() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000736 return CallLoweringInfo.get();
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000737 }
738
Tom Stellardca166212017-01-30 21:56:46 +0000739 const InstructionSelector *getInstructionSelector() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000740 return InstSelector.get();
Tom Stellardca166212017-01-30 21:56:46 +0000741 }
742
743 const LegalizerInfo *getLegalizerInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000744 return Legalizer.get();
Tom Stellardca166212017-01-30 21:56:46 +0000745 }
746
747 const RegisterBankInfo *getRegBankInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000748 return RegBankInfo.get();
Tom Stellardca166212017-01-30 21:56:46 +0000749 }
750
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000751 const SIRegisterInfo *getRegisterInfo() const override {
752 return &InstrInfo.getRegisterInfo();
753 }
754
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000755 // XXX - Why is this here if it isn't in the default pass set?
756 bool enableEarlyIfConversion() const override {
757 return true;
758 }
759
Tom Stellard83f0bce2015-01-29 16:55:25 +0000760 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000761 unsigned NumRegionInstrs) const override;
762
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000763 bool isVGPRSpillingEnabled(const Function& F) const;
764
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000765 unsigned getMaxNumUserSGPRs() const {
766 return 16;
767 }
768
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000769 bool hasSMemRealTime() const {
770 return HasSMemRealTime;
771 }
772
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000773 bool hasMovrel() const {
774 return HasMovrel;
775 }
776
777 bool hasVGPRIndexMode() const {
778 return HasVGPRIndexMode;
779 }
780
Marek Olsake22fdb92017-03-21 17:00:32 +0000781 bool useVGPRIndexMode(bool UserEnable) const {
782 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
783 }
784
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000785 bool hasScalarCompareEq64() const {
786 return getGeneration() >= VOLCANIC_ISLANDS;
787 }
788
Matt Arsenault7b647552016-10-28 21:55:15 +0000789 bool hasScalarStores() const {
790 return HasScalarStores;
791 }
792
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000793 bool hasScalarAtomics() const {
794 return HasScalarAtomics;
795 }
796
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000797 bool hasInv2PiInlineImm() const {
798 return HasInv2PiInlineImm;
799 }
800
Sam Kolton07dbde22017-01-20 10:01:25 +0000801 bool hasDPP() const {
802 return HasDPP;
803 }
804
Tom Stellardde008d32016-01-21 04:28:34 +0000805 bool enableSIScheduler() const {
806 return EnableSIScheduler;
807 }
808
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000809 bool debuggerSupported() const {
810 return debuggerInsertNops() && debuggerReserveRegs() &&
811 debuggerEmitPrologue();
812 }
813
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000814 bool debuggerInsertNops() const {
815 return DebuggerInsertNops;
816 }
817
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000818 bool debuggerReserveRegs() const {
819 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000820 }
821
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000822 bool debuggerEmitPrologue() const {
823 return DebuggerEmitPrologue;
824 }
825
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000826 bool loadStoreOptEnabled() const {
827 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000828 }
829
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000830 bool hasSGPRInitBug() const {
831 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000832 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000833
Tom Stellardb133fbb2016-10-27 23:05:31 +0000834 bool has12DWordStoreHazard() const {
835 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
836 }
837
Matt Arsenaulte823d922017-02-18 18:29:53 +0000838 bool hasSMovFedHazard() const {
839 return getGeneration() >= AMDGPUSubtarget::GFX9;
840 }
841
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000842 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000843 return getGeneration() >= AMDGPUSubtarget::GFX9;
844 }
845
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000846 bool hasReadM0SendMsgHazard() const {
847 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
848 }
849
Matt Arsenault9166ce82017-07-28 15:52:08 +0000850 unsigned getKernArgSegmentSize(const MachineFunction &MF,
851 unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000852
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000853 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
854 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
855
856 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
857 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000858
Matt Arsenaulte823d922017-02-18 18:29:53 +0000859 /// \returns true if the flat_scratch register should be initialized with the
860 /// pointer to the wave's scratch memory rather than a size and offset.
861 bool flatScratchIsPointer() const {
862 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000863 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000864
Tim Renouf832f90f2018-02-26 14:46:43 +0000865 /// \returns true if the machine has merged shaders in which s0-s7 are
866 /// reserved by the hardware and user SGPRs start at s8
867 bool hasMergedShaders() const {
868 return getGeneration() >= GFX9;
869 }
870
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000871 /// \returns SGPR allocation granularity supported by the subtarget.
872 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000873 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000874 }
875
876 /// \returns SGPR encoding granularity supported by the subtarget.
877 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000878 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000879 }
880
881 /// \returns Total number of SGPRs supported by the subtarget.
882 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000883 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000884 }
885
886 /// \returns Addressable number of SGPRs supported by the subtarget.
887 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000888 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000889 }
890
891 /// \returns Minimum number of SGPRs that meets the given number of waves per
892 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000893 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
894 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
895 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000896
897 /// \returns Maximum number of SGPRs that meets the given number of waves per
898 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000899 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
900 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
901 Addressable);
902 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000903
904 /// \returns Reserved number of SGPRs for given function \p MF.
905 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
906
907 /// \returns Maximum number of SGPRs that meets number of waves per execution
908 /// unit requirement for function \p MF, or number of SGPRs explicitly
909 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
910 ///
911 /// \returns Value that meets number of waves per execution unit requirement
912 /// if explicitly requested value cannot be converted to integer, violates
913 /// subtarget's specifications, or does not meet number of waves per execution
914 /// unit requirement.
915 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
916
917 /// \returns VGPR allocation granularity supported by the subtarget.
918 unsigned getVGPRAllocGranule() const {
Mandeep Singh Grang5e1697e2017-06-06 05:08:36 +0000919 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000920 }
921
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000922 /// \returns VGPR encoding granularity supported by the subtarget.
923 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000924 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000925 }
926
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000927 /// \returns Total number of VGPRs supported by the subtarget.
928 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000929 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000930 }
931
932 /// \returns Addressable number of VGPRs supported by the subtarget.
933 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000934 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000935 }
936
937 /// \returns Minimum number of VGPRs that meets given number of waves per
938 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000939 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
940 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
941 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000942
943 /// \returns Maximum number of VGPRs that meets given number of waves per
944 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000945 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
946 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
947 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000948
949 /// \returns Reserved number of VGPRs for given function \p MF.
950 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
951 return debuggerReserveRegs() ? 4 : 0;
952 }
953
954 /// \returns Maximum number of VGPRs that meets number of waves per execution
955 /// unit requirement for function \p MF, or number of VGPRs explicitly
956 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
957 ///
958 /// \returns Value that meets number of waves per execution unit requirement
959 /// if explicitly requested value cannot be converted to integer, violates
960 /// subtarget's specifications, or does not meet number of waves per execution
961 /// unit requirement.
962 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000963
964 void getPostRAMutations(
965 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
966 const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000967};
968
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000969} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000970
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000971#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H