blob: 3b1ed618677e5b765d212f333dd0f4b66be6be1a [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,
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +000058 GFX9 = 7,
59 GFX10 = 8
Tom Stellard5bfbae52018-07-11 20:59:01 +000060 };
61
Tom Stellardc5a154d2018-06-28 23:47:12 +000062private:
63 Triple TargetTriple;
64
65protected:
Tom Stellardc5a154d2018-06-28 23:47:12 +000066 bool Has16BitInsts;
67 bool HasMadMixInsts;
68 bool FP32Denormals;
69 bool FPExceptions;
70 bool HasSDWA;
71 bool HasVOP3PInsts;
72 bool HasMulI24;
73 bool HasMulU24;
Matt Arsenault6c7ba822018-08-15 21:03:55 +000074 bool HasInv2PiInlineImm;
Tom Stellardc5a154d2018-06-28 23:47:12 +000075 bool HasFminFmaxLegacy;
76 bool EnablePromoteAlloca;
David Stuttard20de3e92018-09-14 10:27:19 +000077 bool HasTrigReducedRange;
Tom Stellardc5a154d2018-06-28 23:47:12 +000078 int LocalMemorySize;
79 unsigned WavefrontSize;
80
81public:
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +000082 AMDGPUSubtarget(const Triple &TT);
Tom Stellardc5a154d2018-06-28 23:47:12 +000083
Tom Stellard5bfbae52018-07-11 20:59:01 +000084 static const AMDGPUSubtarget &get(const MachineFunction &MF);
85 static const AMDGPUSubtarget &get(const TargetMachine &TM,
Matt Arsenault4bec7d42018-07-20 09:05:08 +000086 const Function &F);
Tom Stellardc5a154d2018-06-28 23:47:12 +000087
88 /// \returns Default range flat work group size for a calling convention.
89 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
90
91 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
92 /// for function \p F, or minimum/maximum flat work group sizes explicitly
93 /// requested using "amdgpu-flat-work-group-size" attribute attached to
94 /// function \p F.
95 ///
96 /// \returns Subtarget's default values if explicitly requested values cannot
97 /// be converted to integer, or violate subtarget's specifications.
98 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
99
100 /// \returns Subtarget's default pair of minimum/maximum number of waves per
101 /// execution unit for function \p F, or minimum/maximum number of waves per
102 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
103 /// attached to function \p F.
104 ///
105 /// \returns Subtarget's default values if explicitly requested values cannot
106 /// be converted to integer, violate subtarget's specifications, or are not
107 /// compatible with minimum/maximum number of waves limited by flat work group
108 /// size, register usage, and/or lds usage.
109 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
110
111 /// Return the amount of LDS that can be used that will not restrict the
112 /// occupancy lower than WaveCount.
113 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
114 const Function &) const;
115
116 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
117 /// the given LDS memory size is the only constraint.
118 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
119
120 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const;
121
122 bool isAmdHsaOS() const {
123 return TargetTriple.getOS() == Triple::AMDHSA;
124 }
125
126 bool isAmdPalOS() const {
127 return TargetTriple.getOS() == Triple::AMDPAL;
128 }
129
Tom Stellardec4feae2018-07-06 17:16:17 +0000130 bool isMesa3DOS() const {
131 return TargetTriple.getOS() == Triple::Mesa3D;
132 }
133
134 bool isMesaKernel(const Function &F) const {
135 return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
136 }
137
Konstantin Zhuravlyovaa067cb2018-10-04 21:02:16 +0000138 bool isAmdHsaOrMesa(const Function &F) const {
Tom Stellardec4feae2018-07-06 17:16:17 +0000139 return isAmdHsaOS() || isMesaKernel(F);
140 }
141
Tom Stellardc5a154d2018-06-28 23:47:12 +0000142 bool has16BitInsts() const {
143 return Has16BitInsts;
144 }
145
146 bool hasMadMixInsts() const {
147 return HasMadMixInsts;
148 }
149
150 bool hasFP32Denormals() const {
151 return FP32Denormals;
152 }
153
154 bool hasFPExceptions() const {
155 return FPExceptions;
156 }
157
158 bool hasSDWA() const {
159 return HasSDWA;
160 }
161
162 bool hasVOP3PInsts() const {
163 return HasVOP3PInsts;
164 }
165
166 bool hasMulI24() const {
167 return HasMulI24;
168 }
169
170 bool hasMulU24() const {
171 return HasMulU24;
172 }
173
Matt Arsenault6c7ba822018-08-15 21:03:55 +0000174 bool hasInv2PiInlineImm() const {
175 return HasInv2PiInlineImm;
176 }
177
Tom Stellardc5a154d2018-06-28 23:47:12 +0000178 bool hasFminFmaxLegacy() const {
179 return HasFminFmaxLegacy;
180 }
181
David Stuttard20de3e92018-09-14 10:27:19 +0000182 bool hasTrigReducedRange() const {
183 return HasTrigReducedRange;
184 }
185
Tom Stellardc5a154d2018-06-28 23:47:12 +0000186 bool isPromoteAllocaEnabled() const {
187 return EnablePromoteAlloca;
188 }
189
190 unsigned getWavefrontSize() const {
191 return WavefrontSize;
192 }
193
194 int getLocalMemorySize() const {
195 return LocalMemorySize;
196 }
197
198 unsigned getAlignmentForImplicitArgPtr() const {
199 return isAmdHsaOS() ? 8 : 4;
200 }
201
Tom Stellardec4feae2018-07-06 17:16:17 +0000202 /// Returns the offset in bytes from the start of the input buffer
203 /// of the first explicit kernel argument.
204 unsigned getExplicitKernelArgOffset(const Function &F) const {
Konstantin Zhuravlyovaa067cb2018-10-04 21:02:16 +0000205 return isAmdHsaOrMesa(F) ? 0 : 36;
Tom Stellardec4feae2018-07-06 17:16:17 +0000206 }
207
Tom Stellardc5a154d2018-06-28 23:47:12 +0000208 /// \returns Maximum number of work groups per compute unit supported by the
209 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000210 virtual unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000211
212 /// \returns Minimum flat work group size supported by the subtarget.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000213 virtual unsigned getMinFlatWorkGroupSize() const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000214
215 /// \returns Maximum flat work group size supported by the subtarget.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000216 virtual unsigned getMaxFlatWorkGroupSize() const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000217
218 /// \returns Maximum number of waves per execution unit supported by the
219 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000220 virtual unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000221
222 /// \returns Minimum number of waves per execution unit supported by the
223 /// subtarget.
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000224 virtual unsigned getMinWavesPerEU() const = 0;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000225
226 unsigned getMaxWavesPerEU() const { return 10; }
227
228 /// Creates value range metadata on an workitemid.* inrinsic call or load.
229 bool makeLIDRangeMetadata(Instruction *I) const;
230
Matt Arsenault4bec7d42018-07-20 09:05:08 +0000231 /// \returns Number of bytes of arguments that are passed to a shader or
232 /// kernel in addition to the explicit ones declared for the function.
233 unsigned getImplicitArgNumBytes(const Function &F) const {
234 if (isMesaKernel(F))
235 return 16;
236 return AMDGPU::getIntegerAttribute(F, "amdgpu-implicitarg-num-bytes", 0);
237 }
238 uint64_t getExplicitKernArgSize(const Function &F,
239 unsigned &MaxAlign) const;
240 unsigned getKernArgSegmentSize(const Function &F,
241 unsigned &MaxAlign) const;
242
Tom Stellard5bfbae52018-07-11 20:59:01 +0000243 virtual ~AMDGPUSubtarget() {}
Tom Stellardc5a154d2018-06-28 23:47:12 +0000244};
245
Tom Stellard5bfbae52018-07-11 20:59:01 +0000246class GCNSubtarget : public AMDGPUGenSubtargetInfo,
247 public AMDGPUSubtarget {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000248public:
Wei Ding205bfdb2017-02-10 02:15:29 +0000249 enum TrapHandlerAbi {
250 TrapHandlerAbiNone = 0,
251 TrapHandlerAbiHsa = 1
252 };
253
Wei Dingf2cce022017-02-22 23:22:19 +0000254 enum TrapID {
255 TrapIDHardwareReserved = 0,
256 TrapIDHSADebugTrap = 1,
257 TrapIDLLVMTrap = 2,
258 TrapIDLLVMDebugTrap = 3,
259 TrapIDDebugBreakpoint = 7,
260 TrapIDDebugReserved8 = 8,
261 TrapIDDebugReservedFE = 0xfe,
262 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +0000263 };
264
265 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +0000266 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +0000267 };
268
Tom Stellardc5a154d2018-06-28 23:47:12 +0000269private:
Tom Stellardc5a154d2018-06-28 23:47:12 +0000270 /// GlobalISel related APIs.
271 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
272 std::unique_ptr<InstructionSelector> InstSelector;
273 std::unique_ptr<LegalizerInfo> Legalizer;
274 std::unique_ptr<RegisterBankInfo> RegBankInfo;
275
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000276protected:
277 // Basic subtarget description.
278 Triple TargetTriple;
Tom Stellardc5a154d2018-06-28 23:47:12 +0000279 unsigned Gen;
Stanislav Mekhanoshin06d3b412018-09-17 16:04:32 +0000280 InstrItineraryData InstrItins;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000281 int LDSBankCount;
282 unsigned MaxPrivateElementSize;
283
284 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000285 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000286 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000287
288 // Dynamially set bits that enable features.
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000289 bool FP64FP16Denormals;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000290 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000291 bool AutoWaitcntBeforeBarrier;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000292 bool CodeObjectV3;
Tom Stellard64a9d082016-10-14 18:10:39 +0000293 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000294 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000295 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000296 bool EnableXNACK;
Matt Arsenaultdf24c922019-05-16 14:48:34 +0000297 bool DoesNotSupportXNACK;
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000298 bool EnableCuMode;
Wei Ding205bfdb2017-02-10 02:15:29 +0000299 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000300
301 // Used as options.
Matt Arsenault41033282014-10-10 22:01:59 +0000302 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000303 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000304 bool EnableSIScheduler;
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000305 bool EnableDS128;
David Stuttardf77079f2019-01-14 11:55:24 +0000306 bool EnablePRTStrictNull;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000307 bool DumpCode;
308
309 // Subtarget statically properties set by tablegen
310 bool FP64;
Jan Vesely39aeab42017-12-04 23:07:28 +0000311 bool FMA;
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000312 bool MIMG_R128;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000313 bool IsGCN;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000314 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000315 bool CIInsts;
Stanislav Mekhanoshin7895c032019-04-05 18:24:34 +0000316 bool GFX8Insts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000317 bool GFX9Insts;
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000318 bool GFX10Insts;
Stanislav Mekhanoshin7895c032019-04-05 18:24:34 +0000319 bool GFX7GFX8GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000320 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000321 bool HasSMemRealTime;
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000322 bool HasIntClamp;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000323 bool HasFmaMixInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000324 bool HasMovrel;
325 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000326 bool HasScalarStores;
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000327 bool HasScalarAtomics;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000328 bool HasSDWAOmod;
329 bool HasSDWAScalar;
330 bool HasSDWASdst;
331 bool HasSDWAMac;
Sam Koltona179d252017-06-27 15:02:23 +0000332 bool HasSDWAOutModsVOPC;
Sam Kolton07dbde22017-01-20 10:01:25 +0000333 bool HasDPP;
Stanislav Mekhanoshin245b5ba2019-06-12 18:02:41 +0000334 bool HasDPP8;
Ryan Taylor1f334d02018-08-28 15:07:30 +0000335 bool HasR128A16;
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000336 bool HasNSAEncoding;
Matt Arsenault0084adc2018-04-30 19:08:16 +0000337 bool HasDLInsts;
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000338 bool HasDot1Insts;
339 bool HasDot2Insts;
Stanislav Mekhanoshinc43e67b2019-06-14 00:33:31 +0000340 bool HasDot5Insts;
341 bool HasDot6Insts;
Konstantin Zhuravlyov108927b2018-11-05 22:44:19 +0000342 bool EnableSRAMECC;
Matt Arsenaultf426ddb2019-04-03 01:58:57 +0000343 bool DoesNotSupportSRAMECC;
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000344 bool HasNoSdstCMPX;
345 bool HasVscnt;
346 bool HasRegisterBanking;
347 bool HasVOP3Literal;
348 bool HasNoDataDepHazard;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000349 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000350 bool FlatInstOffsets;
351 bool FlatGlobalInsts;
352 bool FlatScratchInsts;
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000353 bool ScalarFlatScratchInsts;
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000354 bool AddNoCarryInsts;
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000355 bool HasUnpackedD16VMem;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000356 bool R600ALUInst;
357 bool CaymanISA;
358 bool CFALUBug;
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000359 bool LDSMisalignedBug;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000360 bool HasVertexCache;
361 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000362 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000363
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000364 bool HasVcmpxPermlaneHazard;
365 bool HasVMEMtoScalarWriteHazard;
366 bool HasSMEMtoVectorWriteHazard;
367 bool HasInstFwdPrefetchBug;
368 bool HasVcmpxExecWARHazard;
369 bool HasLdsBranchVmemWARHazard;
370 bool HasNSAtoVMEMBug;
371 bool HasFlatSegmentOffsetBug;
372
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000373 // Dummy feature to use for assembler in tablegen.
374 bool FeatureDisable;
375
Matt Arsenault56684d42016-08-11 17:31:42 +0000376 SelectionDAGTargetInfo TSInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000377private:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000378 SIInstrInfo InstrInfo;
Tom Stellard752ddbd2018-07-11 22:15:15 +0000379 SITargetLowering TLInfo;
Tom Stellard5bfbae52018-07-11 20:59:01 +0000380 SIFrameLowering FrameLowering;
Tom Stellard75aadc22012-12-11 21:25:42 +0000381
Matt Arsenault5c714cb2019-05-23 19:38:14 +0000382 // See COMPUTE_TMPRING_SIZE.WAVESIZE, 13-bit field in units of 256-dword.
383 static const unsigned MaxWaveScratchSize = (256 * 4) * ((1 << 13) - 1);
384
Tom Stellard75aadc22012-12-11 21:25:42 +0000385public:
Tom Stellard5bfbae52018-07-11 20:59:01 +0000386 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
387 const GCNTargetMachine &TM);
388 ~GCNSubtarget() override;
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000389
Tom Stellard5bfbae52018-07-11 20:59:01 +0000390 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000391 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000392
Tom Stellard5bfbae52018-07-11 20:59:01 +0000393 const SIInstrInfo *getInstrInfo() const override {
394 return &InstrInfo;
395 }
Tom Stellard000c5af2016-04-14 19:09:28 +0000396
Tom Stellardc5a154d2018-06-28 23:47:12 +0000397 const SIFrameLowering *getFrameLowering() const override {
398 return &FrameLowering;
399 }
400
Tom Stellard5bfbae52018-07-11 20:59:01 +0000401 const SITargetLowering *getTargetLowering() const override {
402 return &TLInfo;
403 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000404
Tom Stellard5bfbae52018-07-11 20:59:01 +0000405 const SIRegisterInfo *getRegisterInfo() const override {
406 return &InstrInfo.getRegisterInfo();
407 }
Tom Stellardc5a154d2018-06-28 23:47:12 +0000408
409 const CallLowering *getCallLowering() const override {
410 return CallLoweringInfo.get();
411 }
412
413 const InstructionSelector *getInstructionSelector() const override {
414 return InstSelector.get();
415 }
416
417 const LegalizerInfo *getLegalizerInfo() const override {
418 return Legalizer.get();
419 }
420
421 const RegisterBankInfo *getRegBankInfo() const override {
422 return RegBankInfo.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000423 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000424
Matt Arsenault56684d42016-08-11 17:31:42 +0000425 // Nothing implemented, just prevent crashes on use.
426 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
427 return &TSInfo;
428 }
429
Stanislav Mekhanoshin06d3b412018-09-17 16:04:32 +0000430 const InstrItineraryData *getInstrItineraryData() const override {
431 return &InstrItins;
432 }
433
Craig Topperee7b0f32014-04-30 05:53:27 +0000434 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000435
Matt Arsenaultd782d052014-06-27 17:57:00 +0000436 Generation getGeneration() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000437 return (Generation)Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000438 }
439
Matt Arsenault4eea3f32017-11-13 22:55:05 +0000440 unsigned getWavefrontSizeLog2() const {
441 return Log2_32(WavefrontSize);
442 }
443
Matt Arsenault5c714cb2019-05-23 19:38:14 +0000444 /// Return the number of high bits known to be zero fror a frame index.
445 unsigned getKnownHighZeroBitsForFrameIndex() const {
446 return countLeadingZeros(MaxWaveScratchSize) + getWavefrontSizeLog2();
447 }
448
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000449 int getLDSBankCount() const {
450 return LDSBankCount;
451 }
452
453 unsigned getMaxPrivateElementSize() const {
454 return MaxPrivateElementSize;
455 }
456
Stanislav Mekhanoshinf2baae02019-05-02 03:47:23 +0000457 unsigned getConstantBusLimit(unsigned Opcode) const;
458
Dmitry Preobrazhenskyff64aa52017-08-16 13:51:56 +0000459 bool hasIntClamp() const {
460 return HasIntClamp;
461 }
462
Jan Veselyd1c9b612017-12-04 22:57:29 +0000463 bool hasFP64() const {
Matt Arsenaultd782d052014-06-27 17:57:00 +0000464 return FP64;
465 }
466
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000467 bool hasMIMG_R128() const {
468 return MIMG_R128;
469 }
470
Tom Stellardc5a154d2018-06-28 23:47:12 +0000471 bool hasHWFP64() const {
472 return FP64;
473 }
474
Matt Arsenaultb035a572015-01-29 19:34:25 +0000475 bool hasFastFMAF32() const {
476 return FastFMAF32;
477 }
478
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000479 bool hasHalfRate64Ops() const {
480 return HalfRate64Ops;
481 }
482
Matt Arsenault88701812016-06-09 23:42:48 +0000483 bool hasAddr64() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000484 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
Matt Arsenault88701812016-06-09 23:42:48 +0000485 }
486
Matt Arsenaulte4c2e9b2019-06-19 23:54:58 +0000487 // Return true if the target only has the reverse operand versions of VALU
488 // shift instructions (e.g. v_lshrrev_b32, and no v_lshr_b32).
489 bool hasOnlyRevVALUShifts() const {
490 return getGeneration() >= VOLCANIC_ISLANDS;
491 }
492
Matt Arsenaultfae02982014-03-17 18:58:11 +0000493 bool hasBFE() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000494 return true;
Matt Arsenaultfae02982014-03-17 18:58:11 +0000495 }
496
Matt Arsenault6e439652014-06-10 19:00:20 +0000497 bool hasBFI() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000498 return true;
Matt Arsenault6e439652014-06-10 19:00:20 +0000499 }
500
Matt Arsenaultfae02982014-03-17 18:58:11 +0000501 bool hasBFM() const {
502 return hasBFE();
503 }
504
Matt Arsenault60425062014-06-10 19:18:28 +0000505 bool hasBCNT(unsigned Size) const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000506 return true;
Tom Stellard50122a52014-04-07 19:45:41 +0000507 }
508
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000509 bool hasFFBL() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000510 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000511 }
512
513 bool hasFFBH() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000514 return true;
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000515 }
516
Matt Arsenault10268f92017-02-27 22:40:39 +0000517 bool hasMed3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000518 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenault10268f92017-02-27 22:40:39 +0000519 }
520
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000521 bool hasMin3Max3_16() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000522 return getGeneration() >= AMDGPUSubtarget::GFX9;
Matt Arsenaultd7e23032017-09-07 18:05:07 +0000523 }
524
Matt Arsenault0084adc2018-04-30 19:08:16 +0000525 bool hasFmaMixInsts() const {
526 return HasFmaMixInsts;
527 }
528
Jan Vesely808fff52015-04-30 17:15:56 +0000529 bool hasCARRY() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000530 return true;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000531 }
532
Jan Vesely39aeab42017-12-04 23:07:28 +0000533 bool hasFMA() const {
534 return FMA;
535 }
536
Stanislav Mekhanoshin79080ec2018-10-29 17:26:01 +0000537 bool hasSwap() const {
538 return GFX9Insts;
539 }
540
Wei Ding205bfdb2017-02-10 02:15:29 +0000541 TrapHandlerAbi getTrapHandlerAbi() const {
542 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
543 }
544
Matt Arsenaulte4c2e9b2019-06-19 23:54:58 +0000545 /// True if the offset field of DS instructions works as expected. On SI, the
546 /// offset uses a 16-bit adder and does not always wrap properly.
547 bool hasUsableDSOffset() const {
548 return getGeneration() >= SEA_ISLANDS;
549 }
550
Matt Arsenault706f9302015-07-06 16:01:58 +0000551 bool unsafeDSOffsetFoldingEnabled() const {
552 return EnableUnsafeDSOffsetFolding;
553 }
554
Matt Arsenaulte4c2e9b2019-06-19 23:54:58 +0000555 /// Condition output from div_scale is usable.
556 bool hasUsableDivScaleConditionOutput() const {
557 return getGeneration() != SOUTHERN_ISLANDS;
558 }
559
560 /// Extra wait hazard is needed in some cases before
561 /// s_cbranch_vccnz/s_cbranch_vccz.
562 bool hasReadVCCZBug() const {
563 return getGeneration() <= SEA_ISLANDS;
564 }
565
566 /// A read of an SGPR by SMRD instruction requires 4 wait states when the SGPR
567 /// was written by a VALU instruction.
568 bool hasSMRDReadVALUDefHazard() const {
569 return getGeneration() == SOUTHERN_ISLANDS;
570 }
571
572 /// A read of an SGPR by a VMEM instruction requires 5 wait states when the
573 /// SGPR was written by a VALU Instruction.
574 bool hasVMEMReadSGPRVALUDefHazard() const {
575 return getGeneration() >= VOLCANIC_ISLANDS;
576 }
577
578 bool hasRFEHazards() const {
579 return getGeneration() >= VOLCANIC_ISLANDS;
580 }
581
582 /// Number of hazard wait states for s_setreg_b32/s_setreg_imm32_b32.
583 unsigned getSetRegWaitStates() const {
584 return getGeneration() <= SEA_ISLANDS ? 1 : 2;
585 }
586
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000587 bool dumpCode() const {
588 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000589 }
590
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000591 /// Return the amount of LDS that can be used that will not restrict the
592 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000593 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
594 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000595
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000596 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000597 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000598 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000599
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000600 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000601 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000602 }
603
Stanislav Mekhanoshindc2890a2017-07-13 23:59:15 +0000604 bool supportsMinMaxDenormModes() const {
605 return getGeneration() >= AMDGPUSubtarget::GFX9;
606 }
607
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000608 bool useFlatForGlobal() const {
609 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000610 }
611
Farhana Aleena7cb3112018-03-09 17:41:39 +0000612 /// \returns If target supports ds_read/write_b128 and user enables generation
613 /// of ds_read/write_b128.
Marek Olsaka9a58fa2018-04-10 22:48:23 +0000614 bool useDS128() const {
615 return CIInsts && EnableDS128;
Farhana Aleena7cb3112018-03-09 17:41:39 +0000616 }
617
Matt Arsenaulte4c2e9b2019-06-19 23:54:58 +0000618 /// Have v_trunc_f64, v_ceil_f64, v_rndne_f64
619 bool haveRoundOpsF64() const {
620 return CIInsts;
621 }
622
Matt Arsenaultcaf0ed42017-11-30 00:52:40 +0000623 /// \returns If MUBUF instructions always perform range checking, even for
624 /// buffer resources used for private memory access.
625 bool privateMemoryResourceIsRangeChecked() const {
626 return getGeneration() < AMDGPUSubtarget::GFX9;
627 }
628
David Stuttardf77079f2019-01-14 11:55:24 +0000629 /// \returns If target requires PRT Struct NULL support (zero result registers
630 /// for sparse texture support).
631 bool usePRTStrictNull() const {
632 return EnablePRTStrictNull;
633 }
634
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000635 bool hasAutoWaitcntBeforeBarrier() const {
636 return AutoWaitcntBeforeBarrier;
637 }
638
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000639 bool hasCodeObjectV3() const {
Konstantin Zhuravlyova25e0522018-11-15 02:32:43 +0000640 // FIXME: Need to add code object v3 support for mesa and pal.
641 return isAmdHsaOS() ? CodeObjectV3 : false;
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000642 }
643
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000644 bool hasUnalignedBufferAccess() const {
645 return UnalignedBufferAccess;
646 }
647
Tom Stellard64a9d082016-10-14 18:10:39 +0000648 bool hasUnalignedScratchAccess() const {
649 return UnalignedScratchAccess;
650 }
651
Matt Arsenaulte823d922017-02-18 18:29:53 +0000652 bool hasApertureRegs() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000653 return HasApertureRegs;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000654 }
655
Wei Ding205bfdb2017-02-10 02:15:29 +0000656 bool isTrapHandlerEnabled() const {
657 return TrapHandler;
658 }
659
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000660 bool isXNACKEnabled() const {
661 return EnableXNACK;
662 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000663
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000664 bool isCuModeEnabled() const {
665 return EnableCuMode;
666 }
667
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000668 bool hasFlatAddressSpace() const {
669 return FlatAddressSpace;
670 }
671
Matt Arsenaulte4c2e9b2019-06-19 23:54:58 +0000672 bool hasFlatScrRegister() const {
673 return hasFlatAddressSpace();
674 }
675
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000676 bool hasFlatInstOffsets() const {
677 return FlatInstOffsets;
678 }
679
680 bool hasFlatGlobalInsts() const {
681 return FlatGlobalInsts;
682 }
683
684 bool hasFlatScratchInsts() const {
685 return FlatScratchInsts;
686 }
687
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000688 bool hasScalarFlatScratchInsts() const {
689 return ScalarFlatScratchInsts;
690 }
691
692 bool hasFlatSegmentOffsetBug() const {
693 return HasFlatSegmentOffsetBug;
694 }
695
Mark Searlesf0b93f12018-06-04 16:51:59 +0000696 bool hasFlatLgkmVMemCountInOrder() const {
697 return getGeneration() > GFX9;
698 }
699
Matt Arsenaulted6e8f02017-09-01 18:36:06 +0000700 bool hasD16LoadStore() const {
701 return getGeneration() >= GFX9;
702 }
703
Matt Arsenaulte8c03a22019-03-08 20:58:11 +0000704 bool d16PreservesUnusedBits() const {
705 return hasD16LoadStore() && !isSRAMECCEnabled();
706 }
707
Matt Arsenaulte4c2e9b2019-06-19 23:54:58 +0000708 bool hasD16Images() const {
709 return getGeneration() >= VOLCANIC_ISLANDS;
710 }
711
Matt Arsenault3f71c0e2017-11-29 00:55:57 +0000712 /// Return if most LDS instructions have an m0 use that require m0 to be
713 /// iniitalized.
714 bool ldsRequiresM0Init() const {
715 return getGeneration() < GFX9;
716 }
717
Matt Arsenaultc37fe662017-07-20 17:42:47 +0000718 bool hasAddNoCarry() const {
719 return AddNoCarryInsts;
720 }
721
Changpeng Fang44dfa1d2018-01-12 21:12:19 +0000722 bool hasUnpackedD16VMem() const {
723 return HasUnpackedD16VMem;
724 }
725
Tom Stellard2f3f9852017-01-25 01:25:13 +0000726 // Covers VS/PS/CS graphics shaders
Matt Arsenaultceafc552018-05-29 17:42:50 +0000727 bool isMesaGfxShader(const Function &F) const {
728 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
Tom Stellard2f3f9852017-01-25 01:25:13 +0000729 }
730
Matt Arsenault4f6318f2017-11-06 17:04:37 +0000731 bool hasMad64_32() const {
732 return getGeneration() >= SEA_ISLANDS;
733 }
734
Sam Kolton3c4933f2017-06-22 06:26:41 +0000735 bool hasSDWAOmod() const {
736 return HasSDWAOmod;
737 }
738
739 bool hasSDWAScalar() const {
740 return HasSDWAScalar;
741 }
742
743 bool hasSDWASdst() const {
744 return HasSDWASdst;
745 }
746
747 bool hasSDWAMac() const {
748 return HasSDWAMac;
749 }
750
Sam Koltona179d252017-06-27 15:02:23 +0000751 bool hasSDWAOutModsVOPC() const {
752 return HasSDWAOutModsVOPC;
Sam Kolton3c4933f2017-06-22 06:26:41 +0000753 }
754
Matt Arsenault0084adc2018-04-30 19:08:16 +0000755 bool hasDLInsts() const {
756 return HasDLInsts;
757 }
758
Stanislav Mekhanoshin0e858b02019-02-09 00:34:21 +0000759 bool hasDot1Insts() const {
760 return HasDot1Insts;
761 }
762
763 bool hasDot2Insts() const {
764 return HasDot2Insts;
Stanislav Mekhanoshind3757d32019-01-10 03:25:20 +0000765 }
766
Stanislav Mekhanoshinc43e67b2019-06-14 00:33:31 +0000767 bool hasDot5Insts() const {
768 return HasDot5Insts;
769 }
770
771 bool hasDot6Insts() const {
772 return HasDot6Insts;
773 }
774
Konstantin Zhuravlyov108927b2018-11-05 22:44:19 +0000775 bool isSRAMECCEnabled() const {
776 return EnableSRAMECC;
Konstantin Zhuravlyovc2c2eb72018-05-04 20:06:57 +0000777 }
778
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000779 bool hasNoSdstCMPX() const {
780 return HasNoSdstCMPX;
781 }
782
783 bool hasVscnt() const {
784 return HasVscnt;
785 }
786
787 bool hasRegisterBanking() const {
788 return HasRegisterBanking;
789 }
790
791 bool hasVOP3Literal() const {
792 return HasVOP3Literal;
793 }
794
795 bool hasNoDataDepHazard() const {
796 return HasNoDataDepHazard;
797 }
798
799 bool vmemWriteNeedsExpWaitcnt() const {
800 return getGeneration() < SEA_ISLANDS;
801 }
802
Matt Arsenault869fec22017-04-17 19:48:24 +0000803 // Scratch is allocated in 256 dword per wave blocks for the entire
804 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
805 // is 4-byte aligned.
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000806 //
807 // Only 4-byte alignment is really needed to access anything. Transformations
808 // on the pointer value itself may rely on the alignment / known low bits of
809 // the pointer. Set this to something above the minimum to avoid needing
810 // dynamic realignment in common cases.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000811 unsigned getStackAlignment() const {
Matt Arsenaultffb132e2018-03-29 20:22:04 +0000812 return 16;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000813 }
Tom Stellard347ac792015-06-26 21:15:07 +0000814
Craig Topper5656db42014-04-29 07:57:24 +0000815 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000816 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000817 }
818
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000819 bool enableSubRegLiveness() const override {
820 return true;
821 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000822
Tom Stellardc5a154d2018-06-28 23:47:12 +0000823 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
824 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000825
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000826 /// \returns Number of execution units per compute unit supported by the
827 /// subtarget.
828 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000829 return AMDGPU::IsaInfo::getEUsPerCU(this);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000830 }
831
832 /// \returns Maximum number of waves per compute unit supported by the
833 /// subtarget without any kind of limitation.
834 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000835 return AMDGPU::IsaInfo::getMaxWavesPerCU(this);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000836 }
837
838 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000839 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000840 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000841 return AMDGPU::IsaInfo::getMaxWavesPerCU(this, FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000842 }
843
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000844 /// \returns Maximum number of waves per execution unit supported by the
845 /// subtarget without any kind of limitation.
846 unsigned getMaxWavesPerEU() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000847 return AMDGPU::IsaInfo::getMaxWavesPerEU();
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000848 }
849
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000850 /// \returns Number of waves per work group supported by the subtarget and
851 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000852 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +0000853 return AMDGPU::IsaInfo::getWavesPerWorkGroup(this, FlatWorkGroupSize);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000854 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000855
Tom Stellardc5a154d2018-06-28 23:47:12 +0000856 // static wrappers
857 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000858
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000859 // XXX - Why is this here if it isn't in the default pass set?
860 bool enableEarlyIfConversion() const override {
861 return true;
862 }
863
Tom Stellard83f0bce2015-01-29 16:55:25 +0000864 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000865 unsigned NumRegionInstrs) const override;
866
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000867 unsigned getMaxNumUserSGPRs() const {
868 return 16;
869 }
870
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000871 bool hasSMemRealTime() const {
872 return HasSMemRealTime;
873 }
874
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000875 bool hasMovrel() const {
876 return HasMovrel;
877 }
878
879 bool hasVGPRIndexMode() const {
880 return HasVGPRIndexMode;
881 }
882
Marek Olsake22fdb92017-03-21 17:00:32 +0000883 bool useVGPRIndexMode(bool UserEnable) const {
884 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
885 }
886
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000887 bool hasScalarCompareEq64() const {
888 return getGeneration() >= VOLCANIC_ISLANDS;
889 }
890
Matt Arsenault7b647552016-10-28 21:55:15 +0000891 bool hasScalarStores() const {
892 return HasScalarStores;
893 }
894
Dmitry Preobrazhensky6bad04e2018-04-02 16:10:25 +0000895 bool hasScalarAtomics() const {
896 return HasScalarAtomics;
897 }
898
Matt Arsenaulta5840c32019-01-22 18:36:06 +0000899 bool hasLDSFPAtomics() const {
Stanislav Mekhanoshin7895c032019-04-05 18:24:34 +0000900 return GFX8Insts;
Matt Arsenaulta5840c32019-01-22 18:36:06 +0000901 }
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000902
Sam Kolton07dbde22017-01-20 10:01:25 +0000903 bool hasDPP() const {
904 return HasDPP;
905 }
906
Stanislav Mekhanoshin245b5ba2019-06-12 18:02:41 +0000907 bool hasDPP8() const {
908 return HasDPP8;
909 }
910
Ryan Taylor1f334d02018-08-28 15:07:30 +0000911 bool hasR128A16() const {
912 return HasR128A16;
913 }
914
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000915 bool hasNSAEncoding() const {
916 return HasNSAEncoding;
917 }
918
919 bool hasMadF16() const;
920
Tom Stellardde008d32016-01-21 04:28:34 +0000921 bool enableSIScheduler() const {
922 return EnableSIScheduler;
923 }
924
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000925 bool loadStoreOptEnabled() const {
926 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000927 }
928
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000929 bool hasSGPRInitBug() const {
930 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000931 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000932
Tom Stellardb133fbb2016-10-27 23:05:31 +0000933 bool has12DWordStoreHazard() const {
934 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
935 }
936
Neil Henninge85d45a2019-01-10 16:21:08 +0000937 // \returns true if the subtarget supports DWORDX3 load/store instructions.
938 bool hasDwordx3LoadStores() const {
939 return CIInsts;
940 }
941
Matt Arsenaulte823d922017-02-18 18:29:53 +0000942 bool hasSMovFedHazard() const {
Stanislav Mekhanoshin7895c032019-04-05 18:24:34 +0000943 return getGeneration() == AMDGPUSubtarget::GFX9;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000944 }
945
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000946 bool hasReadM0MovRelInterpHazard() const {
Stanislav Mekhanoshin7895c032019-04-05 18:24:34 +0000947 return getGeneration() == AMDGPUSubtarget::GFX9;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000948 }
949
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000950 bool hasReadM0SendMsgHazard() const {
Stanislav Mekhanoshin7895c032019-04-05 18:24:34 +0000951 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS &&
952 getGeneration() <= AMDGPUSubtarget::GFX9;
Matt Arsenaulta41351e2017-11-17 21:35:32 +0000953 }
954
Stanislav Mekhanoshincee607e2019-04-24 17:03:15 +0000955 bool hasVcmpxPermlaneHazard() const {
956 return HasVcmpxPermlaneHazard;
957 }
958
959 bool hasVMEMtoScalarWriteHazard() const {
960 return HasVMEMtoScalarWriteHazard;
961 }
962
963 bool hasSMEMtoVectorWriteHazard() const {
964 return HasSMEMtoVectorWriteHazard;
965 }
966
967 bool hasLDSMisalignedBug() const {
968 return LDSMisalignedBug && !EnableCuMode;
969 }
970
971 bool hasInstFwdPrefetchBug() const {
972 return HasInstFwdPrefetchBug;
973 }
974
975 bool hasVcmpxExecWARHazard() const {
976 return HasVcmpxExecWARHazard;
977 }
978
979 bool hasLdsBranchVmemWARHazard() const {
980 return HasLdsBranchVmemWARHazard;
981 }
982
983 bool hasNSAtoVMEMBug() const {
984 return HasNSAtoVMEMBug;
985 }
986
Tom Stellardc5a154d2018-06-28 23:47:12 +0000987 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
988 /// SGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000989 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
990
Tom Stellardc5a154d2018-06-28 23:47:12 +0000991 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
992 /// VGPRs
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000993 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000994
Matt Arsenaulte823d922017-02-18 18:29:53 +0000995 /// \returns true if the flat_scratch register should be initialized with the
996 /// pointer to the wave's scratch memory rather than a size and offset.
997 bool flatScratchIsPointer() const {
Tom Stellardc5a154d2018-06-28 23:47:12 +0000998 return getGeneration() >= AMDGPUSubtarget::GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000999 }
Matt Arsenault4eae3012016-10-28 20:31:47 +00001000
Tim Renouf832f90f2018-02-26 14:46:43 +00001001 /// \returns true if the machine has merged shaders in which s0-s7 are
1002 /// reserved by the hardware and user SGPRs start at s8
1003 bool hasMergedShaders() const {
1004 return getGeneration() >= GFX9;
1005 }
1006
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001007 /// \returns SGPR allocation granularity supported by the subtarget.
1008 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001009 return AMDGPU::IsaInfo::getSGPRAllocGranule(this);
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +00001010 }
1011
1012 /// \returns SGPR encoding granularity supported by the subtarget.
1013 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001014 return AMDGPU::IsaInfo::getSGPREncodingGranule(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001015 }
1016
1017 /// \returns Total number of SGPRs supported by the subtarget.
1018 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001019 return AMDGPU::IsaInfo::getTotalNumSGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001020 }
1021
1022 /// \returns Addressable number of SGPRs supported by the subtarget.
1023 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001024 return AMDGPU::IsaInfo::getAddressableNumSGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001025 }
1026
1027 /// \returns Minimum number of SGPRs that meets the given number of waves per
1028 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001029 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001030 return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001031 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001032
1033 /// \returns Maximum number of SGPRs that meets the given number of waves per
1034 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001035 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001036 return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001037 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001038
1039 /// \returns Reserved number of SGPRs for given function \p MF.
1040 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
1041
1042 /// \returns Maximum number of SGPRs that meets number of waves per execution
1043 /// unit requirement for function \p MF, or number of SGPRs explicitly
1044 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
1045 ///
1046 /// \returns Value that meets number of waves per execution unit requirement
1047 /// if explicitly requested value cannot be converted to integer, violates
1048 /// subtarget's specifications, or does not meet number of waves per execution
1049 /// unit requirement.
1050 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
1051
1052 /// \returns VGPR allocation granularity supported by the subtarget.
1053 unsigned getVGPRAllocGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001054 return AMDGPU::IsaInfo::getVGPRAllocGranule(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001055 }
1056
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +00001057 /// \returns VGPR encoding granularity supported by the subtarget.
1058 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001059 return AMDGPU::IsaInfo::getVGPREncodingGranule(this);
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +00001060 }
1061
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001062 /// \returns Total number of VGPRs supported by the subtarget.
1063 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001064 return AMDGPU::IsaInfo::getTotalNumVGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001065 }
1066
1067 /// \returns Addressable number of VGPRs supported by the subtarget.
1068 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001069 return AMDGPU::IsaInfo::getAddressableNumVGPRs(this);
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001070 }
1071
1072 /// \returns Minimum number of VGPRs that meets given number of waves per
1073 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001074 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001075 return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001076 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001077
1078 /// \returns Maximum number of VGPRs that meets given number of waves per
1079 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001080 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001081 return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +00001082 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001083
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +00001084 /// \returns Maximum number of VGPRs that meets number of waves per execution
1085 /// unit requirement for function \p MF, or number of VGPRs explicitly
1086 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
1087 ///
1088 /// \returns Value that meets number of waves per execution unit requirement
1089 /// if explicitly requested value cannot be converted to integer, violates
1090 /// subtarget's specifications, or does not meet number of waves per execution
1091 /// unit requirement.
1092 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Stanislav Mekhanoshind4ae4702017-09-19 20:54:38 +00001093
1094 void getPostRAMutations(
1095 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
1096 const override;
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001097
Stanislav Mekhanoshin68a2fef2019-06-13 23:47:36 +00001098 bool isWave32() const {
1099 return WavefrontSize == 32;
1100 }
1101
Stanislav Mekhanoshin52500212019-06-16 17:13:09 +00001102 const TargetRegisterClass *getBoolRC() const {
1103 return getRegisterInfo()->getBoolRC();
1104 }
1105
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001106 /// \returns Maximum number of work groups per compute unit supported by the
1107 /// subtarget and limited by given \p FlatWorkGroupSize.
1108 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
1109 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
1110 }
1111
1112 /// \returns Minimum flat work group size supported by the subtarget.
1113 unsigned getMinFlatWorkGroupSize() const override {
1114 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1115 }
1116
1117 /// \returns Maximum flat work group size supported by the subtarget.
1118 unsigned getMaxFlatWorkGroupSize() const override {
1119 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1120 }
1121
1122 /// \returns Maximum number of waves per execution unit supported by the
1123 /// subtarget and limited by given \p FlatWorkGroupSize.
1124 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const override {
1125 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize);
1126 }
1127
1128 /// \returns Minimum number of waves per execution unit supported by the
1129 /// subtarget.
1130 unsigned getMinWavesPerEU() const override {
1131 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1132 }
Tom Stellard75aadc22012-12-11 21:25:42 +00001133};
1134
Tom Stellardc5a154d2018-06-28 23:47:12 +00001135class R600Subtarget final : public R600GenSubtargetInfo,
Tom Stellard5bfbae52018-07-11 20:59:01 +00001136 public AMDGPUSubtarget {
Tom Stellardc5a154d2018-06-28 23:47:12 +00001137private:
1138 R600InstrInfo InstrInfo;
1139 R600FrameLowering FrameLowering;
1140 bool FMA;
1141 bool CaymanISA;
1142 bool CFALUBug;
Tom Stellardc5a154d2018-06-28 23:47:12 +00001143 bool HasVertexCache;
1144 bool R600ALUInst;
1145 bool FP64;
1146 short TexVTXClauseSize;
1147 Generation Gen;
1148 R600TargetLowering TLInfo;
1149 InstrItineraryData InstrItins;
1150 SelectionDAGTargetInfo TSInfo;
Tom Stellardc5a154d2018-06-28 23:47:12 +00001151
1152public:
1153 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
1154 const TargetMachine &TM);
1155
1156 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
1157
1158 const R600FrameLowering *getFrameLowering() const override {
1159 return &FrameLowering;
1160 }
1161
1162 const R600TargetLowering *getTargetLowering() const override {
1163 return &TLInfo;
1164 }
1165
1166 const R600RegisterInfo *getRegisterInfo() const override {
1167 return &InstrInfo.getRegisterInfo();
1168 }
1169
1170 const InstrItineraryData *getInstrItineraryData() const override {
1171 return &InstrItins;
1172 }
1173
1174 // Nothing implemented, just prevent crashes on use.
1175 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
1176 return &TSInfo;
1177 }
1178
1179 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1180
1181 Generation getGeneration() const {
1182 return Gen;
1183 }
1184
1185 unsigned getStackAlignment() const {
1186 return 4;
1187 }
1188
1189 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1190 StringRef GPU, StringRef FS);
1191
1192 bool hasBFE() const {
1193 return (getGeneration() >= EVERGREEN);
1194 }
1195
1196 bool hasBFI() const {
1197 return (getGeneration() >= EVERGREEN);
1198 }
1199
1200 bool hasBCNT(unsigned Size) const {
1201 if (Size == 32)
1202 return (getGeneration() >= EVERGREEN);
1203
1204 return false;
1205 }
1206
1207 bool hasBORROW() const {
1208 return (getGeneration() >= EVERGREEN);
1209 }
1210
1211 bool hasCARRY() const {
1212 return (getGeneration() >= EVERGREEN);
1213 }
1214
1215 bool hasCaymanISA() const {
1216 return CaymanISA;
1217 }
1218
1219 bool hasFFBL() const {
1220 return (getGeneration() >= EVERGREEN);
1221 }
1222
1223 bool hasFFBH() const {
1224 return (getGeneration() >= EVERGREEN);
1225 }
1226
1227 bool hasFMA() const { return FMA; }
1228
Tom Stellardc5a154d2018-06-28 23:47:12 +00001229 bool hasCFAluBug() const { return CFALUBug; }
1230
1231 bool hasVertexCache() const { return HasVertexCache; }
1232
1233 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1234
Tom Stellardc5a154d2018-06-28 23:47:12 +00001235 bool enableMachineScheduler() const override {
1236 return true;
1237 }
1238
1239 bool enableSubRegLiveness() const override {
1240 return true;
1241 }
Konstantin Zhuravlyov71e43ee2018-09-12 18:50:47 +00001242
1243 /// \returns Maximum number of work groups per compute unit supported by the
1244 /// subtarget and limited by given \p FlatWorkGroupSize.
1245 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
1246 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
1247 }
1248
1249 /// \returns Minimum flat work group size supported by the subtarget.
1250 unsigned getMinFlatWorkGroupSize() const override {
1251 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1252 }
1253
1254 /// \returns Maximum flat work group size supported by the subtarget.
1255 unsigned getMaxFlatWorkGroupSize() const override {
1256 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1257 }
1258
1259 /// \returns Maximum number of waves per execution unit supported by the
1260 /// subtarget and limited by given \p FlatWorkGroupSize.
1261 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const override {
1262 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize);
1263 }
1264
1265 /// \returns Minimum number of waves per execution unit supported by the
1266 /// subtarget.
1267 unsigned getMinWavesPerEU() const override {
1268 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1269 }
Tom Stellardc5a154d2018-06-28 23:47:12 +00001270};
1271
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001272} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +00001273
Eugene Zelenko2bc2f332016-12-09 22:06:55 +00001274#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H