xref: /freebsd/contrib/llvm-project/llvm/include/llvm/TargetParser/TargetParser.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a target parser to recognise hardware features such as
10 // FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TARGETPARSER_TARGETPARSER_H
15 #define LLVM_TARGETPARSER_TARGETPARSER_H
16 
17 #include "SubtargetFeature.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/Compiler.h"
22 
23 namespace llvm {
24 
25 template <typename T> class SmallVectorImpl;
26 class Triple;
27 
28 // Target specific information in their own namespaces.
29 // (ARM/AArch64/X86 are declared in ARM/AArch64/X86TargetParser.h)
30 // These should be generated from TableGen because the information is already
31 // there, and there is where new information about targets will be added.
32 // FIXME: To TableGen this we need to make some table generated files available
33 // even if the back-end is not compiled with LLVM, plus we need to create a new
34 // back-end to TableGen to create these clean tables.
35 namespace AMDGPU {
36 
37 /// GPU kinds supported by the AMDGPU target.
38 enum GPUKind : uint32_t {
39   // Not specified processor.
40   GK_NONE = 0,
41 
42   // R600-based processors.
43   GK_R600,
44   GK_R630,
45   GK_RS880,
46   GK_RV670,
47   GK_RV710,
48   GK_RV730,
49   GK_RV770,
50   GK_CEDAR,
51   GK_CYPRESS,
52   GK_JUNIPER,
53   GK_REDWOOD,
54   GK_SUMO,
55   GK_BARTS,
56   GK_CAICOS,
57   GK_CAYMAN,
58   GK_TURKS,
59 
60   GK_R600_FIRST = GK_R600,
61   GK_R600_LAST = GK_TURKS,
62 
63   // AMDGCN-based processors.
64   GK_GFX600,
65   GK_GFX601,
66   GK_GFX602,
67 
68   GK_GFX700,
69   GK_GFX701,
70   GK_GFX702,
71   GK_GFX703,
72   GK_GFX704,
73   GK_GFX705,
74 
75   GK_GFX801,
76   GK_GFX802,
77   GK_GFX803,
78   GK_GFX805,
79   GK_GFX810,
80 
81   GK_GFX900,
82   GK_GFX902,
83   GK_GFX904,
84   GK_GFX906,
85   GK_GFX908,
86   GK_GFX909,
87   GK_GFX90A,
88   GK_GFX90C,
89   GK_GFX942,
90   GK_GFX950,
91 
92   GK_GFX1010,
93   GK_GFX1011,
94   GK_GFX1012,
95   GK_GFX1013,
96   GK_GFX1030,
97   GK_GFX1031,
98   GK_GFX1032,
99   GK_GFX1033,
100   GK_GFX1034,
101   GK_GFX1035,
102   GK_GFX1036,
103 
104   GK_GFX1100,
105   GK_GFX1101,
106   GK_GFX1102,
107   GK_GFX1103,
108   GK_GFX1150,
109   GK_GFX1151,
110   GK_GFX1152,
111   GK_GFX1153,
112 
113   GK_GFX1200,
114   GK_GFX1201,
115   GK_GFX1250,
116 
117   GK_AMDGCN_FIRST = GK_GFX600,
118   GK_AMDGCN_LAST = GK_GFX1250,
119 
120   GK_GFX9_GENERIC,
121   GK_GFX10_1_GENERIC,
122   GK_GFX10_3_GENERIC,
123   GK_GFX11_GENERIC,
124   GK_GFX12_GENERIC,
125   GK_GFX9_4_GENERIC,
126 
127   GK_AMDGCN_GENERIC_FIRST = GK_GFX9_GENERIC,
128   GK_AMDGCN_GENERIC_LAST = GK_GFX9_4_GENERIC,
129 };
130 
131 /// Instruction set architecture version.
132 struct IsaVersion {
133   unsigned Major;
134   unsigned Minor;
135   unsigned Stepping;
136 };
137 
138 // This isn't comprehensive for now, just things that are needed from the
139 // frontend driver.
140 enum ArchFeatureKind : uint32_t {
141   FEATURE_NONE = 0,
142 
143   // These features only exist for r600, and are implied true for amdgcn.
144   FEATURE_FMA = 1 << 1,
145   FEATURE_LDEXP = 1 << 2,
146   FEATURE_FP64 = 1 << 3,
147 
148   // Common features.
149   FEATURE_FAST_FMA_F32 = 1 << 4,
150   FEATURE_FAST_DENORMAL_F32 = 1 << 5,
151 
152   // Wavefront 32 is available.
153   FEATURE_WAVE32 = 1 << 6,
154 
155   // Xnack is available.
156   FEATURE_XNACK = 1 << 7,
157 
158   // Sram-ecc is available.
159   FEATURE_SRAMECC = 1 << 8,
160 
161   // WGP mode is supported.
162   FEATURE_WGP = 1 << 9,
163 };
164 
165 enum FeatureError : uint32_t {
166   NO_ERROR = 0,
167   INVALID_FEATURE_COMBINATION,
168   UNSUPPORTED_TARGET_FEATURE
169 };
170 
171 LLVM_ABI StringRef getArchFamilyNameAMDGCN(GPUKind AK);
172 
173 LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK);
174 LLVM_ABI StringRef getArchNameR600(GPUKind AK);
175 LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch);
176 LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU);
177 LLVM_ABI GPUKind parseArchR600(StringRef CPU);
178 LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK);
179 LLVM_ABI unsigned getArchAttrR600(GPUKind AK);
180 
181 LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values);
182 LLVM_ABI void fillValidArchListR600(SmallVectorImpl<StringRef> &Values);
183 
184 LLVM_ABI IsaVersion getIsaVersion(StringRef GPU);
185 
186 /// Fills Features map with default values for given target GPU
187 LLVM_ABI void fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
188                                    StringMap<bool> &Features);
189 
190 /// Inserts wave size feature for given GPU into features map
191 LLVM_ABI std::pair<FeatureError, StringRef>
192 insertWaveSizeFeature(StringRef GPU, const Triple &T,
193                       StringMap<bool> &Features);
194 
195 } // namespace AMDGPU
196 
197 struct BasicSubtargetFeatureKV {
198   const char *Key;         ///< K-V key string
199   unsigned Value;          ///< K-V integer value
200   FeatureBitArray Implies; ///< K-V bit mask
201 };
202 
203 /// Used to provide key value pairs for feature and CPU bit flags.
204 struct BasicSubtargetSubTypeKV {
205   const char *Key;         ///< K-V key string
206   FeatureBitArray Implies; ///< K-V bit mask
207 
208   /// Compare routine for std::lower_bound
209   bool operator<(StringRef S) const { return StringRef(Key) < S; }
210 
211   /// Compare routine for std::is_sorted.
212   bool operator<(const BasicSubtargetSubTypeKV &Other) const {
213     return StringRef(Key) < StringRef(Other.Key);
214   }
215 };
216 
217 LLVM_ABI std::optional<llvm::StringMap<bool>>
218 getCPUDefaultTargetFeatures(StringRef CPU,
219                             ArrayRef<BasicSubtargetSubTypeKV> ProcDesc,
220                             ArrayRef<BasicSubtargetFeatureKV> ProcFeatures);
221 } // namespace llvm
222 
223 #endif
224