blob: 251ad8d2fc8fc09a154d4aeb4441bbc1b872e2e6 [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"
Tom Stellardc5a154d2018-06-28 23:47:12 +000042#define GET_SUBTARGETINFO_HEADER
43#include "R600GenSubtargetInfo.inc"
Tom Stellard75aadc22012-12-11 21:25:42 +000044
Tom Stellard75aadc22012-12-11 21:25:42 +000045namespace llvm {
46
Matt Arsenault43e92fe2016-06-24 06:30:11 +000047class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000048
Tom Stellardc5a154d2018-06-28 23:47:12 +000049class AMDGPUCommonSubtarget {
50private:
51 Triple TargetTriple;
52
53protected:
54 const FeatureBitset &SubtargetFeatureBits;
55 bool Has16BitInsts;
56 bool HasMadMixInsts;
57 bool FP32Denormals;
58 bool FPExceptions;
59 bool HasSDWA;
60 bool HasVOP3PInsts;
61 bool HasMulI24;
62 bool HasMulU24;
63 bool HasFminFmaxLegacy;
64 bool EnablePromoteAlloca;
65 int LocalMemorySize;
66 unsigned WavefrontSize;
67
68public:
69 AMDGPUCommonSubtarget(const Triple &TT, const FeatureBitset &FeatureBits);
70
71 static const AMDGPUCommonSubtarget &get(const MachineFunction &MF);
72 static const AMDGPUCommonSubtarget &get(const TargetMachine &TM,
73 const Function &F);
74
75 /// \returns Default range flat work group size for a calling convention.
76 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
77
78 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
79 /// for function \p F, or minimum/maximum flat work group sizes explicitly
80 /// requested using "amdgpu-flat-work-group-size" attribute attached to
81 /// function \p F.
82 ///
83 /// \returns Subtarget's default values if explicitly requested values cannot
84 /// be converted to integer, or violate subtarget's specifications.
85 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
86
87 /// \returns Subtarget's default pair of minimum/maximum number of waves per
88 /// execution unit for function \p F, or minimum/maximum number of waves per
89 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
90 /// attached to function \p F.
91 ///
92 /// \returns Subtarget's default values if explicitly requested values cannot
93 /// be converted to integer, violate subtarget's specifications, or are not
94 /// compatible with minimum/maximum number of waves limited by flat work group
95 /// size, register usage, and/or lds usage.
96 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
97
98 /// Return the amount of LDS that can be used that will not restrict the
99 /// occupancy lower than WaveCount.
100 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
101 const Function &) const;
102
103 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
104 /// the given LDS memory size is the only constraint.
105 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
106
107 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const;
108
109 bool isAmdHsaOS() const {
110 return TargetTriple.getOS() == Triple::AMDHSA;
111 }
112
113 bool isAmdPalOS() const {
114 return TargetTriple.getOS() == Triple::AMDPAL;
115 }
116
Tom Stellardec4feae2018-07-06 17:16:17 +0000117 bool isMesa3DOS() const {
118 return TargetTriple.getOS() == Triple::Mesa3D;
119 }
120
121 bool isMesaKernel(const Function &F) const {
122 return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
123 }
124
125 bool isAmdCodeObjectV2(const Function &F) const {
126 return isAmdHsaOS() || isMesaKernel(F);
127 }
128
Tom Stellardc5a154d2018-06-28 23:47:12 +0000129 bool has16BitInsts() const {
130 return Has16BitInsts;
131 }
132
133 bool hasMadMixInsts() const {
134 return HasMadMixInsts;
135 }
136
137 bool hasFP32Denormals() const {
138 return FP32Denormals;
139 }
140
141 bool hasFPExceptions() const {
142 return FPExceptions;
143 }
144
145 bool hasSDWA() const {
146 return HasSDWA;
147 }
148
149 bool hasVOP3PInsts() const {
150 return HasVOP3PInsts;
151 }
152
153 bool hasMulI24() const {
154 return HasMulI24;
155 }
156
157 bool hasMulU24() const {
158 return HasMulU24;
159 }
160
161 bool hasFminFmaxLegacy() const {
162 return HasFminFmaxLegacy;
163 }
164
165 bool isPromoteAllocaEnabled() const {
166 return EnablePromoteAlloca;
167 }
168
169 unsigned getWavefrontSize() const {
170 return WavefrontSize;
171 }
172
173 int getLocalMemorySize() const {
174 return LocalMemorySize;
175 }
176
177 unsigned getAlignmentForImplicitArgPtr() const {
178 return isAmdHsaOS() ? 8 : 4;
179 }
180
Tom Stellardec4feae2018-07-06 17:16:17 +0000181 /// Returns the offset in bytes from the start of the input buffer
182 /// of the first explicit kernel argument.
183 unsigned getExplicitKernelArgOffset(const Function &F) const {
184 return isAmdCodeObjectV2(F) ? 0 : 36;
185 }
186
Tom Stellardc5a154d2018-06-28 23:47:12 +0000187 /// \returns Maximum number of work groups per compute unit supported by the
188 /// subtarget and limited by given \p FlatWorkGroupSize.
189 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
190 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(SubtargetFeatureBits,
191 FlatWorkGroupSize);
192 }
193
194 /// \returns Minimum flat work group size supported by the subtarget.
195 unsigned getMinFlatWorkGroupSize() const {
196 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(SubtargetFeatureBits);
197 }
198
199 /// \returns Maximum flat work group size supported by the subtarget.
200 unsigned getMaxFlatWorkGroupSize() const {
201 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(SubtargetFeatureBits);
202 }
203
204 /// \returns Maximum number of waves per execution unit supported by the
205 /// subtarget and limited by given \p FlatWorkGroupSize.
206 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
207 return AMDGPU::IsaInfo::getMaxWavesPerEU(SubtargetFeatureBits,
208 FlatWorkGroupSize);
209 }
210
211 /// \returns Minimum number of waves per execution unit supported by the
212 /// subtarget.
213 unsigned getMinWavesPerEU() const {
214 return AMDGPU::IsaInfo::getMinWavesPerEU(SubtargetFeatureBits);
215 }
216
217 unsigned getMaxWavesPerEU() const { return 10; }
218
219 /// Creates value range metadata on an workitemid.* inrinsic call or load.
220 bool makeLIDRangeMetadata(Instruction *I) const;
221
222 virtual ~AMDGPUCommonSubtarget() {}
223};
224
225class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo,
226 public AMDGPUCommonSubtarget {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000227public:
228 enum Generation {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000229 // Gap for R600 generations, so we can do comparisons between
230 // AMDGPUSubtarget and r600Subtarget.
231 SOUTHERN_ISLANDS = 4,
232 SEA_ISLANDS = 5,
233 VOLCANIC_ISLANDS = 6,
234 GFX9 = 7,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000235 };
236
Marek Olsak4d00dd22015-03-09 15:48:09 +0000237 enum {
Tom Stellard347ac792015-06-26 21:15:07 +0000238 ISAVersion0_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +0000239 ISAVersion6_0_0,
240 ISAVersion6_0_1,
Tom Stellard347ac792015-06-26 21:15:07 +0000241 ISAVersion7_0_0,
242 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +0000243 ISAVersion7_0_2,
Wei Ding7c3e5112017-06-10 03:53:19 +0000244 ISAVersion7_0_3,
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000245 ISAVersion7_0_4,
Changpeng Fangc16be002016-01-13 20:39:25 +0000246 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +0000247 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +0000248 ISAVersion8_0_3,
Yaxun Liu94add852016-10-26 16:37:56 +0000249 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +0000250 ISAVersion9_0_0,
Matt Arsenault0084adc2018-04-30 19:08:16 +0000251 ISAVersion9_0_2,
252 ISAVersion9_0_4,
Konstantin Zhuravlyov1501af42018-05-01 18:47:48 +0000253 ISAVersion9_0_6,
Tom Stellard347ac792015-06-26 21:15:07 +0000254 };
255
Wei Ding205bfdb2017-02-10 02:15:29 +0000256 enum TrapHandlerAbi {
257 TrapHandlerAbiNone = 0,
258 TrapHandlerAbiHsa = 1
259 };
260
Wei Dingf2cce022017-02-22 23:22:19 +0000261 enum TrapID {
262 TrapIDHardwareReserved = 0,
263 TrapIDHSADebugTrap = 1,
264 TrapIDLLVMTrap = 2,
265 TrapIDLLVMDebugTrap = 3,
266 TrapIDDebugBreakpoint = 7,
267 TrapIDDebugReserved8 = 8,
268 TrapIDDebugReservedFE = 0xfe,
269 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +0000270 };
271
272 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +0000273 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +0000274 };
275
Tom Stellardc5a154d2018-06-28 23:47:12 +0000276private:
277 SIFrameLowering FrameLowering;
278
279 /// GlobalISel related APIs.
280 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
281 std::unique_ptr<InstructionSelector> InstSelector;
282 std::unique_ptr<LegalizerInfo> Legalizer;
283 std::unique_ptr<RegisterBankInfo> RegBankInfo;
284
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000285protected:
286 // Basic subtarget description.
287 Triple TargetTriple;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000288 unsigned Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000289 unsigned IsaVersion;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000290 int LDSBankCount;
291 unsigned MaxPrivateElementSize;
292
293 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000294 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000295 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000296
297 // Dynamially set bits that enable features.
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000298 bool FP64FP16Denormals;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000299 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000300 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000301 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000302 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000303 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000304 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000305 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000306 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000307 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000308 bool DebuggerInsertNops;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000309 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000310
311 // Used as options.
Matt Arsenault45b98182017-11-15 00:45:43 +0000312 bool EnableHugePrivateBuffer;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000313 bool EnableVGPRSpilling;
Matt Arsenault41033282014-10-10 22:01:59 +0000314 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000315 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000316 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000317 bool EnableDS128;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000318 bool DumpCode;
319
320 // Subtarget statically properties set by tablegen
321 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000322 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000323 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000324 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000325 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000326 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000327 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000328 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000329 bool HasSMemRealTime;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000330 bool HasIntClamp;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000331 bool HasFmaMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000332 bool HasMovrel;
333 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000334 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000335 bool HasScalarAtomics;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000336 bool HasInv2PiInlineImm;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000337 bool HasSDWAOmod;
338 bool HasSDWAScalar;
339 bool HasSDWASdst;
340 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000341 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000342 bool HasDPP;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000343 bool HasDLInsts;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000344 bool D16PreservesUnusedBits;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000345 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000346 bool FlatInstOffsets;
347 bool FlatGlobalInsts;
348 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000349 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000350 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000351 bool R600ALUInst;
352 bool CaymanISA;
353 bool CFALUBug;
354 bool HasVertexCache;
355 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000356 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000357
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000358 // Dummy feature to use for assembler in tablegen.
359 bool FeatureDisable;
360
Matt Arsenault56684d42016-08-11 17:31:42 +0000361 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000362 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000363
364public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000365 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
366 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000367 ~AMDGPUSubtarget() override;
368
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000369 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
370 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000371
Tom Stellardc5a154d2018-06-28 23:47:12 +0000372 virtual const SIInstrInfo *getInstrInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000373
Tom Stellardc5a154d2018-06-28 23:47:12 +0000374 const SIFrameLowering *getFrameLowering() const override {
375 return &FrameLowering;
376 }
377
378 virtual const SITargetLowering *getTargetLowering() const override = 0;
379
380 virtual const SIRegisterInfo *getRegisterInfo() const override = 0;
381
382 const CallLowering *getCallLowering() const override {
383 return CallLoweringInfo.get();
384 }
385
386 const InstructionSelector *getInstructionSelector() const override {
387 return InstSelector.get();
388 }
389
390 const LegalizerInfo *getLegalizerInfo() const override {
391 return Legalizer.get();
392 }
393
394 const RegisterBankInfo *getRegBankInfo() const override {
395 return RegBankInfo.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000396 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000397
Matt Arsenault56684d42016-08-11 17:31:42 +0000398 // Nothing implemented, just prevent crashes on use.
399 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
400 return &TSInfo;
401 }
402
Craig Topperee7b0f32014-04-30 05:53:27 +0000403 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000404
Matt Arsenaultd782d052014-06-27 17:57:00 +0000405 Generation getGeneration() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000406 return (Generation)Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000407 }
408
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000409 unsigned getWavefrontSizeLog2() const {
410 return Log2_32(WavefrontSize);
411 }
412
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000413 int getLDSBankCount() const {
414 return LDSBankCount;
415 }
416
417 unsigned getMaxPrivateElementSize() const {
418 return MaxPrivateElementSize;
419 }
420
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000421 AMDGPUAS getAMDGPUAS() const {
422 return AS;
423 }
424
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000425 bool hasIntClamp() const {
426 return HasIntClamp;
427 }
428
Jan Veselyd1c9b612017-12-04 22:57:29 +0000429 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000430 return FP64;
431 }
432
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000433 bool hasMIMG_R128() const {
434 return MIMG_R128;
435 }
436
Tom Stellardc5a154d2018-06-28 23:47:12 +0000437 bool hasHWFP64() const {
438 return FP64;
439 }
440
Matt Arsenaultb035a572015-01-29 19:34:25 +0000441 bool hasFastFMAF32() const {
442 return FastFMAF32;
443 }
444
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000445 bool hasHalfRate64Ops() const {
446 return HalfRate64Ops;
447 }
448
Matt Arsenault88701812016-06-09 23:42:48 +0000449 bool hasAddr64() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000450 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
Matt Arsenault88701812016-06-09 23:42:48 +0000451 }
452
Matt Arsenaultfae02982014-03-17 18:58:11 +0000453 bool hasBFE() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000454 return true;
Matt Arsenaultfae02982014-03-17 18:58:11 +0000455 }
456
Matt Arsenault6e439652014-06-10 19:00:20 +0000457 bool hasBFI() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000458 return true;
Matt Arsenault6e439652014-06-10 19:00:20 +0000459 }
460
Matt Arsenaultfae02982014-03-17 18:58:11 +0000461 bool hasBFM() const {
462 return hasBFE();
463 }
464
Matt Arsenault60425062014-06-10 19:18:28 +0000465 bool hasBCNT(unsigned Size) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000466 return true;
Tom Stellard50122a52014-04-07 19:45:41 +0000467 }
468
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000469 bool hasFFBL() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000470 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000471 }
472
473 bool hasFFBH() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000474 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000475 }
476
Matt Arsenault10268f92017-02-27 22:40:39 +0000477 bool hasMed3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000478 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenault10268f92017-02-27 22:40:39 +0000479 }
480
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000481 bool hasMin3Max3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000482 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000483 }
484
Matt Arsenault0084adc2018-04-30 19:08:16 +0000485 bool hasFmaMixInsts() const {
486 return HasFmaMixInsts;
487 }
488
Jan Vesely808fff52015-04-30 17:15:56 +0000489 bool hasCARRY() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000490 return true;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000491 }
492
Jan Vesely39aeab42017-12-04 23:07:28 +0000493 bool hasFMA() const {
494 return FMA;
495 }
496
Wei Ding205bfdb2017-02-10 02:15:29 +0000497 TrapHandlerAbi getTrapHandlerAbi() const {
498 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
499 }
500
Matt Arsenault45b98182017-11-15 00:45:43 +0000501 bool enableHugePrivateBuffer() const {
502 return EnableHugePrivateBuffer;
503 }
504
Matt Arsenault706f9302015-07-06 16:01:58 +0000505 bool unsafeDSOffsetFoldingEnabled() const {
506 return EnableUnsafeDSOffsetFolding;
507 }
508
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000509 bool dumpCode() const {
510 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000511 }
512
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000513 /// Return the amount of LDS that can be used that will not restrict the
514 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000515 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
516 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000517
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000518 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000519 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000520 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000521
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000522 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000523 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000524 }
525
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000526 bool supportsMinMaxDenormModes() const {
527 return getGeneration() >= AMDGPUSubtarget::GFX9;
528 }
529
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000530 bool enableDX10Clamp() const {
531 return DX10Clamp;
532 }
533
534 bool enableIEEEBit(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000535 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000536 }
537
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000538 bool useFlatForGlobal() const {
539 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000540 }
541
Farhana Aleena7cb3112018-03-09 17:41:39 +0000542 /// \returns If target supports ds_read/write_b128 and user enables generation
543 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000544 bool useDS128() const {
545 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000546 }
547
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000548 /// \returns If MUBUF instructions always perform range checking, even for
549 /// buffer resources used for private memory access.
550 bool privateMemoryResourceIsRangeChecked() const {
551 return getGeneration() < AMDGPUSubtarget::GFX9;
552 }
553
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000554 bool hasAutoWaitcntBeforeBarrier() const {
555 return AutoWaitcntBeforeBarrier;
556 }
557
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000558 bool hasCodeObjectV3() const {
559 return CodeObjectV3;
560 }
561
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000562 bool hasUnalignedBufferAccess() const {
563 return UnalignedBufferAccess;
564 }
565
Tom Stellard64a9d082016-10-14 18:10:39 +0000566 bool hasUnalignedScratchAccess() const {
567 return UnalignedScratchAccess;
568 }
569
Matt Arsenaulte823d922017-02-18 18:29:53 +0000570 bool hasApertureRegs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000571 return HasApertureRegs;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000572 }
573
Wei Ding205bfdb2017-02-10 02:15:29 +0000574 bool isTrapHandlerEnabled() const {
575 return TrapHandler;
576 }
577
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000578 bool isXNACKEnabled() const {
579 return EnableXNACK;
580 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000581
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000582 bool hasFlatAddressSpace() const {
583 return FlatAddressSpace;
584 }
585
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000586 bool hasFlatInstOffsets() const {
587 return FlatInstOffsets;
588 }
589
590 bool hasFlatGlobalInsts() const {
591 return FlatGlobalInsts;
592 }
593
594 bool hasFlatScratchInsts() const {
595 return FlatScratchInsts;
596 }
597
Mark Searlesf0b93f12018-06-04 16:51:59 +0000598 bool hasFlatLgkmVMemCountInOrder() const {
599 return getGeneration() > GFX9;
600 }
601
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000602 bool hasD16LoadStore() const {
603 return getGeneration() >= GFX9;
604 }
605
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000606 /// Return if most LDS instructions have an m0 use that require m0 to be
607 /// iniitalized.
608 bool ldsRequiresM0Init() const {
609 return getGeneration() < GFX9;
610 }
611
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000612 bool hasAddNoCarry() const {
613 return AddNoCarryInsts;
614 }
615
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000616 bool hasUnpackedD16VMem() const {
617 return HasUnpackedD16VMem;
618 }
619
Tom Stellard2f3f9852017-01-25 01:25:13 +0000620 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000621 bool isMesaGfxShader(const Function &F) const {
622 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000623 }
624
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000625 bool hasMad64_32() const {
626 return getGeneration() >= SEA_ISLANDS;
627 }
628
Sam Kolton3c4933f2017-06-22 06:26:41 +0000629 bool hasSDWAOmod() const {
630 return HasSDWAOmod;
631 }
632
633 bool hasSDWAScalar() const {
634 return HasSDWAScalar;
635 }
636
637 bool hasSDWASdst() const {
638 return HasSDWASdst;
639 }
640
641 bool hasSDWAMac() const {
642 return HasSDWAMac;
643 }
644
Sam Koltona179d252017-06-27 15:02:23 +0000645 bool hasSDWAOutModsVOPC() const {
646 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000647 }
648
Mark Searles2a19af62018-04-26 16:11:19 +0000649 bool vmemWriteNeedsExpWaitcnt() const {
650 return getGeneration() < SEA_ISLANDS;
651 }
652
Matt Arsenault0084adc2018-04-30 19:08:16 +0000653 bool hasDLInsts() const {
654 return HasDLInsts;
655 }
656
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000657 bool d16PreservesUnusedBits() const {
658 return D16PreservesUnusedBits;
659 }
660
Tony Tye7a893d42018-03-23 18:45:18 +0000661 /// \returns Number of bytes of arguments that are passed to a shader or
662 /// kernel in addition to the explicit ones declared for the function.
Matt Arsenaultceafc552018-05-29 17:42:50 +0000663 unsigned getImplicitArgNumBytes(const Function &F) const {
664 if (isMesaKernel(F))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000665 return 16;
Matt Arsenaultceafc552018-05-29 17:42:50 +0000666 return AMDGPU::getIntegerAttribute(F, "amdgpu-implicitarg-num-bytes", 0);
Tom Stellarde88bbc32016-09-23 01:33:26 +0000667 }
668
Matt Arsenault869fec22017-04-17 19:48:24 +0000669 // Scratch is allocated in 256 dword per wave blocks for the entire
670 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
671 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000672 //
673 // Only 4-byte alignment is really needed to access anything. Transformations
674 // on the pointer value itself may rely on the alignment / known low bits of
675 // the pointer. Set this to something above the minimum to avoid needing
676 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000677 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000678 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000679 }
Tom Stellard347ac792015-06-26 21:15:07 +0000680
Craig Topper5656db42014-04-29 07:57:24 +0000681 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000682 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000683 }
684
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000685 bool enableSubRegLiveness() const override {
686 return true;
687 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000688
Tom Stellardc5a154d2018-06-28 23:47:12 +0000689 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
690 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000691
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000692 /// \returns Number of execution units per compute unit supported by the
693 /// subtarget.
694 unsigned getEUsPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000695 return AMDGPU::IsaInfo::getEUsPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000696 }
697
698 /// \returns Maximum number of waves per compute unit supported by the
699 /// subtarget without any kind of limitation.
700 unsigned getMaxWavesPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000701 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000702 }
703
704 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000705 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000706 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000707 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits(),
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000708 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000709 }
710
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000711 /// \returns Maximum number of waves per execution unit supported by the
712 /// subtarget without any kind of limitation.
713 unsigned getMaxWavesPerEU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000714 return AMDGPU::IsaInfo::getMaxWavesPerEU();
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000715 }
716
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000717 /// \returns Number of waves per work group supported by the subtarget and
718 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000719 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000720 return AMDGPU::IsaInfo::getWavesPerWorkGroup(
721 MCSubtargetInfo::getFeatureBits(), FlatWorkGroupSize);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000722 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000723};
724
725class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000726private:
727 SIInstrInfo InstrInfo;
728 SIFrameLowering FrameLowering;
729 SITargetLowering TLInfo;
Quentin Colombet61d71a12017-08-15 22:31:51 +0000730
731 /// GlobalISel related APIs.
732 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
733 std::unique_ptr<InstructionSelector> InstSelector;
734 std::unique_ptr<LegalizerInfo> Legalizer;
735 std::unique_ptr<RegisterBankInfo> RegBankInfo;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000736
737public:
738 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
Matt Arsenaultc3fe46b2018-03-08 16:24:16 +0000739 const GCNTargetMachine &TM);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000740
741 const SIInstrInfo *getInstrInfo() const override {
742 return &InstrInfo;
743 }
744
745 const SIFrameLowering *getFrameLowering() const override {
746 return &FrameLowering;
747 }
748
749 const SITargetLowering *getTargetLowering() const override {
750 return &TLInfo;
751 }
752
753 const CallLowering *getCallLowering() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000754 return CallLoweringInfo.get();
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000755 }
756
Tom Stellardca166212017-01-30 21:56:46 +0000757 const InstructionSelector *getInstructionSelector() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000758 return InstSelector.get();
Tom Stellardca166212017-01-30 21:56:46 +0000759 }
760
761 const LegalizerInfo *getLegalizerInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000762 return Legalizer.get();
Tom Stellardca166212017-01-30 21:56:46 +0000763 }
764
765 const RegisterBankInfo *getRegBankInfo() const override {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000766 return RegBankInfo.get();
Tom Stellardca166212017-01-30 21:56:46 +0000767 }
768
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000769 const SIRegisterInfo *getRegisterInfo() const override {
770 return &InstrInfo.getRegisterInfo();
771 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000772 // static wrappers
773 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000774
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000775 // XXX - Why is this here if it isn't in the default pass set?
776 bool enableEarlyIfConversion() const override {
777 return true;
778 }
779
Tom Stellard83f0bce2015-01-29 16:55:25 +0000780 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000781 unsigned NumRegionInstrs) const override;
782
Tom Stellardc5a154d2018-06-28 23:47:12 +0000783 bool isVGPRSpillingEnabled(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000784
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000785 unsigned getMaxNumUserSGPRs() const {
786 return 16;
787 }
788
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000789 bool hasSMemRealTime() const {
790 return HasSMemRealTime;
791 }
792
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000793 bool hasMovrel() const {
794 return HasMovrel;
795 }
796
797 bool hasVGPRIndexMode() const {
798 return HasVGPRIndexMode;
799 }
800
Marek Olsake22fdb92017-03-21 17:00:32 +0000801 bool useVGPRIndexMode(bool UserEnable) const {
802 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
803 }
804
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000805 bool hasScalarCompareEq64() const {
806 return getGeneration() >= VOLCANIC_ISLANDS;
807 }
808
Matt Arsenault7b647552016-10-28 21:55:15 +0000809 bool hasScalarStores() const {
810 return HasScalarStores;
811 }
812
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000813 bool hasScalarAtomics() const {
814 return HasScalarAtomics;
815 }
816
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000817 bool hasInv2PiInlineImm() const {
818 return HasInv2PiInlineImm;
819 }
820
Sam Kolton07dbde22017-01-20 10:01:25 +0000821 bool hasDPP() const {
822 return HasDPP;
823 }
824
Tom Stellardde008d32016-01-21 04:28:34 +0000825 bool enableSIScheduler() const {
826 return EnableSIScheduler;
827 }
828
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000829 bool debuggerSupported() const {
Konstantin Zhuravlyove004b3d2018-06-21 20:28:19 +0000830 return debuggerInsertNops() && debuggerEmitPrologue();
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000831 }
832
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000833 bool debuggerInsertNops() const {
834 return DebuggerInsertNops;
835 }
836
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000837 bool debuggerEmitPrologue() const {
838 return DebuggerEmitPrologue;
839 }
840
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000841 bool loadStoreOptEnabled() const {
842 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000843 }
844
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000845 bool hasSGPRInitBug() const {
846 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000847 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000848
Tom Stellardb133fbb2016-10-27 23:05:31 +0000849 bool has12DWordStoreHazard() const {
850 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
851 }
852
Matt Arsenaulte823d922017-02-18 18:29:53 +0000853 bool hasSMovFedHazard() const {
854 return getGeneration() >= AMDGPUSubtarget::GFX9;
855 }
856
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000857 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000858 return getGeneration() >= AMDGPUSubtarget::GFX9;
859 }
860
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000861 bool hasReadM0SendMsgHazard() const {
862 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
863 }
864
Matt Arsenaultf5be3ad2018-06-29 17:31:42 +0000865 uint64_t getExplicitKernArgSize(const Function &F) const;
Matt Arsenaultceafc552018-05-29 17:42:50 +0000866 unsigned getKernArgSegmentSize(const Function &F,
Matt Arsenaultf5be3ad2018-06-29 17:31:42 +0000867 int64_t ExplicitArgBytes = -1) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000868
Tom Stellardc5a154d2018-06-28 23:47:12 +0000869 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
870 /// SGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000871 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
872
Tom Stellardc5a154d2018-06-28 23:47:12 +0000873 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
874 /// VGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000875 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000876
Matt Arsenaulte823d922017-02-18 18:29:53 +0000877 /// \returns true if the flat_scratch register should be initialized with the
878 /// pointer to the wave's scratch memory rather than a size and offset.
879 bool flatScratchIsPointer() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000880 return getGeneration() >= AMDGPUSubtarget::GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000881 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000882
Tim Renouf832f90f2018-02-26 14:46:43 +0000883 /// \returns true if the machine has merged shaders in which s0-s7 are
884 /// reserved by the hardware and user SGPRs start at s8
885 bool hasMergedShaders() const {
886 return getGeneration() >= GFX9;
887 }
888
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000889 /// \returns SGPR allocation granularity supported by the subtarget.
890 unsigned getSGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000891 return AMDGPU::IsaInfo::getSGPRAllocGranule(
892 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000893 }
894
895 /// \returns SGPR encoding granularity supported by the subtarget.
896 unsigned getSGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000897 return AMDGPU::IsaInfo::getSGPREncodingGranule(
898 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000899 }
900
901 /// \returns Total number of SGPRs supported by the subtarget.
902 unsigned getTotalNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000903 return AMDGPU::IsaInfo::getTotalNumSGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000904 }
905
906 /// \returns Addressable number of SGPRs supported by the subtarget.
907 unsigned getAddressableNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000908 return AMDGPU::IsaInfo::getAddressableNumSGPRs(
909 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000910 }
911
912 /// \returns Minimum number of SGPRs that meets the given number of waves per
913 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000914 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000915 return AMDGPU::IsaInfo::getMinNumSGPRs(MCSubtargetInfo::getFeatureBits(),
916 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000917 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000918
919 /// \returns Maximum number of SGPRs that meets the given number of waves per
920 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000921 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000922 return AMDGPU::IsaInfo::getMaxNumSGPRs(MCSubtargetInfo::getFeatureBits(),
923 WavesPerEU, Addressable);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000924 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000925
926 /// \returns Reserved number of SGPRs for given function \p MF.
927 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
928
929 /// \returns Maximum number of SGPRs that meets number of waves per execution
930 /// unit requirement for function \p MF, or number of SGPRs explicitly
931 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
932 ///
933 /// \returns Value that meets number of waves per execution unit requirement
934 /// if explicitly requested value cannot be converted to integer, violates
935 /// subtarget's specifications, or does not meet number of waves per execution
936 /// unit requirement.
937 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
938
939 /// \returns VGPR allocation granularity supported by the subtarget.
940 unsigned getVGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000941 return AMDGPU::IsaInfo::getVGPRAllocGranule(
942 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000943 }
944
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000945 /// \returns VGPR encoding granularity supported by the subtarget.
946 unsigned getVGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000947 return AMDGPU::IsaInfo::getVGPREncodingGranule(
948 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000949 }
950
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000951 /// \returns Total number of VGPRs supported by the subtarget.
952 unsigned getTotalNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000953 return AMDGPU::IsaInfo::getTotalNumVGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000954 }
955
956 /// \returns Addressable number of VGPRs supported by the subtarget.
957 unsigned getAddressableNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000958 return AMDGPU::IsaInfo::getAddressableNumVGPRs(
959 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000960 }
961
962 /// \returns Minimum number of VGPRs that meets given number of waves per
963 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000964 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000965 return AMDGPU::IsaInfo::getMinNumVGPRs(MCSubtargetInfo::getFeatureBits(),
966 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000967 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000968
969 /// \returns Maximum number of VGPRs that meets given number of waves per
970 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000971 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000972 return AMDGPU::IsaInfo::getMaxNumVGPRs(MCSubtargetInfo::getFeatureBits(),
973 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000974 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000975
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000976 /// \returns Maximum number of VGPRs that meets number of waves per execution
977 /// unit requirement for function \p MF, or number of VGPRs explicitly
978 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
979 ///
980 /// \returns Value that meets number of waves per execution unit requirement
981 /// if explicitly requested value cannot be converted to integer, violates
982 /// subtarget's specifications, or does not meet number of waves per execution
983 /// unit requirement.
984 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000985
986 void getPostRAMutations(
987 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
988 const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000989};
990
Tom Stellardc5a154d2018-06-28 23:47:12 +0000991
992class R600Subtarget final : public R600GenSubtargetInfo,
993 public AMDGPUCommonSubtarget {
994public:
995 enum Generation { R600 = 0, R700 = 1, EVERGREEN = 2, NORTHERN_ISLANDS = 3 };
996
997private:
998 R600InstrInfo InstrInfo;
999 R600FrameLowering FrameLowering;
1000 bool FMA;
1001 bool CaymanISA;
1002 bool CFALUBug;
1003 bool DX10Clamp;
1004 bool HasVertexCache;
1005 bool R600ALUInst;
1006 bool FP64;
1007 short TexVTXClauseSize;
1008 Generation Gen;
1009 R600TargetLowering TLInfo;
1010 InstrItineraryData InstrItins;
1011 SelectionDAGTargetInfo TSInfo;
1012 AMDGPUAS AS;
1013
1014public:
1015 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
1016 const TargetMachine &TM);
1017
1018 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
1019
1020 const R600FrameLowering *getFrameLowering() const override {
1021 return &FrameLowering;
1022 }
1023
1024 const R600TargetLowering *getTargetLowering() const override {
1025 return &TLInfo;
1026 }
1027
1028 const R600RegisterInfo *getRegisterInfo() const override {
1029 return &InstrInfo.getRegisterInfo();
1030 }
1031
1032 const InstrItineraryData *getInstrItineraryData() const override {
1033 return &InstrItins;
1034 }
1035
1036 // Nothing implemented, just prevent crashes on use.
1037 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
1038 return &TSInfo;
1039 }
1040
1041 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1042
1043 Generation getGeneration() const {
1044 return Gen;
1045 }
1046
1047 unsigned getStackAlignment() const {
1048 return 4;
1049 }
1050
1051 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1052 StringRef GPU, StringRef FS);
1053
1054 bool hasBFE() const {
1055 return (getGeneration() >= EVERGREEN);
1056 }
1057
1058 bool hasBFI() const {
1059 return (getGeneration() >= EVERGREEN);
1060 }
1061
1062 bool hasBCNT(unsigned Size) const {
1063 if (Size == 32)
1064 return (getGeneration() >= EVERGREEN);
1065
1066 return false;
1067 }
1068
1069 bool hasBORROW() const {
1070 return (getGeneration() >= EVERGREEN);
1071 }
1072
1073 bool hasCARRY() const {
1074 return (getGeneration() >= EVERGREEN);
1075 }
1076
1077 bool hasCaymanISA() const {
1078 return CaymanISA;
1079 }
1080
1081 bool hasFFBL() const {
1082 return (getGeneration() >= EVERGREEN);
1083 }
1084
1085 bool hasFFBH() const {
1086 return (getGeneration() >= EVERGREEN);
1087 }
1088
1089 bool hasFMA() const { return FMA; }
1090
Tom Stellardc5a154d2018-06-28 23:47:12 +00001091 bool hasCFAluBug() const { return CFALUBug; }
1092
1093 bool hasVertexCache() const { return HasVertexCache; }
1094
1095 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1096
1097 AMDGPUAS getAMDGPUAS() const { return AS; }
1098
1099 bool enableMachineScheduler() const override {
1100 return true;
1101 }
1102
1103 bool enableSubRegLiveness() const override {
1104 return true;
1105 }
1106};
1107
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001108} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +00001109
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001110#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H