clang 24.0.0git
Builtins.h
Go to the documentation of this file.
1//===--- Builtins.h - Builtin function header -------------------*- 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/// Defines enum values for all the target-independent builtin
11/// functions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_BASIC_BUILTINS_H
16#define LLVM_CLANG_BASIC_BUILTINS_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/SmallString.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/ADT/StringTable.h"
23#include "llvm/TargetParser/Triple.h"
24#include <cstring>
25
26// VC++ defines 'alloca' as an object-like macro, which interferes with our
27// builtins.
28#undef alloca
29
30namespace clang {
31class TargetInfo;
32class IdentifierTable;
33class LangOptions;
34
36 GNU_LANG = 0x1, // builtin requires GNU mode.
37 C_LANG = 0x2, // builtin for c only.
38 CXX_LANG = 0x4, // builtin for cplusplus only.
39 OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
40 MS_LANG = 0x10, // builtin requires MS mode.
41 OMP_LANG = 0x20, // builtin requires OpenMP.
42 CUDA_LANG = 0x40, // builtin requires CUDA.
43 COR_LANG = 0x80, // builtin requires use of 'fcoroutine-ts' option.
44 OCL_GAS = 0x100, // builtin requires OpenCL generic address space.
45 OCL_PIPE = 0x200, // builtin requires OpenCL pipe.
46 OCL_DSE = 0x400, // builtin requires OpenCL device side enqueue.
47 ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages.
48 HLSL_LANG = 0x1000, // builtin requires HLSL.
49 C23_LANG = 0x2000, // builtin requires C23 or later.
50 C2Y_LANG = 0x4000, // builtin requires C2y or later.
51 REFLECTION_LANG = 0x8000, // builtin requires use of 'freflection' option.
52 ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
53 ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
54 ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
55};
56
57struct HeaderDesc {
59#define HEADER(ID, NAME) ID,
60#include "clang/Basic/BuiltinHeaders.def"
61#undef HEADER
62 } ID;
63
64 constexpr HeaderDesc() : ID() {}
65 constexpr HeaderDesc(HeaderID ID) : ID(ID) {}
66
67 const char *getName() const;
68};
69
70namespace Builtin {
71enum ID {
72 NotBuiltin = 0, // This is not a builtin function.
73#define GET_BUILTIN_ENUMERATORS
74#include "clang/Basic/Builtins.inc"
75#undef GET_BUILTIN_ENUMERATORS
77};
78
79struct InfosShard;
80
81/// The info used to represent each builtin.
82struct Info {
83 // Rather than store pointers to the string literals describing these four
84 // aspects of builtins, we store offsets into a common string table.
85 struct StrOffsets {
86 llvm::StringTable::Offset Name = {};
87 llvm::StringTable::Offset Type = {};
88 llvm::StringTable::Offset Attributes = {};
89
90 // Defaults to the empty string offset.
91 llvm::StringTable::Offset Features = {};
93
94 HeaderDesc Header = HeaderDesc::NO_HEADER;
96
97 /// Get the name for the builtin represented by this `Info` object.
98 ///
99 /// Must be provided the `Shard` for this `Info` object.
100 std::string getName(const InfosShard &Shard) const;
101
102 // Builtin non-null attribute modes.
103 // NonOptimizing: attaches Clang's `_Nonnull` type qualifier to parameters.
104 // Optimizing: emits the classic GNU-style `nonnull` attribute for
105 // optimization.
107};
108
109/// A constexpr function to construct an infos array from X-macros.
110///
111/// The input array uses the same data structure, but the offsets are actually
112/// _lengths_ when input. This is all we can compute from the X-macro approach
113/// to builtins. This function will convert these lengths into actual offsets to
114/// a string table built up through sequentially appending strings with the
115/// given lengths.
116template <size_t N>
117static constexpr std::array<Info, N> MakeInfos(std::array<Info, N> Infos) {
118 // Translate lengths to offsets. We start past the initial empty string at
119 // offset zero.
120 unsigned Offset = 1;
121 for (Info &I : Infos) {
122 Info::StrOffsets NewOffsets = {};
123 NewOffsets.Name = Offset;
124 Offset += I.Offsets.Name.value();
125 NewOffsets.Type = Offset;
126 Offset += I.Offsets.Type.value();
127 NewOffsets.Attributes = Offset;
128 Offset += I.Offsets.Attributes.value();
129 NewOffsets.Features = Offset;
130 Offset += I.Offsets.Features.value();
131 I.Offsets = NewOffsets;
132 }
133 return Infos;
134}
135
136/// A shard of a target's builtins string table and info.
137///
138/// Target builtins are sharded across multiple tables due to different
139/// structures, origins, and also to improve the overall scaling by avoiding a
140/// single table across all builtins.
142 const llvm::StringTable *Strings;
144
145 llvm::StringLiteral NamePrefix = "";
146};
147
148// A detail macro used below to emit a string literal that, after string literal
149// concatenation, ends up triggering the `-Woverlength-strings` warning. While
150// the warning is useful in general to catch accidentally excessive strings,
151// here we are creating them intentionally.
152//
153// This relies on a subtle aspect of `_Pragma`: that the *diagnostic* ones don't
154// turn into actual tokens that would disrupt string literal concatenation.
155#ifdef __clang__
156#define CLANG_BUILTIN_DETAIL_STR_TABLE(S) \
157 _Pragma("clang diagnostic push") \
158 _Pragma("clang diagnostic ignored \"-Woverlength-strings\"") \
159 S _Pragma("clang diagnostic pop")
160#else
161#define CLANG_BUILTIN_DETAIL_STR_TABLE(S) S
162#endif
163
164// We require string tables to start with an empty string so that a `0` offset
165// can always be used to refer to an empty string. To satisfy that when building
166// string tables with X-macros, we use this start macro prior to expanding the
167// X-macros.
168#define CLANG_BUILTIN_STR_TABLE_START CLANG_BUILTIN_DETAIL_STR_TABLE("\0")
169
170// A macro that can be used with `Builtins.def` and similar files as an X-macro
171// to add the string arguments to a builtin string table. This is typically the
172// target for the `BUILTIN`, `LANGBUILTIN`, or `LIBBUILTIN` macros in those
173// files.
174#define CLANG_BUILTIN_STR_TABLE(ID, TYPE, ATTRS) \
175 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" /*FEATURE*/ "\0")
176
177// A macro that can be used with target builtin `.def` and `.inc` files as an
178// X-macro to add the string arguments to a builtin string table. this is
179// typically the target for the `TARGET_BUILTIN` macro.
180#define CLANG_TARGET_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, FEATURE) \
181 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
182
183// A macro that can be used with target builtin `.def` and `.inc` files as an
184// X-macro to add the string arguments to a builtin string table. this is
185// typically the target for the `TARGET_HEADER_BUILTIN` macro. We can't delegate
186// to `TARGET_BUILTIN` because the `FEATURE` string changes position.
187#define CLANG_TARGET_HEADER_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, HEADER, LANGS, \
188 FEATURE) \
189 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
190
191// A detail macro used internally to compute the desired string table
192// `StrOffsets` struct for arguments to `MakeInfos`.
193#define CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS) \
194 Builtin::Info::StrOffsets { \
195 sizeof(#ID), sizeof(TYPE), sizeof(ATTRS), sizeof("") \
196 }
197
198// A detail macro used internally to compute the desired string table
199// `StrOffsets` struct for arguments to `Storage::Make`.
200#define CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE) \
201 Builtin::Info::StrOffsets { \
202 sizeof(#ID), sizeof(TYPE), sizeof(ATTRS), sizeof(FEATURE) \
203 }
204
205// A set of macros that can be used with builtin `.def' files as an X-macro to
206// create an `Info` struct for a particular builtin. It both computes the
207// `StrOffsets` value for the string table (the lengths here, translated to
208// offsets by the `MakeInfos` function), and the other metadata for each
209// builtin.
210//
211// There is a corresponding macro for each of `BUILTIN`, `LANGBUILTIN`,
212// `LIBBUILTIN`, `TARGET_BUILTIN`, and `TARGET_HEADER_BUILTIN`.
213#define CLANG_BUILTIN_ENTRY(ID, TYPE, ATTRS) \
214 Builtin::Info{CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS), \
215 HeaderDesc::NO_HEADER, ALL_LANGUAGES},
216#define CLANG_LANGBUILTIN_ENTRY(ID, TYPE, ATTRS, LANG) \
217 Builtin::Info{CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS), \
218 HeaderDesc::NO_HEADER, LANG},
219#define CLANG_LIBBUILTIN_ENTRY(ID, TYPE, ATTRS, HEADER, LANG) \
220 Builtin::Info{CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS), \
221 HeaderDesc::HEADER, LANG},
222#define CLANG_TARGET_BUILTIN_ENTRY(ID, TYPE, ATTRS, FEATURE) \
223 Builtin::Info{ \
224 CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE), \
225 HeaderDesc::NO_HEADER, ALL_LANGUAGES},
226#define CLANG_TARGET_HEADER_BUILTIN_ENTRY(ID, TYPE, ATTRS, HEADER, LANG, \
227 FEATURE) \
228 Builtin::Info{ \
229 CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE), \
230 HeaderDesc::HEADER, LANG},
231
232/// Holds information about both target-independent and
233/// target-specific builtins, allowing easy queries by clients.
234///
235/// Builtins from an optional auxiliary target are stored in
236/// AuxTSRecords. Their IDs are shifted up by TSRecords.size() and need to
237/// be translated back with getAuxBuiltinID() before use.
238class Context {
239 llvm::SmallVector<InfosShard> BuiltinShards;
240
242 llvm::SmallVector<InfosShard> AuxTargetShards;
243
244 unsigned NumTargetBuiltins = 0;
245 unsigned NumAuxTargetBuiltins = 0;
246
247public:
248 Context();
249
250 /// Perform target-specific initialization
251 /// \param AuxTarget Target info to incorporate builtins from. May be nullptr.
252 void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget);
253
254 /// Mark the identifiers for all the builtins with their
255 /// appropriate builtin ID # and mark any non-portable builtin identifiers as
256 /// such.
257 void initializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
258
259 /// Return the identifier name for the specified builtin,
260 /// e.g. "__builtin_abs".
261 std::string getName(unsigned ID) const;
262
263 /// Return the identifier name for the specified builtin inside single quotes
264 /// for a diagnostic, e.g. "'__builtin_abs'".
265 llvm::SmallString<64> getQuotedName(unsigned ID) const;
266
267 /// Get the type descriptor string for the specified builtin.
268 const char *getTypeString(unsigned ID) const;
269
270 /// Get the attributes descriptor string for the specified builtin.
271 const char *getAttributesString(unsigned ID) const;
272
273 /// Return true if this function is a target-specific builtin.
274 bool isTSBuiltin(unsigned ID) const {
275 return ID >= Builtin::FirstTSBuiltin;
276 }
277
278 /// Return true if this function has no side effects.
279 bool isPure(unsigned ID) const {
280 return strchr(getAttributesString(ID), 'U') != nullptr;
281 }
282
283 /// Return true if this function has no side effects and doesn't
284 /// read memory.
285 bool isConst(unsigned ID) const {
286 return strchr(getAttributesString(ID), 'c') != nullptr;
287 }
288
289 /// Return true if we know this builtin never throws an exception.
290 bool isNoThrow(unsigned ID) const {
291 return strchr(getAttributesString(ID), 'n') != nullptr;
292 }
293
294 /// Return true if we know this builtin never returns.
295 bool isNoReturn(unsigned ID) const {
296 return strchr(getAttributesString(ID), 'r') != nullptr;
297 }
298
299 /// Return true if we know this builtin can return twice.
300 bool isReturnsTwice(unsigned ID) const {
301 return strchr(getAttributesString(ID), 'j') != nullptr;
302 }
303
304 /// Returns true if this builtin does not perform the side-effects
305 /// of its arguments.
306 bool isUnevaluated(unsigned ID) const {
307 return strchr(getAttributesString(ID), 'u') != nullptr;
308 }
309
310 /// Return true if this is a builtin for a libc/libm function,
311 /// with a "__builtin_" prefix (e.g. __builtin_abs).
312 bool isLibFunction(unsigned ID) const {
313 return strchr(getAttributesString(ID), 'F') != nullptr;
314 }
315
316 /// Determines whether this builtin is a predefined libc/libm
317 /// function, such as "malloc", where we know the signature a
318 /// priori.
319 /// In C, such functions behave as if they are predeclared,
320 /// possibly with a warning on first use. In Objective-C and C++,
321 /// they do not, but they are recognized as builtins once we see
322 /// a declaration.
323 bool isPredefinedLibFunction(unsigned ID) const {
324 return strchr(getAttributesString(ID), 'f') != nullptr;
325 }
326
327 /// Returns true if this builtin requires appropriate header in other
328 /// compilers. In Clang it will work even without including it, but we can emit
329 /// a warning about missing header.
330 bool isHeaderDependentFunction(unsigned ID) const {
331 return strchr(getAttributesString(ID), 'h') != nullptr;
332 }
333
334 /// Determines whether this builtin is a predefined compiler-rt/libgcc
335 /// function, such as "__clear_cache", where we know the signature a
336 /// priori.
337 bool isPredefinedRuntimeFunction(unsigned ID) const {
338 return strchr(getAttributesString(ID), 'i') != nullptr;
339 }
340
341 /// Determines whether this builtin is a C++ standard library function
342 /// that lives in (possibly-versioned) namespace std, possibly a template
343 /// specialization, where the signature is determined by the standard library
344 /// declaration.
345 bool isInStdNamespace(unsigned ID) const {
346 return strchr(getAttributesString(ID), 'z') != nullptr;
347 }
348
349 /// Determines whether this builtin can have its address taken with no
350 /// special action required.
351 bool isDirectlyAddressable(unsigned ID) const {
352 // Most standard library functions can have their addresses taken. C++
353 // standard library functions formally cannot in C++20 onwards, and when
354 // we allow it, we need to ensure we instantiate a definition.
356 }
357
358 /// Determines whether this builtin has custom typechecking.
359 bool hasCustomTypechecking(unsigned ID) const {
360 return strchr(getAttributesString(ID), 't') != nullptr;
361 }
362
363 /// Determines whether a declaration of this builtin should be recognized
364 /// even if the type doesn't match the specified signature.
365 bool allowTypeMismatch(unsigned ID) const {
366 return strchr(getAttributesString(ID), 'T') != nullptr ||
368 }
369
370 /// Determines whether this builtin has a result or any arguments which
371 /// are pointer types.
372 bool hasPtrArgsOrResult(unsigned ID) const {
373 return strchr(getTypeString(ID), '*') != nullptr;
374 }
375
376 /// Return true if this builtin has a result or any arguments which are
377 /// reference types.
378 bool hasReferenceArgsOrResult(unsigned ID) const {
379 return strchr(getTypeString(ID), '&') != nullptr ||
380 strchr(getTypeString(ID), 'A') != nullptr;
381 }
382
383 /// If this is a library function that comes from a specific
384 /// header, retrieve that header name.
385 const char *getHeaderName(unsigned ID) const {
386 return getInfo(ID).Header.getName();
387 }
388
389 /// Determine whether this builtin is like printf in its
390 /// formatting rules and, if so, set the index to the format string
391 /// argument and whether this function as a va_list argument.
392 bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
393
394 /// Determine whether this builtin is like scanf in its
395 /// formatting rules and, if so, set the index to the format string
396 /// argument and whether this function as a va_list argument.
397 bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
398
399 /// Determine whether this builtin has callback behavior (see
400 /// llvm::AbstractCallSites for details). If so, add the index to the
401 /// callback callee argument and the callback payload arguments.
402 bool performsCallback(unsigned ID,
403 llvm::SmallVectorImpl<int> &Encoding) const;
404
405 /// Return true if this builtin has parameters that must be non-null.
406 /// The parameter indices are appended into 'Indxs'.
407 bool isNonNull(unsigned ID, llvm::SmallVectorImpl<int> &Indxs,
408 Info::NonNullMode &Mode) const;
409
410 /// Return true if this function has no side effects and doesn't
411 /// read memory, except for possibly errno or raising FP exceptions.
412 ///
413 /// Such functions can be const when the MathErrno lang option and FP
414 /// exceptions are disabled.
416 return strchr(getAttributesString(ID), 'e') != nullptr;
417 }
418
419 bool isConstWithoutExceptions(unsigned ID) const {
420 return strchr(getAttributesString(ID), 'g') != nullptr;
421 }
422
423 /// Determine whether we can generate LLVM intrinsics for the given
424 /// builtin ID, based on whether it has side effects such as setting errno.
425 ///
426 /// \param BuiltinID The builtin ID to check.
427 /// \param Trip The target triple.
428 /// \param ErrnoOverwritten Indicates whether the errno setting behavior
429 /// has been overwritten via '#pragma float_control(precise, on/off)'.
430 /// \param MathErrnoEnabled Indicates whether math-errno is enabled on
431 /// command line.
432 /// \param HasOptNoneAttr True iff 'attribute__((optnone))' is used.
433 /// \param IsOptimizationEnabled True iff the optimization level is not 'O0'.
434 bool shouldGenerateFPMathIntrinsic(unsigned BuiltinID, llvm::Triple Trip,
435 std::optional<bool> ErrnoOverwritten,
436 bool MathErrnoEnabled, bool HasOptNoneAttr,
437 bool IsOptimizationEnabled) const;
438
439 const char *getRequiredFeatures(unsigned ID) const;
440
441 unsigned getRequiredVectorWidth(unsigned ID) const;
442
443 /// Return true if the builtin ID belongs exclusively to the AuxTarget,
444 /// and false if it belongs to both primary and aux target, or neither.
445 bool isAuxBuiltinID(unsigned ID) const {
446 return ID >= (Builtin::FirstTSBuiltin + NumTargetBuiltins);
447 }
448
449 /// Return real builtin ID (i.e. ID it would have during compilation
450 /// for AuxTarget).
451 unsigned getAuxBuiltinID(unsigned ID) const { return ID - NumTargetBuiltins; }
452
453 /// Returns true if this is a libc/libm function without the '__builtin_'
454 /// prefix.
455 static bool isBuiltinFunc(llvm::StringRef Name);
456
457 /// Returns true if this is a builtin that can be redeclared. Returns true
458 /// for non-builtins.
459 bool canBeRedeclared(unsigned ID) const;
460
461 /// Return true if this function can be constant evaluated by Clang frontend.
462 bool isConstantEvaluated(unsigned ID) const {
463 return strchr(getAttributesString(ID), 'E') != nullptr;
464 }
465
466 /// Returns true if this is an immediate (consteval) function
467 bool isImmediate(unsigned ID) const {
468 return strchr(getAttributesString(ID), 'G') != nullptr;
469 }
470
471 /// Returns true if this is a reflection metafunction builtin.
472 bool isReflectionMetafunctionBuiltin(unsigned ID) const {
473 return getInfo(ID).Langs & REFLECTION_LANG;
474 }
475
476private:
477 std::pair<const InfosShard &, const Info &>
478 getShardAndInfo(unsigned ID) const;
479
480 const Info &getInfo(unsigned ID) const { return getShardAndInfo(ID).second; }
481
482 /// Helper function for isPrintfLike and isScanfLike.
483 bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg,
484 const char *Fmt) const;
485};
486
487/// Returns true if the required target features of a builtin function are
488/// enabled.
489/// \p TargetFeatureMap maps a target feature to true if it is enabled and
490/// false if it is disabled.
492 llvm::StringRef RequiredFatures,
493 const llvm::StringMap<bool> &TargetFetureMap);
494
495} // namespace Builtin
496
497/// Kinds of BuiltinTemplateDecl.
499#define BuiltinTemplate(BTName) BTK##BTName,
500#include "clang/Basic/BuiltinTemplates.inc"
501};
502
503} // end namespace clang
504#endif
static const TypeInfo & getInfo(unsigned id)
Definition Types.cpp:44
bool shouldGenerateFPMathIntrinsic(unsigned BuiltinID, llvm::Triple Trip, std::optional< bool > ErrnoOverwritten, bool MathErrnoEnabled, bool HasOptNoneAttr, bool IsOptimizationEnabled) const
Determine whether we can generate LLVM intrinsics for the given builtin ID, based on whether it has s...
Definition Builtins.cpp:247
llvm::SmallString< 64 > getQuotedName(unsigned ID) const
Return the identifier name for the specified builtin inside single quotes for a diagnostic,...
Definition Builtins.cpp:99
bool isUnevaluated(unsigned ID) const
Returns true if this builtin does not perform the side-effects of its arguments.
Definition Builtins.h:306
bool hasReferenceArgsOrResult(unsigned ID) const
Return true if this builtin has a result or any arguments which are reference types.
Definition Builtins.h:378
bool performsCallback(unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details).
Definition Builtins.cpp:454
bool isAuxBuiltinID(unsigned ID) const
Return true if the builtin ID belongs exclusively to the AuxTarget, and false if it belongs to both p...
Definition Builtins.h:445
bool isLibFunction(unsigned ID) const
Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e....
Definition Builtins.h:312
bool isNonNull(unsigned ID, llvm::SmallVectorImpl< int > &Indxs, Info::NonNullMode &Mode) const
Return true if this builtin has parameters that must be non-null.
Definition Builtins.cpp:429
const char * getHeaderName(unsigned ID) const
If this is a library function that comes from a specific header, retrieve that header name.
Definition Builtins.h:385
bool hasPtrArgsOrResult(unsigned ID) const
Determines whether this builtin has a result or any arguments which are pointer types.
Definition Builtins.h:372
bool isReturnsTwice(unsigned ID) const
Return true if we know this builtin can return twice.
Definition Builtins.h:300
bool isImmediate(unsigned ID) const
Returns true if this is an immediate (consteval) function.
Definition Builtins.h:467
bool isConstWithoutErrnoAndExceptions(unsigned ID) const
Return true if this function has no side effects and doesn't read memory, except for possibly errno o...
Definition Builtins.h:415
static bool isBuiltinFunc(llvm::StringRef Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
Definition Builtins.cpp:139
unsigned getRequiredVectorWidth(unsigned ID) const
Definition Builtins.cpp:360
unsigned getAuxBuiltinID(unsigned ID) const
Return real builtin ID (i.e.
Definition Builtins.h:451
bool allowTypeMismatch(unsigned ID) const
Determines whether a declaration of this builtin should be recognized even if the type doesn't match ...
Definition Builtins.h:365
bool isTSBuiltin(unsigned ID) const
Return true if this function is a target-specific builtin.
Definition Builtins.h:274
bool hasCustomTypechecking(unsigned ID) const
Determines whether this builtin has custom typechecking.
Definition Builtins.h:359
std::string getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
Definition Builtins.cpp:94
bool isHeaderDependentFunction(unsigned ID) const
Returns true if this builtin requires appropriate header in other compilers.
Definition Builtins.h:330
void initializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
Definition Builtins.cpp:315
bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like scanf in its formatting rules and, if so, set the index to the...
Definition Builtins.cpp:404
bool isInStdNamespace(unsigned ID) const
Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned)...
Definition Builtins.h:345
bool canBeRedeclared(unsigned ID) const
Returns true if this is a builtin that can be redeclared.
Definition Builtins.cpp:466
const char * getAttributesString(unsigned ID) const
Get the attributes descriptor string for the specified builtin.
Definition Builtins.cpp:113
bool isConstantEvaluated(unsigned ID) const
Return true if this function can be constant evaluated by Clang frontend.
Definition Builtins.h:462
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
Definition Builtins.h:323
bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like printf in its formatting rules and, if so, set the index to th...
Definition Builtins.cpp:399
bool isReflectionMetafunctionBuiltin(unsigned ID) const
Returns true if this is a reflection metafunction builtin.
Definition Builtins.h:472
const char * getTypeString(unsigned ID) const
Get the type descriptor string for the specified builtin.
Definition Builtins.cpp:108
bool isNoReturn(unsigned ID) const
Return true if we know this builtin never returns.
Definition Builtins.h:295
const char * getRequiredFeatures(unsigned ID) const
Definition Builtins.cpp:118
bool isDirectlyAddressable(unsigned ID) const
Determines whether this builtin can have its address taken with no special action required.
Definition Builtins.h:351
bool isConstWithoutExceptions(unsigned ID) const
Definition Builtins.h:419
bool isPredefinedRuntimeFunction(unsigned ID) const
Determines whether this builtin is a predefined compiler-rt/libgcc function, such as "__clear_cache",...
Definition Builtins.h:337
bool isPure(unsigned ID) const
Return true if this function has no side effects.
Definition Builtins.h:279
bool isNoThrow(unsigned ID) const
Return true if we know this builtin never throws an exception.
Definition Builtins.h:290
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
Definition Builtins.cpp:125
bool isConst(unsigned ID) const
Return true if this function has no side effects and doesn't read memory.
Definition Builtins.h:285
Implements an efficient mapping from strings to IdentifierInfo nodes.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Exposes information about the current target.
Definition TargetInfo.h:228
bool evaluateRequiredTargetFeatures(llvm::StringRef RequiredFatures, const llvm::StringMap< bool > &TargetFetureMap)
Returns true if the required target features of a builtin function are enabled.
static constexpr std::array< Info, N > MakeInfos(std::array< Info, N > Infos)
A constexpr function to construct an infos array from X-macros.
Definition Builtins.h:117
Top level wrappers for InstallAPI frontend operations.
LanguageID
Definition Builtins.h:35
@ ALL_LANGUAGES
Definition Builtins.h:52
@ MS_LANG
Definition Builtins.h:40
@ CUDA_LANG
Definition Builtins.h:42
@ OMP_LANG
Definition Builtins.h:41
@ CXX_LANG
Definition Builtins.h:38
@ OBJC_LANG
Definition Builtins.h:39
@ OCL_DSE
Definition Builtins.h:46
@ REFLECTION_LANG
Definition Builtins.h:51
@ C_LANG
Definition Builtins.h:37
@ C23_LANG
Definition Builtins.h:49
@ ALL_OCL_LANGUAGES
Definition Builtins.h:47
@ HLSL_LANG
Definition Builtins.h:48
@ C2Y_LANG
Definition Builtins.h:50
@ OCL_GAS
Definition Builtins.h:44
@ ALL_GNU_LANGUAGES
Definition Builtins.h:53
@ ALL_MS_LANGUAGES
Definition Builtins.h:54
@ GNU_LANG
Definition Builtins.h:36
@ COR_LANG
Definition Builtins.h:43
@ OCL_PIPE
Definition Builtins.h:45
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition Builtins.h:498
__builtin_bitreverse32 uint32_t __builtin_riscv_aaddu_u32 __builtin_riscv_asubu_u32 __builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t uint32_t uint32_t __builtin_riscv_mhacc_i32 __builtin_riscv_mhaccu_u32 __builtin_riscv_mhaccsu_i32 __builtin_riscv_mulq_i32 __builtin_riscv_mqwacc_i64 __packed_splat4 uint16_t
llvm::StringTable::Offset Name
Definition Builtins.h:86
llvm::StringTable::Offset Features
Definition Builtins.h:91
llvm::StringTable::Offset Attributes
Definition Builtins.h:88
llvm::StringTable::Offset Type
Definition Builtins.h:87
The info used to represent each builtin.
Definition Builtins.h:82
HeaderDesc Header
Definition Builtins.h:94
LanguageID Langs
Definition Builtins.h:95
struct clang::Builtin::Info::StrOffsets Offsets
std::string getName(const InfosShard &Shard) const
Get the name for the builtin represented by this Info object.
Definition Builtins.cpp:87
A shard of a target's builtins string table and info.
Definition Builtins.h:141
const llvm::StringTable * Strings
Definition Builtins.h:142
llvm::StringLiteral NamePrefix
Definition Builtins.h:145
llvm::ArrayRef< Info > Infos
Definition Builtins.h:143
const char * getName() const
Definition Builtins.cpp:22
constexpr HeaderDesc()
Definition Builtins.h:64
enum clang::HeaderDesc::HeaderID ID
constexpr HeaderDesc(HeaderID ID)
Definition Builtins.h:65