blob: a92b8fee577188efea75d6781661c33a7d43d1bd [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Tom Stellard75aadc22012-12-11 21:25:42 +00006//
7//==-----------------------------------------------------------------------===//
8//
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// AMDGPU specific subclass of TargetSubtarget.
Tom Stellard75aadc22012-12-11 21:25:42 +000011//
12//===----------------------------------------------------------------------===//
13
Matt Arsenault0c90e952015-11-06 18:17:45 +000014#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
15#define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
Matt Arsenaultf59e5382015-11-06 18:23:00 +000016
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000017#include "AMDGPU.h"
Quentin Colombet61d71a12017-08-15 22:31:51 +000018#include "AMDGPUCallLowering.h"
Matt Arsenault43e92fe2016-06-24 06:30:11 +000019#include "R600FrameLowering.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000020#include "R600ISelLowering.h"
21#include "R600InstrInfo.h"
Matt Arsenault43e92fe2016-06-24 06:30:11 +000022#include "SIFrameLowering.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000023#include "SIISelLowering.h"
24#include "SIInstrInfo.h"
Tom Stellard347ac792015-06-26 21:15:07 +000025#include "Utils/AMDGPUBaseInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000026#include "llvm/ADT/Triple.h"
Quentin Colombet61d71a12017-08-15 22:31:51 +000027#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
28#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
29#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000030#include "llvm/CodeGen/MachineFunction.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000031#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000032#include "llvm/MC/MCInstrItineraries.h"
33#include "llvm/Support/MathExtras.h"
34#include <cassert>
35#include <cstdint>
36#include <memory>
37#include <utility>
Tom Stellard75aadc22012-12-11 21:25:42 +000038
39#define GET_SUBTARGETINFO_HEADER
40#include "AMDGPUGenSubtargetInfo.inc"
Tom Stellardc5a154d2018-06-28 23:47:12 +000041#define GET_SUBTARGETINFO_HEADER
42#include "R600GenSubtargetInfo.inc"
Tom Stellard75aadc22012-12-11 21:25:42 +000043
Tom Stellard75aadc22012-12-11 21:25:42 +000044namespace llvm {
45
Matt Arsenault43e92fe2016-06-24 06:30:11 +000046class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000047
Tom Stellard5bfbae52018-07-11 20:59:01 +000048class AMDGPUSubtarget {
49public:
50 enum Generation {
51 R600 = 0,
52 R700 = 1,
Matt Arsenault4bec7d42018-07-20 09:05:08 +000053 EVERGREEN = 2,
Tom Stellard5bfbae52018-07-11 20:59:01 +000054 NORTHERN_ISLANDS = 3,
55 SOUTHERN_ISLANDS = 4,
56 SEA_ISLANDS = 5,
57 VOLCANIC_ISLANDS = 6,
58 GFX9 = 7
59 };
60
Tom Stellardc5a154d2018-06-28 23:47:12 +000061private:
62 Triple TargetTriple;
63
64protected:
Tom Stellardc5a154d2018-06-28 23:47:12 +000065 bool Has16BitInsts;
66 bool HasMadMixInsts;
67 bool FP32Denormals;
68 bool FPExceptions;
69 bool HasSDWA;
70 bool HasVOP3PInsts;
71 bool HasMulI24;
72 bool HasMulU24;
Matt Arsenault6c7ba822018-08-15 21:03:55 +000073 bool HasInv2PiInlineImm;
Tom Stellardc5a154d2018-06-28 23:47:12 +000074 bool HasFminFmaxLegacy;
75 bool EnablePromoteAlloca;
David Stuttard20de3e92018-09-14 10:27:19 +000076 bool HasTrigReducedRange;
Tom Stellardc5a154d2018-06-28 23:47:12 +000077 int LocalMemorySize;
78 unsigned WavefrontSize;
79
80public:
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +000081 AMDGPUSubtarget(const Triple &TT);
Tom Stellardc5a154d2018-06-28 23:47:12 +000082
Tom Stellard5bfbae52018-07-11 20:59:01 +000083 static const AMDGPUSubtarget &get(const MachineFunction &MF);
84 static const AMDGPUSubtarget &get(const TargetMachine &TM,
Matt Arsenault4bec7d42018-07-20 09:05:08 +000085 const Function &F);
Tom Stellardc5a154d2018-06-28 23:47:12 +000086
87 /// \returns Default range flat work group size for a calling convention.
88 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
89
90 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
91 /// for function \p F, or minimum/maximum flat work group sizes explicitly
92 /// requested using "amdgpu-flat-work-group-size" attribute attached to
93 /// function \p F.
94 ///
95 /// \returns Subtarget's default values if explicitly requested values cannot
96 /// be converted to integer, or violate subtarget's specifications.
97 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
98
99 /// \returns Subtarget's default pair of minimum/maximum number of waves per
100 /// execution unit for function \p F, or minimum/maximum number of waves per
101 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
102 /// attached to function \p F.
103 ///
104 /// \returns Subtarget's default values if explicitly requested values cannot
105 /// be converted to integer, violate subtarget's specifications, or are not
106 /// compatible with minimum/maximum number of waves limited by flat work group
107 /// size, register usage, and/or lds usage.
108 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
109
110 /// Return the amount of LDS that can be used that will not restrict the
111 /// occupancy lower than WaveCount.
112 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
113 const Function &) const;
114
115 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
116 /// the given LDS memory size is the only constraint.
117 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
118
119 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const;
120
121 bool isAmdHsaOS() const {
122 return TargetTriple.getOS() == Triple::AMDHSA;
123 }
124
125 bool isAmdPalOS() const {
126 return TargetTriple.getOS() == Triple::AMDPAL;
127 }
128
Tom Stellardec4feae2018-07-06 17:16:17 +0000129 bool isMesa3DOS() const {
130 return TargetTriple.getOS() == Triple::Mesa3D;
131 }
132
133 bool isMesaKernel(const Function &F) const {
134 return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
135 }
136
Konstantin Zhuravlyovaa067cb2018-10-04 21:02:16 +0000137 bool isAmdHsaOrMesa(const Function &F) const {
Tom Stellardec4feae2018-07-06 17:16:17 +0000138 return isAmdHsaOS() || isMesaKernel(F);
139 }
140
Tom Stellardc5a154d2018-06-28 23:47:12 +0000141 bool has16BitInsts() const {
142 return Has16BitInsts;
143 }
144
145 bool hasMadMixInsts() const {
146 return HasMadMixInsts;
147 }
148
149 bool hasFP32Denormals() const {
150 return FP32Denormals;
151 }
152
153 bool hasFPExceptions() const {
154 return FPExceptions;
155 }
156
157 bool hasSDWA() const {
158 return HasSDWA;
159 }
160
161 bool hasVOP3PInsts() const {
162 return HasVOP3PInsts;
163 }
164
165 bool hasMulI24() const {
166 return HasMulI24;
167 }
168
169 bool hasMulU24() const {
170 return HasMulU24;
171 }
172
Matt Arsenault6c7ba822018-08-15 21:03:55 +0000173 bool hasInv2PiInlineImm() const {
174 return HasInv2PiInlineImm;
175 }
176
Tom Stellardc5a154d2018-06-28 23:47:12 +0000177 bool hasFminFmaxLegacy() const {
178 return HasFminFmaxLegacy;
179 }
180
David Stuttard20de3e92018-09-14 10:27:19 +0000181 bool hasTrigReducedRange() const {
182 return HasTrigReducedRange;
183 }
184
Tom Stellardc5a154d2018-06-28 23:47:12 +0000185 bool isPromoteAllocaEnabled() const {
186 return EnablePromoteAlloca;
187 }
188
189 unsigned getWavefrontSize() const {
190 return WavefrontSize;
191 }
192
193 int getLocalMemorySize() const {
194 return LocalMemorySize;
195 }
196
197 unsigned getAlignmentForImplicitArgPtr() const {
198 return isAmdHsaOS() ? 8 : 4;
199 }
200
Tom Stellardec4feae2018-07-06 17:16:17 +0000201 /// Returns the offset in bytes from the start of the input buffer
202 /// of the first explicit kernel argument.
203 unsigned getExplicitKernelArgOffset(const Function &F) const {
Konstantin Zhuravlyovaa067cb2018-10-04 21:02:16 +0000204 return isAmdHsaOrMesa(F) ? 0 : 36;
Tom Stellardec4feae2018-07-06 17:16:17 +0000205 }
206
Tom Stellardc5a154d2018-06-28 23:47:12 +0000207 /// \returns Maximum number of work groups per compute unit supported by the
208 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000209 virtual unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000210
211 /// \returns Minimum flat work group size supported by the subtarget.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000212 virtual unsigned getMinFlatWorkGroupSize() const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000213
214 /// \returns Maximum flat work group size supported by the subtarget.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000215 virtual unsigned getMaxFlatWorkGroupSize() const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000216
217 /// \returns Maximum number of waves per execution unit supported by the
218 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000219 virtual unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000220
221 /// \returns Minimum number of waves per execution unit supported by the
222 /// subtarget.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000223 virtual unsigned getMinWavesPerEU() const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000224
225 unsigned getMaxWavesPerEU() const { return 10; }
226
227 /// Creates value range metadata on an workitemid.* inrinsic call or load.
228 bool makeLIDRangeMetadata(Instruction *I) const;
229
Matt Arsenault4bec7d42018-07-20 09:05:08 +0000230 /// \returns Number of bytes of arguments that are passed to a shader or
231 /// kernel in addition to the explicit ones declared for the function.
232 unsigned getImplicitArgNumBytes(const Function &F) const {
233 if (isMesaKernel(F))
234 return 16;
235 return AMDGPU::getIntegerAttribute(F, "amdgpu-implicitarg-num-bytes", 0);
236 }
237 uint64_t getExplicitKernArgSize(const Function &F,
238 unsigned &MaxAlign) const;
239 unsigned getKernArgSegmentSize(const Function &F,
240 unsigned &MaxAlign) const;
241
Tom Stellard5bfbae52018-07-11 20:59:01 +0000242 virtual ~AMDGPUSubtarget() {}
Tom Stellardc5a154d2018-06-28 23:47:12 +0000243};
244
Tom Stellard5bfbae52018-07-11 20:59:01 +0000245class GCNSubtarget : public AMDGPUGenSubtargetInfo,
246 public AMDGPUSubtarget {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000247public:
Wei Ding205bfdb2017-02-10 02:15:29 +0000248 enum TrapHandlerAbi {
249 TrapHandlerAbiNone = 0,
250 TrapHandlerAbiHsa = 1
251 };
252
Wei Dingf2cce022017-02-22 23:22:19 +0000253 enum TrapID {
254 TrapIDHardwareReserved = 0,
255 TrapIDHSADebugTrap = 1,
256 TrapIDLLVMTrap = 2,
257 TrapIDLLVMDebugTrap = 3,
258 TrapIDDebugBreakpoint = 7,
259 TrapIDDebugReserved8 = 8,
260 TrapIDDebugReservedFE = 0xfe,
261 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +0000262 };
263
264 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +0000265 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +0000266 };
267
Tom Stellardc5a154d2018-06-28 23:47:12 +0000268private:
Tom Stellardc5a154d2018-06-28 23:47:12 +0000269 /// GlobalISel related APIs.
270 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
271 std::unique_ptr<InstructionSelector> InstSelector;
272 std::unique_ptr<LegalizerInfo> Legalizer;
273 std::unique_ptr<RegisterBankInfo> RegBankInfo;
274
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000275protected:
276 // Basic subtarget description.
277 Triple TargetTriple;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000278 unsigned Gen;
Stanislav Mekhanoshin06d3b412018-09-17 16:04:32 +0000279 InstrItineraryData InstrItins;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000280 int LDSBankCount;
281 unsigned MaxPrivateElementSize;
282
283 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000284 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000285 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000286
287 // Dynamially set bits that enable features.
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000288 bool FP64FP16Denormals;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000289 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000290 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000291 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000292 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000293 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000294 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000295 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000296 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000297
298 // Used as options.
Matt Arsenault45b98182017-11-15 00:45:43 +0000299 bool EnableHugePrivateBuffer;
Matt Arsenault41033282014-10-10 22:01:59 +0000300 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000301 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000302 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000303 bool EnableDS128;
David Stuttardf77079f2019-01-14 11:55:24 +0000304 bool EnablePRTStrictNull;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000305 bool DumpCode;
306
307 // Subtarget statically properties set by tablegen
308 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000309 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000310 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000311 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000312 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000313 bool CIInsts;
Matt Arsenault96b67842018-08-07 07:28:46 +0000314 bool VIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000315 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000316 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000317 bool HasSMemRealTime;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000318 bool HasIntClamp;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000319 bool HasFmaMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000320 bool HasMovrel;
321 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000322 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000323 bool HasScalarAtomics;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000324 bool HasSDWAOmod;
325 bool HasSDWAScalar;
326 bool HasSDWASdst;
327 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000328 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000329 bool HasDPP;
Ryan Taylor1f334d02018-08-28 15:07:30 +0000330 bool HasR128A16;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000331 bool HasDLInsts;
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000332 bool HasDot1Insts;
333 bool HasDot2Insts;
Konstantin Zhuravlyov108927b2018-11-05 22:44:19 +0000334 bool EnableSRAMECC;
Matt Arsenaultf426ddb2019-04-03 01:58:57 +0000335 bool DoesNotSupportSRAMECC;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000336 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000337 bool FlatInstOffsets;
338 bool FlatGlobalInsts;
339 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000340 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000341 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000342 bool R600ALUInst;
343 bool CaymanISA;
344 bool CFALUBug;
345 bool HasVertexCache;
346 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000347 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000348
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000349 // Dummy feature to use for assembler in tablegen.
350 bool FeatureDisable;
351
Matt Arsenault56684d42016-08-11 17:31:42 +0000352 SelectionDAGTargetInfo TSInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000353private:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000354 SIInstrInfo InstrInfo;
Tom Stellard752ddbd2018-07-11 22:15:15 +0000355 SITargetLowering TLInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000356 SIFrameLowering FrameLowering;
Tom Stellard75aadc22012-12-11 21:25:42 +0000357
358public:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000359 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
360 const GCNTargetMachine &TM);
361 ~GCNSubtarget() override;
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000362
Tom Stellard5bfbae52018-07-11 20:59:01 +0000363 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000364 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000365
Tom Stellard5bfbae52018-07-11 20:59:01 +0000366 const SIInstrInfo *getInstrInfo() const override {
367 return &InstrInfo;
368 }
Tom Stellard000c5af2016-04-14 19:09:28 +0000369
Tom Stellardc5a154d2018-06-28 23:47:12 +0000370 const SIFrameLowering *getFrameLowering() const override {
371 return &FrameLowering;
372 }
373
Tom Stellard5bfbae52018-07-11 20:59:01 +0000374 const SITargetLowering *getTargetLowering() const override {
375 return &TLInfo;
376 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000377
Tom Stellard5bfbae52018-07-11 20:59:01 +0000378 const SIRegisterInfo *getRegisterInfo() const override {
379 return &InstrInfo.getRegisterInfo();
380 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000381
382 const CallLowering *getCallLowering() const override {
383 return CallLoweringInfo.get();
384 }
385
386 const InstructionSelector *getInstructionSelector() const override {
387 return InstSelector.get();
388 }
389
390 const LegalizerInfo *getLegalizerInfo() const override {
391 return Legalizer.get();
392 }
393
394 const RegisterBankInfo *getRegBankInfo() const override {
395 return RegBankInfo.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000396 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000397
Matt Arsenault56684d42016-08-11 17:31:42 +0000398 // Nothing implemented, just prevent crashes on use.
399 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
400 return &TSInfo;
401 }
402
Stanislav Mekhanoshin06d3b412018-09-17 16:04:32 +0000403 const InstrItineraryData *getInstrItineraryData() const override {
404 return &InstrItins;
405 }
406
Craig Topperee7b0f32014-04-30 05:53:27 +0000407 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000408
Matt Arsenaultd782d052014-06-27 17:57:00 +0000409 Generation getGeneration() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000410 return (Generation)Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000411 }
412
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000413 unsigned getWavefrontSizeLog2() const {
414 return Log2_32(WavefrontSize);
415 }
416
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000417 int getLDSBankCount() const {
418 return LDSBankCount;
419 }
420
421 unsigned getMaxPrivateElementSize() const {
422 return MaxPrivateElementSize;
423 }
424
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000425 bool hasIntClamp() const {
426 return HasIntClamp;
427 }
428
Jan Veselyd1c9b612017-12-04 22:57:29 +0000429 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000430 return FP64;
431 }
432
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000433 bool hasMIMG_R128() const {
434 return MIMG_R128;
435 }
436
Tom Stellardc5a154d2018-06-28 23:47:12 +0000437 bool hasHWFP64() const {
438 return FP64;
439 }
440
Matt Arsenaultb035a572015-01-29 19:34:25 +0000441 bool hasFastFMAF32() const {
442 return FastFMAF32;
443 }
444
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000445 bool hasHalfRate64Ops() const {
446 return HalfRate64Ops;
447 }
448
Matt Arsenault88701812016-06-09 23:42:48 +0000449 bool hasAddr64() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000450 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
Matt Arsenault88701812016-06-09 23:42:48 +0000451 }
452
Matt Arsenaultfae02982014-03-17 18:58:11 +0000453 bool hasBFE() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000454 return true;
Matt Arsenaultfae02982014-03-17 18:58:11 +0000455 }
456
Matt Arsenault6e439652014-06-10 19:00:20 +0000457 bool hasBFI() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000458 return true;
Matt Arsenault6e439652014-06-10 19:00:20 +0000459 }
460
Matt Arsenaultfae02982014-03-17 18:58:11 +0000461 bool hasBFM() const {
462 return hasBFE();
463 }
464
Matt Arsenault60425062014-06-10 19:18:28 +0000465 bool hasBCNT(unsigned Size) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000466 return true;
Tom Stellard50122a52014-04-07 19:45:41 +0000467 }
468
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000469 bool hasFFBL() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000470 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000471 }
472
473 bool hasFFBH() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000474 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000475 }
476
Matt Arsenault10268f92017-02-27 22:40:39 +0000477 bool hasMed3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000478 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenault10268f92017-02-27 22:40:39 +0000479 }
480
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000481 bool hasMin3Max3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000482 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000483 }
484
Matt Arsenault0084adc2018-04-30 19:08:16 +0000485 bool hasFmaMixInsts() const {
486 return HasFmaMixInsts;
487 }
488
Jan Vesely808fff52015-04-30 17:15:56 +0000489 bool hasCARRY() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000490 return true;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000491 }
492
Jan Vesely39aeab42017-12-04 23:07:28 +0000493 bool hasFMA() const {
494 return FMA;
495 }
496
Stanislav Mekhanoshin79080ec2018-10-29 17:26:01 +0000497 bool hasSwap() const {
498 return GFX9Insts;
499 }
500
Wei Ding205bfdb2017-02-10 02:15:29 +0000501 TrapHandlerAbi getTrapHandlerAbi() const {
502 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
503 }
504
Matt Arsenault45b98182017-11-15 00:45:43 +0000505 bool enableHugePrivateBuffer() const {
506 return EnableHugePrivateBuffer;
507 }
508
Matt Arsenault706f9302015-07-06 16:01:58 +0000509 bool unsafeDSOffsetFoldingEnabled() const {
510 return EnableUnsafeDSOffsetFolding;
511 }
512
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000513 bool dumpCode() const {
514 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000515 }
516
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000517 /// Return the amount of LDS that can be used that will not restrict the
518 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000519 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
520 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000521
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000522 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000523 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000524 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000525
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000526 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000527 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000528 }
529
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000530 bool supportsMinMaxDenormModes() const {
531 return getGeneration() >= AMDGPUSubtarget::GFX9;
532 }
533
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000534 bool useFlatForGlobal() const {
535 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000536 }
537
Farhana Aleena7cb3112018-03-09 17:41:39 +0000538 /// \returns If target supports ds_read/write_b128 and user enables generation
539 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000540 bool useDS128() const {
541 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000542 }
543
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000544 /// \returns If MUBUF instructions always perform range checking, even for
545 /// buffer resources used for private memory access.
546 bool privateMemoryResourceIsRangeChecked() const {
547 return getGeneration() < AMDGPUSubtarget::GFX9;
548 }
549
David Stuttardf77079f2019-01-14 11:55:24 +0000550 /// \returns If target requires PRT Struct NULL support (zero result registers
551 /// for sparse texture support).
552 bool usePRTStrictNull() const {
553 return EnablePRTStrictNull;
554 }
555
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000556 bool hasAutoWaitcntBeforeBarrier() const {
557 return AutoWaitcntBeforeBarrier;
558 }
559
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000560 bool hasCodeObjectV3() const {
Konstantin Zhuravlyova25e0522018-11-15 02:32:43 +0000561 // FIXME: Need to add code object v3 support for mesa and pal.
562 return isAmdHsaOS() ? CodeObjectV3 : false;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000563 }
564
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000565 bool hasUnalignedBufferAccess() const {
566 return UnalignedBufferAccess;
567 }
568
Tom Stellard64a9d082016-10-14 18:10:39 +0000569 bool hasUnalignedScratchAccess() const {
570 return UnalignedScratchAccess;
571 }
572
Matt Arsenaulte823d922017-02-18 18:29:53 +0000573 bool hasApertureRegs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000574 return HasApertureRegs;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000575 }
576
Wei Ding205bfdb2017-02-10 02:15:29 +0000577 bool isTrapHandlerEnabled() const {
578 return TrapHandler;
579 }
580
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000581 bool isXNACKEnabled() const {
582 return EnableXNACK;
583 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000584
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000585 bool hasFlatAddressSpace() const {
586 return FlatAddressSpace;
587 }
588
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000589 bool hasFlatInstOffsets() const {
590 return FlatInstOffsets;
591 }
592
593 bool hasFlatGlobalInsts() const {
594 return FlatGlobalInsts;
595 }
596
597 bool hasFlatScratchInsts() const {
598 return FlatScratchInsts;
599 }
600
Mark Searlesf0b93f12018-06-04 16:51:59 +0000601 bool hasFlatLgkmVMemCountInOrder() const {
602 return getGeneration() > GFX9;
603 }
604
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000605 bool hasD16LoadStore() const {
606 return getGeneration() >= GFX9;
607 }
608
Matt Arsenaulte8c03a22019-03-08 20:58:11 +0000609 bool d16PreservesUnusedBits() const {
610 return hasD16LoadStore() && !isSRAMECCEnabled();
611 }
612
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000613 /// Return if most LDS instructions have an m0 use that require m0 to be
614 /// iniitalized.
615 bool ldsRequiresM0Init() const {
616 return getGeneration() < GFX9;
617 }
618
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000619 bool hasAddNoCarry() const {
620 return AddNoCarryInsts;
621 }
622
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000623 bool hasUnpackedD16VMem() const {
624 return HasUnpackedD16VMem;
625 }
626
Tom Stellard2f3f9852017-01-25 01:25:13 +0000627 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000628 bool isMesaGfxShader(const Function &F) const {
629 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000630 }
631
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000632 bool hasMad64_32() const {
633 return getGeneration() >= SEA_ISLANDS;
634 }
635
Sam Kolton3c4933f2017-06-22 06:26:41 +0000636 bool hasSDWAOmod() const {
637 return HasSDWAOmod;
638 }
639
640 bool hasSDWAScalar() const {
641 return HasSDWAScalar;
642 }
643
644 bool hasSDWASdst() const {
645 return HasSDWASdst;
646 }
647
648 bool hasSDWAMac() const {
649 return HasSDWAMac;
650 }
651
Sam Koltona179d252017-06-27 15:02:23 +0000652 bool hasSDWAOutModsVOPC() const {
653 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000654 }
655
Mark Searles2a19af62018-04-26 16:11:19 +0000656 bool vmemWriteNeedsExpWaitcnt() const {
657 return getGeneration() < SEA_ISLANDS;
658 }
659
Matt Arsenault0084adc2018-04-30 19:08:16 +0000660 bool hasDLInsts() const {
661 return HasDLInsts;
662 }
663
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000664 bool hasDot1Insts() const {
665 return HasDot1Insts;
666 }
667
668 bool hasDot2Insts() const {
669 return HasDot2Insts;
Stanislav Mekhanoshind3757d32019-01-10 03:25:20 +0000670 }
671
Konstantin Zhuravlyov108927b2018-11-05 22:44:19 +0000672 bool isSRAMECCEnabled() const {
673 return EnableSRAMECC;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000674 }
675
Matt Arsenault869fec22017-04-17 19:48:24 +0000676 // Scratch is allocated in 256 dword per wave blocks for the entire
677 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
678 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000679 //
680 // Only 4-byte alignment is really needed to access anything. Transformations
681 // on the pointer value itself may rely on the alignment / known low bits of
682 // the pointer. Set this to something above the minimum to avoid needing
683 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000684 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000685 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000686 }
Tom Stellard347ac792015-06-26 21:15:07 +0000687
Craig Topper5656db42014-04-29 07:57:24 +0000688 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000689 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000690 }
691
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000692 bool enableSubRegLiveness() const override {
693 return true;
694 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000695
Tom Stellardc5a154d2018-06-28 23:47:12 +0000696 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
697 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000698
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000699 /// \returns Number of execution units per compute unit supported by the
700 /// subtarget.
701 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000702 return AMDGPU::IsaInfo::getEUsPerCU(this);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000703 }
704
705 /// \returns Maximum number of waves per compute unit supported by the
706 /// subtarget without any kind of limitation.
707 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000708 return AMDGPU::IsaInfo::getMaxWavesPerCU(this);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000709 }
710
711 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000712 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000713 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000714 return AMDGPU::IsaInfo::getMaxWavesPerCU(this, FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000715 }
716
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000717 /// \returns Maximum number of waves per execution unit supported by the
718 /// subtarget without any kind of limitation.
719 unsigned getMaxWavesPerEU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000720 return AMDGPU::IsaInfo::getMaxWavesPerEU();
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000721 }
722
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000723 /// \returns Number of waves per work group supported by the subtarget and
724 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000725 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000726 return AMDGPU::IsaInfo::getWavesPerWorkGroup(this, FlatWorkGroupSize);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000727 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000728
Tom Stellardc5a154d2018-06-28 23:47:12 +0000729 // static wrappers
730 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000731
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000732 // XXX - Why is this here if it isn't in the default pass set?
733 bool enableEarlyIfConversion() const override {
734 return true;
735 }
736
Tom Stellard83f0bce2015-01-29 16:55:25 +0000737 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000738 unsigned NumRegionInstrs) const override;
739
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000740 unsigned getMaxNumUserSGPRs() const {
741 return 16;
742 }
743
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000744 bool hasSMemRealTime() const {
745 return HasSMemRealTime;
746 }
747
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000748 bool hasMovrel() const {
749 return HasMovrel;
750 }
751
752 bool hasVGPRIndexMode() const {
753 return HasVGPRIndexMode;
754 }
755
Marek Olsake22fdb92017-03-21 17:00:32 +0000756 bool useVGPRIndexMode(bool UserEnable) const {
757 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
758 }
759
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000760 bool hasScalarCompareEq64() const {
761 return getGeneration() >= VOLCANIC_ISLANDS;
762 }
763
Matt Arsenault7b647552016-10-28 21:55:15 +0000764 bool hasScalarStores() const {
765 return HasScalarStores;
766 }
767
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000768 bool hasScalarAtomics() const {
769 return HasScalarAtomics;
770 }
771
Matt Arsenaulta5840c32019-01-22 18:36:06 +0000772 bool hasLDSFPAtomics() const {
773 return VIInsts;
774 }
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000775
Sam Kolton07dbde22017-01-20 10:01:25 +0000776 bool hasDPP() const {
777 return HasDPP;
778 }
779
Ryan Taylor1f334d02018-08-28 15:07:30 +0000780 bool hasR128A16() const {
781 return HasR128A16;
782 }
783
Tom Stellardde008d32016-01-21 04:28:34 +0000784 bool enableSIScheduler() const {
785 return EnableSIScheduler;
786 }
787
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000788 bool loadStoreOptEnabled() const {
789 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000790 }
791
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000792 bool hasSGPRInitBug() const {
793 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000794 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000795
Tom Stellardb133fbb2016-10-27 23:05:31 +0000796 bool has12DWordStoreHazard() const {
797 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
798 }
799
Neil Henninge85d45a2019-01-10 16:21:08 +0000800 // \returns true if the subtarget supports DWORDX3 load/store instructions.
801 bool hasDwordx3LoadStores() const {
802 return CIInsts;
803 }
804
Matt Arsenaulte823d922017-02-18 18:29:53 +0000805 bool hasSMovFedHazard() const {
806 return getGeneration() >= AMDGPUSubtarget::GFX9;
807 }
808
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000809 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000810 return getGeneration() >= AMDGPUSubtarget::GFX9;
811 }
812
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000813 bool hasReadM0SendMsgHazard() const {
814 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
815 }
816
Tom Stellardc5a154d2018-06-28 23:47:12 +0000817 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
818 /// SGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000819 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
820
Tom Stellardc5a154d2018-06-28 23:47:12 +0000821 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
822 /// VGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000823 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000824
Matt Arsenaulte823d922017-02-18 18:29:53 +0000825 /// \returns true if the flat_scratch register should be initialized with the
826 /// pointer to the wave's scratch memory rather than a size and offset.
827 bool flatScratchIsPointer() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000828 return getGeneration() >= AMDGPUSubtarget::GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000829 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000830
Tim Renouf832f90f2018-02-26 14:46:43 +0000831 /// \returns true if the machine has merged shaders in which s0-s7 are
832 /// reserved by the hardware and user SGPRs start at s8
833 bool hasMergedShaders() const {
834 return getGeneration() >= GFX9;
835 }
836
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000837 /// \returns SGPR allocation granularity supported by the subtarget.
838 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000839 return AMDGPU::IsaInfo::getSGPRAllocGranule(this);
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000840 }
841
842 /// \returns SGPR encoding granularity supported by the subtarget.
843 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000844 return AMDGPU::IsaInfo::getSGPREncodingGranule(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000845 }
846
847 /// \returns Total number of SGPRs supported by the subtarget.
848 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000849 return AMDGPU::IsaInfo::getTotalNumSGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000850 }
851
852 /// \returns Addressable number of SGPRs supported by the subtarget.
853 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000854 return AMDGPU::IsaInfo::getAddressableNumSGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000855 }
856
857 /// \returns Minimum number of SGPRs that meets the given number of waves per
858 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000859 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000860 return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000861 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000862
863 /// \returns Maximum number of SGPRs that meets the given number of waves per
864 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000865 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000866 return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000867 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000868
869 /// \returns Reserved number of SGPRs for given function \p MF.
870 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
871
872 /// \returns Maximum number of SGPRs that meets number of waves per execution
873 /// unit requirement for function \p MF, or number of SGPRs explicitly
874 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
875 ///
876 /// \returns Value that meets number of waves per execution unit requirement
877 /// if explicitly requested value cannot be converted to integer, violates
878 /// subtarget's specifications, or does not meet number of waves per execution
879 /// unit requirement.
880 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
881
882 /// \returns VGPR allocation granularity supported by the subtarget.
883 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000884 return AMDGPU::IsaInfo::getVGPRAllocGranule(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000885 }
886
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000887 /// \returns VGPR encoding granularity supported by the subtarget.
888 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000889 return AMDGPU::IsaInfo::getVGPREncodingGranule(this);
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000890 }
891
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000892 /// \returns Total number of VGPRs supported by the subtarget.
893 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000894 return AMDGPU::IsaInfo::getTotalNumVGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000895 }
896
897 /// \returns Addressable number of VGPRs supported by the subtarget.
898 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000899 return AMDGPU::IsaInfo::getAddressableNumVGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000900 }
901
902 /// \returns Minimum number of VGPRs that meets given number of waves per
903 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000904 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000905 return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000906 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000907
908 /// \returns Maximum number of VGPRs that meets given number of waves per
909 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000910 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000911 return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000912 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000913
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000914 /// \returns Maximum number of VGPRs that meets number of waves per execution
915 /// unit requirement for function \p MF, or number of VGPRs explicitly
916 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
917 ///
918 /// \returns Value that meets number of waves per execution unit requirement
919 /// if explicitly requested value cannot be converted to integer, violates
920 /// subtarget's specifications, or does not meet number of waves per execution
921 /// unit requirement.
922 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000923
924 void getPostRAMutations(
925 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
926 const override;
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000927
928 /// \returns Maximum number of work groups per compute unit supported by the
929 /// subtarget and limited by given \p FlatWorkGroupSize.
930 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
931 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
932 }
933
934 /// \returns Minimum flat work group size supported by the subtarget.
935 unsigned getMinFlatWorkGroupSize() const override {
936 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
937 }
938
939 /// \returns Maximum flat work group size supported by the subtarget.
940 unsigned getMaxFlatWorkGroupSize() const override {
941 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
942 }
943
944 /// \returns Maximum number of waves per execution unit supported by the
945 /// subtarget and limited by given \p FlatWorkGroupSize.
946 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const override {
947 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize);
948 }
949
950 /// \returns Minimum number of waves per execution unit supported by the
951 /// subtarget.
952 unsigned getMinWavesPerEU() const override {
953 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
954 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000955};
956
Tom Stellardc5a154d2018-06-28 23:47:12 +0000957class R600Subtarget final : public R600GenSubtargetInfo,
Tom Stellard5bfbae52018-07-11 20:59:01 +0000958 public AMDGPUSubtarget {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000959private:
960 R600InstrInfo InstrInfo;
961 R600FrameLowering FrameLowering;
962 bool FMA;
963 bool CaymanISA;
964 bool CFALUBug;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000965 bool HasVertexCache;
966 bool R600ALUInst;
967 bool FP64;
968 short TexVTXClauseSize;
969 Generation Gen;
970 R600TargetLowering TLInfo;
971 InstrItineraryData InstrItins;
972 SelectionDAGTargetInfo TSInfo;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000973
974public:
975 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
976 const TargetMachine &TM);
977
978 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
979
980 const R600FrameLowering *getFrameLowering() const override {
981 return &FrameLowering;
982 }
983
984 const R600TargetLowering *getTargetLowering() const override {
985 return &TLInfo;
986 }
987
988 const R600RegisterInfo *getRegisterInfo() const override {
989 return &InstrInfo.getRegisterInfo();
990 }
991
992 const InstrItineraryData *getInstrItineraryData() const override {
993 return &InstrItins;
994 }
995
996 // Nothing implemented, just prevent crashes on use.
997 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
998 return &TSInfo;
999 }
1000
1001 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1002
1003 Generation getGeneration() const {
1004 return Gen;
1005 }
1006
1007 unsigned getStackAlignment() const {
1008 return 4;
1009 }
1010
1011 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1012 StringRef GPU, StringRef FS);
1013
1014 bool hasBFE() const {
1015 return (getGeneration() >= EVERGREEN);
1016 }
1017
1018 bool hasBFI() const {
1019 return (getGeneration() >= EVERGREEN);
1020 }
1021
1022 bool hasBCNT(unsigned Size) const {
1023 if (Size == 32)
1024 return (getGeneration() >= EVERGREEN);
1025
1026 return false;
1027 }
1028
1029 bool hasBORROW() const {
1030 return (getGeneration() >= EVERGREEN);
1031 }
1032
1033 bool hasCARRY() const {
1034 return (getGeneration() >= EVERGREEN);
1035 }
1036
1037 bool hasCaymanISA() const {
1038 return CaymanISA;
1039 }
1040
1041 bool hasFFBL() const {
1042 return (getGeneration() >= EVERGREEN);
1043 }
1044
1045 bool hasFFBH() const {
1046 return (getGeneration() >= EVERGREEN);
1047 }
1048
1049 bool hasFMA() const { return FMA; }
1050
Tom Stellardc5a154d2018-06-28 23:47:12 +00001051 bool hasCFAluBug() const { return CFALUBug; }
1052
1053 bool hasVertexCache() const { return HasVertexCache; }
1054
1055 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1056
Tom Stellardc5a154d2018-06-28 23:47:12 +00001057 bool enableMachineScheduler() const override {
1058 return true;
1059 }
1060
1061 bool enableSubRegLiveness() const override {
1062 return true;
1063 }
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001064
1065 /// \returns Maximum number of work groups per compute unit supported by the
1066 /// subtarget and limited by given \p FlatWorkGroupSize.
1067 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
1068 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
1069 }
1070
1071 /// \returns Minimum flat work group size supported by the subtarget.
1072 unsigned getMinFlatWorkGroupSize() const override {
1073 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1074 }
1075
1076 /// \returns Maximum flat work group size supported by the subtarget.
1077 unsigned getMaxFlatWorkGroupSize() const override {
1078 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1079 }
1080
1081 /// \returns Maximum number of waves per execution unit supported by the
1082 /// subtarget and limited by given \p FlatWorkGroupSize.
1083 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const override {
1084 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize);
1085 }
1086
1087 /// \returns Minimum number of waves per execution unit supported by the
1088 /// subtarget.
1089 unsigned getMinWavesPerEU() const override {
1090 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1091 }
Tom Stellardc5a154d2018-06-28 23:47:12 +00001092};
1093
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001094} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +00001095
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001096#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H