blob: 5f4f20316a6ba8e1e7d7bbda3e097ac88a755291 [file] [log] [blame]
Matt Arsenault0c90e952015-11-06 18:17:45 +00001//=====-- AMDGPUSubtarget.h - Define Subtarget for AMDGPU ------*- C++ -*-====//
Tom Stellard75aadc22012-12-11 21:25:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//==-----------------------------------------------------------------------===//
9//
10/// \file
11/// \brief AMDGPU specific subclass of TargetSubtarget.
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault0c90e952015-11-06 18:17:45 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
Matt Arsenaultf59e5382015-11-06 18:23:00 +000017
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000018#include "AMDGPU.h"
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"
Valery Pykhtinfd4c4102017-03-21 13:15:46 +000025#include "SIMachineFunctionInfo.h"
Tom Stellard347ac792015-06-26 21:15:07 +000026#include "Utils/AMDGPUBaseInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000027#include "llvm/ADT/Triple.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000028#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000029#include "llvm/CodeGen/MachineFunction.h"
Matt Arsenault56684d42016-08-11 17:31:42 +000030#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000031#include "llvm/MC/MCInstrItineraries.h"
32#include "llvm/Support/MathExtras.h"
33#include <cassert>
34#include <cstdint>
35#include <memory>
36#include <utility>
Tom Stellard75aadc22012-12-11 21:25:42 +000037
38#define GET_SUBTARGETINFO_HEADER
39#include "AMDGPUGenSubtargetInfo.inc"
40
Tom Stellard75aadc22012-12-11 21:25:42 +000041namespace llvm {
42
Matt Arsenault43e92fe2016-06-24 06:30:11 +000043class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000044
Tom Stellard75aadc22012-12-11 21:25:42 +000045class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000046public:
47 enum Generation {
48 R600 = 0,
49 R700,
50 EVERGREEN,
51 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000052 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000053 SEA_ISLANDS,
54 VOLCANIC_ISLANDS,
Matt Arsenaulte823d922017-02-18 18:29:53 +000055 GFX9,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000056 };
57
Marek Olsak4d00dd22015-03-09 15:48:09 +000058 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000059 ISAVersion0_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +000060 ISAVersion6_0_0,
61 ISAVersion6_0_1,
Tom Stellard347ac792015-06-26 21:15:07 +000062 ISAVersion7_0_0,
63 ISAVersion7_0_1,
Yaxun Liu94add852016-10-26 16:37:56 +000064 ISAVersion7_0_2,
Wei Ding7c3e5112017-06-10 03:53:19 +000065 ISAVersion7_0_3,
Tom Stellard347ac792015-06-26 21:15:07 +000066 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000067 ISAVersion8_0_1,
Changpeng Fang98317d22016-10-11 16:00:47 +000068 ISAVersion8_0_2,
Yaxun Liu94add852016-10-26 16:37:56 +000069 ISAVersion8_0_3,
70 ISAVersion8_0_4,
71 ISAVersion8_1_0,
Matt Arsenaulte823d922017-02-18 18:29:53 +000072 ISAVersion9_0_0,
Wei Ding7c3e5112017-06-10 03:53:19 +000073 ISAVersion9_0_1,
74 ISAVersion9_0_2,
75 ISAVersion9_0_3
Tom Stellard347ac792015-06-26 21:15:07 +000076 };
77
Wei Ding205bfdb2017-02-10 02:15:29 +000078 enum TrapHandlerAbi {
79 TrapHandlerAbiNone = 0,
80 TrapHandlerAbiHsa = 1
81 };
82
Wei Dingf2cce022017-02-22 23:22:19 +000083 enum TrapID {
84 TrapIDHardwareReserved = 0,
85 TrapIDHSADebugTrap = 1,
86 TrapIDLLVMTrap = 2,
87 TrapIDLLVMDebugTrap = 3,
88 TrapIDDebugBreakpoint = 7,
89 TrapIDDebugReserved8 = 8,
90 TrapIDDebugReservedFE = 0xfe,
91 TrapIDDebugReservedFF = 0xff
Wei Ding205bfdb2017-02-10 02:15:29 +000092 };
93
94 enum TrapRegValues {
Wei Dingf2cce022017-02-22 23:22:19 +000095 LLVMTrapHandlerRegValue = 1
Wei Ding205bfdb2017-02-10 02:15:29 +000096 };
97
Matt Arsenault43e92fe2016-06-24 06:30:11 +000098protected:
99 // Basic subtarget description.
100 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000101 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000102 unsigned IsaVersion;
103 unsigned WavefrontSize;
104 int LocalMemorySize;
105 int LDSBankCount;
106 unsigned MaxPrivateElementSize;
107
108 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +0000109 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000110 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000111
112 // Dynamially set bits that enable features.
113 bool FP32Denormals;
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000114 bool FP64FP16Denormals;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000115 bool FPExceptions;
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000116 bool DX10Clamp;
Changpeng Fangb41574a2015-12-22 20:55:23 +0000117 bool FlatForGlobal;
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000118 bool AutoWaitcntBeforeBarrier;
Tom Stellard64a9d082016-10-14 18:10:39 +0000119 bool UnalignedScratchAccess;
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000120 bool UnalignedBufferAccess;
Matt Arsenaulte823d922017-02-18 18:29:53 +0000121 bool HasApertureRegs;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000122 bool EnableXNACK;
Wei Ding205bfdb2017-02-10 02:15:29 +0000123 bool TrapHandler;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000124 bool DebuggerInsertNops;
125 bool DebuggerReserveRegs;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000126 bool DebuggerEmitPrologue;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000127
128 // Used as options.
129 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000130 bool EnablePromoteAlloca;
Matt Arsenault41033282014-10-10 22:01:59 +0000131 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +0000132 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000133 bool EnableSIScheduler;
134 bool DumpCode;
135
136 // Subtarget statically properties set by tablegen
137 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000138 bool IsGCN;
139 bool GCN1Encoding;
140 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +0000141 bool CIInsts;
Matt Arsenault2021f082017-02-18 19:12:26 +0000142 bool GFX9Insts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000143 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000144 bool HasSMemRealTime;
145 bool Has16BitInsts;
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000146 bool HasVOP3PInsts;
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000147 bool HasMovrel;
148 bool HasVGPRIndexMode;
Matt Arsenault7b647552016-10-28 21:55:15 +0000149 bool HasScalarStores;
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000150 bool HasInv2PiInlineImm;
Sam Kolton07dbde22017-01-20 10:01:25 +0000151 bool HasSDWA;
152 bool HasDPP;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000153 bool FlatAddressSpace;
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000154 bool FlatInstOffsets;
155 bool FlatGlobalInsts;
156 bool FlatScratchInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000157 bool R600ALUInst;
158 bool CaymanISA;
159 bool CFALUBug;
160 bool HasVertexCache;
161 short TexVTXClauseSize;
Alexander Timofeev18009562016-12-08 17:28:47 +0000162 bool ScalarizeGlobal;
Tom Stellard75aadc22012-12-11 21:25:42 +0000163
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000164 // Dummy feature to use for assembler in tablegen.
165 bool FeatureDisable;
166
Tom Stellard75aadc22012-12-11 21:25:42 +0000167 InstrItineraryData InstrItins;
Matt Arsenault56684d42016-08-11 17:31:42 +0000168 SelectionDAGTargetInfo TSInfo;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000169 AMDGPUAS AS;
Tom Stellard75aadc22012-12-11 21:25:42 +0000170
171public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000172 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
173 const TargetMachine &TM);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000174 ~AMDGPUSubtarget() override;
175
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000176 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
177 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000178
Matt Arsenaultf9245b72016-07-22 17:01:25 +0000179 const AMDGPUInstrInfo *getInstrInfo() const override = 0;
180 const AMDGPUFrameLowering *getFrameLowering() const override = 0;
181 const AMDGPUTargetLowering *getTargetLowering() const override = 0;
182 const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
Tom Stellard000c5af2016-04-14 19:09:28 +0000183
Eric Christopherd9134482014-08-04 21:25:23 +0000184 const InstrItineraryData *getInstrItineraryData() const override {
185 return &InstrItins;
186 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000187
Matt Arsenault56684d42016-08-11 17:31:42 +0000188 // Nothing implemented, just prevent crashes on use.
189 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
190 return &TSInfo;
191 }
192
Craig Topperee7b0f32014-04-30 05:53:27 +0000193 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000194
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000195 bool isAmdHsaOS() const {
196 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000197 }
198
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000199 bool isMesa3DOS() const {
200 return TargetTriple.getOS() == Triple::Mesa3D;
201 }
202
Tom Stellarde88bbc32016-09-23 01:33:26 +0000203 bool isOpenCLEnv() const {
Yaxun Liua618acf2017-06-01 21:31:53 +0000204 return TargetTriple.getEnvironment() == Triple::OpenCL ||
205 TargetTriple.getEnvironmentName() == "amdgizcl";
Tom Stellarde88bbc32016-09-23 01:33:26 +0000206 }
207
Matt Arsenaultd782d052014-06-27 17:57:00 +0000208 Generation getGeneration() const {
209 return Gen;
210 }
211
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000212 unsigned getWavefrontSize() const {
213 return WavefrontSize;
214 }
215
216 int getLocalMemorySize() const {
217 return LocalMemorySize;
218 }
219
220 int getLDSBankCount() const {
221 return LDSBankCount;
222 }
223
224 unsigned getMaxPrivateElementSize() const {
225 return MaxPrivateElementSize;
226 }
227
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000228 AMDGPUAS getAMDGPUAS() const {
229 return AS;
230 }
231
Konstantin Zhuravlyovd971a112016-11-01 17:49:33 +0000232 bool has16BitInsts() const {
233 return Has16BitInsts;
234 }
235
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000236 bool hasVOP3PInsts() const {
237 return HasVOP3PInsts;
238 }
239
Matt Arsenaultd782d052014-06-27 17:57:00 +0000240 bool hasHWFP64() const {
241 return FP64;
242 }
243
Matt Arsenaultb035a572015-01-29 19:34:25 +0000244 bool hasFastFMAF32() const {
245 return FastFMAF32;
246 }
247
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000248 bool hasHalfRate64Ops() const {
249 return HalfRate64Ops;
250 }
251
Matt Arsenault88701812016-06-09 23:42:48 +0000252 bool hasAddr64() const {
253 return (getGeneration() < VOLCANIC_ISLANDS);
254 }
255
Matt Arsenaultfae02982014-03-17 18:58:11 +0000256 bool hasBFE() const {
257 return (getGeneration() >= EVERGREEN);
258 }
259
Matt Arsenault6e439652014-06-10 19:00:20 +0000260 bool hasBFI() const {
261 return (getGeneration() >= EVERGREEN);
262 }
263
Matt Arsenaultfae02982014-03-17 18:58:11 +0000264 bool hasBFM() const {
265 return hasBFE();
266 }
267
Matt Arsenault60425062014-06-10 19:18:28 +0000268 bool hasBCNT(unsigned Size) const {
269 if (Size == 32)
270 return (getGeneration() >= EVERGREEN);
271
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000272 if (Size == 64)
273 return (getGeneration() >= SOUTHERN_ISLANDS);
274
275 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000276 }
277
Tom Stellard50122a52014-04-07 19:45:41 +0000278 bool hasMulU24() const {
279 return (getGeneration() >= EVERGREEN);
280 }
281
282 bool hasMulI24() const {
283 return (getGeneration() >= SOUTHERN_ISLANDS ||
284 hasCaymanISA());
285 }
286
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000287 bool hasFFBL() const {
288 return (getGeneration() >= EVERGREEN);
289 }
290
291 bool hasFFBH() const {
292 return (getGeneration() >= EVERGREEN);
293 }
294
Matt Arsenault10268f92017-02-27 22:40:39 +0000295 bool hasMed3_16() const {
296 return getGeneration() >= GFX9;
297 }
298
Matt Arsenaultee324ff2017-05-17 19:25:06 +0000299 bool hasMin3Max3_16() const {
300 return getGeneration() >= GFX9;
301 }
302
Jan Vesely808fff52015-04-30 17:15:56 +0000303 bool hasCARRY() const {
304 return (getGeneration() >= EVERGREEN);
305 }
306
307 bool hasBORROW() const {
308 return (getGeneration() >= EVERGREEN);
309 }
310
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000311 bool hasCaymanISA() const {
312 return CaymanISA;
313 }
314
Wei Ding205bfdb2017-02-10 02:15:29 +0000315 TrapHandlerAbi getTrapHandlerAbi() const {
316 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
317 }
318
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000319 bool isPromoteAllocaEnabled() const {
320 return EnablePromoteAlloca;
321 }
322
Matt Arsenault706f9302015-07-06 16:01:58 +0000323 bool unsafeDSOffsetFoldingEnabled() const {
324 return EnableUnsafeDSOffsetFolding;
325 }
326
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000327 bool dumpCode() const {
328 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000329 }
330
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000331 /// Return the amount of LDS that can be used that will not restrict the
332 /// occupancy lower than WaveCount.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000333 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
334 const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000335
336 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
337 /// the given LDS memory size is the only constraint.
Stanislav Mekhanoshin2b913b12017-02-01 22:59:50 +0000338 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000339
Valery Pykhtinfd4c4102017-03-21 13:15:46 +0000340 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
341 const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
342 return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
343 }
344
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000345 bool hasFP16Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000346 return FP64FP16Denormals;
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +0000347 }
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000348
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000349 bool hasFP32Denormals() const {
350 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000351 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000352
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000353 bool hasFP64Denormals() const {
Matt Arsenaulta6867fd2017-01-23 22:31:03 +0000354 return FP64FP16Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000355 }
356
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000357 bool hasFPExceptions() const {
358 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000359 }
360
Matt Arsenault2fdf2a12017-02-21 23:35:48 +0000361 bool enableDX10Clamp() const {
362 return DX10Clamp;
363 }
364
365 bool enableIEEEBit(const MachineFunction &MF) const {
366 return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
367 }
368
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000369 bool useFlatForGlobal() const {
370 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000371 }
372
Konstantin Zhuravlyovbe6c0ca2017-06-02 17:40:26 +0000373 bool hasAutoWaitcntBeforeBarrier() const {
374 return AutoWaitcntBeforeBarrier;
375 }
376
Matt Arsenault7f681ac2016-07-01 23:03:44 +0000377 bool hasUnalignedBufferAccess() const {
378 return UnalignedBufferAccess;
379 }
380
Tom Stellard64a9d082016-10-14 18:10:39 +0000381 bool hasUnalignedScratchAccess() const {
382 return UnalignedScratchAccess;
383 }
384
Matt Arsenaulte823d922017-02-18 18:29:53 +0000385 bool hasApertureRegs() const {
386 return HasApertureRegs;
387 }
388
Wei Ding205bfdb2017-02-10 02:15:29 +0000389 bool isTrapHandlerEnabled() const {
390 return TrapHandler;
391 }
392
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000393 bool isXNACKEnabled() const {
394 return EnableXNACK;
395 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000396
Matt Arsenaultb6491cc2017-01-31 01:20:54 +0000397 bool hasFlatAddressSpace() const {
398 return FlatAddressSpace;
399 }
400
Matt Arsenaultacdc7652017-05-10 21:19:05 +0000401 bool hasFlatInstOffsets() const {
402 return FlatInstOffsets;
403 }
404
405 bool hasFlatGlobalInsts() const {
406 return FlatGlobalInsts;
407 }
408
409 bool hasFlatScratchInsts() const {
410 return FlatScratchInsts;
411 }
412
Tom Stellard2f3f9852017-01-25 01:25:13 +0000413 bool isMesaKernel(const MachineFunction &MF) const {
414 return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
415 }
416
417 // Covers VS/PS/CS graphics shaders
418 bool isMesaGfxShader(const MachineFunction &MF) const {
419 return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
420 }
421
422 bool isAmdCodeObjectV2(const MachineFunction &MF) const {
423 return isAmdHsaOS() || isMesaKernel(MF);
Tom Stellard0b76fc4c2016-09-16 21:34:26 +0000424 }
425
Matt Arsenaultda7a6562017-02-01 00:42:40 +0000426 bool hasFminFmaxLegacy() const {
427 return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
428 }
429
Stanislav Mekhanoshin53a21292017-05-23 19:54:48 +0000430 bool hasSDWA() const {
431 return HasSDWA;
432 }
433
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000434 /// \brief Returns the offset in bytes from the start of the input buffer
435 /// of the first explicit kernel argument.
Tom Stellard2f3f9852017-01-25 01:25:13 +0000436 unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
437 return isAmdCodeObjectV2(MF) ? 0 : 36;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000438 }
439
Tom Stellardb2869eb2016-09-09 19:28:00 +0000440 unsigned getAlignmentForImplicitArgPtr() const {
441 return isAmdHsaOS() ? 8 : 4;
442 }
443
Tom Stellard2f3f9852017-01-25 01:25:13 +0000444 unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
445 if (isMesaKernel(MF))
Tom Stellarde88bbc32016-09-23 01:33:26 +0000446 return 16;
447 if (isAmdHsaOS() && isOpenCLEnv())
448 return 32;
449 return 0;
450 }
451
Matt Arsenault869fec22017-04-17 19:48:24 +0000452 // Scratch is allocated in 256 dword per wave blocks for the entire
453 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
454 // is 4-byte aligned.
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000455 unsigned getStackAlignment() const {
Matt Arsenault869fec22017-04-17 19:48:24 +0000456 return 4;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000457 }
Tom Stellard347ac792015-06-26 21:15:07 +0000458
Craig Topper5656db42014-04-29 07:57:24 +0000459 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000460 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000461 }
462
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000463 bool enableSubRegLiveness() const override {
464 return true;
465 }
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000466
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000467 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
468 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
469
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000470 /// \returns Number of execution units per compute unit supported by the
471 /// subtarget.
472 unsigned getEUsPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000473 return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000474 }
475
476 /// \returns Maximum number of work groups per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000477 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000478 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000479 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
480 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000481 }
482
483 /// \returns Maximum number of waves per compute unit supported by the
484 /// subtarget without any kind of limitation.
485 unsigned getMaxWavesPerCU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000486 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000487 }
488
489 /// \returns Maximum number of waves per compute unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000490 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000491 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000492 return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
493 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000494 }
495
496 /// \returns Minimum number of waves per execution unit supported by the
497 /// subtarget.
498 unsigned getMinWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000499 return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000500 }
501
502 /// \returns Maximum number of waves per execution unit supported by the
503 /// subtarget without any kind of limitation.
504 unsigned getMaxWavesPerEU() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000505 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000506 }
507
508 /// \returns Maximum number of waves per execution unit supported by the
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000509 /// subtarget and limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000510 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000511 return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
512 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000513 }
514
515 /// \returns Minimum flat work group size supported by the subtarget.
516 unsigned getMinFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000517 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000518 }
519
520 /// \returns Maximum flat work group size supported by the subtarget.
521 unsigned getMaxFlatWorkGroupSize() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000522 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000523 }
524
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000525 /// \returns Number of waves per work group supported by the subtarget and
526 /// limited by given \p FlatWorkGroupSize.
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000527 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000528 return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
529 FlatWorkGroupSize);
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000530 }
531
532 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
533 /// for function \p F, or minimum/maximum flat work group sizes explicitly
534 /// requested using "amdgpu-flat-work-group-size" attribute attached to
535 /// function \p F.
536 ///
537 /// \returns Subtarget's default values if explicitly requested values cannot
538 /// be converted to integer, or violate subtarget's specifications.
539 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
540
541 /// \returns Subtarget's default pair of minimum/maximum number of waves per
542 /// execution unit for function \p F, or minimum/maximum number of waves per
543 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
544 /// attached to function \p F.
545 ///
546 /// \returns Subtarget's default values if explicitly requested values cannot
547 /// be converted to integer, violate subtarget's specifications, or are not
548 /// compatible with minimum/maximum number of waves limited by flat work group
549 /// size, register usage, and/or lds usage.
550 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
Stanislav Mekhanoshinc90347d2017-04-12 20:48:56 +0000551
552 /// Creates value range metadata on an workitemid.* inrinsic call or load.
553 bool makeLIDRangeMetadata(Instruction *I) const;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000554};
555
556class R600Subtarget final : public AMDGPUSubtarget {
557private:
558 R600InstrInfo InstrInfo;
559 R600FrameLowering FrameLowering;
560 R600TargetLowering TLInfo;
561
562public:
563 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
564 const TargetMachine &TM);
565
566 const R600InstrInfo *getInstrInfo() const override {
567 return &InstrInfo;
568 }
569
570 const R600FrameLowering *getFrameLowering() const override {
571 return &FrameLowering;
572 }
573
574 const R600TargetLowering *getTargetLowering() const override {
575 return &TLInfo;
576 }
577
578 const R600RegisterInfo *getRegisterInfo() const override {
579 return &InstrInfo.getRegisterInfo();
580 }
581
582 bool hasCFAluBug() const {
583 return CFALUBug;
584 }
585
586 bool hasVertexCache() const {
587 return HasVertexCache;
588 }
589
590 short getTexVTXClauseSize() const {
591 return TexVTXClauseSize;
592 }
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000593};
594
595class SISubtarget final : public AMDGPUSubtarget {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000596private:
597 SIInstrInfo InstrInfo;
598 SIFrameLowering FrameLowering;
599 SITargetLowering TLInfo;
600 std::unique_ptr<GISelAccessor> GISel;
601
602public:
603 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
604 const TargetMachine &TM);
605
606 const SIInstrInfo *getInstrInfo() const override {
607 return &InstrInfo;
608 }
609
610 const SIFrameLowering *getFrameLowering() const override {
611 return &FrameLowering;
612 }
613
614 const SITargetLowering *getTargetLowering() const override {
615 return &TLInfo;
616 }
617
618 const CallLowering *getCallLowering() const override {
619 assert(GISel && "Access to GlobalISel APIs not set");
620 return GISel->getCallLowering();
621 }
622
Tom Stellardca166212017-01-30 21:56:46 +0000623 const InstructionSelector *getInstructionSelector() const override {
624 assert(GISel && "Access to GlobalISel APIs not set");
625 return GISel->getInstructionSelector();
626 }
627
628 const LegalizerInfo *getLegalizerInfo() const override {
629 assert(GISel && "Access to GlobalISel APIs not set");
630 return GISel->getLegalizerInfo();
631 }
632
633 const RegisterBankInfo *getRegBankInfo() const override {
634 assert(GISel && "Access to GlobalISel APIs not set");
635 return GISel->getRegBankInfo();
636 }
637
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000638 const SIRegisterInfo *getRegisterInfo() const override {
639 return &InstrInfo.getRegisterInfo();
640 }
641
642 void setGISelAccessor(GISelAccessor &GISel) {
643 this->GISel.reset(&GISel);
644 }
645
Matt Arsenault9f5e0ef2017-01-25 04:25:02 +0000646 // XXX - Why is this here if it isn't in the default pass set?
647 bool enableEarlyIfConversion() const override {
648 return true;
649 }
650
Tom Stellard83f0bce2015-01-29 16:55:25 +0000651 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000652 unsigned NumRegionInstrs) const override;
653
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000654 bool isVGPRSpillingEnabled(const Function& F) const;
655
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000656 unsigned getMaxNumUserSGPRs() const {
657 return 16;
658 }
659
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000660 bool hasSMemRealTime() const {
661 return HasSMemRealTime;
662 }
663
Matt Arsenaultcc88ce32016-10-12 18:00:51 +0000664 bool hasMovrel() const {
665 return HasMovrel;
666 }
667
668 bool hasVGPRIndexMode() const {
669 return HasVGPRIndexMode;
670 }
671
Marek Olsake22fdb92017-03-21 17:00:32 +0000672 bool useVGPRIndexMode(bool UserEnable) const {
673 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
674 }
675
Matt Arsenault7b1dc2c2016-09-17 02:02:19 +0000676 bool hasScalarCompareEq64() const {
677 return getGeneration() >= VOLCANIC_ISLANDS;
678 }
679
Matt Arsenault7b647552016-10-28 21:55:15 +0000680 bool hasScalarStores() const {
681 return HasScalarStores;
682 }
683
Matt Arsenaultc88ba362016-10-29 04:05:06 +0000684 bool hasInv2PiInlineImm() const {
685 return HasInv2PiInlineImm;
686 }
687
Sam Kolton07dbde22017-01-20 10:01:25 +0000688 bool hasDPP() const {
689 return HasDPP;
690 }
691
Tom Stellardde008d32016-01-21 04:28:34 +0000692 bool enableSIScheduler() const {
693 return EnableSIScheduler;
694 }
695
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000696 bool debuggerSupported() const {
697 return debuggerInsertNops() && debuggerReserveRegs() &&
698 debuggerEmitPrologue();
699 }
700
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000701 bool debuggerInsertNops() const {
702 return DebuggerInsertNops;
703 }
704
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000705 bool debuggerReserveRegs() const {
706 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000707 }
708
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +0000709 bool debuggerEmitPrologue() const {
710 return DebuggerEmitPrologue;
711 }
712
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000713 bool loadStoreOptEnabled() const {
714 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000715 }
716
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000717 bool hasSGPRInitBug() const {
718 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000719 }
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000720
Tom Stellardb133fbb2016-10-27 23:05:31 +0000721 bool has12DWordStoreHazard() const {
722 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
723 }
724
Matt Arsenaulte823d922017-02-18 18:29:53 +0000725 bool hasSMovFedHazard() const {
726 return getGeneration() >= AMDGPUSubtarget::GFX9;
727 }
728
729 bool hasReadM0Hazard() const {
730 return getGeneration() >= AMDGPUSubtarget::GFX9;
731 }
732
Tom Stellard2f3f9852017-01-25 01:25:13 +0000733 unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
Tom Stellarde88bbc32016-09-23 01:33:26 +0000734
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000735 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
736 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
737
738 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
739 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000740
Matt Arsenaulte823d922017-02-18 18:29:53 +0000741 /// \returns true if the flat_scratch register should be initialized with the
742 /// pointer to the wave's scratch memory rather than a size and offset.
743 bool flatScratchIsPointer() const {
744 return getGeneration() >= GFX9;
Konstantin Zhuravlyovd7bdf242016-09-30 16:50:36 +0000745 }
Matt Arsenault4eae3012016-10-28 20:31:47 +0000746
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000747 /// \returns SGPR allocation granularity supported by the subtarget.
748 unsigned getSGPRAllocGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000749 return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000750 }
751
752 /// \returns SGPR encoding granularity supported by the subtarget.
753 unsigned getSGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000754 return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000755 }
756
757 /// \returns Total number of SGPRs supported by the subtarget.
758 unsigned getTotalNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000759 return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000760 }
761
762 /// \returns Addressable number of SGPRs supported by the subtarget.
763 unsigned getAddressableNumSGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000764 return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000765 }
766
767 /// \returns Minimum number of SGPRs that meets the given number of waves per
768 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000769 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
770 return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
771 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000772
773 /// \returns Maximum number of SGPRs that meets the given number of waves per
774 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000775 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
776 return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
777 Addressable);
778 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000779
780 /// \returns Reserved number of SGPRs for given function \p MF.
781 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
782
783 /// \returns Maximum number of SGPRs that meets number of waves per execution
784 /// unit requirement for function \p MF, or number of SGPRs explicitly
785 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
786 ///
787 /// \returns Value that meets number of waves per execution unit requirement
788 /// if explicitly requested value cannot be converted to integer, violates
789 /// subtarget's specifications, or does not meet number of waves per execution
790 /// unit requirement.
791 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
792
793 /// \returns VGPR allocation granularity supported by the subtarget.
794 unsigned getVGPRAllocGranule() const {
Mandeep Singh Grang5e1697e2017-06-06 05:08:36 +0000795 return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000796 }
797
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000798 /// \returns VGPR encoding granularity supported by the subtarget.
799 unsigned getVGPREncodingGranule() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000800 return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
Konstantin Zhuravlyove22fbcb2017-02-08 13:18:40 +0000801 }
802
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000803 /// \returns Total number of VGPRs supported by the subtarget.
804 unsigned getTotalNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000805 return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000806 }
807
808 /// \returns Addressable number of VGPRs supported by the subtarget.
809 unsigned getAddressableNumVGPRs() const {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000810 return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000811 }
812
813 /// \returns Minimum number of VGPRs that meets given number of waves per
814 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000815 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
816 return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
817 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000818
819 /// \returns Maximum number of VGPRs that meets given number of waves per
820 /// execution unit requirement supported by the subtarget.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000821 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
822 return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
823 }
Konstantin Zhuravlyove03b1d72017-02-08 13:02:33 +0000824
825 /// \returns Reserved number of VGPRs for given function \p MF.
826 unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
827 return debuggerReserveRegs() ? 4 : 0;
828 }
829
830 /// \returns Maximum number of VGPRs that meets number of waves per execution
831 /// unit requirement for function \p MF, or number of VGPRs explicitly
832 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
833 ///
834 /// \returns Value that meets number of waves per execution unit requirement
835 /// if explicitly requested value cannot be converted to integer, violates
836 /// subtarget's specifications, or does not meet number of waves per execution
837 /// unit requirement.
838 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000839};
840
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000841} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000842
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000843#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H