blob: 3a4266947b4eebc07b4976af1321a44718f12c70 [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 std::string DevName;
62 bool Is64bit;
Tom Stellard75aadc22012-12-11 21:25:42 +000063 bool DumpCode;
64 bool R600ALUInst;
Vincent Lejeunec2991642013-04-30 00:13:39 +000065 bool HasVertexCache;
Vincent Lejeunef9f4e1e2013-05-17 16:49:55 +000066 short TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +000067 Generation Gen;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000068 bool FP64;
Matt Arsenaultf171cf22014-07-14 23:40:49 +000069 bool FP64Denormals;
70 bool FP32Denormals;
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;
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;
91 bool FeatureDisable;
Tom Stellardec87f842015-05-25 16:15:54 +000092 int LDSBankCount;
Matt Arsenaultf59e5382015-11-06 18:23:00 +000093 unsigned IsaVersion;
Tom Stellardc98ee202015-07-16 19:40:07 +000094 bool EnableHugeScratchBuffer;
Tom Stellard75aadc22012-12-11 21:25:42 +000095
Matt Arsenault0c90e952015-11-06 18:17:45 +000096 std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
Eric Christopherac4b69e2014-07-25 22:22:39 +000097 std::unique_ptr<AMDGPUTargetLowering> TLInfo;
98 std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +000099 InstrItineraryData InstrItins;
Tom Stellard794c8c02014-12-02 17:05:41 +0000100 Triple TargetTriple;
Tom Stellard75aadc22012-12-11 21:25:42 +0000101
102public:
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000103 AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
104 TargetMachine &TM);
105 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
106 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000107
Eric Christopherd9134482014-08-04 21:25:23 +0000108 const AMDGPUFrameLowering *getFrameLowering() const override {
Matt Arsenault0c90e952015-11-06 18:17:45 +0000109 return FrameLowering.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000110 }
111 const AMDGPUInstrInfo *getInstrInfo() const override {
112 return InstrInfo.get();
113 }
114 const AMDGPURegisterInfo *getRegisterInfo() const override {
Eric Christopherac4b69e2014-07-25 22:22:39 +0000115 return &InstrInfo->getRegisterInfo();
Tom Stellard2e59a452014-06-13 01:32:00 +0000116 }
Eric Christopherd9134482014-08-04 21:25:23 +0000117 AMDGPUTargetLowering *getTargetLowering() const override {
118 return TLInfo.get();
119 }
Eric Christopherd9134482014-08-04 21:25:23 +0000120 const InstrItineraryData *getInstrItineraryData() const override {
121 return &InstrItins;
122 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000123
Craig Topperee7b0f32014-04-30 05:53:27 +0000124 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000125
Matt Arsenaultd782d052014-06-27 17:57:00 +0000126 bool is64bit() const {
127 return Is64bit;
128 }
129
130 bool hasVertexCache() const {
131 return HasVertexCache;
132 }
133
134 short getTexVTXClauseSize() const {
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000135 return TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000136 }
137
138 Generation getGeneration() const {
139 return Gen;
140 }
141
142 bool hasHWFP64() const {
143 return FP64;
144 }
145
146 bool hasCaymanISA() const {
147 return CaymanISA;
148 }
Matt Arsenaultfae02982014-03-17 18:58:11 +0000149
Matt Arsenaultf171cf22014-07-14 23:40:49 +0000150 bool hasFP32Denormals() const {
151 return FP32Denormals;
152 }
153
154 bool hasFP64Denormals() const {
155 return FP64Denormals;
156 }
157
Matt Arsenaultb035a572015-01-29 19:34:25 +0000158 bool hasFastFMAF32() const {
159 return FastFMAF32;
160 }
161
Matt Arsenaulte83690c2016-01-18 21:13:50 +0000162 bool hasHalfRate64Ops() const {
163 return HalfRate64Ops;
164 }
165
Matt Arsenault3f981402014-09-15 15:41:53 +0000166 bool hasFlatAddressSpace() const {
167 return FlatAddressSpace;
168 }
169
Changpeng Fangb41574a2015-12-22 20:55:23 +0000170 bool useFlatForGlobal() const {
171 return FlatForGlobal;
172 }
173
Matt Arsenaultfae02982014-03-17 18:58:11 +0000174 bool hasBFE() const {
175 return (getGeneration() >= EVERGREEN);
176 }
177
Matt Arsenault6e439652014-06-10 19:00:20 +0000178 bool hasBFI() const {
179 return (getGeneration() >= EVERGREEN);
180 }
181
Matt Arsenaultfae02982014-03-17 18:58:11 +0000182 bool hasBFM() const {
183 return hasBFE();
184 }
185
Matt Arsenault60425062014-06-10 19:18:28 +0000186 bool hasBCNT(unsigned Size) const {
187 if (Size == 32)
188 return (getGeneration() >= EVERGREEN);
189
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000190 if (Size == 64)
191 return (getGeneration() >= SOUTHERN_ISLANDS);
192
193 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000194 }
195
Tom Stellard50122a52014-04-07 19:45:41 +0000196 bool hasMulU24() const {
197 return (getGeneration() >= EVERGREEN);
198 }
199
200 bool hasMulI24() const {
201 return (getGeneration() >= SOUTHERN_ISLANDS ||
202 hasCaymanISA());
203 }
204
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000205 bool hasFFBL() const {
206 return (getGeneration() >= EVERGREEN);
207 }
208
209 bool hasFFBH() const {
210 return (getGeneration() >= EVERGREEN);
211 }
212
Jan Vesely808fff52015-04-30 17:15:56 +0000213 bool hasCARRY() const {
214 return (getGeneration() >= EVERGREEN);
215 }
216
217 bool hasBORROW() const {
218 return (getGeneration() >= EVERGREEN);
219 }
220
Matt Arsenaultd782d052014-06-27 17:57:00 +0000221 bool IsIRStructurizerEnabled() const {
222 return EnableIRStructurizer;
223 }
224
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000225 bool isPromoteAllocaEnabled() const {
226 return EnablePromoteAlloca;
227 }
228
Matt Arsenaultd782d052014-06-27 17:57:00 +0000229 bool isIfCvtEnabled() const {
230 return EnableIfCvt;
231 }
232
Matt Arsenault41033282014-10-10 22:01:59 +0000233 bool loadStoreOptEnabled() const {
234 return EnableLoadStoreOpt;
235 }
236
Matt Arsenault706f9302015-07-06 16:01:58 +0000237 bool unsafeDSOffsetFoldingEnabled() const {
238 return EnableUnsafeDSOffsetFolding;
239 }
240
Matt Arsenaultd782d052014-06-27 17:57:00 +0000241 unsigned getWavefrontSize() const {
242 return WavefrontSize;
243 }
244
Tom Stellarda40f9712014-01-22 21:55:43 +0000245 unsigned getStackEntrySize() const;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000246
247 bool hasCFAluBug() const {
248 assert(getGeneration() <= NORTHERN_ISLANDS);
249 return CFALUBug;
250 }
251
252 int getLocalMemorySize() const {
253 return LocalMemorySize;
254 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000255
Marek Olsak4d00dd22015-03-09 15:48:09 +0000256 bool hasSGPRInitBug() const {
257 return SGPRInitBug;
258 }
259
Tom Stellardec87f842015-05-25 16:15:54 +0000260 int getLDSBankCount() const {
261 return LDSBankCount;
262 }
263
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000264 unsigned getAmdKernelCodeChipID() const;
265
Tom Stellard347ac792015-06-26 21:15:07 +0000266 AMDGPU::IsaVersion getIsaVersion() const;
267
Craig Topper5656db42014-04-29 07:57:24 +0000268 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000269 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000270 }
271
Tom Stellard83f0bce2015-01-29 16:55:25 +0000272 void overrideSchedPolicy(MachineSchedPolicy &Policy,
273 MachineInstr *begin, MachineInstr *end,
274 unsigned NumRegionInstrs) const override;
275
Tom Stellard75aadc22012-12-11 21:25:42 +0000276 // Helper functions to simplify if statements
Matt Arsenaultd782d052014-06-27 17:57:00 +0000277 bool isTargetELF() const {
278 return false;
279 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000280
Matt Arsenaultd782d052014-06-27 17:57:00 +0000281 StringRef getDeviceName() const {
282 return DevName;
283 }
284
Tom Stellardc98ee202015-07-16 19:40:07 +0000285 bool enableHugeScratchBuffer() const {
286 return EnableHugeScratchBuffer;
287 }
288
Matt Arsenaultd782d052014-06-27 17:57:00 +0000289 bool dumpCode() const {
290 return DumpCode;
291 }
292 bool r600ALUEncoding() const {
293 return R600ALUInst;
294 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000295 bool isAmdHsaOS() const {
296 return TargetTriple.getOS() == Triple::AMDHSA;
297 }
Tom Stellarde99fb652015-01-20 19:33:04 +0000298 bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000299
Nicolai Haehnle5b504972016-01-04 23:35:53 +0000300 bool isXNACKEnabled() const {
301 return EnableXNACK;
302 }
303
Tom Stellard83f0bce2015-01-29 16:55:25 +0000304 unsigned getMaxWavesPerCU() const {
305 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
306 return 10;
307
308 // FIXME: Not sure what this is for other subtagets.
309 llvm_unreachable("do not know max waves per CU for this subtarget.");
310 }
Tom Stellardf6afc802015-02-04 23:14:18 +0000311
312 bool enableSubRegLiveness() const override {
Tom Stellard1ba52fe2015-06-04 01:20:04 +0000313 return true;
Tom Stellardf6afc802015-02-04 23:14:18 +0000314 }
Tom Stellardb5798b02015-06-26 21:15:03 +0000315
316 /// \brief Returns the offset in bytes from the start of the input buffer
317 /// of the first explicit kernel argument.
318 unsigned getExplicitKernelArgOffset() const {
319 return isAmdHsaOS() ? 0 : 36;
320 }
321
Matt Arsenault41003af2015-11-30 21:16:07 +0000322 unsigned getMaxNumUserSGPRs() const {
323 return 16;
324 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000325};
326
327} // End namespace llvm
328
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000329#endif