blob: db9ebd1a778d5fcbfb0dcfb0fb4f608f575c8c56 [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,
Matt Arsenault4bec7d42018-07-20 09:05:08 +000054 EVERGREEN = 2,
Tom Stellard5bfbae52018-07-11 20:59:01 +000055 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;
Matt Arsenault6c7ba822018-08-15 21:03:55 +000075 bool HasInv2PiInlineImm;
Tom Stellardc5a154d2018-06-28 23:47:12 +000076 bool HasFminFmaxLegacy;
77 bool EnablePromoteAlloca;
78 int LocalMemorySize;
79 unsigned WavefrontSize;
80
81public:
Tom Stellard5bfbae52018-07-11 20:59:01 +000082 AMDGPUSubtarget(const Triple &TT, const FeatureBitset &FeatureBits);
Tom Stellardc5a154d2018-06-28 23:47:12 +000083
Tom Stellard5bfbae52018-07-11 20:59:01 +000084 static const AMDGPUSubtarget &get(const MachineFunction &MF);
85 static const AMDGPUSubtarget &get(const TargetMachine &TM,
Matt Arsenault4bec7d42018-07-20 09:05:08 +000086 const Function &F);
Tom Stellardc5a154d2018-06-28 23:47:12 +000087
88 /// \returns Default range flat work group size for a calling convention.
89 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
90
91 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
92 /// for function \p F, or minimum/maximum flat work group sizes explicitly
93 /// requested using "amdgpu-flat-work-group-size" attribute attached to
94 /// function \p F.
95 ///
96 /// \returns Subtarget's default values if explicitly requested values cannot
97 /// be converted to integer, or violate subtarget's specifications.
98 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
99
100 /// \returns Subtarget's default pair of minimum/maximum number of waves per
101 /// execution unit for function \p F, or minimum/maximum number of waves per
102 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
103 /// attached to function \p F.
104 ///
105 /// \returns Subtarget's default values if explicitly requested values cannot
106 /// be converted to integer, violate subtarget's specifications, or are not
107 /// compatible with minimum/maximum number of waves limited by flat work group
108 /// size, register usage, and/or lds usage.
109 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
110
111 /// Return the amount of LDS that can be used that will not restrict the
112 /// occupancy lower than WaveCount.
113 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
114 const Function &) const;
115
116 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
117 /// the given LDS memory size is the only constraint.
118 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
119
120 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const;
121
122 bool isAmdHsaOS() const {
123 return TargetTriple.getOS() == Triple::AMDHSA;
124 }
125
126 bool isAmdPalOS() const {
127 return TargetTriple.getOS() == Triple::AMDPAL;
128 }
129
Tom Stellardec4feae2018-07-06 17:16:17 +0000130 bool isMesa3DOS() const {
131 return TargetTriple.getOS() == Triple::Mesa3D;
132 }
133
134 bool isMesaKernel(const Function &F) const {
135 return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
136 }
137
138 bool isAmdCodeObjectV2(const Function &F) const {
139 return isAmdHsaOS() || isMesaKernel(F);
140 }
141
Tom Stellardc5a154d2018-06-28 23:47:12 +0000142 bool has16BitInsts() const {
143 return Has16BitInsts;
144 }
145
146 bool hasMadMixInsts() const {
147 return HasMadMixInsts;
148 }
149
150 bool hasFP32Denormals() const {
151 return FP32Denormals;
152 }
153
154 bool hasFPExceptions() const {
155 return FPExceptions;
156 }
157
158 bool hasSDWA() const {
159 return HasSDWA;
160 }
161
162 bool hasVOP3PInsts() const {
163 return HasVOP3PInsts;
164 }
165
166 bool hasMulI24() const {
167 return HasMulI24;
168 }
169
170 bool hasMulU24() const {
171 return HasMulU24;
172 }
173
Matt Arsenault6c7ba822018-08-15 21:03:55 +0000174 bool hasInv2PiInlineImm() const {
175 return HasInv2PiInlineImm;
176 }
177
Tom Stellardc5a154d2018-06-28 23:47:12 +0000178 bool hasFminFmaxLegacy() const {
179 return HasFminFmaxLegacy;
180 }
181
182 bool isPromoteAllocaEnabled() const {
183 return EnablePromoteAlloca;
184 }
185
186 unsigned getWavefrontSize() const {
187 return WavefrontSize;
188 }
189
190 int getLocalMemorySize() const {
191 return LocalMemorySize;
192 }
193
194 unsigned getAlignmentForImplicitArgPtr() const {
195 return isAmdHsaOS() ? 8 : 4;
196 }
197
Tom Stellardec4feae2018-07-06 17:16:17 +0000198 /// Returns the offset in bytes from the start of the input buffer
199 /// of the first explicit kernel argument.
200 unsigned getExplicitKernelArgOffset(const Function &F) const {
201 return isAmdCodeObjectV2(F) ? 0 : 36;
202 }
203
Tom Stellardc5a154d2018-06-28 23:47:12 +0000204 /// \returns Maximum number of work groups per compute unit supported by the
205 /// subtarget and limited by given \p FlatWorkGroupSize.
206 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
207 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(SubtargetFeatureBits,
208 FlatWorkGroupSize);
209 }
210
211 /// \returns Minimum flat work group size supported by the subtarget.
212 unsigned getMinFlatWorkGroupSize() const {
213 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(SubtargetFeatureBits);
214 }
215
216 /// \returns Maximum flat work group size supported by the subtarget.
217 unsigned getMaxFlatWorkGroupSize() const {
218 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(SubtargetFeatureBits);
219 }
220
221 /// \returns Maximum number of waves per execution unit supported by the
222 /// subtarget and limited by given \p FlatWorkGroupSize.
223 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
224 return AMDGPU::IsaInfo::getMaxWavesPerEU(SubtargetFeatureBits,
225 FlatWorkGroupSize);
226 }
227
228 /// \returns Minimum number of waves per execution unit supported by the
229 /// subtarget.
230 unsigned getMinWavesPerEU() const {
231 return AMDGPU::IsaInfo::getMinWavesPerEU(SubtargetFeatureBits);
232 }
233
234 unsigned getMaxWavesPerEU() const { return 10; }
235
236 /// Creates value range metadata on an workitemid.* inrinsic call or load.
237 bool makeLIDRangeMetadata(Instruction *I) const;
238
Matt Arsenault4bec7d42018-07-20 09:05:08 +0000239 /// \returns Number of bytes of arguments that are passed to a shader or
240 /// kernel in addition to the explicit ones declared for the function.
241 unsigned getImplicitArgNumBytes(const Function &F) const {
242 if (isMesaKernel(F))
243 return 16;
244 return AMDGPU::getIntegerAttribute(F, "amdgpu-implicitarg-num-bytes", 0);
245 }
246 uint64_t getExplicitKernArgSize(const Function &F,
247 unsigned &MaxAlign) const;
248 unsigned getKernArgSegmentSize(const Function &F,
249 unsigned &MaxAlign) const;
250
Tom Stellard5bfbae52018-07-11 20:59:01 +0000251 virtual ~AMDGPUSubtarget() {}
Tom Stellardc5a154d2018-06-28 23:47:12 +0000252};
253
Tom Stellard5bfbae52018-07-11 20:59:01 +0000254class GCNSubtarget : public AMDGPUGenSubtargetInfo,
255 public AMDGPUSubtarget {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000256public:
Marek Olsak4d00dd22015-03-09 15:48:09 +0000257 enum {
Tom Stellard347ac792015-06-26 21:15:07 +0000258 ISAVersion0_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +0000259 ISAVersion6_0_0,
260 ISAVersion6_0_1,
Tom Stellard347ac792015-06-26 21:15:07 +0000261 ISAVersion7_0_0,
262 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +0000263 ISAVersion7_0_2,
Wei Ding7c3e5112017-06-10 03:53:19 +0000264 ISAVersion7_0_3,
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000265 ISAVersion7_0_4,
Changpeng Fangc16be002016-01-13 20:39:25 +0000266 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +0000267 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +0000268 ISAVersion8_0_3,
Yaxun Liu94add852016-10-26 16:37:56 +0000269 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +0000270 ISAVersion9_0_0,
Matt Arsenault0084adc2018-04-30 19:08:16 +0000271 ISAVersion9_0_2,
272 ISAVersion9_0_4,
Konstantin Zhuravlyov1501af42018-05-01 18:47:48 +0000273 ISAVersion9_0_6,
Tom Stellard347ac792015-06-26 21:15:07 +0000274 };
275
Wei Ding205bfdb2017-02-10 02:15:29 +0000276 enum TrapHandlerAbi {
277 TrapHandlerAbiNone = 0,
278 TrapHandlerAbiHsa = 1
279 };
280
Wei Dingf2cce022017-02-22 23:22:19 +0000281 enum TrapID {
282 TrapIDHardwareReserved = 0,
283 TrapIDHSADebugTrap = 1,
284 TrapIDLLVMTrap = 2,
285 TrapIDLLVMDebugTrap = 3,
286 TrapIDDebugBreakpoint = 7,
287 TrapIDDebugReserved8 = 8,
288 TrapIDDebugReservedFE = 0xfe,
289 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +0000290 };
291
292 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +0000293 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +0000294 };
295
Tom Stellardc5a154d2018-06-28 23:47:12 +0000296private:
Tom Stellardc5a154d2018-06-28 23:47:12 +0000297 /// GlobalISel related APIs.
298 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
299 std::unique_ptr<InstructionSelector> InstSelector;
300 std::unique_ptr<LegalizerInfo> Legalizer;
301 std::unique_ptr<RegisterBankInfo> RegBankInfo;
302
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000303protected:
304 // Basic subtarget description.
305 Triple TargetTriple;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000306 unsigned Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000307 unsigned IsaVersion;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000308 int LDSBankCount;
309 unsigned MaxPrivateElementSize;
310
311 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000312 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000313 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000314
315 // Dynamially set bits that enable features.
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000316 bool FP64FP16Denormals;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000317 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000318 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000319 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000320 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000321 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000322 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000323 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000324 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000325 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000326 bool DebuggerInsertNops;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000327 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000328
329 // Used as options.
Matt Arsenault45b98182017-11-15 00:45:43 +0000330 bool EnableHugePrivateBuffer;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000331 bool EnableVGPRSpilling;
Matt Arsenault41033282014-10-10 22:01:59 +0000332 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000333 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000334 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000335 bool EnableDS128;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000336 bool DumpCode;
337
338 // Subtarget statically properties set by tablegen
339 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000340 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000341 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000342 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000343 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000344 bool CIInsts;
Matt Arsenault96b67842018-08-07 07:28:46 +0000345 bool VIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000346 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000347 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000348 bool HasSMemRealTime;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000349 bool HasIntClamp;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000350 bool HasFmaMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000351 bool HasMovrel;
352 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000353 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000354 bool HasScalarAtomics;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000355 bool HasSDWAOmod;
356 bool HasSDWAScalar;
357 bool HasSDWASdst;
358 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000359 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000360 bool HasDPP;
Ryan Taylor1f334d02018-08-28 15:07:30 +0000361 bool HasR128A16;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000362 bool HasDLInsts;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000363 bool D16PreservesUnusedBits;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000364 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000365 bool FlatInstOffsets;
366 bool FlatGlobalInsts;
367 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000368 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000369 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000370 bool R600ALUInst;
371 bool CaymanISA;
372 bool CFALUBug;
373 bool HasVertexCache;
374 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000375 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000376
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000377 // Dummy feature to use for assembler in tablegen.
378 bool FeatureDisable;
379
Matt Arsenault56684d42016-08-11 17:31:42 +0000380 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000381 AMDGPUAS AS;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000382private:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000383 SIInstrInfo InstrInfo;
Tom Stellard752ddbd2018-07-11 22:15:15 +0000384 SITargetLowering TLInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000385 SIFrameLowering FrameLowering;
Tom Stellard75aadc22012-12-11 21:25:42 +0000386
387public:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000388 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
389 const GCNTargetMachine &TM);
390 ~GCNSubtarget() override;
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000391
Tom Stellard5bfbae52018-07-11 20:59:01 +0000392 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000393 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000394
Tom Stellard5bfbae52018-07-11 20:59:01 +0000395 const SIInstrInfo *getInstrInfo() const override {
396 return &InstrInfo;
397 }
Tom Stellard000c5af2016-04-14 19:09:28 +0000398
Tom Stellardc5a154d2018-06-28 23:47:12 +0000399 const SIFrameLowering *getFrameLowering() const override {
400 return &FrameLowering;
401 }
402
Tom Stellard5bfbae52018-07-11 20:59:01 +0000403 const SITargetLowering *getTargetLowering() const override {
404 return &TLInfo;
405 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000406
Tom Stellard5bfbae52018-07-11 20:59:01 +0000407 const SIRegisterInfo *getRegisterInfo() const override {
408 return &InstrInfo.getRegisterInfo();
409 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000410
411 const CallLowering *getCallLowering() const override {
412 return CallLoweringInfo.get();
413 }
414
415 const InstructionSelector *getInstructionSelector() const override {
416 return InstSelector.get();
417 }
418
419 const LegalizerInfo *getLegalizerInfo() const override {
420 return Legalizer.get();
421 }
422
423 const RegisterBankInfo *getRegBankInfo() const override {
424 return RegBankInfo.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000425 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000426
Matt Arsenault56684d42016-08-11 17:31:42 +0000427 // Nothing implemented, just prevent crashes on use.
428 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
429 return &TSInfo;
430 }
431
Craig Topperee7b0f32014-04-30 05:53:27 +0000432 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000433
Matt Arsenaultd782d052014-06-27 17:57:00 +0000434 Generation getGeneration() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000435 return (Generation)Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000436 }
437
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000438 unsigned getWavefrontSizeLog2() const {
439 return Log2_32(WavefrontSize);
440 }
441
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000442 int getLDSBankCount() const {
443 return LDSBankCount;
444 }
445
446 unsigned getMaxPrivateElementSize() const {
447 return MaxPrivateElementSize;
448 }
449
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000450 AMDGPUAS getAMDGPUAS() const {
451 return AS;
452 }
453
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000454 bool hasIntClamp() const {
455 return HasIntClamp;
456 }
457
Jan Veselyd1c9b612017-12-04 22:57:29 +0000458 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000459 return FP64;
460 }
461
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000462 bool hasMIMG_R128() const {
463 return MIMG_R128;
464 }
465
Tom Stellardc5a154d2018-06-28 23:47:12 +0000466 bool hasHWFP64() const {
467 return FP64;
468 }
469
Matt Arsenaultb035a572015-01-29 19:34:25 +0000470 bool hasFastFMAF32() const {
471 return FastFMAF32;
472 }
473
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000474 bool hasHalfRate64Ops() const {
475 return HalfRate64Ops;
476 }
477
Matt Arsenault88701812016-06-09 23:42:48 +0000478 bool hasAddr64() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000479 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
Matt Arsenault88701812016-06-09 23:42:48 +0000480 }
481
Matt Arsenaultfae02982014-03-17 18:58:11 +0000482 bool hasBFE() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000483 return true;
Matt Arsenaultfae02982014-03-17 18:58:11 +0000484 }
485
Matt Arsenault6e439652014-06-10 19:00:20 +0000486 bool hasBFI() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000487 return true;
Matt Arsenault6e439652014-06-10 19:00:20 +0000488 }
489
Matt Arsenaultfae02982014-03-17 18:58:11 +0000490 bool hasBFM() const {
491 return hasBFE();
492 }
493
Matt Arsenault60425062014-06-10 19:18:28 +0000494 bool hasBCNT(unsigned Size) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000495 return true;
Tom Stellard50122a52014-04-07 19:45:41 +0000496 }
497
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000498 bool hasFFBL() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000499 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000500 }
501
502 bool hasFFBH() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000503 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000504 }
505
Matt Arsenault10268f92017-02-27 22:40:39 +0000506 bool hasMed3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000507 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenault10268f92017-02-27 22:40:39 +0000508 }
509
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000510 bool hasMin3Max3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000511 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000512 }
513
Matt Arsenault0084adc2018-04-30 19:08:16 +0000514 bool hasFmaMixInsts() const {
515 return HasFmaMixInsts;
516 }
517
Jan Vesely808fff52015-04-30 17:15:56 +0000518 bool hasCARRY() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000519 return true;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000520 }
521
Jan Vesely39aeab42017-12-04 23:07:28 +0000522 bool hasFMA() const {
523 return FMA;
524 }
525
Wei Ding205bfdb2017-02-10 02:15:29 +0000526 TrapHandlerAbi getTrapHandlerAbi() const {
527 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
528 }
529
Matt Arsenault45b98182017-11-15 00:45:43 +0000530 bool enableHugePrivateBuffer() const {
531 return EnableHugePrivateBuffer;
532 }
533
Matt Arsenault706f9302015-07-06 16:01:58 +0000534 bool unsafeDSOffsetFoldingEnabled() const {
535 return EnableUnsafeDSOffsetFolding;
536 }
537
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000538 bool dumpCode() const {
539 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000540 }
541
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000542 /// Return the amount of LDS that can be used that will not restrict the
543 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000544 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
545 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000546
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000547 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000548 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000549 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000550
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000551 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000552 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000553 }
554
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000555 bool supportsMinMaxDenormModes() const {
556 return getGeneration() >= AMDGPUSubtarget::GFX9;
557 }
558
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000559 bool enableDX10Clamp() const {
560 return DX10Clamp;
561 }
562
563 bool enableIEEEBit(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000564 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000565 }
566
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000567 bool useFlatForGlobal() const {
568 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000569 }
570
Farhana Aleena7cb3112018-03-09 17:41:39 +0000571 /// \returns If target supports ds_read/write_b128 and user enables generation
572 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000573 bool useDS128() const {
574 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000575 }
576
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000577 /// \returns If MUBUF instructions always perform range checking, even for
578 /// buffer resources used for private memory access.
579 bool privateMemoryResourceIsRangeChecked() const {
580 return getGeneration() < AMDGPUSubtarget::GFX9;
581 }
582
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000583 bool hasAutoWaitcntBeforeBarrier() const {
584 return AutoWaitcntBeforeBarrier;
585 }
586
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000587 bool hasCodeObjectV3() const {
588 return CodeObjectV3;
589 }
590
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000591 bool hasUnalignedBufferAccess() const {
592 return UnalignedBufferAccess;
593 }
594
Tom Stellard64a9d082016-10-14 18:10:39 +0000595 bool hasUnalignedScratchAccess() const {
596 return UnalignedScratchAccess;
597 }
598
Matt Arsenaulte823d922017-02-18 18:29:53 +0000599 bool hasApertureRegs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000600 return HasApertureRegs;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000601 }
602
Wei Ding205bfdb2017-02-10 02:15:29 +0000603 bool isTrapHandlerEnabled() const {
604 return TrapHandler;
605 }
606
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000607 bool isXNACKEnabled() const {
608 return EnableXNACK;
609 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000610
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000611 bool hasFlatAddressSpace() const {
612 return FlatAddressSpace;
613 }
614
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000615 bool hasFlatInstOffsets() const {
616 return FlatInstOffsets;
617 }
618
619 bool hasFlatGlobalInsts() const {
620 return FlatGlobalInsts;
621 }
622
623 bool hasFlatScratchInsts() const {
624 return FlatScratchInsts;
625 }
626
Mark Searlesf0b93f12018-06-04 16:51:59 +0000627 bool hasFlatLgkmVMemCountInOrder() const {
628 return getGeneration() > GFX9;
629 }
630
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000631 bool hasD16LoadStore() const {
632 return getGeneration() >= GFX9;
633 }
634
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000635 /// Return if most LDS instructions have an m0 use that require m0 to be
636 /// iniitalized.
637 bool ldsRequiresM0Init() const {
638 return getGeneration() < GFX9;
639 }
640
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000641 bool hasAddNoCarry() const {
642 return AddNoCarryInsts;
643 }
644
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000645 bool hasUnpackedD16VMem() const {
646 return HasUnpackedD16VMem;
647 }
648
Tom Stellard2f3f9852017-01-25 01:25:13 +0000649 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000650 bool isMesaGfxShader(const Function &F) const {
651 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000652 }
653
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000654 bool hasMad64_32() const {
655 return getGeneration() >= SEA_ISLANDS;
656 }
657
Sam Kolton3c4933f2017-06-22 06:26:41 +0000658 bool hasSDWAOmod() const {
659 return HasSDWAOmod;
660 }
661
662 bool hasSDWAScalar() const {
663 return HasSDWAScalar;
664 }
665
666 bool hasSDWASdst() const {
667 return HasSDWASdst;
668 }
669
670 bool hasSDWAMac() const {
671 return HasSDWAMac;
672 }
673
Sam Koltona179d252017-06-27 15:02:23 +0000674 bool hasSDWAOutModsVOPC() const {
675 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000676 }
677
Mark Searles2a19af62018-04-26 16:11:19 +0000678 bool vmemWriteNeedsExpWaitcnt() const {
679 return getGeneration() < SEA_ISLANDS;
680 }
681
Matt Arsenault0084adc2018-04-30 19:08:16 +0000682 bool hasDLInsts() const {
683 return HasDLInsts;
684 }
685
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000686 bool d16PreservesUnusedBits() const {
687 return D16PreservesUnusedBits;
688 }
689
Matt Arsenault869fec22017-04-17 19:48:24 +0000690 // Scratch is allocated in 256 dword per wave blocks for the entire
691 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
692 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000693 //
694 // Only 4-byte alignment is really needed to access anything. Transformations
695 // on the pointer value itself may rely on the alignment / known low bits of
696 // the pointer. Set this to something above the minimum to avoid needing
697 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000698 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000699 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000700 }
Tom Stellard347ac792015-06-26 21:15:07 +0000701
Craig Topper5656db42014-04-29 07:57:24 +0000702 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000703 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000704 }
705
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000706 bool enableSubRegLiveness() const override {
707 return true;
708 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000709
Tom Stellardc5a154d2018-06-28 23:47:12 +0000710 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
711 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000712
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000713 /// \returns Number of execution units per compute unit supported by the
714 /// subtarget.
715 unsigned getEUsPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000716 return AMDGPU::IsaInfo::getEUsPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000717 }
718
719 /// \returns Maximum number of waves per compute unit supported by the
720 /// subtarget without any kind of limitation.
721 unsigned getMaxWavesPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000722 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000723 }
724
725 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000726 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000727 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000728 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits(),
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000729 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000730 }
731
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000732 /// \returns Maximum number of waves per execution unit supported by the
733 /// subtarget without any kind of limitation.
734 unsigned getMaxWavesPerEU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000735 return AMDGPU::IsaInfo::getMaxWavesPerEU();
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000736 }
737
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000738 /// \returns Number of waves per work group supported by the subtarget and
739 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000740 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000741 return AMDGPU::IsaInfo::getWavesPerWorkGroup(
742 MCSubtargetInfo::getFeatureBits(), FlatWorkGroupSize);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000743 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000744
Tom Stellardc5a154d2018-06-28 23:47:12 +0000745 // static wrappers
746 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000747
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000748 // XXX - Why is this here if it isn't in the default pass set?
749 bool enableEarlyIfConversion() const override {
750 return true;
751 }
752
Tom Stellard83f0bce2015-01-29 16:55:25 +0000753 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000754 unsigned NumRegionInstrs) const override;
755
Tom Stellardc5a154d2018-06-28 23:47:12 +0000756 bool isVGPRSpillingEnabled(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000757
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000758 unsigned getMaxNumUserSGPRs() const {
759 return 16;
760 }
761
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000762 bool hasSMemRealTime() const {
763 return HasSMemRealTime;
764 }
765
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000766 bool hasMovrel() const {
767 return HasMovrel;
768 }
769
770 bool hasVGPRIndexMode() const {
771 return HasVGPRIndexMode;
772 }
773
Marek Olsake22fdb92017-03-21 17:00:32 +0000774 bool useVGPRIndexMode(bool UserEnable) const {
775 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
776 }
777
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000778 bool hasScalarCompareEq64() const {
779 return getGeneration() >= VOLCANIC_ISLANDS;
780 }
781
Matt Arsenault7b647552016-10-28 21:55:15 +0000782 bool hasScalarStores() const {
783 return HasScalarStores;
784 }
785
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000786 bool hasScalarAtomics() const {
787 return HasScalarAtomics;
788 }
789
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000790
Sam Kolton07dbde22017-01-20 10:01:25 +0000791 bool hasDPP() const {
792 return HasDPP;
793 }
794
Ryan Taylor1f334d02018-08-28 15:07:30 +0000795 bool hasR128A16() const {
796 return HasR128A16;
797 }
798
Tom Stellardde008d32016-01-21 04:28:34 +0000799 bool enableSIScheduler() const {
800 return EnableSIScheduler;
801 }
802
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000803 bool debuggerSupported() const {
Konstantin Zhuravlyove004b3d2018-06-21 20:28:19 +0000804 return debuggerInsertNops() && debuggerEmitPrologue();
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000805 }
806
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000807 bool debuggerInsertNops() const {
808 return DebuggerInsertNops;
809 }
810
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000811 bool debuggerEmitPrologue() const {
812 return DebuggerEmitPrologue;
813 }
814
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000815 bool loadStoreOptEnabled() const {
816 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000817 }
818
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000819 bool hasSGPRInitBug() const {
820 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000821 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000822
Tom Stellardb133fbb2016-10-27 23:05:31 +0000823 bool has12DWordStoreHazard() const {
824 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
825 }
826
Matt Arsenaulte823d922017-02-18 18:29:53 +0000827 bool hasSMovFedHazard() const {
828 return getGeneration() >= AMDGPUSubtarget::GFX9;
829 }
830
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000831 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000832 return getGeneration() >= AMDGPUSubtarget::GFX9;
833 }
834
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000835 bool hasReadM0SendMsgHazard() const {
836 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
837 }
838
Tom Stellardc5a154d2018-06-28 23:47:12 +0000839 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
840 /// SGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000841 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
842
Tom Stellardc5a154d2018-06-28 23:47:12 +0000843 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
844 /// VGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000845 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000846
Matt Arsenaulte823d922017-02-18 18:29:53 +0000847 /// \returns true if the flat_scratch register should be initialized with the
848 /// pointer to the wave's scratch memory rather than a size and offset.
849 bool flatScratchIsPointer() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000850 return getGeneration() >= AMDGPUSubtarget::GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000851 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000852
Tim Renouf832f90f2018-02-26 14:46:43 +0000853 /// \returns true if the machine has merged shaders in which s0-s7 are
854 /// reserved by the hardware and user SGPRs start at s8
855 bool hasMergedShaders() const {
856 return getGeneration() >= GFX9;
857 }
858
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000859 /// \returns SGPR allocation granularity supported by the subtarget.
860 unsigned getSGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000861 return AMDGPU::IsaInfo::getSGPRAllocGranule(
862 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000863 }
864
865 /// \returns SGPR encoding granularity supported by the subtarget.
866 unsigned getSGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000867 return AMDGPU::IsaInfo::getSGPREncodingGranule(
868 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000869 }
870
871 /// \returns Total number of SGPRs supported by the subtarget.
872 unsigned getTotalNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000873 return AMDGPU::IsaInfo::getTotalNumSGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000874 }
875
876 /// \returns Addressable number of SGPRs supported by the subtarget.
877 unsigned getAddressableNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000878 return AMDGPU::IsaInfo::getAddressableNumSGPRs(
879 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000880 }
881
882 /// \returns Minimum 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 getMinNumSGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000885 return AMDGPU::IsaInfo::getMinNumSGPRs(MCSubtargetInfo::getFeatureBits(),
886 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000887 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000888
889 /// \returns Maximum number of SGPRs that meets the given number of waves per
890 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000891 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000892 return AMDGPU::IsaInfo::getMaxNumSGPRs(MCSubtargetInfo::getFeatureBits(),
893 WavesPerEU, Addressable);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000894 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000895
896 /// \returns Reserved number of SGPRs for given function \p MF.
897 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
898
899 /// \returns Maximum number of SGPRs that meets number of waves per execution
900 /// unit requirement for function \p MF, or number of SGPRs explicitly
901 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
902 ///
903 /// \returns Value that meets number of waves per execution unit requirement
904 /// if explicitly requested value cannot be converted to integer, violates
905 /// subtarget's specifications, or does not meet number of waves per execution
906 /// unit requirement.
907 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
908
909 /// \returns VGPR allocation granularity supported by the subtarget.
910 unsigned getVGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000911 return AMDGPU::IsaInfo::getVGPRAllocGranule(
912 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000913 }
914
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000915 /// \returns VGPR encoding granularity supported by the subtarget.
916 unsigned getVGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000917 return AMDGPU::IsaInfo::getVGPREncodingGranule(
918 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000919 }
920
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000921 /// \returns Total number of VGPRs supported by the subtarget.
922 unsigned getTotalNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000923 return AMDGPU::IsaInfo::getTotalNumVGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000924 }
925
926 /// \returns Addressable number of VGPRs supported by the subtarget.
927 unsigned getAddressableNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000928 return AMDGPU::IsaInfo::getAddressableNumVGPRs(
929 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000930 }
931
932 /// \returns Minimum 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 getMinNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000935 return AMDGPU::IsaInfo::getMinNumVGPRs(MCSubtargetInfo::getFeatureBits(),
936 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000937 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000938
939 /// \returns Maximum number of VGPRs that meets given number of waves per
940 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000941 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000942 return AMDGPU::IsaInfo::getMaxNumVGPRs(MCSubtargetInfo::getFeatureBits(),
943 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000944 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000945
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000946 /// \returns Maximum number of VGPRs that meets number of waves per execution
947 /// unit requirement for function \p MF, or number of VGPRs explicitly
948 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
949 ///
950 /// \returns Value that meets number of waves per execution unit requirement
951 /// if explicitly requested value cannot be converted to integer, violates
952 /// subtarget's specifications, or does not meet number of waves per execution
953 /// unit requirement.
954 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000955
956 void getPostRAMutations(
957 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
958 const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000959};
960
Tom Stellardc5a154d2018-06-28 23:47:12 +0000961class R600Subtarget final : public R600GenSubtargetInfo,
Tom Stellard5bfbae52018-07-11 20:59:01 +0000962 public AMDGPUSubtarget {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000963private:
964 R600InstrInfo InstrInfo;
965 R600FrameLowering FrameLowering;
966 bool FMA;
967 bool CaymanISA;
968 bool CFALUBug;
969 bool DX10Clamp;
970 bool HasVertexCache;
971 bool R600ALUInst;
972 bool FP64;
973 short TexVTXClauseSize;
974 Generation Gen;
975 R600TargetLowering TLInfo;
976 InstrItineraryData InstrItins;
977 SelectionDAGTargetInfo TSInfo;
978 AMDGPUAS AS;
979
980public:
981 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
982 const TargetMachine &TM);
983
984 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
985
986 const R600FrameLowering *getFrameLowering() const override {
987 return &FrameLowering;
988 }
989
990 const R600TargetLowering *getTargetLowering() const override {
991 return &TLInfo;
992 }
993
994 const R600RegisterInfo *getRegisterInfo() const override {
995 return &InstrInfo.getRegisterInfo();
996 }
997
998 const InstrItineraryData *getInstrItineraryData() const override {
999 return &InstrItins;
1000 }
1001
1002 // Nothing implemented, just prevent crashes on use.
1003 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
1004 return &TSInfo;
1005 }
1006
1007 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1008
1009 Generation getGeneration() const {
1010 return Gen;
1011 }
1012
1013 unsigned getStackAlignment() const {
1014 return 4;
1015 }
1016
1017 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1018 StringRef GPU, StringRef FS);
1019
1020 bool hasBFE() const {
1021 return (getGeneration() >= EVERGREEN);
1022 }
1023
1024 bool hasBFI() const {
1025 return (getGeneration() >= EVERGREEN);
1026 }
1027
1028 bool hasBCNT(unsigned Size) const {
1029 if (Size == 32)
1030 return (getGeneration() >= EVERGREEN);
1031
1032 return false;
1033 }
1034
1035 bool hasBORROW() const {
1036 return (getGeneration() >= EVERGREEN);
1037 }
1038
1039 bool hasCARRY() const {
1040 return (getGeneration() >= EVERGREEN);
1041 }
1042
1043 bool hasCaymanISA() const {
1044 return CaymanISA;
1045 }
1046
1047 bool hasFFBL() const {
1048 return (getGeneration() >= EVERGREEN);
1049 }
1050
1051 bool hasFFBH() const {
1052 return (getGeneration() >= EVERGREEN);
1053 }
1054
1055 bool hasFMA() const { return FMA; }
1056
Tom Stellardc5a154d2018-06-28 23:47:12 +00001057 bool hasCFAluBug() const { return CFALUBug; }
1058
1059 bool hasVertexCache() const { return HasVertexCache; }
1060
1061 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1062
1063 AMDGPUAS getAMDGPUAS() const { return AS; }
1064
1065 bool enableMachineScheduler() const override {
1066 return true;
1067 }
1068
1069 bool enableSubRegLiveness() const override {
1070 return true;
1071 }
1072};
1073
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001074} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +00001075
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001076#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H