clang 24.0.0git
Builtins.cpp
Go to the documentation of this file.
1//===--- Builtins.cpp - Builtin function implementation -------------------===//
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 various things for builtin functions.
10//
11//===----------------------------------------------------------------------===//
12
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/SmallString.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/MathExtras.h"
21#include "llvm/Support/xxhash.h"
22#include <memory>
23using namespace clang;
24
25const char *HeaderDesc::getName() const {
26 switch (ID) {
27#define HEADER(ID, NAME) \
28 case ID: \
29 return NAME;
30#include "clang/Basic/BuiltinHeaders.def"
31#undef HEADER
32 };
33 llvm_unreachable("Unknown HeaderDesc::HeaderID enum");
34}
35
36static constexpr unsigned NumBuiltins = Builtin::FirstTSBuiltin;
37
38#define GET_BUILTIN_STR_TABLE
39#include "clang/Basic/Builtins.inc"
40#undef GET_BUILTIN_STR_TABLE
41
42static constexpr Builtin::Info BuiltinInfos[] = {
43 Builtin::Info{}, // No-builtin info entry.
44#define GET_BUILTIN_INFOS
45#include "clang/Basic/Builtins.inc"
46#undef GET_BUILTIN_INFOS
47};
48static_assert(std::size(BuiltinInfos) == NumBuiltins);
49
50/// The shard of the target-independent builtins, which every context has.
53
54std::pair<const Builtin::InfosShard &, const Builtin::Info &>
55Builtin::Context::getShardAndInfo(unsigned ID) const {
56 if (Builtins)
57 return Builtins->getShardAndInfo(ID);
58 assert(ID < Builtin::FirstTSBuiltin && "Invalid builtin ID!");
60}
61
62/// Return a non-owning StringRef of the builtin's name, reconstructed into Buf.
63static StringRef getBuiltinNameInto(const Builtin::InfosShard &Shard,
64 const Builtin::Info &BuiltinInfo,
66 StringRef Name = (*Shard.Strings)[BuiltinInfo.Offsets.Name];
67 if (Shard.NamePrefix.empty())
68 return Name;
69 Buf.assign(Shard.NamePrefix.begin(), Shard.NamePrefix.end());
70 Buf.append(Name.begin(), Name.end());
71 return StringRef(Buf.data(), Buf.size());
72}
73
74std::string Builtin::Info::getName(const Builtin::InfosShard &Shard) const {
76 return getBuiltinNameInto(Shard, *this, Buf).str();
77}
78
79/// Return the identifier name for the specified builtin,
80/// e.g. "__builtin_abs".
81std::string Builtin::Context::getName(unsigned ID) const {
82 const auto &[Shard, I] = getShardAndInfo(ID);
83 return I.getName(Shard);
84}
85
87 const auto &[Shard, I] = getShardAndInfo(ID);
89 Result += Shard.NamePrefix;
90 Result += (*Shard.Strings)[I.Offsets.Name];
91 Result += '\'';
92 return Result;
93}
94
95const char *Builtin::Context::getTypeString(unsigned ID) const {
96 const auto &[Shard, I] = getShardAndInfo(ID);
97 return (*Shard.Strings)[I.Offsets.Type].data();
98}
99
100const char *Builtin::Context::getAttributesString(unsigned ID) const {
101 const auto &[Shard, I] = getShardAndInfo(ID);
102 return (*Shard.Strings)[I.Offsets.Attributes].data();
103}
104
105const char *Builtin::Context::getRequiredFeatures(unsigned ID) const {
106 const auto &[Shard, I] = getShardAndInfo(ID);
107 return (*Shard.Strings)[I.Offsets.Features].data();
108}
109
110Builtin::Context::Context() = default;
111
113 : Context(std::make_shared<const TargetBuiltins>(Target, AuxTarget)) {}
114
115Builtin::Context::Context(std::shared_ptr<const TargetBuiltins> Builtins)
116 : Builtins(std::move(Builtins)),
117 NumTargetBuiltins(this->Builtins->getNumTargetBuiltins()) {}
118
119bool Builtin::Context::isBuiltinFunc(llvm::StringRef FuncName) {
120 bool InStdNamespace = FuncName.consume_front("std-");
121 for (const auto &Shard : TargetIndependentShards)
122 if (llvm::StringRef FuncNameSuffix = FuncName;
123 FuncNameSuffix.consume_front(Shard.NamePrefix))
124 for (const auto &I : Shard.Infos)
125 if (FuncNameSuffix == (*Shard.Strings)[I.Offsets.Name] &&
126 (bool)strchr((*Shard.Strings)[I.Offsets.Attributes].data(), 'z') ==
127 InStdNamespace)
128 return strchr((*Shard.Strings)[I.Offsets.Attributes].data(), 'f') !=
129 nullptr;
130
131 return false;
132}
133
134/// Is this builtin supported according to the given language options?
135static bool builtinIsSupported(const llvm::StringTable &Strings,
136 const Builtin::Info &BuiltinInfo,
137 const LangOptions &LangOpts) {
138 auto AttributesStr = Strings[BuiltinInfo.Offsets.Attributes];
139
140 /* Builtins Unsupported */
141 if (LangOpts.NoBuiltin && strchr(AttributesStr.data(), 'f') != nullptr)
142 return false;
143 /* CorBuiltins Unsupported */
144 if (!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG))
145 return false;
146 /* MathBuiltins Unsupported */
147 if (LangOpts.NoMathBuiltin && BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
148 return false;
149 /* GnuMode Unsupported */
150 if (!LangOpts.GNUMode && (BuiltinInfo.Langs & GNU_LANG))
151 return false;
152 /* MSMode Unsupported */
153 if (!LangOpts.MicrosoftExt && (BuiltinInfo.Langs & MS_LANG))
154 return false;
155 /* HLSLMode Unsupported */
156 if (!LangOpts.HLSL && (BuiltinInfo.Langs & HLSL_LANG))
157 return false;
158 /* ObjC Unsupported */
159 if (!LangOpts.ObjC && BuiltinInfo.Langs == OBJC_LANG)
160 return false;
161 /* OpenCLC Unsupported */
162 if (!LangOpts.OpenCL && (BuiltinInfo.Langs & ALL_OCL_LANGUAGES))
163 return false;
164 /* OpenCL GAS Unsupported */
165 if (!LangOpts.OpenCLGenericAddressSpace && (BuiltinInfo.Langs & OCL_GAS))
166 return false;
167 /* OpenCL Pipe Unsupported */
168 if (!LangOpts.OpenCLPipes && (BuiltinInfo.Langs & OCL_PIPE))
169 return false;
170
171 // Device side enqueue is not supported until OpenCL 2.0. In 2.0 and higher
172 // support is indicated with language option for blocks.
173
174 /* OpenCL DSE Unsupported */
175 if ((LangOpts.getOpenCLCompatibleVersion() < 200 || !LangOpts.Blocks) &&
176 (BuiltinInfo.Langs & OCL_DSE))
177 return false;
178 /* OpenMP Unsupported */
179 if (!LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG)
180 return false;
181 /* CUDA Unsupported */
182 if (!LangOpts.CUDA && BuiltinInfo.Langs == CUDA_LANG)
183 return false;
184 /* CPlusPlus Unsupported */
185 if (!LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG)
186 return false;
187 /* consteval Unsupported */
188 if (!LangOpts.CPlusPlus20 && strchr(AttributesStr.data(), 'G') != nullptr)
189 return false;
190 /* C23 unsupported */
191 if (!LangOpts.C23 && BuiltinInfo.Langs == C23_LANG)
192 return false;
193 /* C2y unsupported */
194 if (!LangOpts.C2y && BuiltinInfo.Langs == C2Y_LANG)
195 return false;
196 /* Reflection unsupported */
197 if (!LangOpts.Reflection && (BuiltinInfo.Langs & REFLECTION_LANG))
198 return false;
199 return true;
200}
201
202static bool isBuiltinConstForTriple(unsigned BuiltinID, llvm::Triple Trip) {
203 // There's a special case with the fma builtins where they are always const
204 // if the target environment is GNU or the target is OS is Windows and we're
205 // targeting the MSVCRT.dll environment.
206 // FIXME: This list can be become outdated. Need to find a way to get it some
207 // other way.
208 switch (BuiltinID) {
209 case Builtin::BI__builtin_fma:
210 case Builtin::BI__builtin_fmaf:
211 case Builtin::BI__builtin_fmal:
212 case Builtin::BI__builtin_fmaf16:
213 case Builtin::BIfma:
214 case Builtin::BIfmaf:
215 case Builtin::BIfmal: {
216 if (Trip.isGNUEnvironment() || Trip.isOSMSVCRT())
217 return true;
218 break;
219 }
220 default:
221 break;
222 }
223
224 return false;
225}
226
228 unsigned BuiltinID, llvm::Triple Trip, std::optional<bool> ErrnoOverwritten,
229 bool MathErrnoEnabled, bool HasOptNoneAttr,
230 bool IsOptimizationEnabled) const {
231
232 // True if we are compiling at -O2 and errno has been disabled
233 // using the '#pragma float_control(precise, off)', and
234 // attribute opt-none hasn't been seen.
235 bool ErrnoOverridenToFalseWithOpt = ErrnoOverwritten.has_value() &&
236 !ErrnoOverwritten.value() &&
237 !HasOptNoneAttr && IsOptimizationEnabled;
238
239 // There are LLVM math intrinsics/instructions corresponding to math library
240 // functions except the LLVM op will never set errno while the math library
241 // might. Also, math builtins have the same semantics as their math library
242 // twins. Thus, we can transform math library and builtin calls to their
243 // LLVM counterparts if the call is marked 'const' (known to never set errno).
244 // In case FP exceptions are enabled, the experimental versions of the
245 // intrinsics model those.
246 bool ConstAlways =
247 isConst(BuiltinID) || isBuiltinConstForTriple(BuiltinID, Trip);
248
249 bool ConstWithoutErrnoAndExceptions =
251 bool ConstWithoutExceptions = isConstWithoutExceptions(BuiltinID);
252
253 // ConstAttr is enabled in fast-math mode. In fast-math mode, math-errno is
254 // disabled.
255 // Math intrinsics are generated only when math-errno is disabled. Any pragmas
256 // or attributes that affect math-errno should prevent or allow math
257 // intrinsics to be generated. Intrinsics are generated:
258 // 1- In fast math mode, unless math-errno is overriden
259 // via '#pragma float_control(precise, on)', or via an
260 // 'attribute__((optnone))'.
261 // 2- If math-errno was enabled on command line but overriden
262 // to false via '#pragma float_control(precise, off))' and
263 // 'attribute__((optnone))' hasn't been used.
264 // 3- If we are compiling with optimization and errno has been disabled
265 // via '#pragma float_control(precise, off)', and
266 // 'attribute__((optnone))' hasn't been used.
267
268 bool ConstWithoutErrnoOrExceptions =
269 ConstWithoutErrnoAndExceptions || ConstWithoutExceptions;
270 bool GenerateIntrinsics =
271 (ConstAlways && !HasOptNoneAttr) ||
272 (!MathErrnoEnabled &&
273 !(ErrnoOverwritten.has_value() && ErrnoOverwritten.value()) &&
274 !HasOptNoneAttr);
275 if (!GenerateIntrinsics) {
276 GenerateIntrinsics =
277 ConstWithoutErrnoOrExceptions && !ConstWithoutErrnoAndExceptions;
278 if (!GenerateIntrinsics)
279 GenerateIntrinsics =
280 ConstWithoutErrnoOrExceptions &&
281 (!MathErrnoEnabled &&
282 !(ErrnoOverwritten.has_value() && ErrnoOverwritten.value()) &&
283 !HasOptNoneAttr);
284 if (!GenerateIntrinsics)
285 GenerateIntrinsics =
286 ConstWithoutErrnoOrExceptions && ErrnoOverridenToFalseWithOpt;
287 }
288
289 return GenerateIntrinsics;
290}
291
292static uint32_t hashBuiltinName(StringRef Name) {
293 return static_cast<uint32_t>(llvm::xxh3_64bits(Name));
294}
295
297 const TargetInfo *AuxTarget) {
298 llvm::append_range(Shards, TargetIndependentShards);
299 llvm::append_range(Shards, Target.getTargetBuiltins());
300 NumTargetShards = Shards.size() - 1;
301 if (AuxTarget)
302 llvm::append_range(Shards, AuxTarget->getTargetBuiltins());
303 for (const InfosShard &Shard : getTargetShards())
304 NumTargetBuiltins += Shard.Infos.size();
305 for (const InfosShard &Shard : getAuxTargetShards())
306 NumAuxTargetBuiltins += Shard.Infos.size();
307
308 size_t NumNames = 0;
309 for (const InfosShard &Shard : Shards)
310 NumNames += Shard.Infos.size();
311 // Keep the load factor at or below 1/2.
312 size_t NumSlots = llvm::PowerOf2Ceil(NumNames * 2);
313 Slots = std::make_unique<uint64_t[]>(NumSlots);
314 Mask = NumSlots - 1;
315 unsigned ID = 0;
316 SmallString<256> NameBuf;
317 for (const InfosShard &Shard : Shards) {
318 for (const Info &I : Shard.Infos) {
319 // Skip the "not a builtin" entry.
320 if (ID != NotBuiltin) {
321 uint32_t Hash = hashBuiltinName(getBuiltinNameInto(Shard, I, NameBuf));
322 size_t Slot = Hash & Mask;
323 while (Slots[Slot])
324 Slot = (Slot + 1) & Mask;
325 Slots[Slot] = (uint64_t(Hash) << 32) | ID;
326 }
327 ++ID;
328 }
329 }
330}
331
332std::pair<const Builtin::InfosShard &, const Builtin::Info &>
334 assert(ID < FirstTSBuiltin + NumTargetBuiltins + NumAuxTargetBuiltins &&
335 "Invalid builtin ID!");
336 // Find the group of shards from the ID, then loop over the shards of the
337 // group to find the one matching this ID. We don't expect to have many
338 // shards and so its better to search linearly than with a binary search.
339 ArrayRef<InfosShard> Group = ArrayRef(Shards).take_front(1);
340 if (ID >= FirstTSBuiltin + NumTargetBuiltins) {
341 Group = getAuxTargetShards();
342 ID -= FirstTSBuiltin + NumTargetBuiltins;
343 } else if (ID >= FirstTSBuiltin) {
344 Group = getTargetShards();
346 }
347 for (const InfosShard &Shard : Group) {
348 if (ID < Shard.Infos.size())
349 return {Shard, Shard.Infos[ID]};
350 ID -= Shard.Infos.size();
351 }
352 llvm_unreachable("Invalid target builtin shard structure!");
353}
354
355bool Builtin::TargetBuiltins::hasName(unsigned ID, StringRef Name) const {
356 const auto &[Shard, I] = getShardAndInfo(ID);
357 return Name.consume_front(Shard.NamePrefix) &&
358 Name == (*Shard.Strings)[I.Offsets.Name];
359}
360
363 uint32_t Hash = hashBuiltinName(Name);
364 for (size_t Slot = Hash & Mask; uint64_t Entry = Slots[Slot];
365 Slot = (Slot + 1) & Mask) {
366 unsigned ID = static_cast<uint32_t>(Entry);
367 if (Entry >> 32 == Hash && hasName(ID, Name))
368 IDs.push_back(ID);
369 }
370 return IDs;
371}
372
373unsigned Builtin::Context::lookupBuiltinID(StringRef Name,
374 const LangOptions &LangOpts) const {
375 // This needs to behave as if the builtins were registered in the order of
376 // their IDs, with later registrations overriding earlier ones: aux target
377 // builtins win over target builtins, which win over target-independent
378 // ones. Aux target builtins are registered even if unsupported.
379 if (!Builtins)
380 return NotBuiltin;
381 unsigned Result = NotBuiltin;
382 for (unsigned ID : Builtins->lookup(Name)) {
383 if (ID <= Result)
384 continue;
385 const auto &[Shard, I] = getShardAndInfo(ID);
386 if (isAuxBuiltinID(ID) || builtinIsSupported(*Shard.Strings, I, LangOpts))
387 Result = ID;
388 }
389 if (Result == NotBuiltin)
390 return NotBuiltin;
391
392 // Library builtins can be disabled with -fno-builtin-foo, or with
393 // -fno-builtin-std-foo for those in namespace std.
395 bool InStdNamespace = isInStdNamespace(Result);
396 for (StringRef NoBuiltin : LangOpts.NoBuiltinFuncs)
397 if (NoBuiltin.consume_front("std-") == InStdNamespace &&
398 NoBuiltin == Name)
399 return NotBuiltin;
400 }
401 return Result;
402}
403
405 const LangOptions &LangOpts, llvm::function_ref<void(StringRef)> Fn) const {
406 if (!Builtins)
407 return;
409 // Skip the "not a builtin" entry.
410 for (const auto &Shard : TargetIndependentShards)
411 for (const auto &I : Shard.Infos.drop_front())
412 if (builtinIsSupported(*Shard.Strings, I, LangOpts))
413 Fn(getBuiltinNameInto(Shard, I, NameBuf));
414 for (const auto &Shard : Builtins->getTargetShards())
415 for (const auto &I : Shard.Infos)
416 if (builtinIsSupported(*Shard.Strings, I, LangOpts))
417 Fn(getBuiltinNameInto(Shard, I, NameBuf));
418 for (const auto &Shard : Builtins->getAuxTargetShards())
419 for (const auto &I : Shard.Infos)
420 Fn(getBuiltinNameInto(Shard, I, NameBuf));
421}
422
424 const char *WidthPos = ::strchr(getAttributesString(ID), 'V');
425 if (!WidthPos)
426 return 0;
427
428 ++WidthPos;
429 assert(*WidthPos == ':' &&
430 "Vector width specifier must be followed by a ':'");
431 ++WidthPos;
432
433 char *EndPos;
434 unsigned Width = ::strtol(WidthPos, &EndPos, 10);
435 assert(*EndPos == ':' && "Vector width specific must end with a ':'");
436 return Width;
437}
438
439bool Builtin::Context::isLike(unsigned ID, unsigned &FormatIdx,
440 bool &HasVAListArg, const char *Fmt) const {
441 assert(Fmt && "Not passed a format string");
442 assert(::strlen(Fmt) == 2 &&
443 "Format string needs to be two characters long");
444 assert(::toupper(Fmt[0]) == Fmt[1] &&
445 "Format string is not in the form \"xX\"");
446
447 const char *Like = ::strpbrk(getAttributesString(ID), Fmt);
448 if (!Like)
449 return false;
450
451 HasVAListArg = (*Like == Fmt[1]);
452
453 ++Like;
454 assert(*Like == ':' && "Format specifier must be followed by a ':'");
455 ++Like;
456
457 assert(::strchr(Like, ':') && "Format specifier must end with a ':'");
458 FormatIdx = ::strtol(Like, nullptr, 10);
459 return true;
460}
461
462bool Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx,
463 bool &HasVAListArg) {
464 return isLike(ID, FormatIdx, HasVAListArg, "pP");
465}
466
467bool Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx,
468 bool &HasVAListArg) {
469 return isLike(ID, FormatIdx, HasVAListArg, "sS");
470}
471
472static void parseCommaSeparatedIndices(const char *CurrPos,
474 assert(*CurrPos == '<' && "Expected '<' to start index list");
475 ++CurrPos;
476
477 char *EndPos;
478 int PosIdx = ::strtol(CurrPos, &EndPos, 10);
479 assert(PosIdx >= 0 && "Index is supposed to be positive!");
480 Indxs.push_back(PosIdx);
481
482 while (*EndPos == ',') {
483 const char *PayloadPos = EndPos + 1;
484
485 int PayloadIdx = ::strtol(PayloadPos, &EndPos, 10);
486 Indxs.push_back(PayloadIdx);
487 }
488
489 assert(*EndPos == '>' && "Index list must end with '>'");
490}
491
493 Info::NonNullMode &Mode) const {
494
495 const char *AttrPos = ::strchr(getAttributesString(ID), 'N');
496 if (!AttrPos)
497 return false;
498
499 ++AttrPos;
500 assert(*AttrPos == ':' && "Format specifier must be followed by a ':'");
501 ++AttrPos;
502 if (*AttrPos == '0')
504 else if (*AttrPos == '1')
506 else
507 llvm_unreachable("Unrecognized NonNull optimization mode");
508 ++AttrPos; // skip mode
509 assert(*AttrPos == ':' && "Mode must be followed by a ':'");
510 ++AttrPos;
511
512 parseCommaSeparatedIndices(AttrPos, Indxs);
513
514 return true;
515}
516
518 unsigned ID, llvm::SmallVectorImpl<ArgRange> &Ranges) const {
519 StringRef Attrs = getAttributesString(ID);
520 size_t Pos = Attrs.find('R');
521 if (Pos == StringRef::npos)
522 return;
523
524 StringRef Str = Attrs.drop_front(Pos + 1);
525 if (!Str.consume_front("<"))
526 llvm_unreachable("Expected '<' to start range list");
527
528 do {
529 ArgRange Range;
530 if (Str.consumeInteger(10, Range.Index) || !Str.consume_front(":") ||
531 Str.consumeInteger(10, Range.Lower) || !Str.consume_front(":") ||
532 Str.consumeInteger(10, Range.Upper))
533 llvm_unreachable("Malformed argument range");
534 Ranges.push_back(Range);
535 } while (Str.consume_front(","));
536
537 assert(Str.starts_with('>') && "Range list must end with '>'");
538}
539
541 SmallVectorImpl<int> &Encoding) const {
542 const char *CalleePos = ::strchr(getAttributesString(ID), 'C');
543 if (!CalleePos)
544 return false;
545
546 ++CalleePos;
547 parseCommaSeparatedIndices(CalleePos, Encoding);
548
549 return true;
550}
551
553 return ID == Builtin::NotBuiltin || ID == Builtin::BI__va_start ||
554 ID == Builtin::BI__builtin_assume_aligned ||
557}
558
560 StringRef RequiredFeatures, const llvm::StringMap<bool> &TargetFetureMap) {
561 // Return true if the builtin doesn't have any required features.
562 if (RequiredFeatures.empty())
563 return true;
564 assert(!RequiredFeatures.contains(' ') && "Space in feature list");
565
566 TargetFeatures TF(TargetFetureMap);
567 return TF.hasRequiredFeatures(RequiredFeatures);
568}
static constexpr llvm::StringTable BuiltinStrings
Definition Mips.cpp:25
static StringRef getBuiltinNameInto(const Builtin::InfosShard &Shard, const Builtin::Info &BuiltinInfo, SmallVectorImpl< char > &Buf)
Return a non-owning StringRef of the builtin's name, reconstructed into Buf.
Definition Builtins.cpp:63
static constexpr Builtin::Info BuiltinInfos[]
Definition Builtins.cpp:42
static bool builtinIsSupported(const llvm::StringTable &Strings, const Builtin::Info &BuiltinInfo, const LangOptions &LangOpts)
Is this builtin supported according to the given language options?
Definition Builtins.cpp:135
static constexpr unsigned NumBuiltins
Definition Builtins.cpp:36
static void parseCommaSeparatedIndices(const char *CurrPos, llvm::SmallVectorImpl< int > &Indxs)
Definition Builtins.cpp:472
static bool isBuiltinConstForTriple(unsigned BuiltinID, llvm::Triple Trip)
Definition Builtins.cpp:202
static const Builtin::InfosShard TargetIndependentShards[]
The shard of the target-independent builtins, which every context has.
Definition Builtins.cpp:51
static uint32_t hashBuiltinName(StringRef Name)
Definition Builtins.cpp:292
Defines enum values for all the target-independent builtin functions.
Defines the clang::LangOptions interface.
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:227
llvm::SmallString< 64 > getQuotedName(unsigned ID) const
Return the identifier name for the specified builtin inside single quotes for a diagnostic,...
Definition Builtins.cpp:86
bool hasReferenceArgsOrResult(unsigned ID) const
Return true if this builtin has a result or any arguments which are reference types.
Definition Builtins.h:444
bool performsCallback(unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details).
Definition Builtins.cpp:540
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:521
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:492
unsigned lookupBuiltinID(llvm::StringRef Name, const LangOptions &LangOpts) const
Return the ID of the builtin named Name, or NotBuiltin if there's none, LangOpts doesn't support it,...
Definition Builtins.cpp:373
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:491
static bool isBuiltinFunc(llvm::StringRef Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
Definition Builtins.cpp:119
unsigned getRequiredVectorWidth(unsigned ID) const
Definition Builtins.cpp:423
bool hasCustomTypechecking(unsigned ID) const
Determines whether this builtin has custom typechecking.
Definition Builtins.h:425
std::string getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
Definition Builtins.cpp:81
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:467
bool isInStdNamespace(unsigned ID) const
Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned)...
Definition Builtins.h:411
bool canBeRedeclared(unsigned ID) const
Returns true if this is a builtin that can be redeclared.
Definition Builtins.cpp:552
const char * getAttributesString(unsigned ID) const
Get the attributes descriptor string for the specified builtin.
Definition Builtins.cpp:100
void forEachBuiltinName(const LangOptions &LangOpts, llvm::function_ref< void(llvm::StringRef)> Fn) const
Call Fn with the name of every builtin supported by LangOpts, whether or not the identifier table con...
Definition Builtins.cpp:404
Context()
Create a context with only the target-independent builtins.
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
Definition Builtins.h:389
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:462
const char * getTypeString(unsigned ID) const
Get the type descriptor string for the specified builtin.
Definition Builtins.cpp:95
const char * getRequiredFeatures(unsigned ID) const
Definition Builtins.cpp:105
bool isConstWithoutExceptions(unsigned ID) const
Definition Builtins.h:495
void getArgRanges(unsigned ID, llvm::SmallVectorImpl< ArgRange > &Ranges) const
Append the constant argument ranges of this builtin into Ranges.
Definition Builtins.cpp:517
bool isConst(unsigned ID) const
Return true if this function has no side effects and doesn't read memory.
Definition Builtins.h:351
The builtins of a target and an optional aux target: their shards, and a hash table from their names ...
Definition Builtins.h:240
TargetBuiltins(const TargetInfo &Target, const TargetInfo *AuxTarget)
Collect the builtins of Target and AuxTarget, which may be null.
Definition Builtins.cpp:296
llvm::ArrayRef< InfosShard > getAuxTargetShards() const
The shards of the aux target's builtins.
Definition Builtins.h:268
std::pair< const InfosShard &, const Info & > getShardAndInfo(unsigned ID) const
Return the shard of the builtin with ID and its info.
Definition Builtins.cpp:333
llvm::ArrayRef< InfosShard > getTargetShards() const
The shards of the target's builtins.
Definition Builtins.h:263
llvm::SmallVector< unsigned, 2 > lookup(llvm::StringRef Name) const
Return the IDs of all builtins named Name, in no particular order.
Definition Builtins.cpp:361
TargetFeatures - This class is used to check whether the builtin function has the required target spe...
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.
Definition TargetInfo.h:228
virtual llvm::SmallVector< Builtin::InfosShard > 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.
internal::Matcher< NamedDecl > hasName(StringRef Name)
Matches NamedDecl nodes that have the specified name.
Top level wrappers for InstallAPI frontend operations.
@ MS_LANG
Definition Builtins.h:41
@ CUDA_LANG
Definition Builtins.h:43
@ OMP_LANG
Definition Builtins.h:42
@ CXX_LANG
Definition Builtins.h:39
@ OBJC_LANG
Definition Builtins.h:40
@ OCL_DSE
Definition Builtins.h:47
@ REFLECTION_LANG
Definition Builtins.h:52
@ C23_LANG
Definition Builtins.h:50
@ ALL_OCL_LANGUAGES
Definition Builtins.h:48
@ HLSL_LANG
Definition Builtins.h:49
@ C2Y_LANG
Definition Builtins.h:51
@ OCL_GAS
Definition Builtins.h:45
@ GNU_LANG
Definition Builtins.h:37
@ COR_LANG
Definition Builtins.h:44
@ OCL_PIPE
Definition Builtins.h:46
@ Result
The result type of a method or function.
Definition TypeBase.h:906
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
A constant argument that must be in the half-open range [Lower, Upper).
Definition Builtins.h:472
llvm::StringTable::Offset Name
Definition Builtins.h:87
llvm::StringTable::Offset Attributes
Definition Builtins.h:89
The info used to represent each builtin.
Definition Builtins.h:83
HeaderDesc Header
Definition Builtins.h:95
LanguageID Langs
Definition Builtins.h:96
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:74
A shard of a target's builtins string table and info.
Definition Builtins.h:142
const llvm::StringTable * Strings
Definition Builtins.h:143
llvm::StringLiteral NamePrefix
Definition Builtins.h:146
const char * getName() const
Definition Builtins.cpp:25
enum clang::HeaderDesc::HeaderID ID