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 
18 #include "AMDGPU.h"
19 #include "AMDGPUFrameLowering.h"
20 #include "AMDGPUInstrInfo.h"
21 #include "AMDGPUISelLowering.h"
22 #include "AMDGPUSubtarget.h"
23 #include "Utils/AMDGPUBaseInfo.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   enum {
52     ISAVersion0_0_0,
53     ISAVersion7_0_0,
54     ISAVersion7_0_1,
55     ISAVersion8_0_0,
56     ISAVersion8_0_1,
57     ISAVersion8_0_3
58   };
59 
60 private:
61   bool DumpCode;
62   bool R600ALUInst;
63   bool HasVertexCache;
64   short TexVTXClauseSize;
65   Generation Gen;
66   bool FP64;
67   bool FP64Denormals;
68   bool FP32Denormals;
69   bool FPExceptions;
70   bool FastFMAF32;
71   bool HalfRate64Ops;
72   bool CaymanISA;
73   bool FlatAddressSpace;
74   bool FlatForGlobal;
75   bool EnableIRStructurizer;
76   bool EnablePromoteAlloca;
77   bool EnableIfCvt;
78   bool EnableLoadStoreOpt;
79   bool EnableUnsafeDSOffsetFolding;
80   bool EnableXNACK;
81   unsigned WavefrontSize;
82   bool CFALUBug;
83   int LocalMemorySize;
84   unsigned MaxPrivateElementSize;
85   bool EnableVGPRSpilling;
86   bool SGPRInitBug;
87   bool IsGCN;
88   bool GCN1Encoding;
89   bool GCN3Encoding;
90   bool CIInsts;
91   bool HasSMemRealTime;
92   bool Has16BitInsts;
93   bool FeatureDisable;
94   int LDSBankCount;
95   unsigned IsaVersion;
96   bool EnableSIScheduler;
97 
98   std::unique_ptr<AMDGPUFrameLowering> FrameLowering;
99   std::unique_ptr<AMDGPUTargetLowering> TLInfo;
100   std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
101   InstrItineraryData InstrItins;
102   Triple TargetTriple;
103 
104 public:
105   AMDGPUSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
106                   TargetMachine &TM);
107   AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
108                                                    StringRef GPU, StringRef FS);
109 
110   const AMDGPUFrameLowering *getFrameLowering() const override {
111     return FrameLowering.get();
112   }
113   const AMDGPUInstrInfo *getInstrInfo() const override {
114     return InstrInfo.get();
115   }
116   const AMDGPURegisterInfo *getRegisterInfo() const override {
117     return &InstrInfo->getRegisterInfo();
118   }
119   AMDGPUTargetLowering *getTargetLowering() const override {
120     return TLInfo.get();
121   }
122   const InstrItineraryData *getInstrItineraryData() const override {
123     return &InstrItins;
124   }
125 
126   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
127 
128   bool hasVertexCache() const {
129     return HasVertexCache;
130   }
131 
132   short getTexVTXClauseSize() const {
133     return TexVTXClauseSize;
134   }
135 
136   Generation getGeneration() const {
137     return Gen;
138   }
139 
140   bool hasHWFP64() const {
141     return FP64;
142   }
143 
144   bool hasCaymanISA() const {
145     return CaymanISA;
146   }
147 
148   bool hasFP32Denormals() const {
149     return FP32Denormals;
150   }
151 
152   bool hasFP64Denormals() const {
153     return FP64Denormals;
154   }
155 
156   bool hasFPExceptions() const {
157     return FPExceptions;
158   }
159 
160   bool hasFastFMAF32() const {
161     return FastFMAF32;
162   }
163 
164   bool hasHalfRate64Ops() const {
165     return HalfRate64Ops;
166   }
167 
168   bool hasFlatAddressSpace() const {
169     return FlatAddressSpace;
170   }
171 
172   bool hasSMemRealTime() const {
173     return HasSMemRealTime;
174   }
175 
176   bool has16BitInsts() const {
177     return Has16BitInsts;
178   }
179 
180   bool useFlatForGlobal() const {
181     return FlatForGlobal;
182   }
183 
184   bool hasBFE() const {
185     return (getGeneration() >= EVERGREEN);
186   }
187 
188   bool hasBFI() const {
189     return (getGeneration() >= EVERGREEN);
190   }
191 
192   bool hasBFM() const {
193     return hasBFE();
194   }
195 
196   bool hasBCNT(unsigned Size) const {
197     if (Size == 32)
198       return (getGeneration() >= EVERGREEN);
199 
200     if (Size == 64)
201       return (getGeneration() >= SOUTHERN_ISLANDS);
202 
203     return false;
204   }
205 
206   bool hasMulU24() const {
207     return (getGeneration() >= EVERGREEN);
208   }
209 
210   bool hasMulI24() const {
211     return (getGeneration() >= SOUTHERN_ISLANDS ||
212             hasCaymanISA());
213   }
214 
215   bool hasFFBL() const {
216     return (getGeneration() >= EVERGREEN);
217   }
218 
219   bool hasFFBH() const {
220     return (getGeneration() >= EVERGREEN);
221   }
222 
223   bool hasCARRY() const {
224     return (getGeneration() >= EVERGREEN);
225   }
226 
227   bool hasBORROW() const {
228     return (getGeneration() >= EVERGREEN);
229   }
230 
231   bool IsIRStructurizerEnabled() const {
232     return EnableIRStructurizer;
233   }
234 
235   bool isPromoteAllocaEnabled() const {
236     return EnablePromoteAlloca;
237   }
238 
239   bool isIfCvtEnabled() const {
240     return EnableIfCvt;
241   }
242 
243   bool loadStoreOptEnabled() const {
244     return EnableLoadStoreOpt;
245   }
246 
247   bool unsafeDSOffsetFoldingEnabled() const {
248     return EnableUnsafeDSOffsetFolding;
249   }
250 
251   unsigned getWavefrontSize() const {
252     return WavefrontSize;
253   }
254 
255   unsigned getStackEntrySize() const;
256 
257   bool hasCFAluBug() const {
258     assert(getGeneration() <= NORTHERN_ISLANDS);
259     return CFALUBug;
260   }
261 
262   int getLocalMemorySize() const {
263     return LocalMemorySize;
264   }
265 
266   unsigned getMaxPrivateElementSize() const {
267     return MaxPrivateElementSize;
268   }
269 
270   bool hasSGPRInitBug() const {
271     return SGPRInitBug;
272   }
273 
274   int getLDSBankCount() const {
275     return LDSBankCount;
276   }
277 
278   unsigned getAmdKernelCodeChipID() const;
279 
280   AMDGPU::IsaVersion getIsaVersion() const;
281 
282   bool enableMachineScheduler() const override {
283     return true;
284   }
285 
286   void overrideSchedPolicy(MachineSchedPolicy &Policy,
287                            MachineInstr *begin, MachineInstr *end,
288                            unsigned NumRegionInstrs) const override;
289 
290   // Helper functions to simplify if statements
291   bool isTargetELF() const {
292     return false;
293   }
294 
295   bool enableSIScheduler() const {
296     return EnableSIScheduler;
297   }
298 
299   bool dumpCode() const {
300     return DumpCode;
301   }
302   bool r600ALUEncoding() const {
303     return R600ALUInst;
304   }
305   bool isAmdHsaOS() const {
306     return TargetTriple.getOS() == Triple::AMDHSA;
307   }
308   bool isVGPRSpillingEnabled(const SIMachineFunctionInfo *MFI) const;
309 
310   bool isXNACKEnabled() const {
311     return EnableXNACK;
312   }
313 
314   unsigned getMaxWavesPerCU() const {
315     if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
316       return 10;
317 
318     // FIXME: Not sure what this is for other subtagets.
319     llvm_unreachable("do not know max waves per CU for this subtarget.");
320   }
321 
322   bool enableSubRegLiveness() const override {
323     return true;
324   }
325 
326   /// \brief Returns the offset in bytes from the start of the input buffer
327   ///        of the first explicit kernel argument.
328   unsigned getExplicitKernelArgOffset() const {
329     return isAmdHsaOS() ? 0 : 36;
330   }
331 
332   unsigned getMaxNumUserSGPRs() const {
333     return 16;
334   }
335 };
336 
337 } // End namespace llvm
338 
339 #endif
340