15#ifndef LLVM_CLANG_BASIC_BUILTINS_H
16#define LLVM_CLANG_BASIC_BUILTINS_H
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"
59#define HEADER(ID, NAME) ID,
60#include "clang/Basic/BuiltinHeaders.def"
73#define GET_BUILTIN_ENUMERATORS
74#include "clang/Basic/Builtins.inc"
75#undef GET_BUILTIN_ENUMERATORS
86 llvm::StringTable::Offset
Name = {};
87 llvm::StringTable::Offset
Type = {};
117static constexpr std::array<Info, N>
MakeInfos(std::array<Info, N> Infos) {
121 for (
Info &I : Infos) {
123 NewOffsets.
Name = Offset;
124 Offset += I.Offsets.Name.value();
125 NewOffsets.
Type = Offset;
126 Offset += I.Offsets.Type.value();
128 Offset += I.Offsets.Attributes.value();
130 Offset += I.Offsets.Features.value();
131 I.Offsets = NewOffsets;
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")
161#define CLANG_BUILTIN_DETAIL_STR_TABLE(S) S
168#define CLANG_BUILTIN_STR_TABLE_START CLANG_BUILTIN_DETAIL_STR_TABLE("\0")
174#define CLANG_BUILTIN_STR_TABLE(ID, TYPE, ATTRS) \
175 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" "\0")
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")
187#define CLANG_TARGET_HEADER_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, HEADER, LANGS, \
189 CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
193#define CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS) \
194 Builtin::Info::StrOffsets { \
195 sizeof(#ID), sizeof(TYPE), sizeof(ATTRS), sizeof("") \
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) \
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) \
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, \
229 CLANG_TARGET_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS, FEATURE), \
230 HeaderDesc::HEADER, LANG},
244 unsigned NumTargetBuiltins = 0;
245 unsigned NumAuxTargetBuiltins = 0;
386 return getInfo(
ID).Header.getName();
392 bool isPrintfLike(
unsigned ID,
unsigned &FormatIdx,
bool &HasVAListArg);
397 bool isScanfLike(
unsigned ID,
unsigned &FormatIdx,
bool &HasVAListArg);
435 std::optional<bool> ErrnoOverwritten,
436 bool MathErrnoEnabled,
bool HasOptNoneAttr,
437 bool IsOptimizationEnabled)
const;
477 std::pair<const InfosShard &, const Info &>
478 getShardAndInfo(
unsigned ID)
const;
480 const Info &
getInfo(
unsigned ID)
const {
return getShardAndInfo(
ID).second; }
483 bool isLike(
unsigned ID,
unsigned &FormatIdx,
bool &HasVAListArg,
484 const char *Fmt)
const;
492 llvm::StringRef RequiredFatures,
493 const llvm::StringMap<bool> &TargetFetureMap);
499#define BuiltinTemplate(BTName) BTK##BTName,
500#include "clang/Basic/BuiltinTemplates.inc"
static const TypeInfo & getInfo(unsigned id)
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...
llvm::SmallString< 64 > getQuotedName(unsigned ID) const
Return the identifier name for the specified builtin inside single quotes for a diagnostic,...
bool isUnevaluated(unsigned ID) const
Returns true if this builtin does not perform the side-effects of its arguments.
bool hasReferenceArgsOrResult(unsigned ID) const
Return true if this builtin has a result or any arguments which are reference types.
bool performsCallback(unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details).
bool isAuxBuiltinID(unsigned ID) const
Return true if the builtin ID belongs exclusively to the AuxTarget, and false if it belongs to both p...
bool isLibFunction(unsigned ID) const
Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e....
bool isNonNull(unsigned ID, llvm::SmallVectorImpl< int > &Indxs, Info::NonNullMode &Mode) const
Return true if this builtin has parameters that must be non-null.
const char * getHeaderName(unsigned ID) const
If this is a library function that comes from a specific header, retrieve that header name.
bool hasPtrArgsOrResult(unsigned ID) const
Determines whether this builtin has a result or any arguments which are pointer types.
bool isReturnsTwice(unsigned ID) const
Return true if we know this builtin can return twice.
bool isImmediate(unsigned ID) const
Returns true if this is an immediate (consteval) function.
bool isConstWithoutErrnoAndExceptions(unsigned ID) const
Return true if this function has no side effects and doesn't read memory, except for possibly errno o...
static bool isBuiltinFunc(llvm::StringRef Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
unsigned getRequiredVectorWidth(unsigned ID) const
unsigned getAuxBuiltinID(unsigned ID) const
Return real builtin ID (i.e.
bool allowTypeMismatch(unsigned ID) const
Determines whether a declaration of this builtin should be recognized even if the type doesn't match ...
bool isTSBuiltin(unsigned ID) const
Return true if this function is a target-specific builtin.
bool hasCustomTypechecking(unsigned ID) const
Determines whether this builtin has custom typechecking.
std::string getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
bool isHeaderDependentFunction(unsigned ID) const
Returns true if this builtin requires appropriate header in other compilers.
void initializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
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...
bool isInStdNamespace(unsigned ID) const
Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned)...
bool canBeRedeclared(unsigned ID) const
Returns true if this is a builtin that can be redeclared.
const char * getAttributesString(unsigned ID) const
Get the attributes descriptor string for the specified builtin.
bool isConstantEvaluated(unsigned ID) const
Return true if this function can be constant evaluated by Clang frontend.
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
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...
bool isReflectionMetafunctionBuiltin(unsigned ID) const
Returns true if this is a reflection metafunction builtin.
const char * getTypeString(unsigned ID) const
Get the type descriptor string for the specified builtin.
bool isNoReturn(unsigned ID) const
Return true if we know this builtin never returns.
const char * getRequiredFeatures(unsigned ID) const
bool isDirectlyAddressable(unsigned ID) const
Determines whether this builtin can have its address taken with no special action required.
bool isConstWithoutExceptions(unsigned ID) const
bool isPredefinedRuntimeFunction(unsigned ID) const
Determines whether this builtin is a predefined compiler-rt/libgcc function, such as "__clear_cache",...
bool isPure(unsigned ID) const
Return true if this function has no side effects.
bool isNoThrow(unsigned ID) const
Return true if we know this builtin never throws an exception.
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
bool isConst(unsigned ID) const
Return true if this function has no side effects and doesn't read memory.
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.
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.
Top level wrappers for InstallAPI frontend operations.
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
__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
llvm::StringTable::Offset Features
llvm::StringTable::Offset Attributes
llvm::StringTable::Offset Type
The info used to represent each builtin.
struct clang::Builtin::Info::StrOffsets Offsets
std::string getName(const InfosShard &Shard) const
Get the name for the builtin represented by this Info object.
A shard of a target's builtins string table and info.
const llvm::StringTable * Strings
llvm::StringLiteral NamePrefix
llvm::ArrayRef< Info > Infos