4796e9ef3454dfe64849736419b5c7e842510bb1
[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   bool EnableSIScheduler;
94
95   std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
96   std::unique_ptr<AMDGPUTargetLowering> TLInfo;
97   std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
98   InstrItineraryData InstrItins;
99   Triple TargetTriple;
100
101 public:
102   AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
103                   TargetMachine &TM);
104   AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
105                                                    StringRef GPU, StringRef FS);
106
107   const AMDGPUFrameLowering *getFrameLowering() const override {
108     return FrameLowering.get();
109   }
110   const AMDGPUInstrInfo *getInstrInfo() const override {
111     return InstrInfo.get();
112   }
113   const AMDGPURegisterInfo *getRegisterInfo() const override {
114     return &InstrInfo->getRegisterInfo();
115   }
116   AMDGPUTargetLowering *getTargetLowering() const override {
117     return TLInfo.get();
118   }
119   const InstrItineraryData *getInstrItineraryData() const override {
120     return &InstrItins;
121   }
122
123   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
124
125   bool is64bit() const {
126     return Is64bit;
127   }
128
129   bool hasVertexCache() const {
130     return HasVertexCache;
131   }
132
133   short getTexVTXClauseSize() const {
134     return TexVTXClauseSize;
135   }
136
137   Generation getGeneration() const {
138     return Gen;
139   }
140
141   bool hasHWFP64() const {
142     return FP64;
143   }
144
145   bool hasCaymanISA() const {
146     return CaymanISA;
147   }
148
149   bool hasFP32Denormals() const {
150     return FP32Denormals;
151   }
152
153   bool hasFP64Denormals() const {
154     return FP64Denormals;
155   }
156
157   bool hasFastFMAF32() const {
158     return FastFMAF32;
159   }
160
161   bool hasFlatAddressSpace() const {
162     return FlatAddressSpace;
163   }
164
165   bool useFlatForGlobal() const {
166     return FlatForGlobal;
167   }
168
169   bool hasBFE() const {
170     return (getGeneration() >= EVERGREEN);
171   }
172
173   bool hasBFI() const {
174     return (getGeneration() >= EVERGREEN);
175   }
176
177   bool hasBFM() const {
178     return hasBFE();
179   }
180
181   bool hasBCNT(unsigned Size) const {
182     if (Size == 32)
183       return (getGeneration() >= EVERGREEN);
184
185     if (Size == 64)
186       return (getGeneration() >= SOUTHERN_ISLANDS);
187
188     return false;
189   }
190
191   bool hasMulU24() const {
192     return (getGeneration() >= EVERGREEN);
193   }
194
195   bool hasMulI24() const {
196     return (getGeneration() >= SOUTHERN_ISLANDS ||
197             hasCaymanISA());
198   }
199
200   bool hasFFBL() const {
201     return (getGeneration() >= EVERGREEN);
202   }
203
204   bool hasFFBH() const {
205     return (getGeneration() >= EVERGREEN);
206   }
207
208   bool hasCARRY() const {
209     return (getGeneration() >= EVERGREEN);
210   }
211
212   bool hasBORROW() const {
213     return (getGeneration() >= EVERGREEN);
214   }
215
216   bool IsIRStructurizerEnabled() const {
217     return EnableIRStructurizer;
218   }
219
220   bool isPromoteAllocaEnabled() const {
221     return EnablePromoteAlloca;
222   }
223
224   bool isIfCvtEnabled() const {
225     return EnableIfCvt;
226   }
227
228   bool loadStoreOptEnabled() const {
229     return EnableLoadStoreOpt;
230   }
231
232   bool unsafeDSOffsetFoldingEnabled() const {
233     return EnableUnsafeDSOffsetFolding;
234   }
235
236   unsigned getWavefrontSize() const {
237     return WavefrontSize;
238   }
239
240   unsigned getStackEntrySize() const;
241
242   bool hasCFAluBug() const {
243     assert(getGeneration() <= NORTHERN_ISLANDS);
244     return CFALUBug;
245   }
246
247   int getLocalMemorySize() const {
248     return LocalMemorySize;
249   }
250
251   bool hasSGPRInitBug() const {
252     return SGPRInitBug;
253   }
254
255   int getLDSBankCount() const {
256     return LDSBankCount;
257   }
258
259   unsigned getAmdKernelCodeChipID() const;
260
261   AMDGPU::IsaVersion getIsaVersion() const;
262
263   bool enableMachineScheduler() const override {
264     return true;
265   }
266
267   void overrideSchedPolicy(MachineSchedPolicy &Policy,
268                            MachineInstr *begin, MachineInstr *end,
269                            unsigned NumRegionInstrs) const override;
270
271   // Helper functions to simplify if statements
272   bool isTargetELF() const {
273     return false;
274   }
275
276   StringRef getDeviceName() const {
277     return DevName;
278   }
279
280   bool enableHugeScratchBuffer() const {
281     return EnableHugeScratchBuffer;
282   }
283
284   bool enableSIScheduler() const {
285     return EnableSIScheduler;
286   }
287
288   bool dumpCode() const {
289     return DumpCode;
290   }
291   bool r600ALUEncoding() const {
292     return R600ALUInst;
293   }
294   bool isAmdHsaOS() const {
295     return TargetTriple.getOS() == Triple::AMDHSA;
296   }
297   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
298
299   bool isXNACKEnabled() const {
300     return EnableXNACK;
301   }
302
303   unsigned getMaxWavesPerCU() const {
304     if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
305       return 10;
306
307     // FIXME: Not sure what this is for other subtagets.
308     llvm_unreachable("do not know max waves per CU for this subtarget.");
309   }
310
311   bool enableSubRegLiveness() const override {
312     return true;
313   }
314
315   /// \brief Returns the offset in bytes from the start of the input buffer
316   ///        of the first explicit kernel argument.
317   unsigned getExplicitKernelArgOffset() const {
318     return isAmdHsaOS() ? 0 : 36;
319   }
320
321   unsigned getMaxNumUserSGPRs() const {
322     return 16;
323   }
324 };
325
326 } // End namespace llvm
327
328 #endif