blob: d9806d6133c69db5e8a1a1671f59b8a8634ca70a [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 Stellard5bfbae52018-07-11 20:59:01 +000049class AMDGPUSubtarget {
50public:
51 enum Generation {
52 R600 = 0,
53 R700 = 1,
54 EVERGREEN = 2,
55 NORTHERN_ISLANDS = 3,
56 SOUTHERN_ISLANDS = 4,
57 SEA_ISLANDS = 5,
58 VOLCANIC_ISLANDS = 6,
59 GFX9 = 7
60 };
61
Tom Stellardc5a154d2018-06-28 23:47:12 +000062private:
63 Triple TargetTriple;
64
65protected:
66 const FeatureBitset &SubtargetFeatureBits;
67 bool Has16BitInsts;
68 bool HasMadMixInsts;
69 bool FP32Denormals;
70 bool FPExceptions;
71 bool HasSDWA;
72 bool HasVOP3PInsts;
73 bool HasMulI24;
74 bool HasMulU24;
75 bool HasFminFmaxLegacy;
76 bool EnablePromoteAlloca;
77 int LocalMemorySize;
78 unsigned WavefrontSize;
79
80public:
Tom Stellard5bfbae52018-07-11 20:59:01 +000081 AMDGPUSubtarget(const Triple &TT, const FeatureBitset &FeatureBits);
Tom Stellardc5a154d2018-06-28 23:47:12 +000082
Tom Stellard5bfbae52018-07-11 20:59:01 +000083 static const AMDGPUSubtarget &get(const MachineFunction &MF);
84 static const AMDGPUSubtarget &get(const TargetMachine &TM,
Tom Stellardc5a154d2018-06-28 23:47:12 +000085 const Function &F);
86
87 /// \returns Default range flat work group size for a calling convention.
88 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
89
90 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
91 /// for function \p F, or minimum/maximum flat work group sizes explicitly
92 /// requested using "amdgpu-flat-work-group-size" attribute attached to
93 /// function \p F.
94 ///
95 /// \returns Subtarget's default values if explicitly requested values cannot
96 /// be converted to integer, or violate subtarget's specifications.
97 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
98
99 /// \returns Subtarget's default pair of minimum/maximum number of waves per
100 /// execution unit for function \p F, or minimum/maximum number of waves per
101 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
102 /// attached to function \p F.
103 ///
104 /// \returns Subtarget's default values if explicitly requested values cannot
105 /// be converted to integer, violate subtarget's specifications, or are not
106 /// compatible with minimum/maximum number of waves limited by flat work group
107 /// size, register usage, and/or lds usage.
108 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
109
110 /// Return the amount of LDS that can be used that will not restrict the
111 /// occupancy lower than WaveCount.
112 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
113 const Function &) const;
114
115 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
116 /// the given LDS memory size is the only constraint.
117 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
118
119 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const;
120
121 bool isAmdHsaOS() const {
122 return TargetTriple.getOS() == Triple::AMDHSA;
123 }
124
125 bool isAmdPalOS() const {
126 return TargetTriple.getOS() == Triple::AMDPAL;
127 }
128
Tom Stellardec4feae2018-07-06 17:16:17 +0000129 bool isMesa3DOS() const {
130 return TargetTriple.getOS() == Triple::Mesa3D;
131 }
132
133 bool isMesaKernel(const Function &F) const {
134 return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
135 }
136
137 bool isAmdCodeObjectV2(const Function &F) const {
138 return isAmdHsaOS() || isMesaKernel(F);
139 }
140
Tom Stellardc5a154d2018-06-28 23:47:12 +0000141 bool has16BitInsts() const {
142 return Has16BitInsts;
143 }
144
145 bool hasMadMixInsts() const {
146 return HasMadMixInsts;
147 }
148
149 bool hasFP32Denormals() const {
150 return FP32Denormals;
151 }
152
153 bool hasFPExceptions() const {
154 return FPExceptions;
155 }
156
157 bool hasSDWA() const {
158 return HasSDWA;
159 }
160
161 bool hasVOP3PInsts() const {
162 return HasVOP3PInsts;
163 }
164
165 bool hasMulI24() const {
166 return HasMulI24;
167 }
168
169 bool hasMulU24() const {
170 return HasMulU24;
171 }
172
173 bool hasFminFmaxLegacy() const {
174 return HasFminFmaxLegacy;
175 }
176
177 bool isPromoteAllocaEnabled() const {
178 return EnablePromoteAlloca;
179 }
180
181 unsigned getWavefrontSize() const {
182 return WavefrontSize;
183 }
184
185 int getLocalMemorySize() const {
186 return LocalMemorySize;
187 }
188
189 unsigned getAlignmentForImplicitArgPtr() const {
190 return isAmdHsaOS() ? 8 : 4;
191 }
192
Tom Stellardec4feae2018-07-06 17:16:17 +0000193 /// Returns the offset in bytes from the start of the input buffer
194 /// of the first explicit kernel argument.
195 unsigned getExplicitKernelArgOffset(const Function &F) const {
196 return isAmdCodeObjectV2(F) ? 0 : 36;
197 }
198
Tom Stellardc5a154d2018-06-28 23:47:12 +0000199 /// \returns Maximum number of work groups per compute unit supported by the
200 /// subtarget and limited by given \p FlatWorkGroupSize.
201 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
202 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(SubtargetFeatureBits,
203 FlatWorkGroupSize);
204 }
205
206 /// \returns Minimum flat work group size supported by the subtarget.
207 unsigned getMinFlatWorkGroupSize() const {
208 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(SubtargetFeatureBits);
209 }
210
211 /// \returns Maximum flat work group size supported by the subtarget.
212 unsigned getMaxFlatWorkGroupSize() const {
213 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(SubtargetFeatureBits);
214 }
215
216 /// \returns Maximum number of waves per execution unit supported by the
217 /// subtarget and limited by given \p FlatWorkGroupSize.
218 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
219 return AMDGPU::IsaInfo::getMaxWavesPerEU(SubtargetFeatureBits,
220 FlatWorkGroupSize);
221 }
222
223 /// \returns Minimum number of waves per execution unit supported by the
224 /// subtarget.
225 unsigned getMinWavesPerEU() const {
226 return AMDGPU::IsaInfo::getMinWavesPerEU(SubtargetFeatureBits);
227 }
228
229 unsigned getMaxWavesPerEU() const { return 10; }
230
231 /// Creates value range metadata on an workitemid.* inrinsic call or load.
232 bool makeLIDRangeMetadata(Instruction *I) const;
233
Tom Stellard5bfbae52018-07-11 20:59:01 +0000234 virtual ~AMDGPUSubtarget() {}
Tom Stellardc5a154d2018-06-28 23:47:12 +0000235};
236
Tom Stellard5bfbae52018-07-11 20:59:01 +0000237class GCNSubtarget : public AMDGPUGenSubtargetInfo,
238 public AMDGPUSubtarget {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000239public:
Marek Olsak4d00dd22015-03-09 15:48:09 +0000240 enum {
Tom Stellard347ac792015-06-26 21:15:07 +0000241 ISAVersion0_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +0000242 ISAVersion6_0_0,
243 ISAVersion6_0_1,
Tom Stellard347ac792015-06-26 21:15:07 +0000244 ISAVersion7_0_0,
245 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +0000246 ISAVersion7_0_2,
Wei Ding7c3e5112017-06-10 03:53:19 +0000247 ISAVersion7_0_3,
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000248 ISAVersion7_0_4,
Changpeng Fangc16be002016-01-13 20:39:25 +0000249 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +0000250 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +0000251 ISAVersion8_0_3,
Yaxun Liu94add852016-10-26 16:37:56 +0000252 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +0000253 ISAVersion9_0_0,
Matt Arsenault0084adc2018-04-30 19:08:16 +0000254 ISAVersion9_0_2,
255 ISAVersion9_0_4,
Konstantin Zhuravlyov1501af42018-05-01 18:47:48 +0000256 ISAVersion9_0_6,
Tom Stellard347ac792015-06-26 21:15:07 +0000257 };
258
Wei Ding205bfdb2017-02-10 02:15:29 +0000259 enum TrapHandlerAbi {
260 TrapHandlerAbiNone = 0,
261 TrapHandlerAbiHsa = 1
262 };
263
Wei Dingf2cce022017-02-22 23:22:19 +0000264 enum TrapID {
265 TrapIDHardwareReserved = 0,
266 TrapIDHSADebugTrap = 1,
267 TrapIDLLVMTrap = 2,
268 TrapIDLLVMDebugTrap = 3,
269 TrapIDDebugBreakpoint = 7,
270 TrapIDDebugReserved8 = 8,
271 TrapIDDebugReservedFE = 0xfe,
272 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +0000273 };
274
275 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +0000276 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +0000277 };
278
Tom Stellardc5a154d2018-06-28 23:47:12 +0000279private:
Tom Stellardc5a154d2018-06-28 23:47:12 +0000280 /// GlobalISel related APIs.
281 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
282 std::unique_ptr<InstructionSelector> InstSelector;
283 std::unique_ptr<LegalizerInfo> Legalizer;
284 std::unique_ptr<RegisterBankInfo> RegBankInfo;
285
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000286protected:
287 // Basic subtarget description.
288 Triple TargetTriple;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000289 unsigned Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000290 unsigned IsaVersion;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000291 int LDSBankCount;
292 unsigned MaxPrivateElementSize;
293
294 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000295 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000296 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000297
298 // Dynamially set bits that enable features.
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000299 bool FP64FP16Denormals;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000300 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000301 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000302 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000303 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000304 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000305 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000306 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000307 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000308 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000309 bool DebuggerInsertNops;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000310 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000311
312 // Used as options.
Matt Arsenault45b98182017-11-15 00:45:43 +0000313 bool EnableHugePrivateBuffer;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000314 bool EnableVGPRSpilling;
Matt Arsenault41033282014-10-10 22:01:59 +0000315 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000316 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000317 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000318 bool EnableDS128;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000319 bool DumpCode;
320
321 // Subtarget statically properties set by tablegen
322 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000323 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000324 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000325 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000326 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000327 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000328 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000329 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000330 bool HasSMemRealTime;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000331 bool HasIntClamp;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000332 bool HasFmaMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000333 bool HasMovrel;
334 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000335 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000336 bool HasScalarAtomics;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000337 bool HasInv2PiInlineImm;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000338 bool HasSDWAOmod;
339 bool HasSDWAScalar;
340 bool HasSDWASdst;
341 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000342 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000343 bool HasDPP;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000344 bool HasDLInsts;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000345 bool D16PreservesUnusedBits;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000346 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000347 bool FlatInstOffsets;
348 bool FlatGlobalInsts;
349 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000350 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000351 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000352 bool R600ALUInst;
353 bool CaymanISA;
354 bool CFALUBug;
355 bool HasVertexCache;
356 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000357 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000358
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000359 // Dummy feature to use for assembler in tablegen.
360 bool FeatureDisable;
361
Matt Arsenault56684d42016-08-11 17:31:42 +0000362 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000363 AMDGPUAS AS;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000364private:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000365 SIInstrInfo InstrInfo;
Tom Stellard752ddbd2018-07-11 22:15:15 +0000366 SITargetLowering TLInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000367 SIFrameLowering FrameLowering;
Tom Stellard75aadc22012-12-11 21:25:42 +0000368
369public:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000370 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
371 const GCNTargetMachine &TM);
372 ~GCNSubtarget() override;
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000373
Tom Stellard5bfbae52018-07-11 20:59:01 +0000374 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000375 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000376
Tom Stellard5bfbae52018-07-11 20:59:01 +0000377 const SIInstrInfo *getInstrInfo() const override {
378 return &InstrInfo;
379 }
Tom Stellard000c5af2016-04-14 19:09:28 +0000380
Tom Stellardc5a154d2018-06-28 23:47:12 +0000381 const SIFrameLowering *getFrameLowering() const override {
382 return &FrameLowering;
383 }
384
Tom Stellard5bfbae52018-07-11 20:59:01 +0000385 const SITargetLowering *getTargetLowering() const override {
386 return &TLInfo;
387 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000388
Tom Stellard5bfbae52018-07-11 20:59:01 +0000389 const SIRegisterInfo *getRegisterInfo() const override {
390 return &InstrInfo.getRegisterInfo();
391 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000392
393 const CallLowering *getCallLowering() const override {
394 return CallLoweringInfo.get();
395 }
396
397 const InstructionSelector *getInstructionSelector() const override {
398 return InstSelector.get();
399 }
400
401 const LegalizerInfo *getLegalizerInfo() const override {
402 return Legalizer.get();
403 }
404
405 const RegisterBankInfo *getRegBankInfo() const override {
406 return RegBankInfo.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000407 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000408
Matt Arsenault56684d42016-08-11 17:31:42 +0000409 // Nothing implemented, just prevent crashes on use.
410 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
411 return &TSInfo;
412 }
413
Craig Topperee7b0f32014-04-30 05:53:27 +0000414 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000415
Matt Arsenaultd782d052014-06-27 17:57:00 +0000416 Generation getGeneration() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000417 return (Generation)Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000418 }
419
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000420 unsigned getWavefrontSizeLog2() const {
421 return Log2_32(WavefrontSize);
422 }
423
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000424 int getLDSBankCount() const {
425 return LDSBankCount;
426 }
427
428 unsigned getMaxPrivateElementSize() const {
429 return MaxPrivateElementSize;
430 }
431
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000432 AMDGPUAS getAMDGPUAS() const {
433 return AS;
434 }
435
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000436 bool hasIntClamp() const {
437 return HasIntClamp;
438 }
439
Jan Veselyd1c9b612017-12-04 22:57:29 +0000440 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000441 return FP64;
442 }
443
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000444 bool hasMIMG_R128() const {
445 return MIMG_R128;
446 }
447
Tom Stellardc5a154d2018-06-28 23:47:12 +0000448 bool hasHWFP64() const {
449 return FP64;
450 }
451
Matt Arsenaultb035a572015-01-29 19:34:25 +0000452 bool hasFastFMAF32() const {
453 return FastFMAF32;
454 }
455
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000456 bool hasHalfRate64Ops() const {
457 return HalfRate64Ops;
458 }
459
Matt Arsenault88701812016-06-09 23:42:48 +0000460 bool hasAddr64() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000461 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
Matt Arsenault88701812016-06-09 23:42:48 +0000462 }
463
Matt Arsenaultfae02982014-03-17 18:58:11 +0000464 bool hasBFE() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000465 return true;
Matt Arsenaultfae02982014-03-17 18:58:11 +0000466 }
467
Matt Arsenault6e439652014-06-10 19:00:20 +0000468 bool hasBFI() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000469 return true;
Matt Arsenault6e439652014-06-10 19:00:20 +0000470 }
471
Matt Arsenaultfae02982014-03-17 18:58:11 +0000472 bool hasBFM() const {
473 return hasBFE();
474 }
475
Matt Arsenault60425062014-06-10 19:18:28 +0000476 bool hasBCNT(unsigned Size) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000477 return true;
Tom Stellard50122a52014-04-07 19:45:41 +0000478 }
479
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000480 bool hasFFBL() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000481 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000482 }
483
484 bool hasFFBH() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000485 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000486 }
487
Matt Arsenault10268f92017-02-27 22:40:39 +0000488 bool hasMed3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000489 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenault10268f92017-02-27 22:40:39 +0000490 }
491
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000492 bool hasMin3Max3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000493 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000494 }
495
Matt Arsenault0084adc2018-04-30 19:08:16 +0000496 bool hasFmaMixInsts() const {
497 return HasFmaMixInsts;
498 }
499
Jan Vesely808fff52015-04-30 17:15:56 +0000500 bool hasCARRY() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000501 return true;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000502 }
503
Jan Vesely39aeab42017-12-04 23:07:28 +0000504 bool hasFMA() const {
505 return FMA;
506 }
507
Wei Ding205bfdb2017-02-10 02:15:29 +0000508 TrapHandlerAbi getTrapHandlerAbi() const {
509 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
510 }
511
Matt Arsenault45b98182017-11-15 00:45:43 +0000512 bool enableHugePrivateBuffer() const {
513 return EnableHugePrivateBuffer;
514 }
515
Matt Arsenault706f9302015-07-06 16:01:58 +0000516 bool unsafeDSOffsetFoldingEnabled() const {
517 return EnableUnsafeDSOffsetFolding;
518 }
519
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000520 bool dumpCode() const {
521 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000522 }
523
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000524 /// Return the amount of LDS that can be used that will not restrict the
525 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000526 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
527 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000528
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000529 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000530 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000531 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000532
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000533 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000534 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000535 }
536
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000537 bool supportsMinMaxDenormModes() const {
538 return getGeneration() >= AMDGPUSubtarget::GFX9;
539 }
540
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000541 bool enableDX10Clamp() const {
542 return DX10Clamp;
543 }
544
545 bool enableIEEEBit(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000546 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000547 }
548
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000549 bool useFlatForGlobal() const {
550 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000551 }
552
Farhana Aleena7cb3112018-03-09 17:41:39 +0000553 /// \returns If target supports ds_read/write_b128 and user enables generation
554 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000555 bool useDS128() const {
556 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000557 }
558
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000559 /// \returns If MUBUF instructions always perform range checking, even for
560 /// buffer resources used for private memory access.
561 bool privateMemoryResourceIsRangeChecked() const {
562 return getGeneration() < AMDGPUSubtarget::GFX9;
563 }
564
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000565 bool hasAutoWaitcntBeforeBarrier() const {
566 return AutoWaitcntBeforeBarrier;
567 }
568
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000569 bool hasCodeObjectV3() const {
570 return CodeObjectV3;
571 }
572
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000573 bool hasUnalignedBufferAccess() const {
574 return UnalignedBufferAccess;
575 }
576
Tom Stellard64a9d082016-10-14 18:10:39 +0000577 bool hasUnalignedScratchAccess() const {
578 return UnalignedScratchAccess;
579 }
580
Matt Arsenaulte823d922017-02-18 18:29:53 +0000581 bool hasApertureRegs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000582 return HasApertureRegs;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000583 }
584
Wei Ding205bfdb2017-02-10 02:15:29 +0000585 bool isTrapHandlerEnabled() const {
586 return TrapHandler;
587 }
588
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000589 bool isXNACKEnabled() const {
590 return EnableXNACK;
591 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000592
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000593 bool hasFlatAddressSpace() const {
594 return FlatAddressSpace;
595 }
596
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000597 bool hasFlatInstOffsets() const {
598 return FlatInstOffsets;
599 }
600
601 bool hasFlatGlobalInsts() const {
602 return FlatGlobalInsts;
603 }
604
605 bool hasFlatScratchInsts() const {
606 return FlatScratchInsts;
607 }
608
Mark Searlesf0b93f12018-06-04 16:51:59 +0000609 bool hasFlatLgkmVMemCountInOrder() const {
610 return getGeneration() > GFX9;
611 }
612
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000613 bool hasD16LoadStore() const {
614 return getGeneration() >= GFX9;
615 }
616
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000617 /// Return if most LDS instructions have an m0 use that require m0 to be
618 /// iniitalized.
619 bool ldsRequiresM0Init() const {
620 return getGeneration() < GFX9;
621 }
622
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000623 bool hasAddNoCarry() const {
624 return AddNoCarryInsts;
625 }
626
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000627 bool hasUnpackedD16VMem() const {
628 return HasUnpackedD16VMem;
629 }
630
Tom Stellard2f3f9852017-01-25 01:25:13 +0000631 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000632 bool isMesaGfxShader(const Function &F) const {
633 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000634 }
635
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000636 bool hasMad64_32() const {
637 return getGeneration() >= SEA_ISLANDS;
638 }
639
Sam Kolton3c4933f2017-06-22 06:26:41 +0000640 bool hasSDWAOmod() const {
641 return HasSDWAOmod;
642 }
643
644 bool hasSDWAScalar() const {
645 return HasSDWAScalar;
646 }
647
648 bool hasSDWASdst() const {
649 return HasSDWASdst;
650 }
651
652 bool hasSDWAMac() const {
653 return HasSDWAMac;
654 }
655
Sam Koltona179d252017-06-27 15:02:23 +0000656 bool hasSDWAOutModsVOPC() const {
657 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000658 }
659
Mark Searles2a19af62018-04-26 16:11:19 +0000660 bool vmemWriteNeedsExpWaitcnt() const {
661 return getGeneration() < SEA_ISLANDS;
662 }
663
Matt Arsenault0084adc2018-04-30 19:08:16 +0000664 bool hasDLInsts() const {
665 return HasDLInsts;
666 }
667
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000668 bool d16PreservesUnusedBits() const {
669 return D16PreservesUnusedBits;
670 }
671
Tony Tye7a893d42018-03-23 18:45:18 +0000672 /// \returns Number of bytes of arguments that are passed to a shader or
673 /// kernel in addition to the explicit ones declared for the function.
Matt Arsenaultceafc552018-05-29 17:42:50 +0000674 unsigned getImplicitArgNumBytes(const Function &F) const {
675 if (isMesaKernel(F))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000676 return 16;
Matt Arsenaultceafc552018-05-29 17:42:50 +0000677 return AMDGPU::getIntegerAttribute(F, "amdgpu-implicitarg-num-bytes", 0);
Tom Stellarde88bbc32016-09-23 01:33:26 +0000678 }
679
Matt Arsenault869fec22017-04-17 19:48:24 +0000680 // Scratch is allocated in 256 dword per wave blocks for the entire
681 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
682 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000683 //
684 // Only 4-byte alignment is really needed to access anything. Transformations
685 // on the pointer value itself may rely on the alignment / known low bits of
686 // the pointer. Set this to something above the minimum to avoid needing
687 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000688 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000689 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000690 }
Tom Stellard347ac792015-06-26 21:15:07 +0000691
Craig Topper5656db42014-04-29 07:57:24 +0000692 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000693 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000694 }
695
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000696 bool enableSubRegLiveness() const override {
697 return true;
698 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000699
Tom Stellardc5a154d2018-06-28 23:47:12 +0000700 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
701 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000702
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000703 /// \returns Number of execution units per compute unit supported by the
704 /// subtarget.
705 unsigned getEUsPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000706 return AMDGPU::IsaInfo::getEUsPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000707 }
708
709 /// \returns Maximum number of waves per compute unit supported by the
710 /// subtarget without any kind of limitation.
711 unsigned getMaxWavesPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000712 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000713 }
714
715 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000716 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000717 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000718 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits(),
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000719 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000720 }
721
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000722 /// \returns Maximum number of waves per execution unit supported by the
723 /// subtarget without any kind of limitation.
724 unsigned getMaxWavesPerEU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000725 return AMDGPU::IsaInfo::getMaxWavesPerEU();
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000726 }
727
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000728 /// \returns Number of waves per work group supported by the subtarget and
729 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000730 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000731 return AMDGPU::IsaInfo::getWavesPerWorkGroup(
732 MCSubtargetInfo::getFeatureBits(), FlatWorkGroupSize);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000733 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000734
Tom Stellardc5a154d2018-06-28 23:47:12 +0000735 // static wrappers
736 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000737
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000738 // XXX - Why is this here if it isn't in the default pass set?
739 bool enableEarlyIfConversion() const override {
740 return true;
741 }
742
Tom Stellard83f0bce2015-01-29 16:55:25 +0000743 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000744 unsigned NumRegionInstrs) const override;
745
Tom Stellardc5a154d2018-06-28 23:47:12 +0000746 bool isVGPRSpillingEnabled(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000747
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000748 unsigned getMaxNumUserSGPRs() const {
749 return 16;
750 }
751
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000752 bool hasSMemRealTime() const {
753 return HasSMemRealTime;
754 }
755
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000756 bool hasMovrel() const {
757 return HasMovrel;
758 }
759
760 bool hasVGPRIndexMode() const {
761 return HasVGPRIndexMode;
762 }
763
Marek Olsake22fdb92017-03-21 17:00:32 +0000764 bool useVGPRIndexMode(bool UserEnable) const {
765 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
766 }
767
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000768 bool hasScalarCompareEq64() const {
769 return getGeneration() >= VOLCANIC_ISLANDS;
770 }
771
Matt Arsenault7b647552016-10-28 21:55:15 +0000772 bool hasScalarStores() const {
773 return HasScalarStores;
774 }
775
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000776 bool hasScalarAtomics() const {
777 return HasScalarAtomics;
778 }
779
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000780 bool hasInv2PiInlineImm() const {
781 return HasInv2PiInlineImm;
782 }
783
Sam Kolton07dbde22017-01-20 10:01:25 +0000784 bool hasDPP() const {
785 return HasDPP;
786 }
787
Tom Stellardde008d32016-01-21 04:28:34 +0000788 bool enableSIScheduler() const {
789 return EnableSIScheduler;
790 }
791
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000792 bool debuggerSupported() const {
Konstantin Zhuravlyove004b3d2018-06-21 20:28:19 +0000793 return debuggerInsertNops() && debuggerEmitPrologue();
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000794 }
795
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000796 bool debuggerInsertNops() const {
797 return DebuggerInsertNops;
798 }
799
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000800 bool debuggerEmitPrologue() const {
801 return DebuggerEmitPrologue;
802 }
803
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000804 bool loadStoreOptEnabled() const {
805 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000806 }
807
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000808 bool hasSGPRInitBug() const {
809 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000810 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000811
Tom Stellardb133fbb2016-10-27 23:05:31 +0000812 bool has12DWordStoreHazard() const {
813 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
814 }
815
Matt Arsenaulte823d922017-02-18 18:29:53 +0000816 bool hasSMovFedHazard() const {
817 return getGeneration() >= AMDGPUSubtarget::GFX9;
818 }
819
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000820 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000821 return getGeneration() >= AMDGPUSubtarget::GFX9;
822 }
823
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000824 bool hasReadM0SendMsgHazard() const {
825 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
826 }
827
Matt Arsenaultf5be3ad2018-06-29 17:31:42 +0000828 uint64_t getExplicitKernArgSize(const Function &F) const;
Matt Arsenaultceafc552018-05-29 17:42:50 +0000829 unsigned getKernArgSegmentSize(const Function &F,
Matt Arsenaultf5be3ad2018-06-29 17:31:42 +0000830 int64_t ExplicitArgBytes = -1) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000831
Tom Stellardc5a154d2018-06-28 23:47:12 +0000832 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
833 /// SGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000834 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
835
Tom Stellardc5a154d2018-06-28 23:47:12 +0000836 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
837 /// VGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000838 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000839
Matt Arsenaulte823d922017-02-18 18:29:53 +0000840 /// \returns true if the flat_scratch register should be initialized with the
841 /// pointer to the wave's scratch memory rather than a size and offset.
842 bool flatScratchIsPointer() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000843 return getGeneration() >= AMDGPUSubtarget::GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000844 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000845
Tim Renouf832f90f2018-02-26 14:46:43 +0000846 /// \returns true if the machine has merged shaders in which s0-s7 are
847 /// reserved by the hardware and user SGPRs start at s8
848 bool hasMergedShaders() const {
849 return getGeneration() >= GFX9;
850 }
851
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000852 /// \returns SGPR allocation granularity supported by the subtarget.
853 unsigned getSGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000854 return AMDGPU::IsaInfo::getSGPRAllocGranule(
855 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000856 }
857
858 /// \returns SGPR encoding granularity supported by the subtarget.
859 unsigned getSGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000860 return AMDGPU::IsaInfo::getSGPREncodingGranule(
861 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000862 }
863
864 /// \returns Total number of SGPRs supported by the subtarget.
865 unsigned getTotalNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000866 return AMDGPU::IsaInfo::getTotalNumSGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000867 }
868
869 /// \returns Addressable number of SGPRs supported by the subtarget.
870 unsigned getAddressableNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000871 return AMDGPU::IsaInfo::getAddressableNumSGPRs(
872 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000873 }
874
875 /// \returns Minimum number of SGPRs that meets the given number of waves per
876 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000877 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000878 return AMDGPU::IsaInfo::getMinNumSGPRs(MCSubtargetInfo::getFeatureBits(),
879 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000880 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000881
882 /// \returns Maximum number of SGPRs that meets the given number of waves per
883 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000884 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000885 return AMDGPU::IsaInfo::getMaxNumSGPRs(MCSubtargetInfo::getFeatureBits(),
886 WavesPerEU, Addressable);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000887 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000888
889 /// \returns Reserved number of SGPRs for given function \p MF.
890 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
891
892 /// \returns Maximum number of SGPRs that meets number of waves per execution
893 /// unit requirement for function \p MF, or number of SGPRs explicitly
894 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
895 ///
896 /// \returns Value that meets number of waves per execution unit requirement
897 /// if explicitly requested value cannot be converted to integer, violates
898 /// subtarget's specifications, or does not meet number of waves per execution
899 /// unit requirement.
900 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
901
902 /// \returns VGPR allocation granularity supported by the subtarget.
903 unsigned getVGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000904 return AMDGPU::IsaInfo::getVGPRAllocGranule(
905 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000906 }
907
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000908 /// \returns VGPR encoding granularity supported by the subtarget.
909 unsigned getVGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000910 return AMDGPU::IsaInfo::getVGPREncodingGranule(
911 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000912 }
913
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000914 /// \returns Total number of VGPRs supported by the subtarget.
915 unsigned getTotalNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000916 return AMDGPU::IsaInfo::getTotalNumVGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000917 }
918
919 /// \returns Addressable number of VGPRs supported by the subtarget.
920 unsigned getAddressableNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000921 return AMDGPU::IsaInfo::getAddressableNumVGPRs(
922 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000923 }
924
925 /// \returns Minimum number of VGPRs that meets given number of waves per
926 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000927 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000928 return AMDGPU::IsaInfo::getMinNumVGPRs(MCSubtargetInfo::getFeatureBits(),
929 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000930 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000931
932 /// \returns Maximum number of VGPRs that meets given number of waves per
933 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000934 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000935 return AMDGPU::IsaInfo::getMaxNumVGPRs(MCSubtargetInfo::getFeatureBits(),
936 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000937 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000938
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000939 /// \returns Maximum number of VGPRs that meets number of waves per execution
940 /// unit requirement for function \p MF, or number of VGPRs explicitly
941 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
942 ///
943 /// \returns Value that meets number of waves per execution unit requirement
944 /// if explicitly requested value cannot be converted to integer, violates
945 /// subtarget's specifications, or does not meet number of waves per execution
946 /// unit requirement.
947 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000948
949 void getPostRAMutations(
950 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
951 const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000952};
953
Tom Stellardc5a154d2018-06-28 23:47:12 +0000954class R600Subtarget final : public R600GenSubtargetInfo,
Tom Stellard5bfbae52018-07-11 20:59:01 +0000955 public AMDGPUSubtarget {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000956private:
957 R600InstrInfo InstrInfo;
958 R600FrameLowering FrameLowering;
959 bool FMA;
960 bool CaymanISA;
961 bool CFALUBug;
962 bool DX10Clamp;
963 bool HasVertexCache;
964 bool R600ALUInst;
965 bool FP64;
966 short TexVTXClauseSize;
967 Generation Gen;
968 R600TargetLowering TLInfo;
969 InstrItineraryData InstrItins;
970 SelectionDAGTargetInfo TSInfo;
971 AMDGPUAS AS;
972
973public:
974 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
975 const TargetMachine &TM);
976
977 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
978
979 const R600FrameLowering *getFrameLowering() const override {
980 return &FrameLowering;
981 }
982
983 const R600TargetLowering *getTargetLowering() const override {
984 return &TLInfo;
985 }
986
987 const R600RegisterInfo *getRegisterInfo() const override {
988 return &InstrInfo.getRegisterInfo();
989 }
990
991 const InstrItineraryData *getInstrItineraryData() const override {
992 return &InstrItins;
993 }
994
995 // Nothing implemented, just prevent crashes on use.
996 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
997 return &TSInfo;
998 }
999
1000 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1001
1002 Generation getGeneration() const {
1003 return Gen;
1004 }
1005
1006 unsigned getStackAlignment() const {
1007 return 4;
1008 }
1009
1010 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1011 StringRef GPU, StringRef FS);
1012
1013 bool hasBFE() const {
1014 return (getGeneration() >= EVERGREEN);
1015 }
1016
1017 bool hasBFI() const {
1018 return (getGeneration() >= EVERGREEN);
1019 }
1020
1021 bool hasBCNT(unsigned Size) const {
1022 if (Size == 32)
1023 return (getGeneration() >= EVERGREEN);
1024
1025 return false;
1026 }
1027
1028 bool hasBORROW() const {
1029 return (getGeneration() >= EVERGREEN);
1030 }
1031
1032 bool hasCARRY() const {
1033 return (getGeneration() >= EVERGREEN);
1034 }
1035
1036 bool hasCaymanISA() const {
1037 return CaymanISA;
1038 }
1039
1040 bool hasFFBL() const {
1041 return (getGeneration() >= EVERGREEN);
1042 }
1043
1044 bool hasFFBH() const {
1045 return (getGeneration() >= EVERGREEN);
1046 }
1047
1048 bool hasFMA() const { return FMA; }
1049
Tom Stellardc5a154d2018-06-28 23:47:12 +00001050 bool hasCFAluBug() const { return CFALUBug; }
1051
1052 bool hasVertexCache() const { return HasVertexCache; }
1053
1054 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1055
1056 AMDGPUAS getAMDGPUAS() const { return AS; }
1057
1058 bool enableMachineScheduler() const override {
1059 return true;
1060 }
1061
1062 bool enableSubRegLiveness() const override {
1063 return true;
1064 }
1065};
1066
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001067} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +00001068
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001069#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H