blob: 3c1bb5c07f0d1782d3d0a78a2cf69d578246d3b3 [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 "R600InstrInfo.h"
20#include "R600ISelLowering.h"
21#include "R600FrameLowering.h"
22#include "SIInstrInfo.h"
23#include "SIISelLowering.h"
24#include "SIFrameLowering.h"
Tom Stellard347ac792015-06-26 21:15:07 +000025#include "Utils/AMDGPUBaseInfo.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000026#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000027#include "llvm/Target/TargetSubtargetInfo.h"
28
29#define GET_SUBTARGETINFO_HEADER
30#include "AMDGPUGenSubtargetInfo.inc"
31
Tom Stellard75aadc22012-12-11 21:25:42 +000032namespace llvm {
33
Tom Stellarde99fb652015-01-20 19:33:04 +000034class SIMachineFunctionInfo;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000035class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000036
Tom Stellard75aadc22012-12-11 21:25:42 +000037class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000038public:
39 enum Generation {
40 R600 = 0,
41 R700,
42 EVERGREEN,
43 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000044 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000045 SEA_ISLANDS,
46 VOLCANIC_ISLANDS,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000047 };
48
Marek Olsak4d00dd22015-03-09 15:48:09 +000049 enum {
Tom Stellard347ac792015-06-26 21:15:07 +000050 ISAVersion0_0_0,
51 ISAVersion7_0_0,
52 ISAVersion7_0_1,
53 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000054 ISAVersion8_0_1,
55 ISAVersion8_0_3
Tom Stellard347ac792015-06-26 21:15:07 +000056 };
57
Matt Arsenault43e92fe2016-06-24 06:30:11 +000058protected:
59 // Basic subtarget description.
60 Triple TargetTriple;
Matt Arsenaultd782d052014-06-27 17:57:00 +000061 Generation Gen;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000062 unsigned IsaVersion;
63 unsigned WavefrontSize;
64 int LocalMemorySize;
65 int LDSBankCount;
66 unsigned MaxPrivateElementSize;
67
68 // Possibly statically set by tablegen, but may want to be overridden.
Matt Arsenaultb035a572015-01-29 19:34:25 +000069 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +000070 bool HalfRate64Ops;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000071
72 // Dynamially set bits that enable features.
73 bool FP32Denormals;
74 bool FP64Denormals;
75 bool FPExceptions;
Changpeng Fangb41574a2015-12-22 20:55:23 +000076 bool FlatForGlobal;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000077 bool EnableXNACK;
78 bool DebuggerInsertNops;
79 bool DebuggerReserveRegs;
80
81 // Used as options.
82 bool EnableVGPRSpilling;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000083 bool EnablePromoteAlloca;
Tom Stellard783893a2013-11-18 19:43:33 +000084 bool EnableIfCvt;
Matt Arsenault41033282014-10-10 22:01:59 +000085 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +000086 bool EnableUnsafeDSOffsetFolding;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000087 bool EnableSIScheduler;
88 bool DumpCode;
89
90 // Subtarget statically properties set by tablegen
91 bool FP64;
Tom Stellardd7e6f132015-04-08 01:09:26 +000092 bool IsGCN;
93 bool GCN1Encoding;
94 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +000095 bool CIInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000096 bool SGPRInitBug;
Matt Arsenault9d82ee72016-02-27 08:53:55 +000097 bool HasSMemRealTime;
98 bool Has16BitInsts;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000099 bool FlatAddressSpace;
100 bool R600ALUInst;
101 bool CaymanISA;
102 bool CFALUBug;
103 bool HasVertexCache;
104 short TexVTXClauseSize;
Tom Stellard75aadc22012-12-11 21:25:42 +0000105
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000106 // Dummy feature to use for assembler in tablegen.
107 bool FeatureDisable;
108
Tom Stellard75aadc22012-12-11 21:25:42 +0000109 InstrItineraryData InstrItins;
110
111public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000112 AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
113 const TargetMachine &TM);
114 virtual ~AMDGPUSubtarget();
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000115 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
116 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000117
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000118 const AMDGPUInstrInfo *getInstrInfo() const override;
119 const AMDGPUFrameLowering *getFrameLowering() const override;
120 const AMDGPUTargetLowering *getTargetLowering() const override;
121 const AMDGPURegisterInfo *getRegisterInfo() const override;
Tom Stellard000c5af2016-04-14 19:09:28 +0000122
Eric Christopherd9134482014-08-04 21:25:23 +0000123 const InstrItineraryData *getInstrItineraryData() const override {
124 return &InstrItins;
125 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000126
Craig Topperee7b0f32014-04-30 05:53:27 +0000127 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000128
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000129 bool isAmdHsaOS() const {
130 return TargetTriple.getOS() == Triple::AMDHSA;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000131 }
132
133 Generation getGeneration() const {
134 return Gen;
135 }
136
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000137 unsigned getWavefrontSize() const {
138 return WavefrontSize;
139 }
140
141 int getLocalMemorySize() const {
142 return LocalMemorySize;
143 }
144
145 int getLDSBankCount() const {
146 return LDSBankCount;
147 }
148
149 unsigned getMaxPrivateElementSize() const {
150 return MaxPrivateElementSize;
151 }
152
Matt Arsenaultd782d052014-06-27 17:57:00 +0000153 bool hasHWFP64() const {
154 return FP64;
155 }
156
Matt Arsenaultb035a572015-01-29 19:34:25 +0000157 bool hasFastFMAF32() const {
158 return FastFMAF32;
159 }
160
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000161 bool hasHalfRate64Ops() const {
162 return HalfRate64Ops;
163 }
164
Matt Arsenault88701812016-06-09 23:42:48 +0000165 bool hasAddr64() const {
166 return (getGeneration() < VOLCANIC_ISLANDS);
167 }
168
Matt Arsenaultfae02982014-03-17 18:58:11 +0000169 bool hasBFE() const {
170 return (getGeneration() >= EVERGREEN);
171 }
172
Matt Arsenault6e439652014-06-10 19:00:20 +0000173 bool hasBFI() const {
174 return (getGeneration() >= EVERGREEN);
175 }
176
Matt Arsenaultfae02982014-03-17 18:58:11 +0000177 bool hasBFM() const {
178 return hasBFE();
179 }
180
Matt Arsenault60425062014-06-10 19:18:28 +0000181 bool hasBCNT(unsigned Size) const {
182 if (Size == 32)
183 return (getGeneration() >= EVERGREEN);
184
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000185 if (Size == 64)
186 return (getGeneration() >= SOUTHERN_ISLANDS);
187
188 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000189 }
190
Tom Stellard50122a52014-04-07 19:45:41 +0000191 bool hasMulU24() const {
192 return (getGeneration() >= EVERGREEN);
193 }
194
195 bool hasMulI24() const {
196 return (getGeneration() >= SOUTHERN_ISLANDS ||
197 hasCaymanISA());
198 }
199
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000200 bool hasFFBL() const {
201 return (getGeneration() >= EVERGREEN);
202 }
203
204 bool hasFFBH() const {
205 return (getGeneration() >= EVERGREEN);
206 }
207
Jan Vesely808fff52015-04-30 17:15:56 +0000208 bool hasCARRY() const {
209 return (getGeneration() >= EVERGREEN);
210 }
211
212 bool hasBORROW() const {
213 return (getGeneration() >= EVERGREEN);
214 }
215
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000216 bool hasCaymanISA() const {
217 return CaymanISA;
218 }
219
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000220 bool isPromoteAllocaEnabled() const {
221 return EnablePromoteAlloca;
222 }
223
Matt Arsenaultd782d052014-06-27 17:57:00 +0000224 bool isIfCvtEnabled() const {
225 return EnableIfCvt;
226 }
227
Matt Arsenault706f9302015-07-06 16:01:58 +0000228 bool unsafeDSOffsetFoldingEnabled() const {
229 return EnableUnsafeDSOffsetFolding;
230 }
231
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000232 bool dumpCode() const {
233 return DumpCode;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000234 }
235
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000236 /// Return the amount of LDS that can be used that will not restrict the
237 /// occupancy lower than WaveCount.
238 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount) const;
239
240 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
241 /// the given LDS memory size is the only constraint.
242 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes) const;
243
244
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000245 bool hasFP32Denormals() const {
246 return FP32Denormals;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000247 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000248
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000249 bool hasFP64Denormals() const {
250 return FP64Denormals;
Matt Arsenault24ee0782016-02-12 02:40:47 +0000251 }
252
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000253 bool hasFPExceptions() const {
254 return FPExceptions;
Marek Olsak4d00dd22015-03-09 15:48:09 +0000255 }
256
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000257 bool useFlatForGlobal() const {
258 return FlatForGlobal;
Tom Stellardec87f842015-05-25 16:15:54 +0000259 }
260
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000261 bool isXNACKEnabled() const {
262 return EnableXNACK;
263 }
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000264
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000265 unsigned getMaxWavesPerCU() const {
266 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
267 return 10;
268
269 // FIXME: Not sure what this is for other subtagets.
270 return 8;
271 }
272
273 /// \brief Returns the offset in bytes from the start of the input buffer
274 /// of the first explicit kernel argument.
275 unsigned getExplicitKernelArgOffset() const {
276 return isAmdHsaOS() ? 0 : 36;
277 }
278
279 unsigned getStackAlignment() const {
280 // Scratch is allocated in 256 dword per wave blocks.
281 return 4 * 256 / getWavefrontSize();
282 }
Tom Stellard347ac792015-06-26 21:15:07 +0000283
Craig Topper5656db42014-04-29 07:57:24 +0000284 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000285 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000286 }
287
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000288 bool enableSubRegLiveness() const override {
289 return true;
290 }
291};
292
293class R600Subtarget final : public AMDGPUSubtarget {
294private:
295 R600InstrInfo InstrInfo;
296 R600FrameLowering FrameLowering;
297 R600TargetLowering TLInfo;
298
299public:
300 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
301 const TargetMachine &TM);
302
303 const R600InstrInfo *getInstrInfo() const override {
304 return &InstrInfo;
305 }
306
307 const R600FrameLowering *getFrameLowering() const override {
308 return &FrameLowering;
309 }
310
311 const R600TargetLowering *getTargetLowering() const override {
312 return &TLInfo;
313 }
314
315 const R600RegisterInfo *getRegisterInfo() const override {
316 return &InstrInfo.getRegisterInfo();
317 }
318
319 bool hasCFAluBug() const {
320 return CFALUBug;
321 }
322
323 bool hasVertexCache() const {
324 return HasVertexCache;
325 }
326
327 short getTexVTXClauseSize() const {
328 return TexVTXClauseSize;
329 }
330
331 unsigned getStackEntrySize() const;
332};
333
334class SISubtarget final : public AMDGPUSubtarget {
335public:
336 enum {
337 FIXED_SGPR_COUNT_FOR_INIT_BUG = 80
338 };
339
340private:
341 SIInstrInfo InstrInfo;
342 SIFrameLowering FrameLowering;
343 SITargetLowering TLInfo;
344 std::unique_ptr<GISelAccessor> GISel;
345
346public:
347 SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
348 const TargetMachine &TM);
349
350 const SIInstrInfo *getInstrInfo() const override {
351 return &InstrInfo;
352 }
353
354 const SIFrameLowering *getFrameLowering() const override {
355 return &FrameLowering;
356 }
357
358 const SITargetLowering *getTargetLowering() const override {
359 return &TLInfo;
360 }
361
362 const CallLowering *getCallLowering() const override {
363 assert(GISel && "Access to GlobalISel APIs not set");
364 return GISel->getCallLowering();
365 }
366
367 const SIRegisterInfo *getRegisterInfo() const override {
368 return &InstrInfo.getRegisterInfo();
369 }
370
371 void setGISelAccessor(GISelAccessor &GISel) {
372 this->GISel.reset(&GISel);
373 }
374
Tom Stellard83f0bce2015-01-29 16:55:25 +0000375 void overrideSchedPolicy(MachineSchedPolicy &Policy,
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000376 MachineInstr *Begin, MachineInstr *End,
Tom Stellard83f0bce2015-01-29 16:55:25 +0000377 unsigned NumRegionInstrs) const override;
378
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000379 bool isVGPRSpillingEnabled(const Function& F) const;
380
381 unsigned getAmdKernelCodeChipID() const;
382
383 AMDGPU::IsaVersion getIsaVersion() const;
384
385 unsigned getMaxNumUserSGPRs() const {
386 return 16;
387 }
388
389 bool hasFlatAddressSpace() const {
390 return FlatAddressSpace;
391 }
392
393 bool hasSMemRealTime() const {
394 return HasSMemRealTime;
395 }
396
397 bool has16BitInsts() const {
398 return Has16BitInsts;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000399 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000400
Tom Stellardde008d32016-01-21 04:28:34 +0000401 bool enableSIScheduler() const {
402 return EnableSIScheduler;
403 }
404
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000405 bool debuggerInsertNops() const {
406 return DebuggerInsertNops;
407 }
408
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000409 bool debuggerReserveRegs() const {
410 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000411 }
412
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000413 bool loadStoreOptEnabled() const {
414 return EnableLoadStoreOpt;
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000415 }
416
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000417 bool hasSGPRInitBug() const {
418 return SGPRInitBug;
Matt Arsenault41003af2015-11-30 21:16:07 +0000419 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000420};
421
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000422
423inline const AMDGPUInstrInfo *AMDGPUSubtarget::getInstrInfo() const {
424 if (getGeneration() >= SOUTHERN_ISLANDS)
425 return static_cast<const SISubtarget *>(this)->getInstrInfo();
426
427 return static_cast<const R600Subtarget *>(this)->getInstrInfo();
428}
429
430inline const AMDGPUFrameLowering *AMDGPUSubtarget::getFrameLowering() const {
431 if (getGeneration() >= SOUTHERN_ISLANDS)
432 return static_cast<const SISubtarget *>(this)->getFrameLowering();
433
434 return static_cast<const R600Subtarget *>(this)->getFrameLowering();
435}
436
437inline const AMDGPUTargetLowering *AMDGPUSubtarget::getTargetLowering() const {
438 if (getGeneration() >= SOUTHERN_ISLANDS)
439 return static_cast<const SISubtarget *>(this)->getTargetLowering();
440
441 return static_cast<const R600Subtarget *>(this)->getTargetLowering();
442}
443
444inline const AMDGPURegisterInfo *AMDGPUSubtarget::getRegisterInfo() const {
445 if (getGeneration() >= SOUTHERN_ISLANDS)
446 return static_cast<const SISubtarget *>(this)->getRegisterInfo();
447
448 return static_cast<const R600Subtarget *>(this)->getRegisterInfo();
449}
450
Tom Stellard75aadc22012-12-11 21:25:42 +0000451} // End namespace llvm
452
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000453#endif