blob: 12e6fee7d260ff9b10a4615e8c32ce6efcb1f5ea [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 Zhuravlyov1d99c4d2016-04-26 15:43:14 +000099 bool DebuggerReserveTrapVGPRs;
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 Arsenaultfae02982014-03-17 18:58:11 +0000194 bool hasBFE() const {
195 return (getGeneration() >= EVERGREEN);
196 }
197
Matt Arsenault6e439652014-06-10 19:00:20 +0000198 bool hasBFI() const {
199 return (getGeneration() >= EVERGREEN);
200 }
201
Matt Arsenaultfae02982014-03-17 18:58:11 +0000202 bool hasBFM() const {
203 return hasBFE();
204 }
205
Matt Arsenault60425062014-06-10 19:18:28 +0000206 bool hasBCNT(unsigned Size) const {
207 if (Size == 32)
208 return (getGeneration() >= EVERGREEN);
209
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000210 if (Size == 64)
211 return (getGeneration() >= SOUTHERN_ISLANDS);
212
213 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000214 }
215
Tom Stellard50122a52014-04-07 19:45:41 +0000216 bool hasMulU24() const {
217 return (getGeneration() >= EVERGREEN);
218 }
219
220 bool hasMulI24() const {
221 return (getGeneration() >= SOUTHERN_ISLANDS ||
222 hasCaymanISA());
223 }
224
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000225 bool hasFFBL() const {
226 return (getGeneration() >= EVERGREEN);
227 }
228
229 bool hasFFBH() const {
230 return (getGeneration() >= EVERGREEN);
231 }
232
Jan Vesely808fff52015-04-30 17:15:56 +0000233 bool hasCARRY() const {
234 return (getGeneration() >= EVERGREEN);
235 }
236
237 bool hasBORROW() const {
238 return (getGeneration() >= EVERGREEN);
239 }
240
Matt Arsenaultd782d052014-06-27 17:57:00 +0000241 bool IsIRStructurizerEnabled() const {
242 return EnableIRStructurizer;
243 }
244
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000245 bool isPromoteAllocaEnabled() const {
246 return EnablePromoteAlloca;
247 }
248
Matt Arsenaultd782d052014-06-27 17:57:00 +0000249 bool isIfCvtEnabled() const {
250 return EnableIfCvt;
251 }
252
Matt Arsenault41033282014-10-10 22:01:59 +0000253 bool loadStoreOptEnabled() const {
254 return EnableLoadStoreOpt;
255 }
256
Matt Arsenault706f9302015-07-06 16:01:58 +0000257 bool unsafeDSOffsetFoldingEnabled() const {
258 return EnableUnsafeDSOffsetFolding;
259 }
260
Matt Arsenaultd782d052014-06-27 17:57:00 +0000261 unsigned getWavefrontSize() const {
262 return WavefrontSize;
263 }
264
Tom Stellarda40f9712014-01-22 21:55:43 +0000265 unsigned getStackEntrySize() const;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000266
267 bool hasCFAluBug() const {
268 assert(getGeneration() <= NORTHERN_ISLANDS);
269 return CFALUBug;
270 }
271
272 int getLocalMemorySize() const {
273 return LocalMemorySize;
274 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000275
Matt Arsenault24ee0782016-02-12 02:40:47 +0000276 unsigned getMaxPrivateElementSize() const {
277 return MaxPrivateElementSize;
278 }
279
Marek Olsak4d00dd22015-03-09 15:48:09 +0000280 bool hasSGPRInitBug() const {
281 return SGPRInitBug;
282 }
283
Tom Stellardec87f842015-05-25 16:15:54 +0000284 int getLDSBankCount() const {
285 return LDSBankCount;
286 }
287
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000288 unsigned getAmdKernelCodeChipID() const;
289
Tom Stellard347ac792015-06-26 21:15:07 +0000290 AMDGPU::IsaVersion getIsaVersion() const;
291
Craig Topper5656db42014-04-29 07:57:24 +0000292 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000293 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000294 }
295
Tom Stellard83f0bce2015-01-29 16:55:25 +0000296 void overrideSchedPolicy(MachineSchedPolicy &Policy,
297 MachineInstr *begin, MachineInstr *end,
298 unsigned NumRegionInstrs) const override;
299
Tom Stellard75aadc22012-12-11 21:25:42 +0000300 // Helper functions to simplify if statements
Matt Arsenaultd782d052014-06-27 17:57:00 +0000301 bool isTargetELF() const {
302 return false;
303 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000304
Tom Stellardde008d32016-01-21 04:28:34 +0000305 bool enableSIScheduler() const {
306 return EnableSIScheduler;
307 }
308
Konstantin Zhuravlyov8c273ad2016-04-18 16:28:23 +0000309 bool debuggerInsertNops() const {
310 return DebuggerInsertNops;
311 }
312
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +0000313 bool debuggerReserveTrapVGPRs() const {
314 return DebuggerReserveTrapVGPRs;
315 }
316
317 unsigned debuggerReserveTrapVGPRCount() const {
318 return debuggerReserveTrapVGPRs() ? 4 : 0;
319 }
320
Matt Arsenaultd782d052014-06-27 17:57:00 +0000321 bool dumpCode() const {
322 return DumpCode;
323 }
324 bool r600ALUEncoding() const {
325 return R600ALUInst;
326 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000327 bool isAmdHsaOS() const {
328 return TargetTriple.getOS() == Triple::AMDHSA;
329 }
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000330 bool isVGPRSpillingEnabled(const Function& F) const;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000331
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000332 bool isXNACKEnabled() const {
333 return EnableXNACK;
334 }
335
Tom Stellard83f0bce2015-01-29 16:55:25 +0000336 unsigned getMaxWavesPerCU() const {
337 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
338 return 10;
339
340 // FIXME: Not sure what this is for other subtagets.
341 llvm_unreachable("do not know max waves per CU for this subtarget.");
342 }
Tom Stellardf6afc802015-02-04 23:14:18 +0000343
344 bool enableSubRegLiveness() const override {
Tom Stellard1ba52fe2015-06-04 01:20:04 +0000345 return true;
Tom Stellardf6afc802015-02-04 23:14:18 +0000346 }
Tom Stellardb5798b02015-06-26 21:15:03 +0000347
348 /// \brief Returns the offset in bytes from the start of the input buffer
349 /// of the first explicit kernel argument.
350 unsigned getExplicitKernelArgOffset() const {
351 return isAmdHsaOS() ? 0 : 36;
352 }
353
Matt Arsenault41003af2015-11-30 21:16:07 +0000354 unsigned getMaxNumUserSGPRs() const {
355 return 16;
356 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000357};
358
359} // End namespace llvm
360
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000361#endif