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