a5a901c739d47b044b5eac1c19898df2d21880f7
[oota-llvm.git] / lib / Target / R600 / 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(StringRef TT, StringRef CPU, StringRef FS, TargetMachine &TM);
89   AMDGPUSubtarget &initializeSubtargetDependencies(StringRef TT, StringRef GPU,
90                                                    StringRef FS);
91
92   const AMDGPUFrameLowering *getFrameLowering() const override {
93     return &FrameLowering;
94   }
95   const AMDGPUInstrInfo *getInstrInfo() const override {
96     return InstrInfo.get();
97   }
98   const AMDGPURegisterInfo *getRegisterInfo() const override {
99     return &InstrInfo->getRegisterInfo();
100   }
101   AMDGPUTargetLowering *getTargetLowering() const override {
102     return TLInfo.get();
103   }
104   const InstrItineraryData *getInstrItineraryData() const override {
105     return &InstrItins;
106   }
107
108   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
109
110   bool is64bit() const {
111     return Is64bit;
112   }
113
114   bool hasVertexCache() const {
115     return HasVertexCache;
116   }
117
118   short getTexVTXClauseSize() const {
119     return TexVTXClauseSize;
120   }
121
122   Generation getGeneration() const {
123     return Gen;
124   }
125
126   bool hasHWFP64() const {
127     return FP64;
128   }
129
130   bool hasCaymanISA() const {
131     return CaymanISA;
132   }
133
134   bool hasFP32Denormals() const {
135     return FP32Denormals;
136   }
137
138   bool hasFP64Denormals() const {
139     return FP64Denormals;
140   }
141
142   bool hasFastFMAF32() const {
143     return FastFMAF32;
144   }
145
146   bool hasFlatAddressSpace() const {
147     return FlatAddressSpace;
148   }
149
150   bool hasBFE() const {
151     return (getGeneration() >= EVERGREEN);
152   }
153
154   bool hasBFI() const {
155     return (getGeneration() >= EVERGREEN);
156   }
157
158   bool hasBFM() const {
159     return hasBFE();
160   }
161
162   bool hasBCNT(unsigned Size) const {
163     if (Size == 32)
164       return (getGeneration() >= EVERGREEN);
165
166     if (Size == 64)
167       return (getGeneration() >= SOUTHERN_ISLANDS);
168
169     return false;
170   }
171
172   bool hasMulU24() const {
173     return (getGeneration() >= EVERGREEN);
174   }
175
176   bool hasMulI24() const {
177     return (getGeneration() >= SOUTHERN_ISLANDS ||
178             hasCaymanISA());
179   }
180
181   bool hasFFBL() const {
182     return (getGeneration() >= EVERGREEN);
183   }
184
185   bool hasFFBH() const {
186     return (getGeneration() >= EVERGREEN);
187   }
188
189   bool hasCARRY() const {
190     return (getGeneration() >= EVERGREEN);
191   }
192
193   bool hasBORROW() const {
194     return (getGeneration() >= EVERGREEN);
195   }
196
197   bool IsIRStructurizerEnabled() const {
198     return EnableIRStructurizer;
199   }
200
201   bool isPromoteAllocaEnabled() const {
202     return EnablePromoteAlloca;
203   }
204
205   bool isIfCvtEnabled() const {
206     return EnableIfCvt;
207   }
208
209   bool loadStoreOptEnabled() const {
210     return EnableLoadStoreOpt;
211   }
212
213   unsigned getWavefrontSize() const {
214     return WavefrontSize;
215   }
216
217   unsigned getStackEntrySize() const;
218
219   bool hasCFAluBug() const {
220     assert(getGeneration() <= NORTHERN_ISLANDS);
221     return CFALUBug;
222   }
223
224   int getLocalMemorySize() const {
225     return LocalMemorySize;
226   }
227
228   bool hasSGPRInitBug() const {
229     return SGPRInitBug;
230   }
231
232   int getLDSBankCount() const {
233     return LDSBankCount;
234   }
235
236   unsigned getAmdKernelCodeChipID() const;
237
238   bool enableMachineScheduler() const override {
239     return true;
240   }
241
242   void overrideSchedPolicy(MachineSchedPolicy &Policy,
243                            MachineInstr *begin, MachineInstr *end,
244                            unsigned NumRegionInstrs) const override;
245
246   // Helper functions to simplify if statements
247   bool isTargetELF() const {
248     return false;
249   }
250
251   StringRef getDeviceName() const {
252     return DevName;
253   }
254
255   bool dumpCode() const {
256     return DumpCode;
257   }
258   bool r600ALUEncoding() const {
259     return R600ALUInst;
260   }
261   bool isAmdHsaOS() const {
262     return TargetTriple.getOS() == Triple::AMDHSA;
263   }
264   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
265
266   unsigned getMaxWavesPerCU() const {
267     if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
268       return 10;
269
270     // FIXME: Not sure what this is for other subtagets.
271     llvm_unreachable("do not know max waves per CU for this subtarget.");
272   }
273
274   bool enableSubRegLiveness() const override {
275     return true;
276   }
277 };
278
279 } // End namespace llvm
280
281 #endif