blob: 03809d8372a01a8165e9010d94a23ef493100b62 [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;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000361 bool HasDLInsts;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000362 bool D16PreservesUnusedBits;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000363 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000364 bool FlatInstOffsets;
365 bool FlatGlobalInsts;
366 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000367 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000368 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000369 bool R600ALUInst;
370 bool CaymanISA;
371 bool CFALUBug;
372 bool HasVertexCache;
373 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000374 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000375
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000376 // Dummy feature to use for assembler in tablegen.
377 bool FeatureDisable;
378
Matt Arsenault56684d42016-08-11 17:31:42 +0000379 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000380 AMDGPUAS AS;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000381private:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000382 SIInstrInfo InstrInfo;
Tom Stellard752ddbd2018-07-11 22:15:15 +0000383 SITargetLowering TLInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000384 SIFrameLowering FrameLowering;
Tom Stellard75aadc22012-12-11 21:25:42 +0000385
386public:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000387 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
388 const GCNTargetMachine &TM);
389 ~GCNSubtarget() override;
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000390
Tom Stellard5bfbae52018-07-11 20:59:01 +0000391 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000392 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000393
Tom Stellard5bfbae52018-07-11 20:59:01 +0000394 const SIInstrInfo *getInstrInfo() const override {
395 return &InstrInfo;
396 }
Tom Stellard000c5af2016-04-14 19:09:28 +0000397
Tom Stellardc5a154d2018-06-28 23:47:12 +0000398 const SIFrameLowering *getFrameLowering() const override {
399 return &FrameLowering;
400 }
401
Tom Stellard5bfbae52018-07-11 20:59:01 +0000402 const SITargetLowering *getTargetLowering() const override {
403 return &TLInfo;
404 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000405
Tom Stellard5bfbae52018-07-11 20:59:01 +0000406 const SIRegisterInfo *getRegisterInfo() const override {
407 return &InstrInfo.getRegisterInfo();
408 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000409
410 const CallLowering *getCallLowering() const override {
411 return CallLoweringInfo.get();
412 }
413
414 const InstructionSelector *getInstructionSelector() const override {
415 return InstSelector.get();
416 }
417
418 const LegalizerInfo *getLegalizerInfo() const override {
419 return Legalizer.get();
420 }
421
422 const RegisterBankInfo *getRegBankInfo() const override {
423 return RegBankInfo.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000424 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000425
Matt Arsenault56684d42016-08-11 17:31:42 +0000426 // Nothing implemented, just prevent crashes on use.
427 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
428 return &TSInfo;
429 }
430
Craig Topperee7b0f32014-04-30 05:53:27 +0000431 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000432
Matt Arsenaultd782d052014-06-27 17:57:00 +0000433 Generation getGeneration() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000434 return (Generation)Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000435 }
436
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000437 unsigned getWavefrontSizeLog2() const {
438 return Log2_32(WavefrontSize);
439 }
440
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000441 int getLDSBankCount() const {
442 return LDSBankCount;
443 }
444
445 unsigned getMaxPrivateElementSize() const {
446 return MaxPrivateElementSize;
447 }
448
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000449 AMDGPUAS getAMDGPUAS() const {
450 return AS;
451 }
452
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000453 bool hasIntClamp() const {
454 return HasIntClamp;
455 }
456
Jan Veselyd1c9b612017-12-04 22:57:29 +0000457 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000458 return FP64;
459 }
460
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000461 bool hasMIMG_R128() const {
462 return MIMG_R128;
463 }
464
Tom Stellardc5a154d2018-06-28 23:47:12 +0000465 bool hasHWFP64() const {
466 return FP64;
467 }
468
Matt Arsenaultb035a572015-01-29 19:34:25 +0000469 bool hasFastFMAF32() const {
470 return FastFMAF32;
471 }
472
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000473 bool hasHalfRate64Ops() const {
474 return HalfRate64Ops;
475 }
476
Matt Arsenault88701812016-06-09 23:42:48 +0000477 bool hasAddr64() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000478 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
Matt Arsenault88701812016-06-09 23:42:48 +0000479 }
480
Matt Arsenaultfae02982014-03-17 18:58:11 +0000481 bool hasBFE() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000482 return true;
Matt Arsenaultfae02982014-03-17 18:58:11 +0000483 }
484
Matt Arsenault6e439652014-06-10 19:00:20 +0000485 bool hasBFI() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000486 return true;
Matt Arsenault6e439652014-06-10 19:00:20 +0000487 }
488
Matt Arsenaultfae02982014-03-17 18:58:11 +0000489 bool hasBFM() const {
490 return hasBFE();
491 }
492
Matt Arsenault60425062014-06-10 19:18:28 +0000493 bool hasBCNT(unsigned Size) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000494 return true;
Tom Stellard50122a52014-04-07 19:45:41 +0000495 }
496
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000497 bool hasFFBL() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000498 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000499 }
500
501 bool hasFFBH() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000502 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000503 }
504
Matt Arsenault10268f92017-02-27 22:40:39 +0000505 bool hasMed3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000506 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenault10268f92017-02-27 22:40:39 +0000507 }
508
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000509 bool hasMin3Max3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000510 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000511 }
512
Matt Arsenault0084adc2018-04-30 19:08:16 +0000513 bool hasFmaMixInsts() const {
514 return HasFmaMixInsts;
515 }
516
Jan Vesely808fff52015-04-30 17:15:56 +0000517 bool hasCARRY() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000518 return true;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000519 }
520
Jan Vesely39aeab42017-12-04 23:07:28 +0000521 bool hasFMA() const {
522 return FMA;
523 }
524
Wei Ding205bfdb2017-02-10 02:15:29 +0000525 TrapHandlerAbi getTrapHandlerAbi() const {
526 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
527 }
528
Matt Arsenault45b98182017-11-15 00:45:43 +0000529 bool enableHugePrivateBuffer() const {
530 return EnableHugePrivateBuffer;
531 }
532
Matt Arsenault706f9302015-07-06 16:01:58 +0000533 bool unsafeDSOffsetFoldingEnabled() const {
534 return EnableUnsafeDSOffsetFolding;
535 }
536
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000537 bool dumpCode() const {
538 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000539 }
540
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000541 /// Return the amount of LDS that can be used that will not restrict the
542 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000543 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
544 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000545
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000546 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000547 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000548 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000549
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000550 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000551 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000552 }
553
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000554 bool supportsMinMaxDenormModes() const {
555 return getGeneration() >= AMDGPUSubtarget::GFX9;
556 }
557
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000558 bool enableDX10Clamp() const {
559 return DX10Clamp;
560 }
561
562 bool enableIEEEBit(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000563 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000564 }
565
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000566 bool useFlatForGlobal() const {
567 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000568 }
569
Farhana Aleena7cb3112018-03-09 17:41:39 +0000570 /// \returns If target supports ds_read/write_b128 and user enables generation
571 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000572 bool useDS128() const {
573 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000574 }
575
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000576 /// \returns If MUBUF instructions always perform range checking, even for
577 /// buffer resources used for private memory access.
578 bool privateMemoryResourceIsRangeChecked() const {
579 return getGeneration() < AMDGPUSubtarget::GFX9;
580 }
581
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000582 bool hasAutoWaitcntBeforeBarrier() const {
583 return AutoWaitcntBeforeBarrier;
584 }
585
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000586 bool hasCodeObjectV3() const {
587 return CodeObjectV3;
588 }
589
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000590 bool hasUnalignedBufferAccess() const {
591 return UnalignedBufferAccess;
592 }
593
Tom Stellard64a9d082016-10-14 18:10:39 +0000594 bool hasUnalignedScratchAccess() const {
595 return UnalignedScratchAccess;
596 }
597
Matt Arsenaulte823d922017-02-18 18:29:53 +0000598 bool hasApertureRegs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000599 return HasApertureRegs;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000600 }
601
Wei Ding205bfdb2017-02-10 02:15:29 +0000602 bool isTrapHandlerEnabled() const {
603 return TrapHandler;
604 }
605
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000606 bool isXNACKEnabled() const {
607 return EnableXNACK;
608 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000609
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000610 bool hasFlatAddressSpace() const {
611 return FlatAddressSpace;
612 }
613
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000614 bool hasFlatInstOffsets() const {
615 return FlatInstOffsets;
616 }
617
618 bool hasFlatGlobalInsts() const {
619 return FlatGlobalInsts;
620 }
621
622 bool hasFlatScratchInsts() const {
623 return FlatScratchInsts;
624 }
625
Mark Searlesf0b93f12018-06-04 16:51:59 +0000626 bool hasFlatLgkmVMemCountInOrder() const {
627 return getGeneration() > GFX9;
628 }
629
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000630 bool hasD16LoadStore() const {
631 return getGeneration() >= GFX9;
632 }
633
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000634 /// Return if most LDS instructions have an m0 use that require m0 to be
635 /// iniitalized.
636 bool ldsRequiresM0Init() const {
637 return getGeneration() < GFX9;
638 }
639
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000640 bool hasAddNoCarry() const {
641 return AddNoCarryInsts;
642 }
643
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000644 bool hasUnpackedD16VMem() const {
645 return HasUnpackedD16VMem;
646 }
647
Tom Stellard2f3f9852017-01-25 01:25:13 +0000648 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000649 bool isMesaGfxShader(const Function &F) const {
650 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000651 }
652
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000653 bool hasMad64_32() const {
654 return getGeneration() >= SEA_ISLANDS;
655 }
656
Sam Kolton3c4933f2017-06-22 06:26:41 +0000657 bool hasSDWAOmod() const {
658 return HasSDWAOmod;
659 }
660
661 bool hasSDWAScalar() const {
662 return HasSDWAScalar;
663 }
664
665 bool hasSDWASdst() const {
666 return HasSDWASdst;
667 }
668
669 bool hasSDWAMac() const {
670 return HasSDWAMac;
671 }
672
Sam Koltona179d252017-06-27 15:02:23 +0000673 bool hasSDWAOutModsVOPC() const {
674 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000675 }
676
Mark Searles2a19af62018-04-26 16:11:19 +0000677 bool vmemWriteNeedsExpWaitcnt() const {
678 return getGeneration() < SEA_ISLANDS;
679 }
680
Matt Arsenault0084adc2018-04-30 19:08:16 +0000681 bool hasDLInsts() const {
682 return HasDLInsts;
683 }
684
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000685 bool d16PreservesUnusedBits() const {
686 return D16PreservesUnusedBits;
687 }
688
Matt Arsenault869fec22017-04-17 19:48:24 +0000689 // Scratch is allocated in 256 dword per wave blocks for the entire
690 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
691 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000692 //
693 // Only 4-byte alignment is really needed to access anything. Transformations
694 // on the pointer value itself may rely on the alignment / known low bits of
695 // the pointer. Set this to something above the minimum to avoid needing
696 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000697 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000698 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000699 }
Tom Stellard347ac792015-06-26 21:15:07 +0000700
Craig Topper5656db42014-04-29 07:57:24 +0000701 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000702 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000703 }
704
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000705 bool enableSubRegLiveness() const override {
706 return true;
707 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000708
Tom Stellardc5a154d2018-06-28 23:47:12 +0000709 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
710 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000711
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000712 /// \returns Number of execution units per compute unit supported by the
713 /// subtarget.
714 unsigned getEUsPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000715 return AMDGPU::IsaInfo::getEUsPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000716 }
717
718 /// \returns Maximum number of waves per compute unit supported by the
719 /// subtarget without any kind of limitation.
720 unsigned getMaxWavesPerCU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000721 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000722 }
723
724 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000725 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000726 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000727 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits(),
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000728 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000729 }
730
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000731 /// \returns Maximum number of waves per execution unit supported by the
732 /// subtarget without any kind of limitation.
733 unsigned getMaxWavesPerEU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000734 return AMDGPU::IsaInfo::getMaxWavesPerEU();
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000735 }
736
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000737 /// \returns Number of waves per work group supported by the subtarget and
738 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000739 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000740 return AMDGPU::IsaInfo::getWavesPerWorkGroup(
741 MCSubtargetInfo::getFeatureBits(), FlatWorkGroupSize);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000742 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000743
Tom Stellardc5a154d2018-06-28 23:47:12 +0000744 // static wrappers
745 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000746
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000747 // XXX - Why is this here if it isn't in the default pass set?
748 bool enableEarlyIfConversion() const override {
749 return true;
750 }
751
Tom Stellard83f0bce2015-01-29 16:55:25 +0000752 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000753 unsigned NumRegionInstrs) const override;
754
Tom Stellardc5a154d2018-06-28 23:47:12 +0000755 bool isVGPRSpillingEnabled(const Function &F) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000756
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000757 unsigned getMaxNumUserSGPRs() const {
758 return 16;
759 }
760
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000761 bool hasSMemRealTime() const {
762 return HasSMemRealTime;
763 }
764
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000765 bool hasMovrel() const {
766 return HasMovrel;
767 }
768
769 bool hasVGPRIndexMode() const {
770 return HasVGPRIndexMode;
771 }
772
Marek Olsake22fdb92017-03-21 17:00:32 +0000773 bool useVGPRIndexMode(bool UserEnable) const {
774 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
775 }
776
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000777 bool hasScalarCompareEq64() const {
778 return getGeneration() >= VOLCANIC_ISLANDS;
779 }
780
Matt Arsenault7b647552016-10-28 21:55:15 +0000781 bool hasScalarStores() const {
782 return HasScalarStores;
783 }
784
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000785 bool hasScalarAtomics() const {
786 return HasScalarAtomics;
787 }
788
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000789
Sam Kolton07dbde22017-01-20 10:01:25 +0000790 bool hasDPP() const {
791 return HasDPP;
792 }
793
Tom Stellardde008d32016-01-21 04:28:34 +0000794 bool enableSIScheduler() const {
795 return EnableSIScheduler;
796 }
797
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000798 bool debuggerSupported() const {
Konstantin Zhuravlyove004b3d2018-06-21 20:28:19 +0000799 return debuggerInsertNops() && debuggerEmitPrologue();
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000800 }
801
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000802 bool debuggerInsertNops() const {
803 return DebuggerInsertNops;
804 }
805
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000806 bool debuggerEmitPrologue() const {
807 return DebuggerEmitPrologue;
808 }
809
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000810 bool loadStoreOptEnabled() const {
811 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000812 }
813
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000814 bool hasSGPRInitBug() const {
815 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000816 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000817
Tom Stellardb133fbb2016-10-27 23:05:31 +0000818 bool has12DWordStoreHazard() const {
819 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
820 }
821
Matt Arsenaulte823d922017-02-18 18:29:53 +0000822 bool hasSMovFedHazard() const {
823 return getGeneration() >= AMDGPUSubtarget::GFX9;
824 }
825
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000826 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000827 return getGeneration() >= AMDGPUSubtarget::GFX9;
828 }
829
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000830 bool hasReadM0SendMsgHazard() const {
831 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
832 }
833
Tom Stellardc5a154d2018-06-28 23:47:12 +0000834 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
835 /// SGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000836 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
837
Tom Stellardc5a154d2018-06-28 23:47:12 +0000838 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
839 /// VGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000840 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000841
Matt Arsenaulte823d922017-02-18 18:29:53 +0000842 /// \returns true if the flat_scratch register should be initialized with the
843 /// pointer to the wave's scratch memory rather than a size and offset.
844 bool flatScratchIsPointer() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000845 return getGeneration() >= AMDGPUSubtarget::GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000846 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000847
Tim Renouf832f90f2018-02-26 14:46:43 +0000848 /// \returns true if the machine has merged shaders in which s0-s7 are
849 /// reserved by the hardware and user SGPRs start at s8
850 bool hasMergedShaders() const {
851 return getGeneration() >= GFX9;
852 }
853
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000854 /// \returns SGPR allocation granularity supported by the subtarget.
855 unsigned getSGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000856 return AMDGPU::IsaInfo::getSGPRAllocGranule(
857 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000858 }
859
860 /// \returns SGPR encoding granularity supported by the subtarget.
861 unsigned getSGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000862 return AMDGPU::IsaInfo::getSGPREncodingGranule(
863 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000864 }
865
866 /// \returns Total number of SGPRs supported by the subtarget.
867 unsigned getTotalNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000868 return AMDGPU::IsaInfo::getTotalNumSGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000869 }
870
871 /// \returns Addressable number of SGPRs supported by the subtarget.
872 unsigned getAddressableNumSGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000873 return AMDGPU::IsaInfo::getAddressableNumSGPRs(
874 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000875 }
876
877 /// \returns Minimum number of SGPRs that meets the given number of waves per
878 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000879 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000880 return AMDGPU::IsaInfo::getMinNumSGPRs(MCSubtargetInfo::getFeatureBits(),
881 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000882 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000883
884 /// \returns Maximum number of SGPRs that meets the given number of waves per
885 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000886 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000887 return AMDGPU::IsaInfo::getMaxNumSGPRs(MCSubtargetInfo::getFeatureBits(),
888 WavesPerEU, Addressable);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000889 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000890
891 /// \returns Reserved number of SGPRs for given function \p MF.
892 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
893
894 /// \returns Maximum number of SGPRs that meets number of waves per execution
895 /// unit requirement for function \p MF, or number of SGPRs explicitly
896 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
897 ///
898 /// \returns Value that meets number of waves per execution unit requirement
899 /// if explicitly requested value cannot be converted to integer, violates
900 /// subtarget's specifications, or does not meet number of waves per execution
901 /// unit requirement.
902 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
903
904 /// \returns VGPR allocation granularity supported by the subtarget.
905 unsigned getVGPRAllocGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000906 return AMDGPU::IsaInfo::getVGPRAllocGranule(
907 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000908 }
909
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000910 /// \returns VGPR encoding granularity supported by the subtarget.
911 unsigned getVGPREncodingGranule() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000912 return AMDGPU::IsaInfo::getVGPREncodingGranule(
913 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000914 }
915
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000916 /// \returns Total number of VGPRs supported by the subtarget.
917 unsigned getTotalNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000918 return AMDGPU::IsaInfo::getTotalNumVGPRs(MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000919 }
920
921 /// \returns Addressable number of VGPRs supported by the subtarget.
922 unsigned getAddressableNumVGPRs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000923 return AMDGPU::IsaInfo::getAddressableNumVGPRs(
924 MCSubtargetInfo::getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000925 }
926
927 /// \returns Minimum number of VGPRs that meets given number of waves per
928 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000929 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000930 return AMDGPU::IsaInfo::getMinNumVGPRs(MCSubtargetInfo::getFeatureBits(),
931 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000932 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000933
934 /// \returns Maximum number of VGPRs that meets given number of waves per
935 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000936 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000937 return AMDGPU::IsaInfo::getMaxNumVGPRs(MCSubtargetInfo::getFeatureBits(),
938 WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000939 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000940
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000941 /// \returns Maximum number of VGPRs that meets number of waves per execution
942 /// unit requirement for function \p MF, or number of VGPRs explicitly
943 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
944 ///
945 /// \returns Value that meets number of waves per execution unit requirement
946 /// if explicitly requested value cannot be converted to integer, violates
947 /// subtarget's specifications, or does not meet number of waves per execution
948 /// unit requirement.
949 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000950
951 void getPostRAMutations(
952 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
953 const override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000954};
955
Tom Stellardc5a154d2018-06-28 23:47:12 +0000956class R600Subtarget final : public R600GenSubtargetInfo,
Tom Stellard5bfbae52018-07-11 20:59:01 +0000957 public AMDGPUSubtarget {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000958private:
959 R600InstrInfo InstrInfo;
960 R600FrameLowering FrameLowering;
961 bool FMA;
962 bool CaymanISA;
963 bool CFALUBug;
964 bool DX10Clamp;
965 bool HasVertexCache;
966 bool R600ALUInst;
967 bool FP64;
968 short TexVTXClauseSize;
969 Generation Gen;
970 R600TargetLowering TLInfo;
971 InstrItineraryData InstrItins;
972 SelectionDAGTargetInfo TSInfo;
973 AMDGPUAS AS;
974
975public:
976 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
977 const TargetMachine &TM);
978
979 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
980
981 const R600FrameLowering *getFrameLowering() const override {
982 return &FrameLowering;
983 }
984
985 const R600TargetLowering *getTargetLowering() const override {
986 return &TLInfo;
987 }
988
989 const R600RegisterInfo *getRegisterInfo() const override {
990 return &InstrInfo.getRegisterInfo();
991 }
992
993 const InstrItineraryData *getInstrItineraryData() const override {
994 return &InstrItins;
995 }
996
997 // Nothing implemented, just prevent crashes on use.
998 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
999 return &TSInfo;
1000 }
1001
1002 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1003
1004 Generation getGeneration() const {
1005 return Gen;
1006 }
1007
1008 unsigned getStackAlignment() const {
1009 return 4;
1010 }
1011
1012 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1013 StringRef GPU, StringRef FS);
1014
1015 bool hasBFE() const {
1016 return (getGeneration() >= EVERGREEN);
1017 }
1018
1019 bool hasBFI() const {
1020 return (getGeneration() >= EVERGREEN);
1021 }
1022
1023 bool hasBCNT(unsigned Size) const {
1024 if (Size == 32)
1025 return (getGeneration() >= EVERGREEN);
1026
1027 return false;
1028 }
1029
1030 bool hasBORROW() const {
1031 return (getGeneration() >= EVERGREEN);
1032 }
1033
1034 bool hasCARRY() const {
1035 return (getGeneration() >= EVERGREEN);
1036 }
1037
1038 bool hasCaymanISA() const {
1039 return CaymanISA;
1040 }
1041
1042 bool hasFFBL() const {
1043 return (getGeneration() >= EVERGREEN);
1044 }
1045
1046 bool hasFFBH() const {
1047 return (getGeneration() >= EVERGREEN);
1048 }
1049
1050 bool hasFMA() const { return FMA; }
1051
Tom Stellardc5a154d2018-06-28 23:47:12 +00001052 bool hasCFAluBug() const { return CFALUBug; }
1053
1054 bool hasVertexCache() const { return HasVertexCache; }
1055
1056 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1057
1058 AMDGPUAS getAMDGPUAS() const { return AS; }
1059
1060 bool enableMachineScheduler() const override {
1061 return true;
1062 }
1063
1064 bool enableSubRegLiveness() const override {
1065 return true;
1066 }
1067};
1068
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001069} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +00001070
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001071#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H