blob: 96cdc9f84b72328a6b70228ffc0a4c24028b83d6 [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"
Eric Christopherac4b69e2014-07-25 22:22:39 +000019#include "AMDGPUFrameLowering.h"
Matt Arsenaultf59e5382015-11-06 18:23:00 +000020#include "AMDGPUISelLowering.h"
Mehdi Aminib550cb12016-04-18 09:17:29 +000021#include "AMDGPUInstrInfo.h"
Eric Christopherac4b69e2014-07-25 22:22:39 +000022#include "AMDGPUSubtarget.h"
Tom Stellard347ac792015-06-26 21:15:07 +000023#include "Utils/AMDGPUBaseInfo.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000024#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000025#include "llvm/Target/TargetSubtargetInfo.h"
26
27#define GET_SUBTARGETINFO_HEADER
28#include "AMDGPUGenSubtargetInfo.inc"
29
Tom Stellard75aadc22012-12-11 21:25:42 +000030namespace llvm {
31
Mehdi Aminib550cb12016-04-18 09:17:29 +000032class StringRef;
Tom Stellarde99fb652015-01-20 19:33:04 +000033class SIMachineFunctionInfo;
34
Tom Stellard75aadc22012-12-11 21:25:42 +000035class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellard2e59a452014-06-13 01:32:00 +000036
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000037public:
38 enum Generation {
39 R600 = 0,
40 R700,
41 EVERGREEN,
42 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000043 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000044 SEA_ISLANDS,
45 VOLCANIC_ISLANDS,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000046 };
47
Marek Olsak4d00dd22015-03-09 15:48:09 +000048 enum {
49 FIXED_SGPR_COUNT_FOR_INIT_BUG = 80
50 };
51
Tom Stellard347ac792015-06-26 21:15:07 +000052 enum {
53 ISAVersion0_0_0,
54 ISAVersion7_0_0,
55 ISAVersion7_0_1,
56 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000057 ISAVersion8_0_1,
58 ISAVersion8_0_3
Tom Stellard347ac792015-06-26 21:15:07 +000059 };
60
Tom Stellard75aadc22012-12-11 21:25:42 +000061private:
Tom Stellard75aadc22012-12-11 21:25:42 +000062 bool DumpCode;
63 bool R600ALUInst;
Vincent Lejeunec2991642013-04-30 00:13:39 +000064 bool HasVertexCache;
Vincent Lejeunef9f4e1e2013-05-17 16:49:55 +000065 short TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +000066 Generation Gen;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000067 bool FP64;
Matt Arsenaultf171cf22014-07-14 23:40:49 +000068 bool FP64Denormals;
69 bool FP32Denormals;
Matt Arsenaultf639c322016-01-28 20:53:42 +000070 bool FPExceptions;
Matt Arsenaultb035a572015-01-29 19:34:25 +000071 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +000072 bool HalfRate64Ops;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000073 bool CaymanISA;
Matt Arsenault3f981402014-09-15 15:41:53 +000074 bool FlatAddressSpace;
Changpeng Fangb41574a2015-12-22 20:55:23 +000075 bool FlatForGlobal;
Tom Stellarded0ceec2013-10-10 17:11:12 +000076 bool EnableIRStructurizer;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000077 bool EnablePromoteAlloca;
Tom Stellard783893a2013-11-18 19:43:33 +000078 bool EnableIfCvt;
Matt Arsenault41033282014-10-10 22:01:59 +000079 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +000080 bool EnableUnsafeDSOffsetFolding;
Nicolai Haehnle5b504972016-01-04 23:35:53 +000081 bool EnableXNACK;
Tom Stellard8c347b02014-01-22 21:55:40 +000082 unsigned WavefrontSize;
Tom Stellard348273d2014-01-23 16:18:02 +000083 bool CFALUBug;
Tom Stellard880a80a2014-06-17 16:53:14 +000084 int LocalMemorySize;
Matt Arsenault24ee0782016-02-12 02:40:47 +000085 unsigned MaxPrivateElementSize;
Tom Stellarde99fb652015-01-20 19:33:04 +000086 bool EnableVGPRSpilling;
Marek Olsak4d00dd22015-03-09 15:48:09 +000087 bool SGPRInitBug;
Tom Stellardd7e6f132015-04-08 01:09:26 +000088 bool IsGCN;
89 bool GCN1Encoding;
90 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +000091 bool CIInsts;
Matt Arsenault9d82ee72016-02-27 08:53:55 +000092 bool HasSMemRealTime;
93 bool Has16BitInsts;
Tom Stellardd1f0f022015-04-23 19:33:54 +000094 bool FeatureDisable;
Tom Stellardec87f842015-05-25 16:15:54 +000095 int LDSBankCount;
Matt Arsenaultf59e5382015-11-06 18:23:00 +000096 unsigned IsaVersion;
Tom Stellardde008d32016-01-21 04:28:34 +000097 bool EnableSIScheduler;
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +000098 bool DebuggerInsertNops;
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +000099 bool DebuggerReserveRegs;
Tom Stellard75aadc22012-12-11 21:25:42 +0000100
Matt Arsenault0c90e952015-11-06 18:17:45 +0000101 std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
Eric Christopherac4b69e2014-07-25 22:22:39 +0000102 std::unique_ptr<AMDGPUTargetLowering> TLInfo;
103 std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
Tom Stellard000c5af2016-04-14 19:09:28 +0000104 std::unique_ptr<GISelAccessor> GISel;
Tom Stellard75aadc22012-12-11 21:25:42 +0000105 InstrItineraryData InstrItins;
Tom Stellard794c8c02014-12-02 17:05:41 +0000106 Triple TargetTriple;
Tom Stellard75aadc22012-12-11 21:25:42 +0000107
108public:
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000109 AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
110 TargetMachine &TM);
111 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
112 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000113
Tom Stellard000c5af2016-04-14 19:09:28 +0000114 void setGISelAccessor(GISelAccessor &GISel) {
115 this->GISel.reset(&GISel);
116 }
117
Eric Christopherd9134482014-08-04 21:25:23 +0000118 const AMDGPUFrameLowering *getFrameLowering() const override {
Matt Arsenault0c90e952015-11-06 18:17:45 +0000119 return FrameLowering.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000120 }
121 const AMDGPUInstrInfo *getInstrInfo() const override {
122 return InstrInfo.get();
123 }
124 const AMDGPURegisterInfo *getRegisterInfo() const override {
Eric Christopherac4b69e2014-07-25 22:22:39 +0000125 return &InstrInfo->getRegisterInfo();
Tom Stellard2e59a452014-06-13 01:32:00 +0000126 }
Eric Christopherd9134482014-08-04 21:25:23 +0000127 AMDGPUTargetLowering *getTargetLowering() const override {
128 return TLInfo.get();
129 }
Eric Christopherd9134482014-08-04 21:25:23 +0000130 const InstrItineraryData *getInstrItineraryData() const override {
131 return &InstrItins;
132 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000133
Tom Stellard000c5af2016-04-14 19:09:28 +0000134 const CallLowering *getCallLowering() const override;
135
Craig Topperee7b0f32014-04-30 05:53:27 +0000136 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000137
Matt Arsenaultd782d052014-06-27 17:57:00 +0000138 bool hasVertexCache() const {
139 return HasVertexCache;
140 }
141
142 short getTexVTXClauseSize() const {
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000143 return TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000144 }
145
146 Generation getGeneration() const {
147 return Gen;
148 }
149
150 bool hasHWFP64() const {
151 return FP64;
152 }
153
154 bool hasCaymanISA() const {
155 return CaymanISA;
156 }
Matt Arsenaultfae02982014-03-17 18:58:11 +0000157
Matt Arsenaultf171cf22014-07-14 23:40:49 +0000158 bool hasFP32Denormals() const {
159 return FP32Denormals;
160 }
161
162 bool hasFP64Denormals() const {
163 return FP64Denormals;
164 }
165
Matt Arsenaultf639c322016-01-28 20:53:42 +0000166 bool hasFPExceptions() const {
167 return FPExceptions;
168 }
169
Matt Arsenaultb035a572015-01-29 19:34:25 +0000170 bool hasFastFMAF32() const {
171 return FastFMAF32;
172 }
173
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000174 bool hasHalfRate64Ops() const {
175 return HalfRate64Ops;
176 }
177
Matt Arsenault3f981402014-09-15 15:41:53 +0000178 bool hasFlatAddressSpace() const {
179 return FlatAddressSpace;
180 }
181
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000182 bool hasSMemRealTime() const {
183 return HasSMemRealTime;
184 }
185
186 bool has16BitInsts() const {
187 return Has16BitInsts;
188 }
189
Changpeng Fangb41574a2015-12-22 20:55:23 +0000190 bool useFlatForGlobal() const {
191 return FlatForGlobal;
192 }
193
Matt Arsenault88701812016-06-09 23:42:48 +0000194 bool hasAddr64() const {
195 return (getGeneration() < VOLCANIC_ISLANDS);
196 }
197
Matt Arsenaultfae02982014-03-17 18:58:11 +0000198 bool hasBFE() const {
199 return (getGeneration() >= EVERGREEN);
200 }
201
Matt Arsenault6e439652014-06-10 19:00:20 +0000202 bool hasBFI() const {
203 return (getGeneration() >= EVERGREEN);
204 }
205
Matt Arsenaultfae02982014-03-17 18:58:11 +0000206 bool hasBFM() const {
207 return hasBFE();
208 }
209
Matt Arsenault60425062014-06-10 19:18:28 +0000210 bool hasBCNT(unsigned Size) const {
211 if (Size == 32)
212 return (getGeneration() >= EVERGREEN);
213
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000214 if (Size == 64)
215 return (getGeneration() >= SOUTHERN_ISLANDS);
216
217 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000218 }
219
Tom Stellard50122a52014-04-07 19:45:41 +0000220 bool hasMulU24() const {
221 return (getGeneration() >= EVERGREEN);
222 }
223
224 bool hasMulI24() const {
225 return (getGeneration() >= SOUTHERN_ISLANDS ||
226 hasCaymanISA());
227 }
228
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000229 bool hasFFBL() const {
230 return (getGeneration() >= EVERGREEN);
231 }
232
233 bool hasFFBH() const {
234 return (getGeneration() >= EVERGREEN);
235 }
236
Jan Vesely808fff52015-04-30 17:15:56 +0000237 bool hasCARRY() const {
238 return (getGeneration() >= EVERGREEN);
239 }
240
241 bool hasBORROW() const {
242 return (getGeneration() >= EVERGREEN);
243 }
244
Matt Arsenaultd782d052014-06-27 17:57:00 +0000245 bool IsIRStructurizerEnabled() const {
246 return EnableIRStructurizer;
247 }
248
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000249 bool isPromoteAllocaEnabled() const {
250 return EnablePromoteAlloca;
251 }
252
Matt Arsenaultd782d052014-06-27 17:57:00 +0000253 bool isIfCvtEnabled() const {
254 return EnableIfCvt;
255 }
256
Matt Arsenault41033282014-10-10 22:01:59 +0000257 bool loadStoreOptEnabled() const {
258 return EnableLoadStoreOpt;
259 }
260
Matt Arsenault706f9302015-07-06 16:01:58 +0000261 bool unsafeDSOffsetFoldingEnabled() const {
262 return EnableUnsafeDSOffsetFolding;
263 }
264
Matt Arsenaultd782d052014-06-27 17:57:00 +0000265 unsigned getWavefrontSize() const {
266 return WavefrontSize;
267 }
268
Tom Stellarda40f9712014-01-22 21:55:43 +0000269 unsigned getStackEntrySize() const;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000270
271 bool hasCFAluBug() const {
272 assert(getGeneration() <= NORTHERN_ISLANDS);
273 return CFALUBug;
274 }
275
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000276 /// Return the amount of LDS that can be used that will not restrict the
277 /// occupancy lower than WaveCount.
278 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount) const;
279
280 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
281 /// the given LDS memory size is the only constraint.
282 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes) const;
283
284
Matt Arsenaultd782d052014-06-27 17:57:00 +0000285 int getLocalMemorySize() const {
286 return LocalMemorySize;
287 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000288
Matt Arsenault24ee0782016-02-12 02:40:47 +0000289 unsigned getMaxPrivateElementSize() const {
290 return MaxPrivateElementSize;
291 }
292
Marek Olsak4d00dd22015-03-09 15:48:09 +0000293 bool hasSGPRInitBug() const {
294 return SGPRInitBug;
295 }
296
Tom Stellardec87f842015-05-25 16:15:54 +0000297 int getLDSBankCount() const {
298 return LDSBankCount;
299 }
300
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000301 unsigned getAmdKernelCodeChipID() const;
302
Tom Stellard347ac792015-06-26 21:15:07 +0000303 AMDGPU::IsaVersion getIsaVersion() const;
304
Craig Topper5656db42014-04-29 07:57:24 +0000305 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000306 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000307 }
308
Tom Stellard83f0bce2015-01-29 16:55:25 +0000309 void overrideSchedPolicy(MachineSchedPolicy &Policy,
310 MachineInstr *begin, MachineInstr *end,
311 unsigned NumRegionInstrs) const override;
312
Tom Stellard75aadc22012-12-11 21:25:42 +0000313 // Helper functions to simplify if statements
Matt Arsenaultd782d052014-06-27 17:57:00 +0000314 bool isTargetELF() const {
315 return false;
316 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000317
Tom Stellardde008d32016-01-21 04:28:34 +0000318 bool enableSIScheduler() const {
319 return EnableSIScheduler;
320 }
321
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000322 bool debuggerInsertNops() const {
323 return DebuggerInsertNops;
324 }
325
Konstantin Zhuravlyov29ddd2b2016-05-24 18:37:18 +0000326 bool debuggerReserveRegs() const {
327 return DebuggerReserveRegs;
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000328 }
329
Matt Arsenaultd782d052014-06-27 17:57:00 +0000330 bool dumpCode() const {
331 return DumpCode;
332 }
333 bool r600ALUEncoding() const {
334 return R600ALUInst;
335 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000336 bool isAmdHsaOS() const {
337 return TargetTriple.getOS() == Triple::AMDHSA;
338 }
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000339 bool isVGPRSpillingEnabled(const Function& F) const;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000340
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000341 bool isXNACKEnabled() const {
342 return EnableXNACK;
343 }
344
Tom Stellard83f0bce2015-01-29 16:55:25 +0000345 unsigned getMaxWavesPerCU() const {
346 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
347 return 10;
348
349 // FIXME: Not sure what this is for other subtagets.
Matt Arsenault8a028bf2016-05-16 21:19:59 +0000350 return 8;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000351 }
Tom Stellardf6afc802015-02-04 23:14:18 +0000352
353 bool enableSubRegLiveness() const override {
Tom Stellard1ba52fe2015-06-04 01:20:04 +0000354 return true;
Tom Stellardf6afc802015-02-04 23:14:18 +0000355 }
Tom Stellardb5798b02015-06-26 21:15:03 +0000356
357 /// \brief Returns the offset in bytes from the start of the input buffer
358 /// of the first explicit kernel argument.
359 unsigned getExplicitKernelArgOffset() const {
360 return isAmdHsaOS() ? 0 : 36;
361 }
362
Matt Arsenault41003af2015-11-30 21:16:07 +0000363 unsigned getMaxNumUserSGPRs() const {
364 return 16;
365 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000366};
367
368} // End namespace llvm
369
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000370#endif