57a084e6b3e953954157f1357dda14ff5e5bd5af
[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 hasCARRY() const {
189     return (getGeneration() >= EVERGREEN);
190   }
191
192   bool hasBORROW() const {
193     return (getGeneration() >= EVERGREEN);
194   }
195
196   bool IsIRStructurizerEnabled() const {
197     return EnableIRStructurizer;
198   }
199
200   bool isPromoteAllocaEnabled() const {
201     return EnablePromoteAlloca;
202   }
203
204   bool isIfCvtEnabled() const {
205     return EnableIfCvt;
206   }
207
208   bool loadStoreOptEnabled() const {
209     return EnableLoadStoreOpt;
210   }
211
212   unsigned getWavefrontSize() const {
213     return WavefrontSize;
214   }
215
216   unsigned getStackEntrySize() const;
217
218   bool hasCFAluBug() const {
219     assert(getGeneration() <= NORTHERN_ISLANDS);
220     return CFALUBug;
221   }
222
223   int getLocalMemorySize() const {
224     return LocalMemorySize;
225   }
226
227   bool hasSGPRInitBug() const {
228     return SGPRInitBug;
229   }
230
231   unsigned getAmdKernelCodeChipID() const;
232
233   bool enableMachineScheduler() const override {
234     return true;
235   }
236
237   void overrideSchedPolicy(MachineSchedPolicy &Policy,
238                            MachineInstr *begin, MachineInstr *end,
239                            unsigned NumRegionInstrs) const override;
240
241   // Helper functions to simplify if statements
242   bool isTargetELF() const {
243     return false;
244   }
245
246   StringRef getDeviceName() const {
247     return DevName;
248   }
249
250   bool dumpCode() const {
251     return DumpCode;
252   }
253   bool r600ALUEncoding() const {
254     return R600ALUInst;
255   }
256   bool isAmdHsaOS() const {
257     return TargetTriple.getOS() == Triple::AMDHSA;
258   }
259   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
260
261   unsigned getMaxWavesPerCU() const {
262     if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
263       return 10;
264
265     // FIXME: Not sure what this is for other subtagets.
266     llvm_unreachable("do not know max waves per CU for this subtarget.");
267   }
268
269   bool enableSubRegLiveness() const override {
270     return false;
271   }
272 };
273
274 } // End namespace llvm
275
276 #endif