R600/SI: Emit amd_kernel_code_t header for AMDGPU environment
[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/IR/DataLayout.h"
24 #include "llvm/ADT/StringExtras.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Target/TargetSubtargetInfo.h"
27
28 #define GET_SUBTARGETINFO_HEADER
29 #include "AMDGPUGenSubtargetInfo.inc"
30
31 namespace llvm {
32
33 class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
34
35 public:
36   enum Generation {
37     R600 = 0,
38     R700,
39     EVERGREEN,
40     NORTHERN_ISLANDS,
41     SOUTHERN_ISLANDS,
42     SEA_ISLANDS
43   };
44
45 private:
46   std::string DevName;
47   bool Is64bit;
48   bool DumpCode;
49   bool R600ALUInst;
50   bool HasVertexCache;
51   short TexVTXClauseSize;
52   Generation Gen;
53   bool FP64;
54   bool FP64Denormals;
55   bool FP32Denormals;
56   bool CaymanISA;
57   bool FlatAddressSpace;
58   bool EnableIRStructurizer;
59   bool EnablePromoteAlloca;
60   bool EnableIfCvt;
61   bool EnableLoadStoreOpt;
62   unsigned WavefrontSize;
63   bool CFALUBug;
64   int LocalMemorySize;
65
66   const DataLayout DL;
67   AMDGPUFrameLowering FrameLowering;
68   std::unique_ptr<AMDGPUTargetLowering> TLInfo;
69   std::unique_ptr<AMDGPUInstrInfo> InstrInfo;
70   InstrItineraryData InstrItins;
71   Triple TargetTriple;
72
73 public:
74   AMDGPUSubtarget(StringRef TT, StringRef CPU, StringRef FS, TargetMachine &TM);
75   AMDGPUSubtarget &initializeSubtargetDependencies(StringRef GPU, StringRef FS);
76
77   const AMDGPUFrameLowering *getFrameLowering() const override {
78     return &FrameLowering;
79   }
80   const AMDGPUInstrInfo *getInstrInfo() const override {
81     return InstrInfo.get();
82   }
83   const AMDGPURegisterInfo *getRegisterInfo() const override {
84     return &InstrInfo->getRegisterInfo();
85   }
86   AMDGPUTargetLowering *getTargetLowering() const override {
87     return TLInfo.get();
88   }
89   const DataLayout *getDataLayout() const override { return &DL; }
90   const InstrItineraryData *getInstrItineraryData() const override {
91     return &InstrItins;
92   }
93
94   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
95
96   bool is64bit() const {
97     return Is64bit;
98   }
99
100   bool hasVertexCache() const {
101     return HasVertexCache;
102   }
103
104   short getTexVTXClauseSize() const {
105     return TexVTXClauseSize;
106   }
107
108   Generation getGeneration() const {
109     return Gen;
110   }
111
112   bool hasHWFP64() const {
113     return FP64;
114   }
115
116   bool hasCaymanISA() const {
117     return CaymanISA;
118   }
119
120   bool hasFP32Denormals() const {
121     return FP32Denormals;
122   }
123
124   bool hasFP64Denormals() const {
125     return FP64Denormals;
126   }
127
128   bool hasFlatAddressSpace() const {
129     return FlatAddressSpace;
130   }
131
132   bool hasBFE() const {
133     return (getGeneration() >= EVERGREEN);
134   }
135
136   bool hasBFI() const {
137     return (getGeneration() >= EVERGREEN);
138   }
139
140   bool hasBFM() const {
141     return hasBFE();
142   }
143
144   bool hasBCNT(unsigned Size) const {
145     if (Size == 32)
146       return (getGeneration() >= EVERGREEN);
147
148     if (Size == 64)
149       return (getGeneration() >= SOUTHERN_ISLANDS);
150
151     return false;
152   }
153
154   bool hasMulU24() const {
155     return (getGeneration() >= EVERGREEN);
156   }
157
158   bool hasMulI24() const {
159     return (getGeneration() >= SOUTHERN_ISLANDS ||
160             hasCaymanISA());
161   }
162
163   bool hasFFBL() const {
164     return (getGeneration() >= EVERGREEN);
165   }
166
167   bool hasFFBH() const {
168     return (getGeneration() >= EVERGREEN);
169   }
170
171   bool IsIRStructurizerEnabled() const {
172     return EnableIRStructurizer;
173   }
174
175   bool isPromoteAllocaEnabled() const {
176     return EnablePromoteAlloca;
177   }
178
179   bool isIfCvtEnabled() const {
180     return EnableIfCvt;
181   }
182
183   bool loadStoreOptEnabled() const {
184     return EnableLoadStoreOpt;
185   }
186
187   unsigned getWavefrontSize() const {
188     return WavefrontSize;
189   }
190
191   unsigned getStackEntrySize() const;
192
193   bool hasCFAluBug() const {
194     assert(getGeneration() <= NORTHERN_ISLANDS);
195     return CFALUBug;
196   }
197
198   int getLocalMemorySize() const {
199     return LocalMemorySize;
200   }
201
202   unsigned getAmdKernelCodeChipID() const;
203
204   bool enableMachineScheduler() const override {
205     return getGeneration() <= NORTHERN_ISLANDS;
206   }
207
208   // Helper functions to simplify if statements
209   bool isTargetELF() const {
210     return false;
211   }
212
213   StringRef getDeviceName() const {
214     return DevName;
215   }
216
217   bool dumpCode() const {
218     return DumpCode;
219   }
220   bool r600ALUEncoding() const {
221     return R600ALUInst;
222   }
223   bool isAmdHsaOS() const {
224     return TargetTriple.getOS() == Triple::AMDHSA;
225   }
226 };
227
228 } // End namespace llvm
229
230 #endif