blob: 9c7bb88f8f4a60858f10450221190db33fdb0db5 [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,
56 ISAVersion8_0_1
57 };
58
Tom Stellard75aadc22012-12-11 21:25:42 +000059private:
Tom Stellard75aadc22012-12-11 21:25:42 +000060 std::string DevName;
61 bool Is64bit;
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 Arsenaultb035a572015-01-29 19:34:25 +000070 bool FastFMAF32;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000071 bool CaymanISA;
Matt Arsenault3f981402014-09-15 15:41:53 +000072 bool FlatAddressSpace;
Changpeng Fangb41574a2015-12-22 20:55:23 +000073 bool FlatForGlobal;
Tom Stellarded0ceec2013-10-10 17:11:12 +000074 bool EnableIRStructurizer;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000075 bool EnablePromoteAlloca;
Tom Stellard783893a2013-11-18 19:43:33 +000076 bool EnableIfCvt;
Matt Arsenault41033282014-10-10 22:01:59 +000077 bool EnableLoadStoreOpt;
Matt Arsenault706f9302015-07-06 16:01:58 +000078 bool EnableUnsafeDSOffsetFolding;
Tom Stellard8c347b02014-01-22 21:55:40 +000079 unsigned WavefrontSize;
Tom Stellard348273d2014-01-23 16:18:02 +000080 bool CFALUBug;
Tom Stellard880a80a2014-06-17 16:53:14 +000081 int LocalMemorySize;
Tom Stellarde99fb652015-01-20 19:33:04 +000082 bool EnableVGPRSpilling;
Marek Olsak4d00dd22015-03-09 15:48:09 +000083 bool SGPRInitBug;
Tom Stellardd7e6f132015-04-08 01:09:26 +000084 bool IsGCN;
85 bool GCN1Encoding;
86 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +000087 bool CIInsts;
88 bool FeatureDisable;
Tom Stellardec87f842015-05-25 16:15:54 +000089 int LDSBankCount;
Matt Arsenaultf59e5382015-11-06 18:23:00 +000090 unsigned IsaVersion;
Tom Stellardc98ee202015-07-16 19:40:07 +000091 bool EnableHugeScratchBuffer;
Tom Stellard75aadc22012-12-11 21:25:42 +000092
Matt Arsenault0c90e952015-11-06 18:17:45 +000093 std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
Eric Christopherac4b69e2014-07-25 22:22:39 +000094 std::unique_ptr<AMDGPUTargetLowering> TLInfo;
95 std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +000096 InstrItineraryData InstrItins;
Tom Stellard794c8c02014-12-02 17:05:41 +000097 Triple TargetTriple;
Tom Stellard75aadc22012-12-11 21:25:42 +000098
99public:
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000100 AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
101 TargetMachine &TM);
102 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
103 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000104
Eric Christopherd9134482014-08-04 21:25:23 +0000105 const AMDGPUFrameLowering *getFrameLowering() const override {
Matt Arsenault0c90e952015-11-06 18:17:45 +0000106 return FrameLowering.get();
Eric Christopherd9134482014-08-04 21:25:23 +0000107 }
108 const AMDGPUInstrInfo *getInstrInfo() const override {
109 return InstrInfo.get();
110 }
111 const AMDGPURegisterInfo *getRegisterInfo() const override {
Eric Christopherac4b69e2014-07-25 22:22:39 +0000112 return &InstrInfo->getRegisterInfo();
Tom Stellard2e59a452014-06-13 01:32:00 +0000113 }
Eric Christopherd9134482014-08-04 21:25:23 +0000114 AMDGPUTargetLowering *getTargetLowering() const override {
115 return TLInfo.get();
116 }
Eric Christopherd9134482014-08-04 21:25:23 +0000117 const InstrItineraryData *getInstrItineraryData() const override {
118 return &InstrItins;
119 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000120
Craig Topperee7b0f32014-04-30 05:53:27 +0000121 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000122
Matt Arsenaultd782d052014-06-27 17:57:00 +0000123 bool is64bit() const {
124 return Is64bit;
125 }
126
127 bool hasVertexCache() const {
128 return HasVertexCache;
129 }
130
131 short getTexVTXClauseSize() const {
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000132 return TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000133 }
134
135 Generation getGeneration() const {
136 return Gen;
137 }
138
139 bool hasHWFP64() const {
140 return FP64;
141 }
142
143 bool hasCaymanISA() const {
144 return CaymanISA;
145 }
Matt Arsenaultfae02982014-03-17 18:58:11 +0000146
Matt Arsenaultf171cf22014-07-14 23:40:49 +0000147 bool hasFP32Denormals() const {
148 return FP32Denormals;
149 }
150
151 bool hasFP64Denormals() const {
152 return FP64Denormals;
153 }
154
Matt Arsenaultb035a572015-01-29 19:34:25 +0000155 bool hasFastFMAF32() const {
156 return FastFMAF32;
157 }
158
Matt Arsenault3f981402014-09-15 15:41:53 +0000159 bool hasFlatAddressSpace() const {
160 return FlatAddressSpace;
161 }
162
Changpeng Fangb41574a2015-12-22 20:55:23 +0000163 bool useFlatForGlobal() const {
164 return FlatForGlobal;
165 }
166
Matt Arsenaultfae02982014-03-17 18:58:11 +0000167 bool hasBFE() const {
168 return (getGeneration() >= EVERGREEN);
169 }
170
Matt Arsenault6e439652014-06-10 19:00:20 +0000171 bool hasBFI() const {
172 return (getGeneration() >= EVERGREEN);
173 }
174
Matt Arsenaultfae02982014-03-17 18:58:11 +0000175 bool hasBFM() const {
176 return hasBFE();
177 }
178
Matt Arsenault60425062014-06-10 19:18:28 +0000179 bool hasBCNT(unsigned Size) const {
180 if (Size == 32)
181 return (getGeneration() >= EVERGREEN);
182
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000183 if (Size == 64)
184 return (getGeneration() >= SOUTHERN_ISLANDS);
185
186 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000187 }
188
Tom Stellard50122a52014-04-07 19:45:41 +0000189 bool hasMulU24() const {
190 return (getGeneration() >= EVERGREEN);
191 }
192
193 bool hasMulI24() const {
194 return (getGeneration() >= SOUTHERN_ISLANDS ||
195 hasCaymanISA());
196 }
197
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000198 bool hasFFBL() const {
199 return (getGeneration() >= EVERGREEN);
200 }
201
202 bool hasFFBH() const {
203 return (getGeneration() >= EVERGREEN);
204 }
205
Jan Vesely808fff52015-04-30 17:15:56 +0000206 bool hasCARRY() const {
207 return (getGeneration() >= EVERGREEN);
208 }
209
210 bool hasBORROW() const {
211 return (getGeneration() >= EVERGREEN);
212 }
213
Matt Arsenaultd782d052014-06-27 17:57:00 +0000214 bool IsIRStructurizerEnabled() const {
215 return EnableIRStructurizer;
216 }
217
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000218 bool isPromoteAllocaEnabled() const {
219 return EnablePromoteAlloca;
220 }
221
Matt Arsenaultd782d052014-06-27 17:57:00 +0000222 bool isIfCvtEnabled() const {
223 return EnableIfCvt;
224 }
225
Matt Arsenault41033282014-10-10 22:01:59 +0000226 bool loadStoreOptEnabled() const {
227 return EnableLoadStoreOpt;
228 }
229
Matt Arsenault706f9302015-07-06 16:01:58 +0000230 bool unsafeDSOffsetFoldingEnabled() const {
231 return EnableUnsafeDSOffsetFolding;
232 }
233
Matt Arsenaultd782d052014-06-27 17:57:00 +0000234 unsigned getWavefrontSize() const {
235 return WavefrontSize;
236 }
237
Tom Stellarda40f9712014-01-22 21:55:43 +0000238 unsigned getStackEntrySize() const;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000239
240 bool hasCFAluBug() const {
241 assert(getGeneration() <= NORTHERN_ISLANDS);
242 return CFALUBug;
243 }
244
245 int getLocalMemorySize() const {
246 return LocalMemorySize;
247 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000248
Marek Olsak4d00dd22015-03-09 15:48:09 +0000249 bool hasSGPRInitBug() const {
250 return SGPRInitBug;
251 }
252
Tom Stellardec87f842015-05-25 16:15:54 +0000253 int getLDSBankCount() const {
254 return LDSBankCount;
255 }
256
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000257 unsigned getAmdKernelCodeChipID() const;
258
Tom Stellard347ac792015-06-26 21:15:07 +0000259 AMDGPU::IsaVersion getIsaVersion() const;
260
Craig Topper5656db42014-04-29 07:57:24 +0000261 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000262 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000263 }
264
Tom Stellard83f0bce2015-01-29 16:55:25 +0000265 void overrideSchedPolicy(MachineSchedPolicy &Policy,
266 MachineInstr *begin, MachineInstr *end,
267 unsigned NumRegionInstrs) const override;
268
Tom Stellard75aadc22012-12-11 21:25:42 +0000269 // Helper functions to simplify if statements
Matt Arsenaultd782d052014-06-27 17:57:00 +0000270 bool isTargetELF() const {
271 return false;
272 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000273
Matt Arsenaultd782d052014-06-27 17:57:00 +0000274 StringRef getDeviceName() const {
275 return DevName;
276 }
277
Tom Stellardc98ee202015-07-16 19:40:07 +0000278 bool enableHugeScratchBuffer() const {
279 return EnableHugeScratchBuffer;
280 }
281
Matt Arsenaultd782d052014-06-27 17:57:00 +0000282 bool dumpCode() const {
283 return DumpCode;
284 }
285 bool r600ALUEncoding() const {
286 return R600ALUInst;
287 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000288 bool isAmdHsaOS() const {
289 return TargetTriple.getOS() == Triple::AMDHSA;
290 }
Tom Stellarde99fb652015-01-20 19:33:04 +0000291 bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000292
293 unsigned getMaxWavesPerCU() const {
294 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
295 return 10;
296
297 // FIXME: Not sure what this is for other subtagets.
298 llvm_unreachable("do not know max waves per CU for this subtarget.");
299 }
Tom Stellardf6afc802015-02-04 23:14:18 +0000300
301 bool enableSubRegLiveness() const override {
Tom Stellard1ba52fe2015-06-04 01:20:04 +0000302 return true;
Tom Stellardf6afc802015-02-04 23:14:18 +0000303 }
Tom Stellardb5798b02015-06-26 21:15:03 +0000304
305 /// \brief Returns the offset in bytes from the start of the input buffer
306 /// of the first explicit kernel argument.
307 unsigned getExplicitKernelArgOffset() const {
308 return isAmdHsaOS() ? 0 : 36;
309 }
310
Matt Arsenault41003af2015-11-30 21:16:07 +0000311 unsigned getMaxNumUserSGPRs() const {
312 return 16;
313 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000314};
315
316} // End namespace llvm
317
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000318#endif