27f269a95f9fb0135d3459409ed020b406765eb7
[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 "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
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 private:
52   std::string DevName;
53   bool Is64bit;
54   bool DumpCode;
55   bool R600ALUInst;
56   bool HasVertexCache;
57   short TexVTXClauseSize;
58   Generation Gen;
59   bool FP64;
60   bool FP64Denormals;
61   bool FP32Denormals;
62   bool FastFMAF32;
63   bool CaymanISA;
64   bool FlatAddressSpace;
65   bool EnableIRStructurizer;
66   bool EnablePromoteAlloca;
67   bool EnableIfCvt;
68   bool EnableLoadStoreOpt;
69   unsigned WavefrontSize;
70   bool CFALUBug;
71   int LocalMemorySize;
72   bool EnableVGPRSpilling;
73   bool SGPRInitBug;
74   bool IsGCN;
75   bool GCN1Encoding;
76   bool GCN3Encoding;
77   bool CIInsts;
78   bool FeatureDisable;
79   int LDSBankCount;
80
81   AMDGPUFrameLowering FrameLowering;
82   std::unique_ptr<AMDGPUTargetLowering> TLInfo;
83   std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
84   InstrItineraryData InstrItins;
85   Triple TargetTriple;
86
87 public:
88   AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
89                   TargetMachine &TM);
90   AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
91                                                    StringRef GPU, StringRef FS);
92
93   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 {
100     return &InstrInfo->getRegisterInfo();
101   }
102   AMDGPUTargetLowering *getTargetLowering() const override {
103     return TLInfo.get();
104   }
105   const InstrItineraryData *getInstrItineraryData() const override {
106     return &InstrItins;
107   }
108
109   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
110
111   bool is64bit() const {
112     return Is64bit;
113   }
114
115   bool hasVertexCache() const {
116     return HasVertexCache;
117   }
118
119   short getTexVTXClauseSize() const {
120     return TexVTXClauseSize;
121   }
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   }
134
135   bool hasFP32Denormals() const {
136     return FP32Denormals;
137   }
138
139   bool hasFP64Denormals() const {
140     return FP64Denormals;
141   }
142
143   bool hasFastFMAF32() const {
144     return FastFMAF32;
145   }
146
147   bool hasFlatAddressSpace() const {
148     return FlatAddressSpace;
149   }
150
151   bool hasBFE() const {
152     return (getGeneration() >= EVERGREEN);
153   }
154
155   bool hasBFI() const {
156     return (getGeneration() >= EVERGREEN);
157   }
158
159   bool hasBFM() const {
160     return hasBFE();
161   }
162
163   bool hasBCNT(unsigned Size) const {
164     if (Size == 32)
165       return (getGeneration() >= EVERGREEN);
166
167     if (Size == 64)
168       return (getGeneration() >= SOUTHERN_ISLANDS);
169
170     return false;
171   }
172
173   bool hasMulU24() const {
174     return (getGeneration() >= EVERGREEN);
175   }
176
177   bool hasMulI24() const {
178     return (getGeneration() >= SOUTHERN_ISLANDS ||
179             hasCaymanISA());
180   }
181
182   bool hasFFBL() const {
183     return (getGeneration() >= EVERGREEN);
184   }
185
186   bool hasFFBH() const {
187     return (getGeneration() >= EVERGREEN);
188   }
189
190   bool hasCARRY() const {
191     return (getGeneration() >= EVERGREEN);
192   }
193
194   bool hasBORROW() const {
195     return (getGeneration() >= EVERGREEN);
196   }
197
198   bool IsIRStructurizerEnabled() const {
199     return EnableIRStructurizer;
200   }
201
202   bool isPromoteAllocaEnabled() const {
203     return EnablePromoteAlloca;
204   }
205
206   bool isIfCvtEnabled() const {
207     return EnableIfCvt;
208   }
209
210   bool loadStoreOptEnabled() const {
211     return EnableLoadStoreOpt;
212   }
213
214   unsigned getWavefrontSize() const {
215     return WavefrontSize;
216   }
217
218   unsigned getStackEntrySize() const;
219
220   bool hasCFAluBug() const {
221     assert(getGeneration() <= NORTHERN_ISLANDS);
222     return CFALUBug;
223   }
224
225   int getLocalMemorySize() const {
226     return LocalMemorySize;
227   }
228
229   bool hasSGPRInitBug() const {
230     return SGPRInitBug;
231   }
232
233   int getLDSBankCount() const {
234     return LDSBankCount;
235   }
236
237   unsigned getAmdKernelCodeChipID() const;
238
239   bool enableMachineScheduler() const override {
240     return true;
241   }
242
243   void overrideSchedPolicy(MachineSchedPolicy &Policy,
244                            MachineInstr *begin, MachineInstr *end,
245                            unsigned NumRegionInstrs) const override;
246
247   // Helper functions to simplify if statements
248   bool isTargetELF() const {
249     return false;
250   }
251
252   StringRef getDeviceName() const {
253     return DevName;
254   }
255
256   bool dumpCode() const {
257     return DumpCode;
258   }
259   bool r600ALUEncoding() const {
260     return R600ALUInst;
261   }
262   bool isAmdHsaOS() const {
263     return TargetTriple.getOS() == Triple::AMDHSA;
264   }
265   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
266
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   }
274
275   bool enableSubRegLiveness() const override {
276     return true;
277   }
278
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
285 };
286
287 } // End namespace llvm
288
289 #endif