9c7bb88f8f4a60858f10450221190db33fdb0db5
[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   unsigned WavefrontSize;
80   bool CFALUBug;
81   int LocalMemorySize;
82   bool EnableVGPRSpilling;
83   bool SGPRInitBug;
84   bool IsGCN;
85   bool GCN1Encoding;
86   bool GCN3Encoding;
87   bool CIInsts;
88   bool FeatureDisable;
89   int LDSBankCount;
90   unsigned IsaVersion;
91   bool EnableHugeScratchBuffer;
92
93   std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
94   std::unique_ptr<AMDGPUTargetLowering> TLInfo;
95   std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
96   InstrItineraryData InstrItins;
97   Triple TargetTriple;
98
99 public:
100   AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
101                   TargetMachine &TM);
102   AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
103                                                    StringRef GPU, StringRef FS);
104
105   const AMDGPUFrameLowering *getFrameLowering() const override {
106     return FrameLowering.get();
107   }
108   const AMDGPUInstrInfo *getInstrInfo() const override {
109     return InstrInfo.get();
110   }
111   const AMDGPURegisterInfo *getRegisterInfo() const override {
112     return &InstrInfo->getRegisterInfo();
113   }
114   AMDGPUTargetLowering *getTargetLowering() const override {
115     return TLInfo.get();
116   }
117   const InstrItineraryData *getInstrItineraryData() const override {
118     return &InstrItins;
119   }
120
121   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
122
123   bool is64bit() const {
124     return Is64bit;
125   }
126
127   bool hasVertexCache() const {
128     return HasVertexCache;
129   }
130
131   short getTexVTXClauseSize() const {
132     return TexVTXClauseSize;
133   }
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   }
146
147   bool hasFP32Denormals() const {
148     return FP32Denormals;
149   }
150
151   bool hasFP64Denormals() const {
152     return FP64Denormals;
153   }
154
155   bool hasFastFMAF32() const {
156     return FastFMAF32;
157   }
158
159   bool hasFlatAddressSpace() const {
160     return FlatAddressSpace;
161   }
162
163   bool useFlatForGlobal() const {
164     return FlatForGlobal;
165   }
166
167   bool hasBFE() const {
168     return (getGeneration() >= EVERGREEN);
169   }
170
171   bool hasBFI() const {
172     return (getGeneration() >= EVERGREEN);
173   }
174
175   bool hasBFM() const {
176     return hasBFE();
177   }
178
179   bool hasBCNT(unsigned Size) const {
180     if (Size == 32)
181       return (getGeneration() >= EVERGREEN);
182
183     if (Size == 64)
184       return (getGeneration() >= SOUTHERN_ISLANDS);
185
186     return false;
187   }
188
189   bool hasMulU24() const {
190     return (getGeneration() >= EVERGREEN);
191   }
192
193   bool hasMulI24() const {
194     return (getGeneration() >= SOUTHERN_ISLANDS ||
195             hasCaymanISA());
196   }
197
198   bool hasFFBL() const {
199     return (getGeneration() >= EVERGREEN);
200   }
201
202   bool hasFFBH() const {
203     return (getGeneration() >= EVERGREEN);
204   }
205
206   bool hasCARRY() const {
207     return (getGeneration() >= EVERGREEN);
208   }
209
210   bool hasBORROW() const {
211     return (getGeneration() >= EVERGREEN);
212   }
213
214   bool IsIRStructurizerEnabled() const {
215     return EnableIRStructurizer;
216   }
217
218   bool isPromoteAllocaEnabled() const {
219     return EnablePromoteAlloca;
220   }
221
222   bool isIfCvtEnabled() const {
223     return EnableIfCvt;
224   }
225
226   bool loadStoreOptEnabled() const {
227     return EnableLoadStoreOpt;
228   }
229
230   bool unsafeDSOffsetFoldingEnabled() const {
231     return EnableUnsafeDSOffsetFolding;
232   }
233
234   unsigned getWavefrontSize() const {
235     return WavefrontSize;
236   }
237
238   unsigned getStackEntrySize() const;
239
240   bool hasCFAluBug() const {
241     assert(getGeneration() <= NORTHERN_ISLANDS);
242     return CFALUBug;
243   }
244
245   int getLocalMemorySize() const {
246     return LocalMemorySize;
247   }
248
249   bool hasSGPRInitBug() const {
250     return SGPRInitBug;
251   }
252
253   int getLDSBankCount() const {
254     return LDSBankCount;
255   }
256
257   unsigned getAmdKernelCodeChipID() const;
258
259   AMDGPU::IsaVersion getIsaVersion() const;
260
261   bool enableMachineScheduler() const override {
262     return true;
263   }
264
265   void overrideSchedPolicy(MachineSchedPolicy &Policy,
266                            MachineInstr *begin, MachineInstr *end,
267                            unsigned NumRegionInstrs) const override;
268
269   // Helper functions to simplify if statements
270   bool isTargetELF() const {
271     return false;
272   }
273
274   StringRef getDeviceName() const {
275     return DevName;
276   }
277
278   bool enableHugeScratchBuffer() const {
279     return EnableHugeScratchBuffer;
280   }
281
282   bool dumpCode() const {
283     return DumpCode;
284   }
285   bool r600ALUEncoding() const {
286     return R600ALUInst;
287   }
288   bool isAmdHsaOS() const {
289     return TargetTriple.getOS() == Triple::AMDHSA;
290   }
291   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
292
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   }
300
301   bool enableSubRegLiveness() const override {
302     return true;
303   }
304
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
311   unsigned getMaxNumUserSGPRs() const {
312     return 16;
313   }
314 };
315
316 } // End namespace llvm
317
318 #endif