blob: 06d750d7b89809f3f6b91fad8a2a949bd077dd5f [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:
Marek Olsak4d00dd22015-03-09 15:48:09 +0000248 enum {
Tom Stellard347ac792015-06-26 21:15:07 +0000249 ISAVersion0_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +0000250 ISAVersion6_0_0,
251 ISAVersion6_0_1,
Tom Stellard347ac792015-06-26 21:15:07 +0000252 ISAVersion7_0_0,
253 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +0000254 ISAVersion7_0_2,
Wei Ding7c3e5112017-06-10 03:53:19 +0000255 ISAVersion7_0_3,
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000256 ISAVersion7_0_4,
Changpeng Fangc16be002016-01-13 20:39:25 +0000257 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +0000258 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +0000259 ISAVersion8_0_3,
Yaxun Liu94add852016-10-26 16:37:56 +0000260 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +0000261 ISAVersion9_0_0,
Matt Arsenault0084adc2018-04-30 19:08:16 +0000262 ISAVersion9_0_2,
263 ISAVersion9_0_4,
Konstantin Zhuravlyov1501af42018-05-01 18:47:48 +0000264 ISAVersion9_0_6,
Tim Renouf2a1b1d92018-10-24 08:14:07 +0000265 ISAVersion9_0_9,
Tom Stellard347ac792015-06-26 21:15:07 +0000266 };
267
Wei Ding205bfdb2017-02-10 02:15:29 +0000268 enum TrapHandlerAbi {
269 TrapHandlerAbiNone = 0,
270 TrapHandlerAbiHsa = 1
271 };
272
Wei Dingf2cce022017-02-22 23:22:19 +0000273 enum TrapID {
274 TrapIDHardwareReserved = 0,
275 TrapIDHSADebugTrap = 1,
276 TrapIDLLVMTrap = 2,
277 TrapIDLLVMDebugTrap = 3,
278 TrapIDDebugBreakpoint = 7,
279 TrapIDDebugReserved8 = 8,
280 TrapIDDebugReservedFE = 0xfe,
281 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +0000282 };
283
284 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +0000285 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +0000286 };
287
Tom Stellardc5a154d2018-06-28 23:47:12 +0000288private:
Tom Stellardc5a154d2018-06-28 23:47:12 +0000289 /// GlobalISel related APIs.
290 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
291 std::unique_ptr<InstructionSelector> InstSelector;
292 std::unique_ptr<LegalizerInfo> Legalizer;
293 std::unique_ptr<RegisterBankInfo> RegBankInfo;
294
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000295protected:
296 // Basic subtarget description.
297 Triple TargetTriple;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000298 unsigned Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000299 unsigned IsaVersion;
Stanislav Mekhanoshin06d3b412018-09-17 16:04:32 +0000300 InstrItineraryData InstrItins;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000301 int LDSBankCount;
302 unsigned MaxPrivateElementSize;
303
304 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000305 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000306 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000307
308 // Dynamially set bits that enable features.
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000309 bool FP64FP16Denormals;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000310 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000311 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000312 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000313 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000314 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000315 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000316 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000317 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000318 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000319 bool DebuggerInsertNops;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000320 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000321
322 // Used as options.
Matt Arsenault45b98182017-11-15 00:45:43 +0000323 bool EnableHugePrivateBuffer;
Matt Arsenault41033282014-10-10 22:01:59 +0000324 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000325 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000326 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000327 bool EnableDS128;
David Stuttardf77079f2019-01-14 11:55:24 +0000328 bool EnablePRTStrictNull;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000329 bool DumpCode;
330
331 // Subtarget statically properties set by tablegen
332 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000333 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000334 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000335 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000336 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000337 bool CIInsts;
Matt Arsenault96b67842018-08-07 07:28:46 +0000338 bool VIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000339 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000340 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000341 bool HasSMemRealTime;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000342 bool HasIntClamp;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000343 bool HasFmaMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000344 bool HasMovrel;
345 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000346 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000347 bool HasScalarAtomics;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000348 bool HasSDWAOmod;
349 bool HasSDWAScalar;
350 bool HasSDWASdst;
351 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000352 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000353 bool HasDPP;
Ryan Taylor1f334d02018-08-28 15:07:30 +0000354 bool HasR128A16;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000355 bool HasDLInsts;
Stanislav Mekhanoshind3757d32019-01-10 03:25:20 +0000356 bool HasDotInsts;
Konstantin Zhuravlyov108927b2018-11-05 22:44:19 +0000357 bool EnableSRAMECC;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000358 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000359 bool FlatInstOffsets;
360 bool FlatGlobalInsts;
361 bool FlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000362 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000363 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000364 bool R600ALUInst;
365 bool CaymanISA;
366 bool CFALUBug;
367 bool HasVertexCache;
368 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000369 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000370
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000371 // Dummy feature to use for assembler in tablegen.
372 bool FeatureDisable;
373
Matt Arsenault56684d42016-08-11 17:31:42 +0000374 SelectionDAGTargetInfo TSInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000375private:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000376 SIInstrInfo InstrInfo;
Tom Stellard752ddbd2018-07-11 22:15:15 +0000377 SITargetLowering TLInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000378 SIFrameLowering FrameLowering;
Tom Stellard75aadc22012-12-11 21:25:42 +0000379
380public:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000381 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
382 const GCNTargetMachine &TM);
383 ~GCNSubtarget() override;
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000384
Tom Stellard5bfbae52018-07-11 20:59:01 +0000385 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000386 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000387
Tom Stellard5bfbae52018-07-11 20:59:01 +0000388 const SIInstrInfo *getInstrInfo() const override {
389 return &InstrInfo;
390 }
Tom Stellard000c5af2016-04-14 19:09:28 +0000391
Tom Stellardc5a154d2018-06-28 23:47:12 +0000392 const SIFrameLowering *getFrameLowering() const override {
393 return &FrameLowering;
394 }
395
Tom Stellard5bfbae52018-07-11 20:59:01 +0000396 const SITargetLowering *getTargetLowering() const override {
397 return &TLInfo;
398 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000399
Tom Stellard5bfbae52018-07-11 20:59:01 +0000400 const SIRegisterInfo *getRegisterInfo() const override {
401 return &InstrInfo.getRegisterInfo();
402 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000403
404 const CallLowering *getCallLowering() const override {
405 return CallLoweringInfo.get();
406 }
407
408 const InstructionSelector *getInstructionSelector() const override {
409 return InstSelector.get();
410 }
411
412 const LegalizerInfo *getLegalizerInfo() const override {
413 return Legalizer.get();
414 }
415
416 const RegisterBankInfo *getRegBankInfo() const override {
417 return RegBankInfo.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000418 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000419
Matt Arsenault56684d42016-08-11 17:31:42 +0000420 // Nothing implemented, just prevent crashes on use.
421 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
422 return &TSInfo;
423 }
424
Stanislav Mekhanoshin06d3b412018-09-17 16:04:32 +0000425 const InstrItineraryData *getInstrItineraryData() const override {
426 return &InstrItins;
427 }
428
Craig Topperee7b0f32014-04-30 05:53:27 +0000429 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000430
Matt Arsenaultd782d052014-06-27 17:57:00 +0000431 Generation getGeneration() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000432 return (Generation)Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000433 }
434
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000435 unsigned getWavefrontSizeLog2() const {
436 return Log2_32(WavefrontSize);
437 }
438
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000439 int getLDSBankCount() const {
440 return LDSBankCount;
441 }
442
443 unsigned getMaxPrivateElementSize() const {
444 return MaxPrivateElementSize;
445 }
446
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000447 bool hasIntClamp() const {
448 return HasIntClamp;
449 }
450
Jan Veselyd1c9b612017-12-04 22:57:29 +0000451 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000452 return FP64;
453 }
454
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000455 bool hasMIMG_R128() const {
456 return MIMG_R128;
457 }
458
Tom Stellardc5a154d2018-06-28 23:47:12 +0000459 bool hasHWFP64() const {
460 return FP64;
461 }
462
Matt Arsenaultb035a572015-01-29 19:34:25 +0000463 bool hasFastFMAF32() const {
464 return FastFMAF32;
465 }
466
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000467 bool hasHalfRate64Ops() const {
468 return HalfRate64Ops;
469 }
470
Matt Arsenault88701812016-06-09 23:42:48 +0000471 bool hasAddr64() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000472 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
Matt Arsenault88701812016-06-09 23:42:48 +0000473 }
474
Matt Arsenaultfae02982014-03-17 18:58:11 +0000475 bool hasBFE() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000476 return true;
Matt Arsenaultfae02982014-03-17 18:58:11 +0000477 }
478
Matt Arsenault6e439652014-06-10 19:00:20 +0000479 bool hasBFI() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000480 return true;
Matt Arsenault6e439652014-06-10 19:00:20 +0000481 }
482
Matt Arsenaultfae02982014-03-17 18:58:11 +0000483 bool hasBFM() const {
484 return hasBFE();
485 }
486
Matt Arsenault60425062014-06-10 19:18:28 +0000487 bool hasBCNT(unsigned Size) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000488 return true;
Tom Stellard50122a52014-04-07 19:45:41 +0000489 }
490
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000491 bool hasFFBL() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000492 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000493 }
494
495 bool hasFFBH() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000496 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000497 }
498
Matt Arsenault10268f92017-02-27 22:40:39 +0000499 bool hasMed3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000500 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenault10268f92017-02-27 22:40:39 +0000501 }
502
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000503 bool hasMin3Max3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000504 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000505 }
506
Matt Arsenault0084adc2018-04-30 19:08:16 +0000507 bool hasFmaMixInsts() const {
508 return HasFmaMixInsts;
509 }
510
Jan Vesely808fff52015-04-30 17:15:56 +0000511 bool hasCARRY() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000512 return true;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000513 }
514
Jan Vesely39aeab42017-12-04 23:07:28 +0000515 bool hasFMA() const {
516 return FMA;
517 }
518
Stanislav Mekhanoshin79080ec2018-10-29 17:26:01 +0000519 bool hasSwap() const {
520 return GFX9Insts;
521 }
522
Wei Ding205bfdb2017-02-10 02:15:29 +0000523 TrapHandlerAbi getTrapHandlerAbi() const {
524 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
525 }
526
Matt Arsenault45b98182017-11-15 00:45:43 +0000527 bool enableHugePrivateBuffer() const {
528 return EnableHugePrivateBuffer;
529 }
530
Matt Arsenault706f9302015-07-06 16:01:58 +0000531 bool unsafeDSOffsetFoldingEnabled() const {
532 return EnableUnsafeDSOffsetFolding;
533 }
534
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000535 bool dumpCode() const {
536 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000537 }
538
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000539 /// Return the amount of LDS that can be used that will not restrict the
540 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000541 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
542 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000543
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000544 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000545 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000546 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000547
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000548 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000549 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000550 }
551
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000552 bool supportsMinMaxDenormModes() const {
553 return getGeneration() >= AMDGPUSubtarget::GFX9;
554 }
555
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000556 bool enableDX10Clamp() const {
557 return DX10Clamp;
558 }
559
560 bool enableIEEEBit(const MachineFunction &MF) const {
Matthias Braunf1caa282017-12-15 22:22:58 +0000561 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000562 }
563
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000564 bool useFlatForGlobal() const {
565 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000566 }
567
Farhana Aleena7cb3112018-03-09 17:41:39 +0000568 /// \returns If target supports ds_read/write_b128 and user enables generation
569 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000570 bool useDS128() const {
571 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000572 }
573
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000574 /// \returns If MUBUF instructions always perform range checking, even for
575 /// buffer resources used for private memory access.
576 bool privateMemoryResourceIsRangeChecked() const {
577 return getGeneration() < AMDGPUSubtarget::GFX9;
578 }
579
David Stuttardf77079f2019-01-14 11:55:24 +0000580 /// \returns If target requires PRT Struct NULL support (zero result registers
581 /// for sparse texture support).
582 bool usePRTStrictNull() const {
583 return EnablePRTStrictNull;
584 }
585
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000586 bool hasAutoWaitcntBeforeBarrier() const {
587 return AutoWaitcntBeforeBarrier;
588 }
589
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000590 bool hasCodeObjectV3() const {
Konstantin Zhuravlyova25e0522018-11-15 02:32:43 +0000591 // FIXME: Need to add code object v3 support for mesa and pal.
592 return isAmdHsaOS() ? CodeObjectV3 : false;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000593 }
594
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000595 bool hasUnalignedBufferAccess() const {
596 return UnalignedBufferAccess;
597 }
598
Tom Stellard64a9d082016-10-14 18:10:39 +0000599 bool hasUnalignedScratchAccess() const {
600 return UnalignedScratchAccess;
601 }
602
Matt Arsenaulte823d922017-02-18 18:29:53 +0000603 bool hasApertureRegs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000604 return HasApertureRegs;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000605 }
606
Wei Ding205bfdb2017-02-10 02:15:29 +0000607 bool isTrapHandlerEnabled() const {
608 return TrapHandler;
609 }
610
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000611 bool isXNACKEnabled() const {
612 return EnableXNACK;
613 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000614
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000615 bool hasFlatAddressSpace() const {
616 return FlatAddressSpace;
617 }
618
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000619 bool hasFlatInstOffsets() const {
620 return FlatInstOffsets;
621 }
622
623 bool hasFlatGlobalInsts() const {
624 return FlatGlobalInsts;
625 }
626
627 bool hasFlatScratchInsts() const {
628 return FlatScratchInsts;
629 }
630
Mark Searlesf0b93f12018-06-04 16:51:59 +0000631 bool hasFlatLgkmVMemCountInOrder() const {
632 return getGeneration() > GFX9;
633 }
634
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000635 bool hasD16LoadStore() const {
636 return getGeneration() >= GFX9;
637 }
638
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000639 /// Return if most LDS instructions have an m0 use that require m0 to be
640 /// iniitalized.
641 bool ldsRequiresM0Init() const {
642 return getGeneration() < GFX9;
643 }
644
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000645 bool hasAddNoCarry() const {
646 return AddNoCarryInsts;
647 }
648
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000649 bool hasUnpackedD16VMem() const {
650 return HasUnpackedD16VMem;
651 }
652
Tom Stellard2f3f9852017-01-25 01:25:13 +0000653 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000654 bool isMesaGfxShader(const Function &F) const {
655 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000656 }
657
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000658 bool hasMad64_32() const {
659 return getGeneration() >= SEA_ISLANDS;
660 }
661
Sam Kolton3c4933f2017-06-22 06:26:41 +0000662 bool hasSDWAOmod() const {
663 return HasSDWAOmod;
664 }
665
666 bool hasSDWAScalar() const {
667 return HasSDWAScalar;
668 }
669
670 bool hasSDWASdst() const {
671 return HasSDWASdst;
672 }
673
674 bool hasSDWAMac() const {
675 return HasSDWAMac;
676 }
677
Sam Koltona179d252017-06-27 15:02:23 +0000678 bool hasSDWAOutModsVOPC() const {
679 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000680 }
681
Mark Searles2a19af62018-04-26 16:11:19 +0000682 bool vmemWriteNeedsExpWaitcnt() const {
683 return getGeneration() < SEA_ISLANDS;
684 }
685
Matt Arsenault0084adc2018-04-30 19:08:16 +0000686 bool hasDLInsts() const {
687 return HasDLInsts;
688 }
689
Stanislav Mekhanoshind3757d32019-01-10 03:25:20 +0000690 bool hasDotInsts() const {
691 return HasDotInsts;
692 }
693
Konstantin Zhuravlyov108927b2018-11-05 22:44:19 +0000694 bool isSRAMECCEnabled() const {
695 return EnableSRAMECC;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000696 }
697
Matt Arsenault869fec22017-04-17 19:48:24 +0000698 // Scratch is allocated in 256 dword per wave blocks for the entire
699 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
700 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000701 //
702 // Only 4-byte alignment is really needed to access anything. Transformations
703 // on the pointer value itself may rely on the alignment / known low bits of
704 // the pointer. Set this to something above the minimum to avoid needing
705 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000706 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000707 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000708 }
Tom Stellard347ac792015-06-26 21:15:07 +0000709
Craig Topper5656db42014-04-29 07:57:24 +0000710 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000711 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000712 }
713
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000714 bool enableSubRegLiveness() const override {
715 return true;
716 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000717
Tom Stellardc5a154d2018-06-28 23:47:12 +0000718 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
719 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000720
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000721 /// \returns Number of execution units per compute unit supported by the
722 /// subtarget.
723 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000724 return AMDGPU::IsaInfo::getEUsPerCU(this);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000725 }
726
727 /// \returns Maximum number of waves per compute unit supported by the
728 /// subtarget without any kind of limitation.
729 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000730 return AMDGPU::IsaInfo::getMaxWavesPerCU(this);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000731 }
732
733 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000734 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000735 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000736 return AMDGPU::IsaInfo::getMaxWavesPerCU(this, FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000737 }
738
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000739 /// \returns Maximum number of waves per execution unit supported by the
740 /// subtarget without any kind of limitation.
741 unsigned getMaxWavesPerEU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000742 return AMDGPU::IsaInfo::getMaxWavesPerEU();
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000743 }
744
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000745 /// \returns Number of waves per work group supported by the subtarget and
746 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000747 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000748 return AMDGPU::IsaInfo::getWavesPerWorkGroup(this, FlatWorkGroupSize);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000749 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000750
Tom Stellardc5a154d2018-06-28 23:47:12 +0000751 // static wrappers
752 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000753
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000754 // XXX - Why is this here if it isn't in the default pass set?
755 bool enableEarlyIfConversion() const override {
756 return true;
757 }
758
Tom Stellard83f0bce2015-01-29 16:55:25 +0000759 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000760 unsigned NumRegionInstrs) const override;
761
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000762 unsigned getMaxNumUserSGPRs() const {
763 return 16;
764 }
765
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000766 bool hasSMemRealTime() const {
767 return HasSMemRealTime;
768 }
769
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000770 bool hasMovrel() const {
771 return HasMovrel;
772 }
773
774 bool hasVGPRIndexMode() const {
775 return HasVGPRIndexMode;
776 }
777
Marek Olsake22fdb92017-03-21 17:00:32 +0000778 bool useVGPRIndexMode(bool UserEnable) const {
779 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
780 }
781
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000782 bool hasScalarCompareEq64() const {
783 return getGeneration() >= VOLCANIC_ISLANDS;
784 }
785
Matt Arsenault7b647552016-10-28 21:55:15 +0000786 bool hasScalarStores() const {
787 return HasScalarStores;
788 }
789
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000790 bool hasScalarAtomics() const {
791 return HasScalarAtomics;
792 }
793
Matt Arsenaulta5840c32019-01-22 18:36:06 +0000794 bool hasLDSFPAtomics() const {
795 return VIInsts;
796 }
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000797
Sam Kolton07dbde22017-01-20 10:01:25 +0000798 bool hasDPP() const {
799 return HasDPP;
800 }
801
Ryan Taylor1f334d02018-08-28 15:07:30 +0000802 bool hasR128A16() const {
803 return HasR128A16;
804 }
805
Tom Stellardde008d32016-01-21 04:28:34 +0000806 bool enableSIScheduler() const {
807 return EnableSIScheduler;
808 }
809
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000810 bool debuggerSupported() const {
Konstantin Zhuravlyove004b3d2018-06-21 20:28:19 +0000811 return debuggerInsertNops() && debuggerEmitPrologue();
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000812 }
813
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000814 bool debuggerInsertNops() const {
815 return DebuggerInsertNops;
816 }
817
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000818 bool debuggerEmitPrologue() const {
819 return DebuggerEmitPrologue;
820 }
821
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000822 bool loadStoreOptEnabled() const {
823 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000824 }
825
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000826 bool hasSGPRInitBug() const {
827 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000828 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000829
Tom Stellardb133fbb2016-10-27 23:05:31 +0000830 bool has12DWordStoreHazard() const {
831 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
832 }
833
Neil Henninge85d45a2019-01-10 16:21:08 +0000834 // \returns true if the subtarget supports DWORDX3 load/store instructions.
835 bool hasDwordx3LoadStores() const {
836 return CIInsts;
837 }
838
Matt Arsenaulte823d922017-02-18 18:29:53 +0000839 bool hasSMovFedHazard() const {
840 return getGeneration() >= AMDGPUSubtarget::GFX9;
841 }
842
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000843 bool hasReadM0MovRelInterpHazard() const {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000844 return getGeneration() >= AMDGPUSubtarget::GFX9;
845 }
846
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000847 bool hasReadM0SendMsgHazard() const {
848 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
849 }
850
Tom Stellardc5a154d2018-06-28 23:47:12 +0000851 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
852 /// SGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000853 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
854
Tom Stellardc5a154d2018-06-28 23:47:12 +0000855 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
856 /// VGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000857 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000858
Matt Arsenaulte823d922017-02-18 18:29:53 +0000859 /// \returns true if the flat_scratch register should be initialized with the
860 /// pointer to the wave's scratch memory rather than a size and offset.
861 bool flatScratchIsPointer() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000862 return getGeneration() >= AMDGPUSubtarget::GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000863 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000864
Tim Renouf832f90f2018-02-26 14:46:43 +0000865 /// \returns true if the machine has merged shaders in which s0-s7 are
866 /// reserved by the hardware and user SGPRs start at s8
867 bool hasMergedShaders() const {
868 return getGeneration() >= GFX9;
869 }
870
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000871 /// \returns SGPR allocation granularity supported by the subtarget.
872 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000873 return AMDGPU::IsaInfo::getSGPRAllocGranule(this);
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000874 }
875
876 /// \returns SGPR encoding granularity supported by the subtarget.
877 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000878 return AMDGPU::IsaInfo::getSGPREncodingGranule(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000879 }
880
881 /// \returns Total number of SGPRs supported by the subtarget.
882 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000883 return AMDGPU::IsaInfo::getTotalNumSGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000884 }
885
886 /// \returns Addressable number of SGPRs supported by the subtarget.
887 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000888 return AMDGPU::IsaInfo::getAddressableNumSGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000889 }
890
891 /// \returns Minimum number of SGPRs that meets the given number of waves per
892 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000893 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000894 return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000895 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000896
897 /// \returns Maximum number of SGPRs that meets the given number of waves per
898 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000899 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000900 return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000901 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000902
903 /// \returns Reserved number of SGPRs for given function \p MF.
904 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
905
906 /// \returns Maximum number of SGPRs that meets number of waves per execution
907 /// unit requirement for function \p MF, or number of SGPRs explicitly
908 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
909 ///
910 /// \returns Value that meets number of waves per execution unit requirement
911 /// if explicitly requested value cannot be converted to integer, violates
912 /// subtarget's specifications, or does not meet number of waves per execution
913 /// unit requirement.
914 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
915
916 /// \returns VGPR allocation granularity supported by the subtarget.
917 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000918 return AMDGPU::IsaInfo::getVGPRAllocGranule(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000919 }
920
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000921 /// \returns VGPR encoding granularity supported by the subtarget.
922 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000923 return AMDGPU::IsaInfo::getVGPREncodingGranule(this);
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000924 }
925
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000926 /// \returns Total number of VGPRs supported by the subtarget.
927 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000928 return AMDGPU::IsaInfo::getTotalNumVGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000929 }
930
931 /// \returns Addressable number of VGPRs supported by the subtarget.
932 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000933 return AMDGPU::IsaInfo::getAddressableNumVGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000934 }
935
936 /// \returns Minimum number of VGPRs that meets given number of waves per
937 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000938 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000939 return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000940 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000941
942 /// \returns Maximum number of VGPRs that meets given number of waves per
943 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000944 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000945 return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000946 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000947
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000948 /// \returns Maximum number of VGPRs that meets number of waves per execution
949 /// unit requirement for function \p MF, or number of VGPRs explicitly
950 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
951 ///
952 /// \returns Value that meets number of waves per execution unit requirement
953 /// if explicitly requested value cannot be converted to integer, violates
954 /// subtarget's specifications, or does not meet number of waves per execution
955 /// unit requirement.
956 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +0000957
958 void getPostRAMutations(
959 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
960 const override;
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000961
962 /// \returns Maximum number of work groups per compute unit supported by the
963 /// subtarget and limited by given \p FlatWorkGroupSize.
964 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
965 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
966 }
967
968 /// \returns Minimum flat work group size supported by the subtarget.
969 unsigned getMinFlatWorkGroupSize() const override {
970 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
971 }
972
973 /// \returns Maximum flat work group size supported by the subtarget.
974 unsigned getMaxFlatWorkGroupSize() const override {
975 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
976 }
977
978 /// \returns Maximum number of waves per execution unit supported by the
979 /// subtarget and limited by given \p FlatWorkGroupSize.
980 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const override {
981 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize);
982 }
983
984 /// \returns Minimum number of waves per execution unit supported by the
985 /// subtarget.
986 unsigned getMinWavesPerEU() const override {
987 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
988 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000989};
990
Tom Stellardc5a154d2018-06-28 23:47:12 +0000991class R600Subtarget final : public R600GenSubtargetInfo,
Tom Stellard5bfbae52018-07-11 20:59:01 +0000992 public AMDGPUSubtarget {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000993private:
994 R600InstrInfo InstrInfo;
995 R600FrameLowering FrameLowering;
996 bool FMA;
997 bool CaymanISA;
998 bool CFALUBug;
999 bool DX10Clamp;
1000 bool HasVertexCache;
1001 bool R600ALUInst;
1002 bool FP64;
1003 short TexVTXClauseSize;
1004 Generation Gen;
1005 R600TargetLowering TLInfo;
1006 InstrItineraryData InstrItins;
1007 SelectionDAGTargetInfo TSInfo;
Tom Stellardc5a154d2018-06-28 23:47:12 +00001008
1009public:
1010 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
1011 const TargetMachine &TM);
1012
1013 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
1014
1015 const R600FrameLowering *getFrameLowering() const override {
1016 return &FrameLowering;
1017 }
1018
1019 const R600TargetLowering *getTargetLowering() const override {
1020 return &TLInfo;
1021 }
1022
1023 const R600RegisterInfo *getRegisterInfo() const override {
1024 return &InstrInfo.getRegisterInfo();
1025 }
1026
1027 const InstrItineraryData *getInstrItineraryData() const override {
1028 return &InstrItins;
1029 }
1030
1031 // Nothing implemented, just prevent crashes on use.
1032 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
1033 return &TSInfo;
1034 }
1035
1036 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1037
1038 Generation getGeneration() const {
1039 return Gen;
1040 }
1041
1042 unsigned getStackAlignment() const {
1043 return 4;
1044 }
1045
1046 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1047 StringRef GPU, StringRef FS);
1048
1049 bool hasBFE() const {
1050 return (getGeneration() >= EVERGREEN);
1051 }
1052
1053 bool hasBFI() const {
1054 return (getGeneration() >= EVERGREEN);
1055 }
1056
1057 bool hasBCNT(unsigned Size) const {
1058 if (Size == 32)
1059 return (getGeneration() >= EVERGREEN);
1060
1061 return false;
1062 }
1063
1064 bool hasBORROW() const {
1065 return (getGeneration() >= EVERGREEN);
1066 }
1067
1068 bool hasCARRY() const {
1069 return (getGeneration() >= EVERGREEN);
1070 }
1071
1072 bool hasCaymanISA() const {
1073 return CaymanISA;
1074 }
1075
1076 bool hasFFBL() const {
1077 return (getGeneration() >= EVERGREEN);
1078 }
1079
1080 bool hasFFBH() const {
1081 return (getGeneration() >= EVERGREEN);
1082 }
1083
1084 bool hasFMA() const { return FMA; }
1085
Tom Stellardc5a154d2018-06-28 23:47:12 +00001086 bool hasCFAluBug() const { return CFALUBug; }
1087
1088 bool hasVertexCache() const { return HasVertexCache; }
1089
1090 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1091
Tom Stellardc5a154d2018-06-28 23:47:12 +00001092 bool enableMachineScheduler() const override {
1093 return true;
1094 }
1095
1096 bool enableSubRegLiveness() const override {
1097 return true;
1098 }
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001099
1100 /// \returns Maximum number of work groups per compute unit supported by the
1101 /// subtarget and limited by given \p FlatWorkGroupSize.
1102 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
1103 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
1104 }
1105
1106 /// \returns Minimum flat work group size supported by the subtarget.
1107 unsigned getMinFlatWorkGroupSize() const override {
1108 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1109 }
1110
1111 /// \returns Maximum flat work group size supported by the subtarget.
1112 unsigned getMaxFlatWorkGroupSize() const override {
1113 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1114 }
1115
1116 /// \returns Maximum number of waves per execution unit supported by the
1117 /// subtarget and limited by given \p FlatWorkGroupSize.
1118 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const override {
1119 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize);
1120 }
1121
1122 /// \returns Minimum number of waves per execution unit supported by the
1123 /// subtarget.
1124 unsigned getMinWavesPerEU() const override {
1125 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1126 }
Tom Stellardc5a154d2018-06-28 23:47:12 +00001127};
1128
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001129} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +00001130
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001131#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H