blob: 27f269a95f9fb0135d3459409ed020b406765eb7 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//=====-- AMDGPUSubtarget.h - Define Subtarget for the AMDIL ---*- C++ -*-====//
2//
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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_R600_AMDGPUSUBTARGET_H
16#define LLVM_LIB_TARGET_R600_AMDGPUSUBTARGET_H
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000017#include "AMDGPU.h"
Eric Christopherac4b69e2014-07-25 22:22:39 +000018#include "AMDGPUFrameLowering.h"
Tom Stellard2e59a452014-06-13 01:32:00 +000019#include "AMDGPUInstrInfo.h"
Eric Christopherac4b69e2014-07-25 22:22:39 +000020#include "AMDGPUIntrinsicInfo.h"
21#include "AMDGPUSubtarget.h"
22#include "R600ISelLowering.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000023#include "llvm/ADT/StringExtras.h"
24#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 Stellard75aadc22012-12-11 21:25:42 +000051private:
Tom Stellard75aadc22012-12-11 21:25:42 +000052 std::string DevName;
53 bool Is64bit;
Tom Stellard75aadc22012-12-11 21:25:42 +000054 bool DumpCode;
55 bool R600ALUInst;
Vincent Lejeunec2991642013-04-30 00:13:39 +000056 bool HasVertexCache;
Vincent Lejeunef9f4e1e2013-05-17 16:49:55 +000057 short TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +000058 Generation Gen;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000059 bool FP64;
Matt Arsenaultf171cf22014-07-14 23:40:49 +000060 bool FP64Denormals;
61 bool FP32Denormals;
Matt Arsenaultb035a572015-01-29 19:34:25 +000062 bool FastFMAF32;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +000063 bool CaymanISA;
Matt Arsenault3f981402014-09-15 15:41:53 +000064 bool FlatAddressSpace;
Tom Stellarded0ceec2013-10-10 17:11:12 +000065 bool EnableIRStructurizer;
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000066 bool EnablePromoteAlloca;
Tom Stellard783893a2013-11-18 19:43:33 +000067 bool EnableIfCvt;
Matt Arsenault41033282014-10-10 22:01:59 +000068 bool EnableLoadStoreOpt;
Tom Stellard8c347b02014-01-22 21:55:40 +000069 unsigned WavefrontSize;
Tom Stellard348273d2014-01-23 16:18:02 +000070 bool CFALUBug;
Tom Stellard880a80a2014-06-17 16:53:14 +000071 int LocalMemorySize;
Tom Stellarde99fb652015-01-20 19:33:04 +000072 bool EnableVGPRSpilling;
Marek Olsak4d00dd22015-03-09 15:48:09 +000073 bool SGPRInitBug;
Tom Stellardd7e6f132015-04-08 01:09:26 +000074 bool IsGCN;
75 bool GCN1Encoding;
76 bool GCN3Encoding;
Tom Stellardd1f0f022015-04-23 19:33:54 +000077 bool CIInsts;
78 bool FeatureDisable;
Tom Stellardec87f842015-05-25 16:15:54 +000079 int LDSBankCount;
Tom Stellard75aadc22012-12-11 21:25:42 +000080
Eric Christopherac4b69e2014-07-25 22:22:39 +000081 AMDGPUFrameLowering FrameLowering;
Eric Christopherac4b69e2014-07-25 22:22:39 +000082 std::unique_ptr<AMDGPUTargetLowering> TLInfo;
83 std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +000084 InstrItineraryData InstrItins;
Tom Stellard794c8c02014-12-02 17:05:41 +000085 Triple TargetTriple;
Tom Stellard75aadc22012-12-11 21:25:42 +000086
87public:
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000088 AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
89 TargetMachine &TM);
90 AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
91 StringRef GPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +000092
Eric Christopherd9134482014-08-04 21:25:23 +000093 const AMDGPUFrameLowering *getFrameLowering() const override {
94 return &FrameLowering;
95 }
96 const AMDGPUInstrInfo *getInstrInfo() const override {
97 return InstrInfo.get();
98 }
99 const AMDGPURegisterInfo *getRegisterInfo() const override {
Eric Christopherac4b69e2014-07-25 22:22:39 +0000100 return &InstrInfo->getRegisterInfo();
Tom Stellard2e59a452014-06-13 01:32:00 +0000101 }
Eric Christopherd9134482014-08-04 21:25:23 +0000102 AMDGPUTargetLowering *getTargetLowering() const override {
103 return TLInfo.get();
104 }
Eric Christopherd9134482014-08-04 21:25:23 +0000105 const InstrItineraryData *getInstrItineraryData() const override {
106 return &InstrItins;
107 }
Matt Arsenaultd782d052014-06-27 17:57:00 +0000108
Craig Topperee7b0f32014-04-30 05:53:27 +0000109 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
Tom Stellard75aadc22012-12-11 21:25:42 +0000110
Matt Arsenaultd782d052014-06-27 17:57:00 +0000111 bool is64bit() const {
112 return Is64bit;
113 }
114
115 bool hasVertexCache() const {
116 return HasVertexCache;
117 }
118
119 short getTexVTXClauseSize() const {
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000120 return TexVTXClauseSize;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000121 }
122
123 Generation getGeneration() const {
124 return Gen;
125 }
126
127 bool hasHWFP64() const {
128 return FP64;
129 }
130
131 bool hasCaymanISA() const {
132 return CaymanISA;
133 }
Matt Arsenaultfae02982014-03-17 18:58:11 +0000134
Matt Arsenaultf171cf22014-07-14 23:40:49 +0000135 bool hasFP32Denormals() const {
136 return FP32Denormals;
137 }
138
139 bool hasFP64Denormals() const {
140 return FP64Denormals;
141 }
142
Matt Arsenaultb035a572015-01-29 19:34:25 +0000143 bool hasFastFMAF32() const {
144 return FastFMAF32;
145 }
146
Matt Arsenault3f981402014-09-15 15:41:53 +0000147 bool hasFlatAddressSpace() const {
148 return FlatAddressSpace;
149 }
150
Matt Arsenaultfae02982014-03-17 18:58:11 +0000151 bool hasBFE() const {
152 return (getGeneration() >= EVERGREEN);
153 }
154
Matt Arsenault6e439652014-06-10 19:00:20 +0000155 bool hasBFI() const {
156 return (getGeneration() >= EVERGREEN);
157 }
158
Matt Arsenaultfae02982014-03-17 18:58:11 +0000159 bool hasBFM() const {
160 return hasBFE();
161 }
162
Matt Arsenault60425062014-06-10 19:18:28 +0000163 bool hasBCNT(unsigned Size) const {
164 if (Size == 32)
165 return (getGeneration() >= EVERGREEN);
166
Matt Arsenault3dd43fc2014-07-18 06:07:13 +0000167 if (Size == 64)
168 return (getGeneration() >= SOUTHERN_ISLANDS);
169
170 return false;
Matt Arsenault60425062014-06-10 19:18:28 +0000171 }
172
Tom Stellard50122a52014-04-07 19:45:41 +0000173 bool hasMulU24() const {
174 return (getGeneration() >= EVERGREEN);
175 }
176
177 bool hasMulI24() const {
178 return (getGeneration() >= SOUTHERN_ISLANDS ||
179 hasCaymanISA());
180 }
181
Jan Vesely6ddb8dd2014-07-15 15:51:09 +0000182 bool hasFFBL() const {
183 return (getGeneration() >= EVERGREEN);
184 }
185
186 bool hasFFBH() const {
187 return (getGeneration() >= EVERGREEN);
188 }
189
Jan Vesely808fff52015-04-30 17:15:56 +0000190 bool hasCARRY() const {
191 return (getGeneration() >= EVERGREEN);
192 }
193
194 bool hasBORROW() const {
195 return (getGeneration() >= EVERGREEN);
196 }
197
Matt Arsenaultd782d052014-06-27 17:57:00 +0000198 bool IsIRStructurizerEnabled() const {
199 return EnableIRStructurizer;
200 }
201
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +0000202 bool isPromoteAllocaEnabled() const {
203 return EnablePromoteAlloca;
204 }
205
Matt Arsenaultd782d052014-06-27 17:57:00 +0000206 bool isIfCvtEnabled() const {
207 return EnableIfCvt;
208 }
209
Matt Arsenault41033282014-10-10 22:01:59 +0000210 bool loadStoreOptEnabled() const {
211 return EnableLoadStoreOpt;
212 }
213
Matt Arsenaultd782d052014-06-27 17:57:00 +0000214 unsigned getWavefrontSize() const {
215 return WavefrontSize;
216 }
217
Tom Stellarda40f9712014-01-22 21:55:43 +0000218 unsigned getStackEntrySize() const;
Matt Arsenaultd782d052014-06-27 17:57:00 +0000219
220 bool hasCFAluBug() const {
221 assert(getGeneration() <= NORTHERN_ISLANDS);
222 return CFALUBug;
223 }
224
225 int getLocalMemorySize() const {
226 return LocalMemorySize;
227 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000228
Marek Olsak4d00dd22015-03-09 15:48:09 +0000229 bool hasSGPRInitBug() const {
230 return SGPRInitBug;
231 }
232
Tom Stellardec87f842015-05-25 16:15:54 +0000233 int getLDSBankCount() const {
234 return LDSBankCount;
235 }
236
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000237 unsigned getAmdKernelCodeChipID() const;
238
Craig Topper5656db42014-04-29 07:57:24 +0000239 bool enableMachineScheduler() const override {
Tom Stellard83f0bce2015-01-29 16:55:25 +0000240 return true;
Andrew Trick978674b2013-09-20 05:14:41 +0000241 }
242
Tom Stellard83f0bce2015-01-29 16:55:25 +0000243 void overrideSchedPolicy(MachineSchedPolicy &Policy,
244 MachineInstr *begin, MachineInstr *end,
245 unsigned NumRegionInstrs) const override;
246
Tom Stellard75aadc22012-12-11 21:25:42 +0000247 // Helper functions to simplify if statements
Matt Arsenaultd782d052014-06-27 17:57:00 +0000248 bool isTargetELF() const {
249 return false;
250 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000251
Matt Arsenaultd782d052014-06-27 17:57:00 +0000252 StringRef getDeviceName() const {
253 return DevName;
254 }
255
256 bool dumpCode() const {
257 return DumpCode;
258 }
259 bool r600ALUEncoding() const {
260 return R600ALUInst;
261 }
Tom Stellard794c8c02014-12-02 17:05:41 +0000262 bool isAmdHsaOS() const {
263 return TargetTriple.getOS() == Triple::AMDHSA;
264 }
Tom Stellarde99fb652015-01-20 19:33:04 +0000265 bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000266
267 unsigned getMaxWavesPerCU() const {
268 if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
269 return 10;
270
271 // FIXME: Not sure what this is for other subtagets.
272 llvm_unreachable("do not know max waves per CU for this subtarget.");
273 }
Tom Stellardf6afc802015-02-04 23:14:18 +0000274
275 bool enableSubRegLiveness() const override {
Tom Stellard1ba52fe2015-06-04 01:20:04 +0000276 return true;
Tom Stellardf6afc802015-02-04 23:14:18 +0000277 }
Tom Stellardb5798b02015-06-26 21:15:03 +0000278
279 /// \brief Returns the offset in bytes from the start of the input buffer
280 /// of the first explicit kernel argument.
281 unsigned getExplicitKernelArgOffset() const {
282 return isAmdHsaOS() ? 0 : 36;
283 }
284
Tom Stellard75aadc22012-12-11 21:25:42 +0000285};
286
287} // End namespace llvm
288
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000289#endif