Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 1 | //===--- TargetBuiltins.h - Target specific builtin IDs ---------*- 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 | /// \file |
||
10 | /// Enumerates target-specific builtins in their own namespaces within |
||
11 | /// namespace ::clang. |
||
12 | /// |
||
13 | //===----------------------------------------------------------------------===// |
||
14 | |||
15 | #ifndef LLVM_CLANG_BASIC_TARGETBUILTINS_H |
||
16 | #define LLVM_CLANG_BASIC_TARGETBUILTINS_H |
||
17 | |||
18 | #include <algorithm> |
||
19 | #include <stdint.h> |
||
20 | #include "clang/Basic/Builtins.h" |
||
21 | #include "llvm/Support/MathExtras.h" |
||
22 | #undef PPC |
||
23 | |||
24 | namespace clang { |
||
25 | |||
26 | namespace NEON { |
||
27 | enum { |
||
28 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
29 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
30 | #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BI##ID, |
||
31 | #include "clang/Basic/BuiltinsNEON.def" |
||
32 | FirstTSBuiltin |
||
33 | }; |
||
34 | } |
||
35 | |||
36 | /// ARM builtins |
||
37 | namespace ARM { |
||
38 | enum { |
||
39 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
40 | LastNEONBuiltin = NEON::FirstTSBuiltin - 1, |
||
41 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
42 | #include "clang/Basic/BuiltinsARM.def" |
||
43 | LastTSBuiltin |
||
44 | }; |
||
45 | } |
||
46 | |||
47 | namespace SVE { |
||
48 | enum { |
||
49 | LastNEONBuiltin = NEON::FirstTSBuiltin - 1, |
||
50 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
51 | #include "clang/Basic/BuiltinsSVE.def" |
||
52 | FirstTSBuiltin, |
||
53 | }; |
||
54 | } |
||
55 | |||
56 | /// AArch64 builtins |
||
57 | namespace AArch64 { |
||
58 | enum { |
||
59 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
60 | LastNEONBuiltin = NEON::FirstTSBuiltin - 1, |
||
61 | FirstSVEBuiltin = NEON::FirstTSBuiltin, |
||
62 | LastSVEBuiltin = SVE::FirstTSBuiltin - 1, |
||
63 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
64 | #include "clang/Basic/BuiltinsAArch64.def" |
||
65 | LastTSBuiltin |
||
66 | }; |
||
67 | } |
||
68 | |||
69 | /// BPF builtins |
||
70 | namespace BPF { |
||
71 | enum { |
||
72 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
73 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
74 | #include "clang/Basic/BuiltinsBPF.def" |
||
75 | LastTSBuiltin |
||
76 | }; |
||
77 | } |
||
78 | |||
79 | /// PPC builtins |
||
80 | namespace PPC { |
||
81 | enum { |
||
82 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
83 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
84 | #include "clang/Basic/BuiltinsPPC.def" |
||
85 | LastTSBuiltin |
||
86 | }; |
||
87 | } |
||
88 | |||
89 | /// NVPTX builtins |
||
90 | namespace NVPTX { |
||
91 | enum { |
||
92 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
93 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
94 | #include "clang/Basic/BuiltinsNVPTX.def" |
||
95 | LastTSBuiltin |
||
96 | }; |
||
97 | } |
||
98 | |||
99 | /// AMDGPU builtins |
||
100 | namespace AMDGPU { |
||
101 | enum { |
||
102 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
103 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
104 | #include "clang/Basic/BuiltinsAMDGPU.def" |
||
105 | LastTSBuiltin |
||
106 | }; |
||
107 | } |
||
108 | |||
109 | /// X86 builtins |
||
110 | namespace X86 { |
||
111 | enum { |
||
112 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
113 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
114 | #include "clang/Basic/BuiltinsX86.def" |
||
115 | FirstX86_64Builtin, |
||
116 | LastX86CommonBuiltin = FirstX86_64Builtin - 1, |
||
117 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
118 | #include "clang/Basic/BuiltinsX86_64.def" |
||
119 | LastTSBuiltin |
||
120 | }; |
||
121 | } |
||
122 | |||
123 | /// VE builtins |
||
124 | namespace VE { |
||
125 | enum { |
||
126 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
127 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
128 | #include "clang/Basic/BuiltinsVE.def" |
||
129 | LastTSBuiltin |
||
130 | }; |
||
131 | } |
||
132 | |||
133 | namespace RISCVVector { |
||
134 | enum { |
||
135 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
136 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
137 | #include "clang/Basic/BuiltinsRISCVVector.def" |
||
138 | FirstTSBuiltin, |
||
139 | }; |
||
140 | } |
||
141 | |||
142 | /// RISCV builtins |
||
143 | namespace RISCV { |
||
144 | enum { |
||
145 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
146 | FirstRVVBuiltin = clang::Builtin::FirstTSBuiltin, |
||
147 | LastRVVBuiltin = RISCVVector::FirstTSBuiltin - 1, |
||
148 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
149 | #include "clang/Basic/BuiltinsRISCV.def" |
||
150 | LastTSBuiltin |
||
151 | }; |
||
152 | } // namespace RISCV |
||
153 | |||
154 | /// LoongArch builtins |
||
155 | namespace LoongArch { |
||
156 | enum { |
||
157 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, |
||
158 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
159 | #include "clang/Basic/BuiltinsLoongArch.def" |
||
160 | LastTSBuiltin |
||
161 | }; |
||
162 | } // namespace LoongArch |
||
163 | |||
164 | /// Flags to identify the types for overloaded Neon builtins. |
||
165 | /// |
||
166 | /// These must be kept in sync with the flags in utils/TableGen/NeonEmitter.h. |
||
167 | class NeonTypeFlags { |
||
168 | enum { |
||
169 | EltTypeMask = 0xf, |
||
170 | UnsignedFlag = 0x10, |
||
171 | QuadFlag = 0x20 |
||
172 | }; |
||
173 | uint32_t Flags; |
||
174 | |||
175 | public: |
||
176 | enum EltType { |
||
177 | Int8, |
||
178 | Int16, |
||
179 | Int32, |
||
180 | Int64, |
||
181 | Poly8, |
||
182 | Poly16, |
||
183 | Poly64, |
||
184 | Poly128, |
||
185 | Float16, |
||
186 | Float32, |
||
187 | Float64, |
||
188 | BFloat16 |
||
189 | }; |
||
190 | |||
191 | NeonTypeFlags(unsigned F) : Flags(F) {} |
||
192 | NeonTypeFlags(EltType ET, bool IsUnsigned, bool IsQuad) : Flags(ET) { |
||
193 | if (IsUnsigned) |
||
194 | Flags |= UnsignedFlag; |
||
195 | if (IsQuad) |
||
196 | Flags |= QuadFlag; |
||
197 | } |
||
198 | |||
199 | EltType getEltType() const { return (EltType)(Flags & EltTypeMask); } |
||
200 | bool isPoly() const { |
||
201 | EltType ET = getEltType(); |
||
202 | return ET == Poly8 || ET == Poly16 || ET == Poly64; |
||
203 | } |
||
204 | bool isUnsigned() const { return (Flags & UnsignedFlag) != 0; } |
||
205 | bool isQuad() const { return (Flags & QuadFlag) != 0; } |
||
206 | }; |
||
207 | |||
208 | /// Flags to identify the types for overloaded SVE builtins. |
||
209 | class SVETypeFlags { |
||
210 | uint64_t Flags; |
||
211 | unsigned EltTypeShift; |
||
212 | unsigned MemEltTypeShift; |
||
213 | unsigned MergeTypeShift; |
||
214 | unsigned SplatOperandMaskShift; |
||
215 | |||
216 | public: |
||
217 | #define LLVM_GET_SVE_TYPEFLAGS |
||
218 | #include "clang/Basic/arm_sve_typeflags.inc" |
||
219 | #undef LLVM_GET_SVE_TYPEFLAGS |
||
220 | |||
221 | enum EltType { |
||
222 | #define LLVM_GET_SVE_ELTTYPES |
||
223 | #include "clang/Basic/arm_sve_typeflags.inc" |
||
224 | #undef LLVM_GET_SVE_ELTTYPES |
||
225 | }; |
||
226 | |||
227 | enum MemEltType { |
||
228 | #define LLVM_GET_SVE_MEMELTTYPES |
||
229 | #include "clang/Basic/arm_sve_typeflags.inc" |
||
230 | #undef LLVM_GET_SVE_MEMELTTYPES |
||
231 | }; |
||
232 | |||
233 | enum MergeType { |
||
234 | #define LLVM_GET_SVE_MERGETYPES |
||
235 | #include "clang/Basic/arm_sve_typeflags.inc" |
||
236 | #undef LLVM_GET_SVE_MERGETYPES |
||
237 | }; |
||
238 | |||
239 | enum ImmCheckType { |
||
240 | #define LLVM_GET_SVE_IMMCHECKTYPES |
||
241 | #include "clang/Basic/arm_sve_typeflags.inc" |
||
242 | #undef LLVM_GET_SVE_IMMCHECKTYPES |
||
243 | }; |
||
244 | |||
245 | SVETypeFlags(uint64_t F) : Flags(F) { |
||
246 | EltTypeShift = llvm::countTrailingZeros(EltTypeMask); |
||
247 | MemEltTypeShift = llvm::countTrailingZeros(MemEltTypeMask); |
||
248 | MergeTypeShift = llvm::countTrailingZeros(MergeTypeMask); |
||
249 | SplatOperandMaskShift = llvm::countTrailingZeros(SplatOperandMask); |
||
250 | } |
||
251 | |||
252 | EltType getEltType() const { |
||
253 | return (EltType)((Flags & EltTypeMask) >> EltTypeShift); |
||
254 | } |
||
255 | |||
256 | MemEltType getMemEltType() const { |
||
257 | return (MemEltType)((Flags & MemEltTypeMask) >> MemEltTypeShift); |
||
258 | } |
||
259 | |||
260 | MergeType getMergeType() const { |
||
261 | return (MergeType)((Flags & MergeTypeMask) >> MergeTypeShift); |
||
262 | } |
||
263 | |||
264 | unsigned getSplatOperand() const { |
||
265 | return ((Flags & SplatOperandMask) >> SplatOperandMaskShift) - 1; |
||
266 | } |
||
267 | |||
268 | bool hasSplatOperand() const { |
||
269 | return Flags & SplatOperandMask; |
||
270 | } |
||
271 | |||
272 | bool isLoad() const { return Flags & IsLoad; } |
||
273 | bool isStore() const { return Flags & IsStore; } |
||
274 | bool isGatherLoad() const { return Flags & IsGatherLoad; } |
||
275 | bool isScatterStore() const { return Flags & IsScatterStore; } |
||
276 | bool isStructLoad() const { return Flags & IsStructLoad; } |
||
277 | bool isStructStore() const { return Flags & IsStructStore; } |
||
278 | bool isZExtReturn() const { return Flags & IsZExtReturn; } |
||
279 | bool isByteIndexed() const { return Flags & IsByteIndexed; } |
||
280 | bool isOverloadNone() const { return Flags & IsOverloadNone; } |
||
281 | bool isOverloadWhile() const { return Flags & IsOverloadWhile; } |
||
282 | bool isOverloadDefault() const { return !(Flags & OverloadKindMask); } |
||
283 | bool isOverloadWhileRW() const { return Flags & IsOverloadWhileRW; } |
||
284 | bool isOverloadCvt() const { return Flags & IsOverloadCvt; } |
||
285 | bool isPrefetch() const { return Flags & IsPrefetch; } |
||
286 | bool isReverseCompare() const { return Flags & ReverseCompare; } |
||
287 | bool isAppendSVALL() const { return Flags & IsAppendSVALL; } |
||
288 | bool isInsertOp1SVALL() const { return Flags & IsInsertOp1SVALL; } |
||
289 | bool isGatherPrefetch() const { return Flags & IsGatherPrefetch; } |
||
290 | bool isReverseUSDOT() const { return Flags & ReverseUSDOT; } |
||
291 | bool isUndef() const { return Flags & IsUndef; } |
||
292 | bool isTupleCreate() const { return Flags & IsTupleCreate; } |
||
293 | bool isTupleGet() const { return Flags & IsTupleGet; } |
||
294 | bool isTupleSet() const { return Flags & IsTupleSet; } |
||
295 | |||
296 | uint64_t getBits() const { return Flags; } |
||
297 | bool isFlagSet(uint64_t Flag) const { return Flags & Flag; } |
||
298 | }; |
||
299 | |||
300 | /// Hexagon builtins |
||
301 | namespace Hexagon { |
||
302 | enum { |
||
303 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
304 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
305 | #include "clang/Basic/BuiltinsHexagon.def" |
||
306 | LastTSBuiltin |
||
307 | }; |
||
308 | } |
||
309 | |||
310 | /// MIPS builtins |
||
311 | namespace Mips { |
||
312 | enum { |
||
313 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
314 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
315 | #include "clang/Basic/BuiltinsMips.def" |
||
316 | LastTSBuiltin |
||
317 | }; |
||
318 | } |
||
319 | |||
320 | /// XCore builtins |
||
321 | namespace XCore { |
||
322 | enum { |
||
323 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
324 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
325 | #include "clang/Basic/BuiltinsXCore.def" |
||
326 | LastTSBuiltin |
||
327 | }; |
||
328 | } |
||
329 | |||
330 | /// SystemZ builtins |
||
331 | namespace SystemZ { |
||
332 | enum { |
||
333 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
334 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
335 | #include "clang/Basic/BuiltinsSystemZ.def" |
||
336 | LastTSBuiltin |
||
337 | }; |
||
338 | } |
||
339 | |||
340 | /// WebAssembly builtins |
||
341 | namespace WebAssembly { |
||
342 | enum { |
||
343 | LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, |
||
344 | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
||
345 | #include "clang/Basic/BuiltinsWebAssembly.def" |
||
346 | LastTSBuiltin |
||
347 | }; |
||
348 | } |
||
349 | |||
350 | static constexpr uint64_t LargestBuiltinID = std::max<uint64_t>( |
||
351 | {ARM::LastTSBuiltin, AArch64::LastTSBuiltin, BPF::LastTSBuiltin, |
||
352 | PPC::LastTSBuiltin, NVPTX::LastTSBuiltin, AMDGPU::LastTSBuiltin, |
||
353 | X86::LastTSBuiltin, VE::LastTSBuiltin, RISCV::LastTSBuiltin, |
||
354 | Hexagon::LastTSBuiltin, Mips::LastTSBuiltin, XCore::LastTSBuiltin, |
||
355 | SystemZ::LastTSBuiltin, WebAssembly::LastTSBuiltin}); |
||
356 | |||
357 | } // end namespace clang. |
||
358 | |||
359 | #endif |