blob: c74edab4b44a447c642f7826e2235bde5100f2bd [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"
Tom Stellard2e59a452014-06-13 01:32:00 +000020#include "AMDGPUInstrInfo.h"
Matt Arsenaultf59e5382015-11-06 18:23:00 +000021#include "AMDGPUISelLowering.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 Stellard75aadc22012-12-11 21:25:42 +000024#include "llvm/ADT/StringRef.h"
Tom Stellard000c5af2016-04-14 19:09:28 +000025#include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000026#include "llvm/Target/TargetSubtargetInfo.h"
27
28#define GET_SUBTARGETINFO_HEADER
29#include "AMDGPUGenSubtargetInfo.inc"
30
Tom Stellard75aadc22012-12-11 21:25:42 +000031namespace llvm {
32
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;
Tom Stellard75aadc22012-12-11 21:25:42 +000098
Matt Arsenault0c90e952015-11-06 18:17:45 +000099 std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
Eric Christopherac4b69e2014-07-25 22:22:39 +0000100 std::unique_ptr<AMDGPUTargetLowering> TLInfo;
101 std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
Tom Stellard000c5af2016-04-14 19:09:28 +0000102 std::unique_ptr<GISelAccessor> GISel;
Tom Stellard75aadc22012-12-11 21:25:42 +0000103 InstrItineraryData InstrItins;
Tom Stellard794c8c02014-12-02 17:05:41 +0000104 Triple TargetTriple;
Tom Stellard75aadc22012-12-11 21:25:42 +0000105
106public:
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000107 AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
108 TargetMachine &TM);
109 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
110 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000111
Tom Stellard000c5af2016-04-14 19:09:28 +0000112 void setGISelAccessor(GISelAccessor &GISel) {
113 this->GISel.reset(&GISel);
114 }
115
Eric Christopherd9134482014-08-04 21:25:23 +0000116 const AMDGPUFrameLowering *getFrameLowering() const override {
Matt Arsenault0c90e952015-11-06 18:17:45 +0000117 return FrameLowering.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000118 }
119 const AMDGPUInstrInfo *getInstrInfo() const override {
120 return InstrInfo.get();
121 }
122 const AMDGPURegisterInfo *getRegisterInfo() const override {
Eric Christopherac4b69e2014-07-25 22:22:39 +0000123 return &InstrInfo->getRegisterInfo();
Tom Stellard2e59a452014-06-13 01:32:00 +0000124 }
Eric Christopherd9134482014-08-04 21:25:23 +0000125 AMDGPUTargetLowering *getTargetLowering() const override {
126 return TLInfo.get();
127 }
Eric Christopherd9134482014-08-04 21:25:23 +0000128 const InstrItineraryData *getInstrItineraryData() const override {
129 return &InstrItins;
130 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000131
Tom Stellard000c5af2016-04-14 19:09:28 +0000132 const CallLowering *getCallLowering() const override;
133
Craig Topperee7b0f32014-04-30 05:53:27 +0000134 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000135
Matt Arsenaultd782d052014-06-27 17:57:00 +0000136 bool hasVertexCache() const {
137 return HasVertexCache;
138 }
139
140 short getTexVTXClauseSize() const {
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000141 return TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000142 }
143
144 Generation getGeneration() const {
145 return Gen;
146 }
147
148 bool hasHWFP64() const {
149 return FP64;
150 }
151
152 bool hasCaymanISA() const {
153 return CaymanISA;
154 }
Matt Arsenaultfae02982014-03-17 18:58:11 +0000155
Matt Arsenaultf171cf22014-07-14 23:40:49 +0000156 bool hasFP32Denormals() const {
157 return FP32Denormals;
158 }
159
160 bool hasFP64Denormals() const {
161 return FP64Denormals;
162 }
163
Matt Arsenaultf639c322016-01-28 20:53:42 +0000164 bool hasFPExceptions() const {
165 return FPExceptions;
166 }
167
Matt Arsenaultb035a572015-01-29 19:34:25 +0000168 bool hasFastFMAF32() const {
169 return FastFMAF32;
170 }
171
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000172 bool hasHalfRate64Ops() const {
173 return HalfRate64Ops;
174 }
175
Matt Arsenault3f981402014-09-15 15:41:53 +0000176 bool hasFlatAddressSpace() const {
177 return FlatAddressSpace;
178 }
179
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000180 bool hasSMemRealTime() const {
181 return HasSMemRealTime;
182 }
183
184 bool has16BitInsts() const {
185 return Has16BitInsts;
186 }
187
Changpeng Fangb41574a2015-12-22 20:55:23 +0000188 bool useFlatForGlobal() const {
189 return FlatForGlobal;
190 }
191
Matt Arsenaultfae02982014-03-17 18:58:11 +0000192 bool hasBFE() const {
193 return (getGeneration() >= EVERGREEN);
194 }
195
Matt Arsenault6e439652014-06-10 19:00:20 +0000196 bool hasBFI() const {
197 return (getGeneration() >= EVERGREEN);
198 }
199
Matt Arsenaultfae02982014-03-17 18:58:11 +0000200 bool hasBFM() const {
201 return hasBFE();
202 }
203
Matt Arsenault60425062014-06-10 19:18:28 +0000204 bool hasBCNT(unsigned Size) const {
205 if (Size == 32)
206 return (getGeneration() >= EVERGREEN);
207
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000208 if (Size == 64)
209 return (getGeneration() >= SOUTHERN_ISLANDS);
210
211 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000212 }
213
Tom Stellard50122a52014-04-07 19:45:41 +0000214 bool hasMulU24() const {
215 return (getGeneration() >= EVERGREEN);
216 }
217
218 bool hasMulI24() const {
219 return (getGeneration() >= SOUTHERN_ISLANDS ||
220 hasCaymanISA());
221 }
222
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000223 bool hasFFBL() const {
224 return (getGeneration() >= EVERGREEN);
225 }
226
227 bool hasFFBH() const {
228 return (getGeneration() >= EVERGREEN);
229 }
230
Jan Vesely808fff52015-04-30 17:15:56 +0000231 bool hasCARRY() const {
232 return (getGeneration() >= EVERGREEN);
233 }
234
235 bool hasBORROW() const {
236 return (getGeneration() >= EVERGREEN);
237 }
238
Matt Arsenaultd782d052014-06-27 17:57:00 +0000239 bool IsIRStructurizerEnabled() const {
240 return EnableIRStructurizer;
241 }
242
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000243 bool isPromoteAllocaEnabled() const {
244 return EnablePromoteAlloca;
245 }
246
Matt Arsenaultd782d052014-06-27 17:57:00 +0000247 bool isIfCvtEnabled() const {
248 return EnableIfCvt;
249 }
250
Matt Arsenault41033282014-10-10 22:01:59 +0000251 bool loadStoreOptEnabled() const {
252 return EnableLoadStoreOpt;
253 }
254
Matt Arsenault706f9302015-07-06 16:01:58 +0000255 bool unsafeDSOffsetFoldingEnabled() const {
256 return EnableUnsafeDSOffsetFolding;
257 }
258
Matt Arsenaultd782d052014-06-27 17:57:00 +0000259 unsigned getWavefrontSize() const {
260 return WavefrontSize;
261 }
262
Tom Stellarda40f9712014-01-22 21:55:43 +0000263 unsigned getStackEntrySize() const;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000264
265 bool hasCFAluBug() const {
266 assert(getGeneration() <= NORTHERN_ISLANDS);
267 return CFALUBug;
268 }
269
270 int getLocalMemorySize() const {
271 return LocalMemorySize;
272 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000273
Matt Arsenault24ee0782016-02-12 02:40:47 +0000274 unsigned getMaxPrivateElementSize() const {
275 return MaxPrivateElementSize;
276 }
277
Marek Olsak4d00dd22015-03-09 15:48:09 +0000278 bool hasSGPRInitBug() const {
279 return SGPRInitBug;
280 }
281
Tom Stellardec87f842015-05-25 16:15:54 +0000282 int getLDSBankCount() const {
283 return LDSBankCount;
284 }
285
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000286 unsigned getAmdKernelCodeChipID() const;
287
Tom Stellard347ac792015-06-26 21:15:07 +0000288 AMDGPU::IsaVersion getIsaVersion() const;
289
Craig Topper5656db42014-04-29 07:57:24 +0000290 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000291 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000292 }
293
Tom Stellard83f0bce2015-01-29 16:55:25 +0000294 void overrideSchedPolicy(MachineSchedPolicy &Policy,
295 MachineInstr *begin, MachineInstr *end,
296 unsigned NumRegionInstrs) const override;
297
Tom Stellard75aadc22012-12-11 21:25:42 +0000298 // Helper functions to simplify if statements
Matt Arsenaultd782d052014-06-27 17:57:00 +0000299 bool isTargetELF() const {
300 return false;
301 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000302
Tom Stellardde008d32016-01-21 04:28:34 +0000303 bool enableSIScheduler() const {
304 return EnableSIScheduler;
305 }
306
Matt Arsenaultd782d052014-06-27 17:57:00 +0000307 bool dumpCode() const {
308 return DumpCode;
309 }
310 bool r600ALUEncoding() const {
311 return R600ALUInst;
312 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000313 bool isAmdHsaOS() const {
314 return TargetTriple.getOS() == Triple::AMDHSA;
315 }
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000316 bool isVGPRSpillingEnabled(const Function& F) const;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000317
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000318 bool isXNACKEnabled() const {
319 return EnableXNACK;
320 }
321
Tom Stellard83f0bce2015-01-29 16:55:25 +0000322 unsigned getMaxWavesPerCU() const {
323 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
324 return 10;
325
326 // FIXME: Not sure what this is for other subtagets.
327 llvm_unreachable("do not know max waves per CU for this subtarget.");
328 }
Tom Stellardf6afc802015-02-04 23:14:18 +0000329
330 bool enableSubRegLiveness() const override {
Tom Stellard1ba52fe2015-06-04 01:20:04 +0000331 return true;
Tom Stellardf6afc802015-02-04 23:14:18 +0000332 }
Tom Stellardb5798b02015-06-26 21:15:03 +0000333
334 /// \brief Returns the offset in bytes from the start of the input buffer
335 /// of the first explicit kernel argument.
336 unsigned getExplicitKernelArgOffset() const {
337 return isAmdHsaOS() ? 0 : 36;
338 }
339
Matt Arsenault41003af2015-11-30 21:16:07 +0000340 unsigned getMaxNumUserSGPRs() const {
341 return 16;
342 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000343};
344
345} // End namespace llvm
346
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000347#endif