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