blob: 318410f98612f5909d065b99a861925ce7248221 [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"
25#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
Tom Stellarde99fb652015-01-20 19:33:04 +000032class SIMachineFunctionInfo;
33
Tom Stellard75aadc22012-12-11 21:25:42 +000034class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
Tom Stellard2e59a452014-06-13 01:32:00 +000035
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000036public:
37 enum Generation {
38 R600 = 0,
39 R700,
40 EVERGREEN,
41 NORTHERN_ISLANDS,
Tom Stellard6e1ee472013-10-29 16:37:28 +000042 SOUTHERN_ISLANDS,
Marek Olsak5df00d62014-12-07 12:18:57 +000043 SEA_ISLANDS,
44 VOLCANIC_ISLANDS,
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000045 };
46
Marek Olsak4d00dd22015-03-09 15:48:09 +000047 enum {
48 FIXED_SGPR_COUNT_FOR_INIT_BUG = 80
49 };
50
Tom Stellard347ac792015-06-26 21:15:07 +000051 enum {
52 ISAVersion0_0_0,
53 ISAVersion7_0_0,
54 ISAVersion7_0_1,
55 ISAVersion8_0_0,
Changpeng Fangc16be002016-01-13 20:39:25 +000056 ISAVersion8_0_1,
57 ISAVersion8_0_3
Tom Stellard347ac792015-06-26 21:15:07 +000058 };
59
Tom Stellard75aadc22012-12-11 21:25:42 +000060private:
Tom Stellard75aadc22012-12-11 21:25:42 +000061 bool DumpCode;
62 bool R600ALUInst;
Vincent Lejeunec2991642013-04-30 00:13:39 +000063 bool HasVertexCache;
Vincent Lejeunef9f4e1e2013-05-17 16:49:55 +000064 short TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +000065 Generation Gen;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000066 bool FP64;
Matt Arsenaultf171cf22014-07-14 23:40:49 +000067 bool FP64Denormals;
68 bool FP32Denormals;
Matt Arsenaultf639c322016-01-28 20:53:42 +000069 bool FPExceptions;
Matt Arsenaultb035a572015-01-29 19:34:25 +000070 bool FastFMAF32;
Matt Arsenaulte83690c2016-01-18 21:13:50 +000071 bool HalfRate64Ops;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000072 bool CaymanISA;
Matt Arsenault3f981402014-09-15 15:41:53 +000073 bool FlatAddressSpace;
Changpeng Fangb41574a2015-12-22 20:55:23 +000074 bool FlatForGlobal;
Tom Stellarded0ceec2013-10-10 17:11:12 +000075 bool EnableIRStructurizer;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000076 bool EnablePromoteAlloca;
Tom Stellard783893a2013-11-18 19:43:33 +000077 bool EnableIfCvt;
Matt Arsenault41033282014-10-10 22:01:59 +000078 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +000079 bool EnableUnsafeDSOffsetFolding;
Nicolai Haehnle5b504972016-01-04 23:35:53 +000080 bool EnableXNACK;
Tom Stellard8c347b02014-01-22 21:55:40 +000081 unsigned WavefrontSize;
Tom Stellard348273d2014-01-23 16:18:02 +000082 bool CFALUBug;
Tom Stellard880a80a2014-06-17 16:53:14 +000083 int LocalMemorySize;
Matt Arsenault24ee0782016-02-12 02:40:47 +000084 unsigned MaxPrivateElementSize;
Tom Stellarde99fb652015-01-20 19:33:04 +000085 bool EnableVGPRSpilling;
Marek Olsak4d00dd22015-03-09 15:48:09 +000086 bool SGPRInitBug;
Tom Stellardd7e6f132015-04-08 01:09:26 +000087 bool IsGCN;
88 bool GCN1Encoding;
89 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +000090 bool CIInsts;
Matt Arsenault9d82ee72016-02-27 08:53:55 +000091 bool HasSMemRealTime;
92 bool Has16BitInsts;
Tom Stellardd1f0f022015-04-23 19:33:54 +000093 bool FeatureDisable;
Tom Stellardec87f842015-05-25 16:15:54 +000094 int LDSBankCount;
Matt Arsenaultf59e5382015-11-06 18:23:00 +000095 unsigned IsaVersion;
Tom Stellardde008d32016-01-21 04:28:34 +000096 bool EnableSIScheduler;
Tom Stellard75aadc22012-12-11 21:25:42 +000097
Matt Arsenault0c90e952015-11-06 18:17:45 +000098 std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
Eric Christopherac4b69e2014-07-25 22:22:39 +000099 std::unique_ptr<AMDGPUTargetLowering> TLInfo;
100 std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +0000101 InstrItineraryData InstrItins;
Tom Stellard794c8c02014-12-02 17:05:41 +0000102 Triple TargetTriple;
Tom Stellard75aadc22012-12-11 21:25:42 +0000103
104public:
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000105 AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
106 TargetMachine &TM);
107 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
108 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000109
Eric Christopherd9134482014-08-04 21:25:23 +0000110 const AMDGPUFrameLowering *getFrameLowering() const override {
Matt Arsenault0c90e952015-11-06 18:17:45 +0000111 return FrameLowering.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000112 }
113 const AMDGPUInstrInfo *getInstrInfo() const override {
114 return InstrInfo.get();
115 }
116 const AMDGPURegisterInfo *getRegisterInfo() const override {
Eric Christopherac4b69e2014-07-25 22:22:39 +0000117 return &InstrInfo->getRegisterInfo();
Tom Stellard2e59a452014-06-13 01:32:00 +0000118 }
Eric Christopherd9134482014-08-04 21:25:23 +0000119 AMDGPUTargetLowering *getTargetLowering() const override {
120 return TLInfo.get();
121 }
Eric Christopherd9134482014-08-04 21:25:23 +0000122 const InstrItineraryData *getInstrItineraryData() const override {
123 return &InstrItins;
124 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000125
Craig Topperee7b0f32014-04-30 05:53:27 +0000126 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000127
Matt Arsenaultd782d052014-06-27 17:57:00 +0000128 bool hasVertexCache() const {
129 return HasVertexCache;
130 }
131
132 short getTexVTXClauseSize() const {
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000133 return TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000134 }
135
136 Generation getGeneration() const {
137 return Gen;
138 }
139
140 bool hasHWFP64() const {
141 return FP64;
142 }
143
144 bool hasCaymanISA() const {
145 return CaymanISA;
146 }
Matt Arsenaultfae02982014-03-17 18:58:11 +0000147
Matt Arsenaultf171cf22014-07-14 23:40:49 +0000148 bool hasFP32Denormals() const {
149 return FP32Denormals;
150 }
151
152 bool hasFP64Denormals() const {
153 return FP64Denormals;
154 }
155
Matt Arsenaultf639c322016-01-28 20:53:42 +0000156 bool hasFPExceptions() const {
157 return FPExceptions;
158 }
159
Matt Arsenaultb035a572015-01-29 19:34:25 +0000160 bool hasFastFMAF32() const {
161 return FastFMAF32;
162 }
163
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000164 bool hasHalfRate64Ops() const {
165 return HalfRate64Ops;
166 }
167
Matt Arsenault3f981402014-09-15 15:41:53 +0000168 bool hasFlatAddressSpace() const {
169 return FlatAddressSpace;
170 }
171
Matt Arsenault9d82ee72016-02-27 08:53:55 +0000172 bool hasSMemRealTime() const {
173 return HasSMemRealTime;
174 }
175
176 bool has16BitInsts() const {
177 return Has16BitInsts;
178 }
179
Changpeng Fangb41574a2015-12-22 20:55:23 +0000180 bool useFlatForGlobal() const {
181 return FlatForGlobal;
182 }
183
Matt Arsenaultfae02982014-03-17 18:58:11 +0000184 bool hasBFE() const {
185 return (getGeneration() >= EVERGREEN);
186 }
187
Matt Arsenault6e439652014-06-10 19:00:20 +0000188 bool hasBFI() const {
189 return (getGeneration() >= EVERGREEN);
190 }
191
Matt Arsenaultfae02982014-03-17 18:58:11 +0000192 bool hasBFM() const {
193 return hasBFE();
194 }
195
Matt Arsenault60425062014-06-10 19:18:28 +0000196 bool hasBCNT(unsigned Size) const {
197 if (Size == 32)
198 return (getGeneration() >= EVERGREEN);
199
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000200 if (Size == 64)
201 return (getGeneration() >= SOUTHERN_ISLANDS);
202
203 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000204 }
205
Tom Stellard50122a52014-04-07 19:45:41 +0000206 bool hasMulU24() const {
207 return (getGeneration() >= EVERGREEN);
208 }
209
210 bool hasMulI24() const {
211 return (getGeneration() >= SOUTHERN_ISLANDS ||
212 hasCaymanISA());
213 }
214
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000215 bool hasFFBL() const {
216 return (getGeneration() >= EVERGREEN);
217 }
218
219 bool hasFFBH() const {
220 return (getGeneration() >= EVERGREEN);
221 }
222
Jan Vesely808fff52015-04-30 17:15:56 +0000223 bool hasCARRY() const {
224 return (getGeneration() >= EVERGREEN);
225 }
226
227 bool hasBORROW() const {
228 return (getGeneration() >= EVERGREEN);
229 }
230
Matt Arsenaultd782d052014-06-27 17:57:00 +0000231 bool IsIRStructurizerEnabled() const {
232 return EnableIRStructurizer;
233 }
234
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000235 bool isPromoteAllocaEnabled() const {
236 return EnablePromoteAlloca;
237 }
238
Matt Arsenaultd782d052014-06-27 17:57:00 +0000239 bool isIfCvtEnabled() const {
240 return EnableIfCvt;
241 }
242
Matt Arsenault41033282014-10-10 22:01:59 +0000243 bool loadStoreOptEnabled() const {
244 return EnableLoadStoreOpt;
245 }
246
Matt Arsenault706f9302015-07-06 16:01:58 +0000247 bool unsafeDSOffsetFoldingEnabled() const {
248 return EnableUnsafeDSOffsetFolding;
249 }
250
Matt Arsenaultd782d052014-06-27 17:57:00 +0000251 unsigned getWavefrontSize() const {
252 return WavefrontSize;
253 }
254
Tom Stellarda40f9712014-01-22 21:55:43 +0000255 unsigned getStackEntrySize() const;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000256
257 bool hasCFAluBug() const {
258 assert(getGeneration() <= NORTHERN_ISLANDS);
259 return CFALUBug;
260 }
261
262 int getLocalMemorySize() const {
263 return LocalMemorySize;
264 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000265
Matt Arsenault24ee0782016-02-12 02:40:47 +0000266 unsigned getMaxPrivateElementSize() const {
267 return MaxPrivateElementSize;
268 }
269
Marek Olsak4d00dd22015-03-09 15:48:09 +0000270 bool hasSGPRInitBug() const {
271 return SGPRInitBug;
272 }
273
Tom Stellardec87f842015-05-25 16:15:54 +0000274 int getLDSBankCount() const {
275 return LDSBankCount;
276 }
277
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000278 unsigned getAmdKernelCodeChipID() const;
279
Tom Stellard347ac792015-06-26 21:15:07 +0000280 AMDGPU::IsaVersion getIsaVersion() const;
281
Craig Topper5656db42014-04-29 07:57:24 +0000282 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000283 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000284 }
285
Tom Stellard83f0bce2015-01-29 16:55:25 +0000286 void overrideSchedPolicy(MachineSchedPolicy &Policy,
287 MachineInstr *begin, MachineInstr *end,
288 unsigned NumRegionInstrs) const override;
289
Tom Stellard75aadc22012-12-11 21:25:42 +0000290 // Helper functions to simplify if statements
Matt Arsenaultd782d052014-06-27 17:57:00 +0000291 bool isTargetELF() const {
292 return false;
293 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000294
Tom Stellardde008d32016-01-21 04:28:34 +0000295 bool enableSIScheduler() const {
296 return EnableSIScheduler;
297 }
298
Matt Arsenaultd782d052014-06-27 17:57:00 +0000299 bool dumpCode() const {
300 return DumpCode;
301 }
302 bool r600ALUEncoding() const {
303 return R600ALUInst;
304 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000305 bool isAmdHsaOS() const {
306 return TargetTriple.getOS() == Triple::AMDHSA;
307 }
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000308 bool isVGPRSpillingEnabled(const Function& F) const;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000309
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000310 bool isXNACKEnabled() const {
311 return EnableXNACK;
312 }
313
Tom Stellard83f0bce2015-01-29 16:55:25 +0000314 unsigned getMaxWavesPerCU() const {
315 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
316 return 10;
317
318 // FIXME: Not sure what this is for other subtagets.
319 llvm_unreachable("do not know max waves per CU for this subtarget.");
320 }
Tom Stellardf6afc802015-02-04 23:14:18 +0000321
322 bool enableSubRegLiveness() const override {
Tom Stellard1ba52fe2015-06-04 01:20:04 +0000323 return true;
Tom Stellardf6afc802015-02-04 23:14:18 +0000324 }
Tom Stellardb5798b02015-06-26 21:15:03 +0000325
326 /// \brief Returns the offset in bytes from the start of the input buffer
327 /// of the first explicit kernel argument.
328 unsigned getExplicitKernelArgOffset() const {
329 return isAmdHsaOS() ? 0 : 36;
330 }
331
Matt Arsenault41003af2015-11-30 21:16:07 +0000332 unsigned getMaxNumUserSGPRs() const {
333 return 16;
334 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000335};
336
337} // End namespace llvm
338
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000339#endif