Merging r257648:
[oota-llvm.git] / lib / Target / AMDGPU / AMDGPUSubtarget.h
1 //=====-- AMDGPUSubtarget.h - Define Subtarget for AMDGPU ------*- 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
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
17
18 #include "AMDGPU.h"
19 #include "AMDGPUFrameLowering.h"
20 #include "AMDGPUInstrInfo.h"
21 #include "AMDGPUISelLowering.h"
22 #include "AMDGPUSubtarget.h"
23 #include "Utils/AMDGPUBaseInfo.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Target/TargetSubtargetInfo.h"
26
27 #define GET_SUBTARGETINFO_HEADER
28 #include "AMDGPUGenSubtargetInfo.inc"
29
30 namespace llvm {
31
32 class SIMachineFunctionInfo;
33
34 class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
35
36 public:
37   enum Generation {
38     R600 = 0,
39     R700,
40     EVERGREEN,
41     NORTHERN_ISLANDS,
42     SOUTHERN_ISLANDS,
43     SEA_ISLANDS,
44     VOLCANIC_ISLANDS,
45   };
46
47   enum {
48     FIXED_SGPR_COUNT_FOR_INIT_BUG = 80
49   };
50
51   enum {
52     ISAVersion0_0_0,
53     ISAVersion7_0_0,
54     ISAVersion7_0_1,
55     ISAVersion8_0_0,
56     ISAVersion8_0_1
57   };
58
59 private:
60   std::string DevName;
61   bool Is64bit;
62   bool DumpCode;
63   bool R600ALUInst;
64   bool HasVertexCache;
65   short TexVTXClauseSize;
66   Generation Gen;
67   bool FP64;
68   bool FP64Denormals;
69   bool FP32Denormals;
70   bool FastFMAF32;
71   bool CaymanISA;
72   bool FlatAddressSpace;
73   bool FlatForGlobal;
74   bool EnableIRStructurizer;
75   bool EnablePromoteAlloca;
76   bool EnableIfCvt;
77   bool EnableLoadStoreOpt;
78   bool EnableUnsafeDSOffsetFolding;
79   bool EnableXNACK;
80   unsigned WavefrontSize;
81   bool CFALUBug;
82   int LocalMemorySize;
83   bool EnableVGPRSpilling;
84   bool SGPRInitBug;
85   bool IsGCN;
86   bool GCN1Encoding;
87   bool GCN3Encoding;
88   bool CIInsts;
89   bool FeatureDisable;
90   int LDSBankCount;
91   unsigned IsaVersion;
92   bool EnableHugeScratchBuffer;
93
94   std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
95   std::unique_ptr<AMDGPUTargetLowering> TLInfo;
96   std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
97   InstrItineraryData InstrItins;
98   Triple TargetTriple;
99
100 public:
101   AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
102                   TargetMachine &TM);
103   AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
104                                                    StringRef GPU, StringRef FS);
105
106   const AMDGPUFrameLowering *getFrameLowering() const override {
107     return FrameLowering.get();
108   }
109   const AMDGPUInstrInfo *getInstrInfo() const override {
110     return InstrInfo.get();
111   }
112   const AMDGPURegisterInfo *getRegisterInfo() const override {
113     return &InstrInfo->getRegisterInfo();
114   }
115   AMDGPUTargetLowering *getTargetLowering() const override {
116     return TLInfo.get();
117   }
118   const InstrItineraryData *getInstrItineraryData() const override {
119     return &InstrItins;
120   }
121
122   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
123
124   bool is64bit() const {
125     return Is64bit;
126   }
127
128   bool hasVertexCache() const {
129     return HasVertexCache;
130   }
131
132   short getTexVTXClauseSize() const {
133     return TexVTXClauseSize;
134   }
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   }
147
148   bool hasFP32Denormals() const {
149     return FP32Denormals;
150   }
151
152   bool hasFP64Denormals() const {
153     return FP64Denormals;
154   }
155
156   bool hasFastFMAF32() const {
157     return FastFMAF32;
158   }
159
160   bool hasFlatAddressSpace() const {
161     return FlatAddressSpace;
162   }
163
164   bool useFlatForGlobal() const {
165     return FlatForGlobal;
166   }
167
168   bool hasBFE() const {
169     return (getGeneration() >= EVERGREEN);
170   }
171
172   bool hasBFI() const {
173     return (getGeneration() >= EVERGREEN);
174   }
175
176   bool hasBFM() const {
177     return hasBFE();
178   }
179
180   bool hasBCNT(unsigned Size) const {
181     if (Size == 32)
182       return (getGeneration() >= EVERGREEN);
183
184     if (Size == 64)
185       return (getGeneration() >= SOUTHERN_ISLANDS);
186
187     return false;
188   }
189
190   bool hasMulU24() const {
191     return (getGeneration() >= EVERGREEN);
192   }
193
194   bool hasMulI24() const {
195     return (getGeneration() >= SOUTHERN_ISLANDS ||
196             hasCaymanISA());
197   }
198
199   bool hasFFBL() const {
200     return (getGeneration() >= EVERGREEN);
201   }
202
203   bool hasFFBH() const {
204     return (getGeneration() >= EVERGREEN);
205   }
206
207   bool hasCARRY() const {
208     return (getGeneration() >= EVERGREEN);
209   }
210
211   bool hasBORROW() const {
212     return (getGeneration() >= EVERGREEN);
213   }
214
215   bool IsIRStructurizerEnabled() const {
216     return EnableIRStructurizer;
217   }
218
219   bool isPromoteAllocaEnabled() const {
220     return EnablePromoteAlloca;
221   }
222
223   bool isIfCvtEnabled() const {
224     return EnableIfCvt;
225   }
226
227   bool loadStoreOptEnabled() const {
228     return EnableLoadStoreOpt;
229   }
230
231   bool unsafeDSOffsetFoldingEnabled() const {
232     return EnableUnsafeDSOffsetFolding;
233   }
234
235   unsigned getWavefrontSize() const {
236     return WavefrontSize;
237   }
238
239   unsigned getStackEntrySize() const;
240
241   bool hasCFAluBug() const {
242     assert(getGeneration() <= NORTHERN_ISLANDS);
243     return CFALUBug;
244   }
245
246   int getLocalMemorySize() const {
247     return LocalMemorySize;
248   }
249
250   bool hasSGPRInitBug() const {
251     return SGPRInitBug;
252   }
253
254   int getLDSBankCount() const {
255     return LDSBankCount;
256   }
257
258   unsigned getAmdKernelCodeChipID() const;
259
260   AMDGPU::IsaVersion getIsaVersion() const;
261
262   bool enableMachineScheduler() const override {
263     return true;
264   }
265
266   void overrideSchedPolicy(MachineSchedPolicy &Policy,
267                            MachineInstr *begin, MachineInstr *end,
268                            unsigned NumRegionInstrs) const override;
269
270   // Helper functions to simplify if statements
271   bool isTargetELF() const {
272     return false;
273   }
274
275   StringRef getDeviceName() const {
276     return DevName;
277   }
278
279   bool enableHugeScratchBuffer() const {
280     return EnableHugeScratchBuffer;
281   }
282
283   bool dumpCode() const {
284     return DumpCode;
285   }
286   bool r600ALUEncoding() const {
287     return R600ALUInst;
288   }
289   bool isAmdHsaOS() const {
290     return TargetTriple.getOS() == Triple::AMDHSA;
291   }
292   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
293
294   bool isXNACKEnabled() const {
295     return EnableXNACK;
296   }
297
298   unsigned getMaxWavesPerCU() const {
299     if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
300       return 10;
301
302     // FIXME: Not sure what this is for other subtagets.
303     llvm_unreachable("do not know max waves per CU for this subtarget.");
304   }
305
306   bool enableSubRegLiveness() const override {
307     return true;
308   }
309
310   /// \brief Returns the offset in bytes from the start of the input buffer
311   ///        of the first explicit kernel argument.
312   unsigned getExplicitKernelArgOffset() const {
313     return isAmdHsaOS() ? 0 : 36;
314   }
315
316   unsigned getMaxNumUserSGPRs() const {
317     return 16;
318   }
319 };
320
321 } // End namespace llvm
322
323 #endif