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