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