blob: b4b0873eaf3735ad12bf1cb07525cf4aabab3990 [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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011/// AMDGPU specific subclass of TargetSubtarget.
Tom Stellard75aadc22012-12-11 21:25:42 +000012//
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"
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"
Quentin Colombet61d71a12017-08-15 22:31:51 +000028#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
29#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
30#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000031#include "llvm/CodeGen/MachineFunction.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000032#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000033#include "llvm/MC/MCInstrItineraries.h"
34#include "llvm/Support/MathExtras.h"
35#include <cassert>
36#include <cstdint>
37#include <memory>
38#include <utility>
Tom Stellard75aadc22012-12-11 21:25:42 +000039
40#define GET_SUBTARGETINFO_HEADER
41#include "AMDGPUGenSubtargetInfo.inc"
42
Tom Stellard75aadc22012-12-11 21:25:42 +000043namespace llvm {
44
Matt Arsenault43e92fe2016-06-24 06:30:11 +000045class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000046
Tom Stellard75aadc22012-12-11 21:25:42 +000047class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000048public:
49 enum Generation {
50 R600 = 0,
51 R700,
52 EVERGREEN,
53 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000054 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000055 SEA_ISLANDS,
56 VOLCANIC_ISLANDS,
Matt Arsenaulte823d922017-02-18 18:29:53 +000057 GFX9,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000058 };
59
Marek Olsak4d00dd22015-03-09 15:48:09 +000060 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000061 ISAVersion0_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +000062 ISAVersion6_0_0,
63 ISAVersion6_0_1,
Tom Stellard347ac792015-06-26 21:15:07 +000064 ISAVersion7_0_0,
65 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +000066 ISAVersion7_0_2,
Wei Ding7c3e5112017-06-10 03:53:19 +000067 ISAVersion7_0_3,
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +000068 ISAVersion7_0_4,
Changpeng Fangc16be002016-01-13 20:39:25 +000069 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +000070 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +000071 ISAVersion8_0_3,
Yaxun Liu94add852016-10-26 16:37:56 +000072 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +000073 ISAVersion9_0_0,
Matt Arsenault0084adc2018-04-30 19:08:16 +000074 ISAVersion9_0_2,
75 ISAVersion9_0_4,
Konstantin Zhuravlyov1501af42018-05-01 18:47:48 +000076 ISAVersion9_0_6,
Tom Stellard347ac792015-06-26 21:15:07 +000077 };
78
Wei Ding205bfdb2017-02-10 02:15:29 +000079 enum TrapHandlerAbi {
80 TrapHandlerAbiNone = 0,
81 TrapHandlerAbiHsa = 1
82 };
83
Wei Dingf2cce022017-02-22 23:22:19 +000084 enum TrapID {
85 TrapIDHardwareReserved = 0,
86 TrapIDHSADebugTrap = 1,
87 TrapIDLLVMTrap = 2,
88 TrapIDLLVMDebugTrap = 3,
89 TrapIDDebugBreakpoint = 7,
90 TrapIDDebugReserved8 = 8,
91 TrapIDDebugReservedFE = 0xfe,
92 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +000093 };
94
95 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +000096 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +000097 };
98
Matt Arsenault43e92fe2016-06-24 06:30:11 +000099protected:
100 // Basic subtarget description.
101 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000102 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000103 unsigned IsaVersion;
104 unsigned WavefrontSize;
105 int LocalMemorySize;
106 int LDSBankCount;
107 unsigned MaxPrivateElementSize;
108
109 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000110 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000111 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000112
113 // Dynamially set bits that enable features.
114 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000115 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000116 bool FPExceptions;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000117 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000118 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000119 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000120 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000121 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000122 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000123 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000124 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000125 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000126 bool DebuggerInsertNops;
127 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000128 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000129
130 // Used as options.
Matt Arsenault45b98182017-11-15 00:45:43 +0000131 bool EnableHugePrivateBuffer;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000132 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000133 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000134 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000135 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000136 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000137 bool EnableDS128;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000138 bool DumpCode;
139
140 // Subtarget statically properties set by tablegen
141 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000142 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000143 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000144 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000145 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000146 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000147 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000148 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000149 bool HasSMemRealTime;
150 bool Has16BitInsts;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000151 bool HasIntClamp;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000152 bool HasVOP3PInsts;
Matt Arsenault28f52e52017-10-25 07:00:51 +0000153 bool HasMadMixInsts;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000154 bool HasFmaMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000155 bool HasMovrel;
156 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000157 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000158 bool HasScalarAtomics;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000159 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000160 bool HasSDWA;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000161 bool HasSDWAOmod;
162 bool HasSDWAScalar;
163 bool HasSDWASdst;
164 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000165 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000166 bool HasDPP;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000167 bool HasDLInsts;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000168 bool D16PreservesUnusedBits;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000169 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000170 bool FlatInstOffsets;
171 bool FlatGlobalInsts;
172 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000173 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000174 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000175 bool R600ALUInst;
176 bool CaymanISA;
177 bool CFALUBug;
178 bool HasVertexCache;
179 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000180 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000181
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000182 // Dummy feature to use for assembler in tablegen.
183 bool FeatureDisable;
184
Tom Stellard75aadc22012-12-11 21:25:42 +0000185 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000186 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000187 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000188
189public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000190 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
191 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000192 ~AMDGPUSubtarget() override;
193
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000194 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
195 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000196
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000197 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
198 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
199 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
200 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000201
Eric Christopherd9134482014-08-04 21:25:23 +0000202 const InstrItineraryData *getInstrItineraryData() const override {
203 return &InstrItins;
204 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000205
Matt Arsenault56684d42016-08-11 17:31:42 +0000206 // Nothing implemented, just prevent crashes on use.
207 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
208 return &TSInfo;
209 }
210
Craig Topperee7b0f32014-04-30 05:53:27 +0000211 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000212
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000213 bool isAmdHsaOS() const {
214 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000215 }
216
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000217 bool isMesa3DOS() const {
218 return TargetTriple.getOS() == Triple::Mesa3D;
219 }
220
Tim Renouf9f7ead32017-09-29 09:48:12 +0000221 bool isAmdPalOS() const {
222 return TargetTriple.getOS() == Triple::AMDPAL;
223 }
224
Matt Arsenaultd782d052014-06-27 17:57:00 +0000225 Generation getGeneration() const {
226 return Gen;
227 }
228
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000229 unsigned getWavefrontSize() const {
230 return WavefrontSize;
231 }
232
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000233 unsigned getWavefrontSizeLog2() const {
234 return Log2_32(WavefrontSize);
235 }
236
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000237 int getLocalMemorySize() const {
238 return LocalMemorySize;
239 }
240
241 int getLDSBankCount() const {
242 return LDSBankCount;
243 }
244
245 unsigned getMaxPrivateElementSize() const {
246 return MaxPrivateElementSize;
247 }
248
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000249 AMDGPUAS getAMDGPUAS() const {
250 return AS;
251 }
252
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000253 bool has16BitInsts() const {
254 return Has16BitInsts;
255 }
256
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000257 bool hasIntClamp() const {
258 return HasIntClamp;
259 }
260
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000261 bool hasVOP3PInsts() const {
262 return HasVOP3PInsts;
263 }
264
Jan Veselyd1c9b612017-12-04 22:57:29 +0000265 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000266 return FP64;
267 }
268
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000269 bool hasMIMG_R128() const {
270 return MIMG_R128;
271 }
272
Matt Arsenaultb035a572015-01-29 19:34:25 +0000273 bool hasFastFMAF32() const {
274 return FastFMAF32;
275 }
276
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000277 bool hasHalfRate64Ops() const {
278 return HalfRate64Ops;
279 }
280
Matt Arsenault88701812016-06-09 23:42:48 +0000281 bool hasAddr64() const {
282 return (getGeneration() < VOLCANIC_ISLANDS);
283 }
284
Matt Arsenaultfae02982014-03-17 18:58:11 +0000285 bool hasBFE() const {
286 return (getGeneration() >= EVERGREEN);
287 }
288
Matt Arsenault6e439652014-06-10 19:00:20 +0000289 bool hasBFI() const {
290 return (getGeneration() >= EVERGREEN);
291 }
292
Matt Arsenaultfae02982014-03-17 18:58:11 +0000293 bool hasBFM() const {
294 return hasBFE();
295 }
296
Matt Arsenault60425062014-06-10 19:18:28 +0000297 bool hasBCNT(unsigned Size) const {
298 if (Size == 32)
299 return (getGeneration() >= EVERGREEN);
300
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000301 if (Size == 64)
302 return (getGeneration() >= SOUTHERN_ISLANDS);
303
304 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000305 }
306
Tom Stellard50122a52014-04-07 19:45:41 +0000307 bool hasMulU24() const {
308 return (getGeneration() >= EVERGREEN);
309 }
310
311 bool hasMulI24() const {
312 return (getGeneration() >= SOUTHERN_ISLANDS ||
313 hasCaymanISA());
314 }
315
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000316 bool hasFFBL() const {
317 return (getGeneration() >= EVERGREEN);
318 }
319
320 bool hasFFBH() const {
321 return (getGeneration() >= EVERGREEN);
322 }
323
Matt Arsenault10268f92017-02-27 22:40:39 +0000324 bool hasMed3_16() const {
325 return getGeneration() >= GFX9;
326 }
327
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000328 bool hasMin3Max3_16() const {
329 return getGeneration() >= GFX9;
330 }
331
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000332 bool hasMadMixInsts() const {
Matt Arsenault28f52e52017-10-25 07:00:51 +0000333 return HasMadMixInsts;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000334 }
335
Matt Arsenault0084adc2018-04-30 19:08:16 +0000336 bool hasFmaMixInsts() const {
337 return HasFmaMixInsts;
338 }
339
Jan Vesely808fff52015-04-30 17:15:56 +0000340 bool hasCARRY() const {
341 return (getGeneration() >= EVERGREEN);
342 }
343
344 bool hasBORROW() const {
345 return (getGeneration() >= EVERGREEN);
346 }
347
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000348 bool hasCaymanISA() const {
349 return CaymanISA;
350 }
351
Jan Vesely39aeab42017-12-04 23:07:28 +0000352 bool hasFMA() const {
353 return FMA;
354 }
355
Wei Ding205bfdb2017-02-10 02:15:29 +0000356 TrapHandlerAbi getTrapHandlerAbi() const {
357 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
358 }
359
Matt Arsenault45b98182017-11-15 00:45:43 +0000360 bool enableHugePrivateBuffer() const {
361 return EnableHugePrivateBuffer;
362 }
363
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000364 bool isPromoteAllocaEnabled() const {
365 return EnablePromoteAlloca;
366 }
367
Matt Arsenault706f9302015-07-06 16:01:58 +0000368 bool unsafeDSOffsetFoldingEnabled() const {
369 return EnableUnsafeDSOffsetFolding;
370 }
371
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000372 bool dumpCode() const {
373 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000374 }
375
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000376 /// Return the amount of LDS that can be used that will not restrict the
377 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000378 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
379 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000380
381 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
382 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000383 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000384
Tom Stellard44b30b42018-05-22 02:03:23 +0000385 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const;
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000386
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000387 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000388 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000389 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000390
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000391 bool hasFP32Denormals() const {
392 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000393 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000394
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000395 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000396 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000397 }
398
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000399 bool supportsMinMaxDenormModes() const {
400 return getGeneration() >= AMDGPUSubtarget::GFX9;
401 }
402
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000403 bool hasFPExceptions() const {
404 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000405 }
406
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000407 bool enableDX10Clamp() const {
408 return DX10Clamp;
409 }
410
411 bool enableIEEEBit(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000412 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000413 }
414
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000415 bool useFlatForGlobal() const {
416 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000417 }
418
Farhana Aleena7cb3112018-03-09 17:41:39 +0000419 /// \returns If target supports ds_read/write_b128 and user enables generation
420 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000421 bool useDS128() const {
422 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000423 }
424
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000425 /// \returns If MUBUF instructions always perform range checking, even for
426 /// buffer resources used for private memory access.
427 bool privateMemoryResourceIsRangeChecked() const {
428 return getGeneration() < AMDGPUSubtarget::GFX9;
429 }
430
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000431 bool hasAutoWaitcntBeforeBarrier() const {
432 return AutoWaitcntBeforeBarrier;
433 }
434
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000435 bool hasCodeObjectV3() const {
436 return CodeObjectV3;
437 }
438
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000439 bool hasUnalignedBufferAccess() const {
440 return UnalignedBufferAccess;
441 }
442
Tom Stellard64a9d082016-10-14 18:10:39 +0000443 bool hasUnalignedScratchAccess() const {
444 return UnalignedScratchAccess;
445 }
446
Matt Arsenaulte823d922017-02-18 18:29:53 +0000447 bool hasApertureRegs() const {
448 return HasApertureRegs;
449 }
450
Wei Ding205bfdb2017-02-10 02:15:29 +0000451 bool isTrapHandlerEnabled() const {
452 return TrapHandler;
453 }
454
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000455 bool isXNACKEnabled() const {
456 return EnableXNACK;
457 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000458
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000459 bool hasFlatAddressSpace() const {
460 return FlatAddressSpace;
461 }
462
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000463 bool hasFlatInstOffsets() const {
464 return FlatInstOffsets;
465 }
466
467 bool hasFlatGlobalInsts() const {
468 return FlatGlobalInsts;
469 }
470
471 bool hasFlatScratchInsts() const {
472 return FlatScratchInsts;
473 }
474
Mark Searlesf0b93f12018-06-04 16:51:59 +0000475 bool hasFlatLgkmVMemCountInOrder() const {
476 return getGeneration() > GFX9;
477 }
478
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000479 bool hasD16LoadStore() const {
480 return getGeneration() >= GFX9;
481 }
482
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000483 /// Return if most LDS instructions have an m0 use that require m0 to be
484 /// iniitalized.
485 bool ldsRequiresM0Init() const {
486 return getGeneration() < GFX9;
487 }
488
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000489 bool hasAddNoCarry() const {
490 return AddNoCarryInsts;
491 }
492
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000493 bool hasUnpackedD16VMem() const {
494 return HasUnpackedD16VMem;
495 }
496
Matt Arsenaultceafc552018-05-29 17:42:50 +0000497 bool isMesaKernel(const Function &F) const {
498 return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000499 }
500
501 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000502 bool isMesaGfxShader(const Function &F) const {
503 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000504 }
505
Matt Arsenaultceafc552018-05-29 17:42:50 +0000506 bool isAmdCodeObjectV2(const Function &F) const {
507 return isAmdHsaOS() || isMesaKernel(F);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000508 }
509
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000510 bool hasMad64_32() const {
511 return getGeneration() >= SEA_ISLANDS;
512 }
513
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000514 bool hasFminFmaxLegacy() const {
515 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
516 }
517
Stanislav Mekhanoshin53a21292017-05-23 19:54:48 +0000518 bool hasSDWA() const {
519 return HasSDWA;
520 }
521
Sam Kolton3c4933f2017-06-22 06:26:41 +0000522 bool hasSDWAOmod() const {
523 return HasSDWAOmod;
524 }
525
526 bool hasSDWAScalar() const {
527 return HasSDWAScalar;
528 }
529
530 bool hasSDWASdst() const {
531 return HasSDWASdst;
532 }
533
534 bool hasSDWAMac() const {
535 return HasSDWAMac;
536 }
537
Sam Koltona179d252017-06-27 15:02:23 +0000538 bool hasSDWAOutModsVOPC() const {
539 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000540 }
541
Mark Searles2a19af62018-04-26 16:11:19 +0000542 bool vmemWriteNeedsExpWaitcnt() const {
543 return getGeneration() < SEA_ISLANDS;
544 }
545
Matt Arsenault0084adc2018-04-30 19:08:16 +0000546 bool hasDLInsts() const {
547 return HasDLInsts;
548 }
549
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000550 bool d16PreservesUnusedBits() const {
551 return D16PreservesUnusedBits;
552 }
553
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000554 /// Returns the offset in bytes from the start of the input buffer
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000555 /// of the first explicit kernel argument.
Matt Arsenaultceafc552018-05-29 17:42:50 +0000556 unsigned getExplicitKernelArgOffset(const Function &F) const {
557 return isAmdCodeObjectV2(F) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000558 }
559
Tom Stellardb2869eb2016-09-09 19:28:00 +0000560 unsigned getAlignmentForImplicitArgPtr() const {
561 return isAmdHsaOS() ? 8 : 4;
562 }
563
Tony Tye7a893d42018-03-23 18:45:18 +0000564 /// \returns Number of bytes of arguments that are passed to a shader or
565 /// kernel in addition to the explicit ones declared for the function.
Matt Arsenaultceafc552018-05-29 17:42:50 +0000566 unsigned getImplicitArgNumBytes(const Function &F) const {
567 if (isMesaKernel(F))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000568 return 16;
Matt Arsenaultceafc552018-05-29 17:42:50 +0000569 return AMDGPU::getIntegerAttribute(F, "amdgpu-implicitarg-num-bytes", 0);
Tom Stellarde88bbc32016-09-23 01:33:26 +0000570 }
571
Matt Arsenault869fec22017-04-17 19:48:24 +0000572 // Scratch is allocated in 256 dword per wave blocks for the entire
573 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
574 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000575 //
576 // Only 4-byte alignment is really needed to access anything. Transformations
577 // on the pointer value itself may rely on the alignment / known low bits of
578 // the pointer. Set this to something above the minimum to avoid needing
579 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000580 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000581 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000582 }
Tom Stellard347ac792015-06-26 21:15:07 +0000583
Craig Topper5656db42014-04-29 07:57:24 +0000584 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000585 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000586 }
587
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000588 bool enableSubRegLiveness() const override {
589 return true;
590 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000591
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000592 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
593 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
594
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000595 /// \returns Number of execution units per compute unit supported by the
596 /// subtarget.
597 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000598 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000599 }
600
601 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000602 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000603 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000604 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
605 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000606 }
607
608 /// \returns Maximum number of waves per compute unit supported by the
609 /// subtarget without any kind of limitation.
610 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000611 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000612 }
613
614 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000615 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000616 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000617 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
618 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000619 }
620
621 /// \returns Minimum number of waves per execution unit supported by the
622 /// subtarget.
623 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000624 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000625 }
626
627 /// \returns Maximum number of waves per execution unit supported by the
628 /// subtarget without any kind of limitation.
629 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000630 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000631 }
632
633 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000634 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000635 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000636 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
637 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000638 }
639
640 /// \returns Minimum flat work group size supported by the subtarget.
641 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000642 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000643 }
644
645 /// \returns Maximum flat work group size supported by the subtarget.
646 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000647 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000648 }
649
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000650 /// \returns Number of waves per work group supported by the subtarget and
651 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000652 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000653 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
654 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000655 }
656
Matt Arsenaultb7918022017-10-23 17:09:35 +0000657 /// \returns Default range flat work group size for a calling convention.
658 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
659
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000660 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
661 /// for function \p F, or minimum/maximum flat work group sizes explicitly
662 /// requested using "amdgpu-flat-work-group-size" attribute attached to
663 /// function \p F.
664 ///
665 /// \returns Subtarget's default values if explicitly requested values cannot
666 /// be converted to integer, or violate subtarget's specifications.
667 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
668
669 /// \returns Subtarget's default pair of minimum/maximum number of waves per
670 /// execution unit for function \p F, or minimum/maximum number of waves per
671 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
672 /// attached to function \p F.
673 ///
674 /// \returns Subtarget's default values if explicitly requested values cannot
675 /// be converted to integer, violate subtarget's specifications, or are not
676 /// compatible with minimum/maximum number of waves limited by flat work group
677 /// size, register usage, and/or lds usage.
678 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000679
680 /// Creates value range metadata on an workitemid.* inrinsic call or load.
681 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000682};
683
684class R600Subtarget final : public AMDGPUSubtarget {
685private:
686 R600InstrInfo InstrInfo;
687 R600FrameLowering FrameLowering;
688 R600TargetLowering TLInfo;
689
690public:
691 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
692 const TargetMachine &TM);
693
694 const R600InstrInfo *getInstrInfo() const override {
695 return &InstrInfo;
696 }
697
698 const R600FrameLowering *getFrameLowering() const override {
699 return &FrameLowering;
700 }
701
702 const R600TargetLowering *getTargetLowering() const override {
703 return &TLInfo;
704 }
705
706 const R600RegisterInfo *getRegisterInfo() const override {
707 return &InstrInfo.getRegisterInfo();
708 }
709
710 bool hasCFAluBug() const {
711 return CFALUBug;
712 }
713
714 bool hasVertexCache() const {
715 return HasVertexCache;
716 }
717
718 short getTexVTXClauseSize() const {
719 return TexVTXClauseSize;
720 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000721};
722
723class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000724private:
725 SIInstrInfo InstrInfo;
726 SIFrameLowering FrameLowering;
727 SITargetLowering TLInfo;
Quentin Colombet61d71a12017-08-15 22:31:51 +0000728
729 /// GlobalISel related APIs.
730 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
731 std::unique_ptr<InstructionSelector> InstSelector;
732 std::unique_ptr<LegalizerInfo> Legalizer;
733 std::unique_ptr<RegisterBankInfo> RegBankInfo;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000734
735public:
736 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
Matt Arsenaultc3fe46b2018-03-08 16:24:16 +0000737 const GCNTargetMachine &TM);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000738
739 const SIInstrInfo *getInstrInfo() const override {
740 return &InstrInfo;
741 }
742
743 const SIFrameLowering *getFrameLowering() const override {
744 return &FrameLowering;
745 }
746
747 const SITargetLowering *getTargetLowering() const override {
748 return &TLInfo;
749 }
750
751 const CallLowering *getCallLowering() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000752 return CallLoweringInfo.get();
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000753 }
754
Tom Stellardca166212017-01-30 21:56:46 +0000755 const InstructionSelector *getInstructionSelector() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000756 return InstSelector.get();
Tom Stellardca166212017-01-30 21:56:46 +0000757 }
758
759 const LegalizerInfo *getLegalizerInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000760 return Legalizer.get();
Tom Stellardca166212017-01-30 21:56:46 +0000761 }
762
763 const RegisterBankInfo *getRegBankInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000764 return RegBankInfo.get();
Tom Stellardca166212017-01-30 21:56:46 +0000765 }
766
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000767 const SIRegisterInfo *getRegisterInfo() const override {
768 return &InstrInfo.getRegisterInfo();
769 }
770
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000771 // XXX - Why is this here if it isn't in the default pass set?
772 bool enableEarlyIfConversion() const override {
773 return true;
774 }
775
Tom Stellard83f0bce2015-01-29 16:55:25 +0000776 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000777 unsigned NumRegionInstrs) const override;
778
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000779 bool isVGPRSpillingEnabled(const Function& F) const;
780
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000781 unsigned getMaxNumUserSGPRs() const {
782 return 16;
783 }
784
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000785 bool hasSMemRealTime() const {
786 return HasSMemRealTime;
787 }
788
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000789 bool hasMovrel() const {
790 return HasMovrel;
791 }
792
793 bool hasVGPRIndexMode() const {
794 return HasVGPRIndexMode;
795 }
796
Marek Olsake22fdb92017-03-21 17:00:32 +0000797 bool useVGPRIndexMode(bool UserEnable) const {
798 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
799 }
800
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000801 bool hasScalarCompareEq64() const {
802 return getGeneration() >= VOLCANIC_ISLANDS;
803 }
804
Matt Arsenault7b647552016-10-28 21:55:15 +0000805 bool hasScalarStores() const {
806 return HasScalarStores;
807 }
808
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000809 bool hasScalarAtomics() const {
810 return HasScalarAtomics;
811 }
812
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000813 bool hasInv2PiInlineImm() const {
814 return HasInv2PiInlineImm;
815 }
816
Sam Kolton07dbde22017-01-20 10:01:25 +0000817 bool hasDPP() const {
818 return HasDPP;
819 }
820
Tom Stellardde008d32016-01-21 04:28:34 +0000821 bool enableSIScheduler() const {
822 return EnableSIScheduler;
823 }
824
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000825 bool debuggerSupported() const {
826 return debuggerInsertNops() && debuggerReserveRegs() &&
827 debuggerEmitPrologue();
828 }
829
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000830 bool debuggerInsertNops() const {
831 return DebuggerInsertNops;
832 }
833
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000834 bool debuggerReserveRegs() const {
835 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000836 }
837
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000838 bool debuggerEmitPrologue() const {
839 return DebuggerEmitPrologue;
840 }
841
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000842 bool loadStoreOptEnabled() const {
843 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000844 }
845
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000846 bool hasSGPRInitBug() const {
847 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000848 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000849
Tom Stellardb133fbb2016-10-27 23:05:31 +0000850 bool has12DWordStoreHazard() const {
851 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
852 }
853
Matt Arsenaulte823d922017-02-18 18:29:53 +0000854 bool hasSMovFedHazard() const {
855 return getGeneration() >= AMDGPUSubtarget::GFX9;
856 }
857
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000858 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000859 return getGeneration() >= AMDGPUSubtarget::GFX9;
860 }
861
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000862 bool hasReadM0SendMsgHazard() const {
863 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
864 }
865
Matt Arsenaultceafc552018-05-29 17:42:50 +0000866 unsigned getKernArgSegmentSize(const Function &F,
Matt Arsenault9166ce82017-07-28 15:52:08 +0000867 unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000868
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000869 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
870 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
871
872 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
873 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000874
Matt Arsenaulte823d922017-02-18 18:29:53 +0000875 /// \returns true if the flat_scratch register should be initialized with the
876 /// pointer to the wave's scratch memory rather than a size and offset.
877 bool flatScratchIsPointer() const {
878 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000879 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000880
Tim Renouf832f90f2018-02-26 14:46:43 +0000881 /// \returns true if the machine has merged shaders in which s0-s7 are
882 /// reserved by the hardware and user SGPRs start at s8
883 bool hasMergedShaders() const {
884 return getGeneration() >= GFX9;
885 }
886
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000887 /// \returns SGPR allocation granularity supported by the subtarget.
888 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000889 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000890 }
891
892 /// \returns SGPR encoding granularity supported by the subtarget.
893 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000894 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000895 }
896
897 /// \returns Total number of SGPRs supported by the subtarget.
898 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000899 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000900 }
901
902 /// \returns Addressable number of SGPRs supported by the subtarget.
903 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000904 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000905 }
906
907 /// \returns Minimum number of SGPRs that meets the given number of waves per
908 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000909 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
910 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
911 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000912
913 /// \returns Maximum number of SGPRs that meets the given number of waves per
914 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000915 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
916 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
917 Addressable);
918 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000919
920 /// \returns Reserved number of SGPRs for given function \p MF.
921 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
922
923 /// \returns Maximum number of SGPRs that meets number of waves per execution
924 /// unit requirement for function \p MF, or number of SGPRs explicitly
925 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
926 ///
927 /// \returns Value that meets number of waves per execution unit requirement
928 /// if explicitly requested value cannot be converted to integer, violates
929 /// subtarget's specifications, or does not meet number of waves per execution
930 /// unit requirement.
931 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
932
933 /// \returns VGPR allocation granularity supported by the subtarget.
934 unsigned getVGPRAllocGranule() const {
Mandeep Singh Grang5e1697e2017-06-06 05:08:36 +0000935 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000936 }
937
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000938 /// \returns VGPR encoding granularity supported by the subtarget.
939 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000940 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000941 }
942
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000943 /// \returns Total number of VGPRs supported by the subtarget.
944 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000945 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000946 }
947
948 /// \returns Addressable number of VGPRs supported by the subtarget.
949 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000950 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000951 }
952
953 /// \returns Minimum number of VGPRs that meets given number of waves per
954 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000955 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
956 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
957 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000958
959 /// \returns Maximum number of VGPRs that meets given number of waves per
960 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000961 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
962 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
963 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000964
965 /// \returns Reserved number of VGPRs for given function \p MF.
966 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
967 return debuggerReserveRegs() ? 4 : 0;
968 }
969
970 /// \returns Maximum number of VGPRs that meets number of waves per execution
971 /// unit requirement for function \p MF, or number of VGPRs explicitly
972 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
973 ///
974 /// \returns Value that meets number of waves per execution unit requirement
975 /// if explicitly requested value cannot be converted to integer, violates
976 /// subtarget's specifications, or does not meet number of waves per execution
977 /// unit requirement.
978 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000979
980 void getPostRAMutations(
981 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
982 const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000983};
984
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000985} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000986
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000987#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H