18#include "llvm/ADT/StringRef.h"
23#define HEADER(ID, NAME) \
26#include "clang/Basic/BuiltinHeaders.def"
29 llvm_unreachable(
"Unknown HeaderDesc::HeaderID enum");
33 {
"not a builtin function",
nullptr,
nullptr,
nullptr, HeaderDesc::NO_HEADER,
35#define BUILTIN(ID, TYPE, ATTRS) \
36 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
37#define LANGBUILTIN(ID, TYPE, ATTRS, LANGS) \
38 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, LANGS},
39#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, LANGS) \
40 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::HEADER, LANGS},
41#include "clang/Basic/Builtins.def"
44const Builtin::Info &Builtin::Context::getRecord(
unsigned ID)
const {
48 (TSRecords.size() + AuxTSRecords.size())) &&
49 "Invalid builtin ID!");
57 assert(TSRecords.empty() &&
"Already initialized target?");
58 TSRecords =
Target.getTargetBuiltins();
64 bool InStdNamespace = FuncName.consume_front(
"std-");
68 (
bool)strchr(
BuiltinInfo[i].Attributes,
'z') == InStdNamespace)
69 return strchr(
BuiltinInfo[i].Attributes,
'f') !=
nullptr;
137 for (
unsigned i = 0, e = TSRecords.size(); i != e; ++i)
142 for (
unsigned i = 0, e = AuxTSRecords.size(); i != e; ++i)
143 Table.
get(AuxTSRecords[i].Name)
148 bool InStdNamespace = Name.consume_front(
"std-");
149 auto NameIt = Table.
find(Name);
150 if (NameIt != Table.
end()) {
151 unsigned ID = NameIt->second->getBuiltinID();
153 isInStdNamespace(
ID) == InStdNamespace) {
154 NameIt->second->clearBuiltinID();
161 const char *WidthPos = ::strchr(getRecord(
ID).Attributes,
'V');
166 assert(*WidthPos ==
':' &&
167 "Vector width specifier must be followed by a ':'");
171 unsigned Width = ::strtol(WidthPos, &EndPos, 10);
172 assert(*EndPos ==
':' &&
"Vector width specific must end with a ':'");
176bool Builtin::Context::isLike(
unsigned ID,
unsigned &FormatIdx,
177 bool &HasVAListArg,
const char *Fmt)
const {
178 assert(Fmt &&
"Not passed a format string");
179 assert(::strlen(Fmt) == 2 &&
180 "Format string needs to be two characters long");
181 assert(::toupper(Fmt[0]) == Fmt[1] &&
182 "Format string is not in the form \"xX\"");
184 const char *Like = ::strpbrk(getRecord(
ID).Attributes, Fmt);
188 HasVAListArg = (*Like == Fmt[1]);
191 assert(*Like ==
':' &&
"Format specifier must be followed by a ':'");
194 assert(::strchr(Like,
':') &&
"Format specifier must end with a ':'");
195 FormatIdx = ::strtol(Like,
nullptr, 10);
200 bool &HasVAListArg) {
201 return isLike(
ID, FormatIdx, HasVAListArg,
"pP");
205 bool &HasVAListArg) {
206 return isLike(
ID, FormatIdx, HasVAListArg,
"sS");
211 const char *CalleePos = ::strchr(getRecord(
ID).Attributes,
'C');
216 assert(*CalleePos ==
'<' &&
217 "Callback callee specifier must be followed by a '<'");
221 int CalleeIdx = ::strtol(CalleePos, &EndPos, 10);
222 assert(CalleeIdx >= 0 &&
"Callee index is supposed to be positive!");
223 Encoding.push_back(CalleeIdx);
225 while (*EndPos ==
',') {
226 const char *PayloadPos = EndPos + 1;
228 int PayloadIdx = ::strtol(PayloadPos, &EndPos, 10);
229 Encoding.push_back(PayloadIdx);
232 assert(*EndPos ==
'>' &&
"Callback callee specifier must end with a '>'");
238 ID == Builtin::BI__builtin_assume_aligned ||
239 (!hasReferenceArgsOrResult(
ID) && !hasCustomTypechecking(
ID)) ||
240 isInStdNamespace(
ID);
244 StringRef RequiredFeatures,
const llvm::StringMap<bool> &TargetFetureMap) {
246 if (RequiredFeatures.empty())
248 assert(!RequiredFeatures.contains(
' ') &&
"Space in feature list");
251 return TF.hasRequiredFeatures(RequiredFeatures);
static bool builtinIsSupported(const Builtin::Info &BuiltinInfo, const LangOptions &LangOpts)
Is this builtin supported according to the given language options?
static constexpr Builtin::Info BuiltinInfo[]
Defines enum values for all the target-independent builtin functions.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines the clang::LangOptions interface.
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 builtin ID belongs to AuxTarget.
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.
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 canBeRedeclared(unsigned ID) const
Returns true if this is a builtin that can be redeclared.
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...
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
TargetFeatures - This class is used to check whether the builtin function has the required tagert spe...
void setBuiltinID(unsigned ID)
Implements an efficient mapping from strings to IdentifierInfo nodes.
iterator find(StringRef Name) const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
Exposes information about the current target.
virtual ArrayRef< Builtin::Info > getTargetBuiltins() const =0
Return information about target-specific builtins for the current primary target, and info about whic...
Defines the clang::TargetInfo interface.
bool evaluateRequiredTargetFeatures(llvm::StringRef RequiredFatures, const llvm::StringMap< bool > &TargetFetureMap)
Returns true if the required target features of a builtin function are enabled.