90831bfb4458c9e5063c5d11078f81ea9ee8f4a3
[oota-llvm.git] / lib / Target / AMDGPU / AMDGPUSubtarget.h
1 //=====-- 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
15 #ifndef LLVM_LIB_TARGET_R600_AMDGPUSUBTARGET_H
16 #define LLVM_LIB_TARGET_R600_AMDGPUSUBTARGET_H
17 #include "AMDGPU.h"
18 #include "AMDGPUFrameLowering.h"
19 #include "AMDGPUInstrInfo.h"
20 #include "AMDGPUIntrinsicInfo.h"
21 #include "AMDGPUSubtarget.h"
22 #include "R600ISelLowering.h"
23 #include "AMDKernelCodeT.h"
24 #include "Utils/AMDGPUBaseInfo.h"
25 #include "llvm/ADT/StringExtras.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/Target/TargetSubtargetInfo.h"
28
29 #define GET_SUBTARGETINFO_HEADER
30 #include "AMDGPUGenSubtargetInfo.inc"
31
32 namespace llvm {
33
34 class SIMachineFunctionInfo;
35
36 class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
37
38 public:
39   enum Generation {
40     R600 = 0,
41     R700,
42     EVERGREEN,
43     NORTHERN_ISLANDS,
44     SOUTHERN_ISLANDS,
45     SEA_ISLANDS,
46     VOLCANIC_ISLANDS,
47   };
48
49   enum {
50     FIXED_SGPR_COUNT_FOR_INIT_BUG = 80
51   };
52
53   enum {
54     ISAVersion0_0_0,
55     ISAVersion7_0_0,
56     ISAVersion7_0_1,
57     ISAVersion8_0_0,
58     ISAVersion8_0_1
59   };
60
61 private:
62   std::string DevName;
63   bool Is64bit;
64   bool DumpCode;
65   bool R600ALUInst;
66   bool HasVertexCache;
67   short TexVTXClauseSize;
68   Generation Gen;
69   bool FP64;
70   bool FP64Denormals;
71   bool FP32Denormals;
72   bool FastFMAF32;
73   bool CaymanISA;
74   bool FlatAddressSpace;
75   bool EnableIRStructurizer;
76   bool EnablePromoteAlloca;
77   bool EnableIfCvt;
78   bool EnableLoadStoreOpt;
79   bool EnableUnsafeDSOffsetFolding;
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
93   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;
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 hasBFE() const {
164     return (getGeneration() >= EVERGREEN);
165   }
166
167   bool hasBFI() const {
168     return (getGeneration() >= EVERGREEN);
169   }
170
171   bool hasBFM() const {
172     return hasBFE();
173   }
174
175   bool hasBCNT(unsigned Size) const {
176     if (Size == 32)
177       return (getGeneration() >= EVERGREEN);
178
179     if (Size == 64)
180       return (getGeneration() >= SOUTHERN_ISLANDS);
181
182     return false;
183   }
184
185   bool hasMulU24() const {
186     return (getGeneration() >= EVERGREEN);
187   }
188
189   bool hasMulI24() const {
190     return (getGeneration() >= SOUTHERN_ISLANDS ||
191             hasCaymanISA());
192   }
193
194   bool hasFFBL() const {
195     return (getGeneration() >= EVERGREEN);
196   }
197
198   bool hasFFBH() const {
199     return (getGeneration() >= EVERGREEN);
200   }
201
202   bool hasCARRY() const {
203     return (getGeneration() >= EVERGREEN);
204   }
205
206   bool hasBORROW() const {
207     return (getGeneration() >= EVERGREEN);
208   }
209
210   bool IsIRStructurizerEnabled() const {
211     return EnableIRStructurizer;
212   }
213
214   bool isPromoteAllocaEnabled() const {
215     return EnablePromoteAlloca;
216   }
217
218   bool isIfCvtEnabled() const {
219     return EnableIfCvt;
220   }
221
222   bool loadStoreOptEnabled() const {
223     return EnableLoadStoreOpt;
224   }
225
226   bool unsafeDSOffsetFoldingEnabled() const {
227     return EnableUnsafeDSOffsetFolding;
228   }
229
230   unsigned getWavefrontSize() const {
231     return WavefrontSize;
232   }
233
234   unsigned getStackEntrySize() const;
235
236   bool hasCFAluBug() const {
237     assert(getGeneration() <= NORTHERN_ISLANDS);
238     return CFALUBug;
239   }
240
241   int getLocalMemorySize() const {
242     return LocalMemorySize;
243   }
244
245   bool hasSGPRInitBug() const {
246     return SGPRInitBug;
247   }
248
249   int getLDSBankCount() const {
250     return LDSBankCount;
251   }
252
253   unsigned getAmdKernelCodeChipID() const;
254
255   AMDGPU::IsaVersion getIsaVersion() const;
256
257   bool enableMachineScheduler() const override {
258     return true;
259   }
260
261   void overrideSchedPolicy(MachineSchedPolicy &Policy,
262                            MachineInstr *begin, MachineInstr *end,
263                            unsigned NumRegionInstrs) const override;
264
265   // Helper functions to simplify if statements
266   bool isTargetELF() const {
267     return false;
268   }
269
270   StringRef getDeviceName() const {
271     return DevName;
272   }
273
274   bool dumpCode() const {
275     return DumpCode;
276   }
277   bool r600ALUEncoding() const {
278     return R600ALUInst;
279   }
280   bool isAmdHsaOS() const {
281     return TargetTriple.getOS() == Triple::AMDHSA;
282   }
283   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
284
285   unsigned getMaxWavesPerCU() const {
286     if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
287       return 10;
288
289     // FIXME: Not sure what this is for other subtagets.
290     llvm_unreachable("do not know max waves per CU for this subtarget.");
291   }
292
293   bool enableSubRegLiveness() const override {
294     return true;
295   }
296
297   /// \brief Returns the offset in bytes from the start of the input buffer
298   ///        of the first explicit kernel argument.
299   unsigned getExplicitKernelArgOffset() const {
300     return isAmdHsaOS() ? 0 : 36;
301   }
302
303 };
304
305 } // End namespace llvm
306
307 #endif